如何在现有excel文件中创建新工作表并写入一些数据 [英] How to create a new sheet in the existing excel file and write some data

查看:317
本文介绍了如何在现有excel文件中创建新工作表并写入一些数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面会覆盖现有的工作表。但不是要创建一个新的表。



我尝试过:



The below overwrites the existing sheet. But not create a new sheet.

What I have tried:

File f= new File(System.getProperty("user.dir")+"\\src\\test\\resources\\Exceldata.xls");		
		HSSFWorkbook workbook = new HSSFWorkbook();			
		HSSFSheet worksheet= workbook.createSheet("Sheet4");		
		HSSFRow row = worksheet.createRow(1);
		HSSFCell cell= row.createCell(1);
		cell.setCellValue("admin");		 
        workbook.write(f);
        workbook.close();

推荐答案

参见 Workbook(POI API文档) [ ^ ]。最好先阅读文档。
See Workbook (POI API Documentation)[^]. Always best to read the documentation first.


我不得不将apache poi jar从4.0降级到3.14以使其正常工作。
I had to downgrade apache poi jar from 4.0 to 3.14 to make it work.


这篇关于如何在现有excel文件中创建新工作表并写入一些数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆