I am trying to append rows to an existing excel using POI api following the steps mentioned below:
try {
lFout = new FileOutputStream(lOutputFileName);
lFin = new FileInputStream(lOutputFileName);
lPOIfs = new POIFSFileSystem(lFin);
lWorkBook = new HSSFWorkbook(lPOIfs);
lWorkSheet = lWorkBook.getSheet("Sheet1");
System.out.println("hello3");
for (Iterator<String> iter = aOutputLines.iterator(); iter.hasNext();) {
String lValue = iter.next();
if (lValue == null) {
System.out.println("=>NULL VALUE => " + lValue);
} else {
// StringBuffer lSqlLine = (StringBuffer) lValue;
HSSFRow lRow = lWorkSheet.createRow(lWorkSheet.getLastRowNum() + 1);
System.out.println("lWorkSheet.getLastRowNum() " + lWorkSheet.getLastRowNum());
HSSFCell lCell = lRow.createCell(0);
lCell.setCellValue(new HSSFRichTextString((lValue)));
}
}
lWorkBook.write(lFout);
lFout.flush();
} catch (IOException e) {
e.printStackTrace();
}
The above code snippet is not able to append the rows and also i found that after running the above snippet, the file size get increased and if I open the file and close it again it remains the same size as it was earlier. Some urgent help would be really apppriciable.