Creating New Sheet In Existing Excel Workbook Using Apache POI for Java

后端 未结 3 1224
有刺的猬
有刺的猬 2020-12-03 19:34

I\'m trying to create a new sheet in an existing excel workbook using apache POI for java but have been unsuccessful so far. Can anyone please tell me how it is done?

相关标签:
3条回答
  • 2020-12-03 20:01

    It's very easy. It's just like adding a new sheet to a new workbook, only you start with the existing workbook rather than a new one

     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();
    
    0 讨论(0)
  • HSSFSheet sheet1= workBook.createSheet("sheet1");
    HSSFSheet sheet2= workBook.createSheet("sheet2");
    HSSFSheet sheet3= workBook.createSheet("sheet3");
    
    0 讨论(0)
  • 2020-12-03 20:13
    //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");
    
    0 讨论(0)
提交回复
热议问题