I am trying to write List data into multiple excel sheet in one work book. like for first list, the code will create new workbook and create new sheet for list[1], for secon
While working with existing workbook , You should not create a file object , Just need to Provide the File Location to FileInputStream
object and pass it's reference to workbook object, then do whatever you want to do with the existing file. To add a sheet just use create Method command
public void AddsheetintoExistingworkbook(String sheetname) throws IOException, InvalidFormatException{
//***************************Add a sheet into Existing workbook***********************************************
String path="C:\\Workspace\\Selenium_2.53\\src\\InputFiles\\Temp.xlsx";
fileinp = new FileInputStream(path);
workbook = new XSSFWorkbook(fileinp);
workbook.createSheet(sheetname);
fileOut = new FileOutputStream(path);
workbook.write(fileOut);
fileOut.close();
System.out.println("File is written successfully");
}