使用Apache POI for Java在现有Excel工作簿中创建新工作表

时间:2012-09-15 09:39:59

标签: java apache-poi

我正在尝试使用apache POI for java在现有excel工作簿中创建一个新工作表,但到目前为止还没有成功。谁能告诉我它是如何完成的?

3 个答案:

答案 0 :(得分:7)

这很容易。这就像在新工作簿中添加新工作表一样,只有从现有工作簿开始而不是从新工作簿开始

 Workbook wb = WorkbookFactory.create(new File("/path/to/existing"));
 Sheet s = wb.createSheet();

 // Do something with the new sheet

 FileOutputStream out = new FileOutputStream("/path/to/new/version");
 wb.write(out);
 out.close();

答案 1 :(得分:3)

HSSFSheet sheet1= workBook.createSheet("sheet1");
HSSFSheet sheet2= workBook.createSheet("sheet2");
HSSFSheet sheet3= workBook.createSheet("sheet3");

答案 2 :(得分:2)

//we can create any number of sheets for single workbook
HSSFSheet sheet1= workBook.createSheet("sheet1");
HSSFSheet sheet2= workBook.createSheet("sheet2");
HSSFSheet sheet3= workBook.createSheet("sheet3");