Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 424
user1673176 Avatar asked Sep 15 '12 09:09

user1673176


Video Answer


3 Answers

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();
like image 93
Gagravarr Avatar answered Sep 28 '22 23:09

Gagravarr


//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");
like image 36
swamy Avatar answered Sep 29 '22 01:09

swamy


HSSFSheet sheet1= workBook.createSheet("sheet1");
HSSFSheet sheet2= workBook.createSheet("sheet2");
HSSFSheet sheet3= workBook.createSheet("sheet3");
like image 26
aaaaa Avatar answered Sep 29 '22 00:09

aaaaa