I want to have just a single FileOutputStream
that writes contents of my workbook to a file in my application, and create multiple worksheets within this excel. I am using Apache POI to read/write to my excel. I have the below method where I am doing this -
private static void writeToSpreadSheet(String test,Map<String,String> errorMap,Object object) throws IOException {
HSSFWorkbook workbook = new HSSFWorkbook()
HSSFSheet sheet = workbook.createSheet(test);
FileOutputStream fis = new FileOutputStream("output/test.xls");
//do stuff and finally write workbook contents to a file
workbook.write(fis);
if (fis != null)
fis.close();
}
The problem I am facing here is, every time I called the writeToSpreadSheet
, a new file is getting created, and the existing data is getting overwritten. I want one file only, and
need new worksheeets to be added to my existing file. How do I achieve this?