Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
    
I prefer Andy Khan's JExcel to POI. If you can, substitute it. –  duffymo May 7 '13 at 9:35
    
Somewhere I found POI is better than JXL. Anyway, Can you please share the link for the abovesaid problem solution in JXL? –  user2357680 May 7 '13 at 11:07
    
I don't know where that somewhere is. I'm basing my opinion on personal experience with both. No, I'm not posting a link. Learn the library and try writing that code in JXL. –  duffymo May 7 '13 at 11:16
    
Are you trying to replace the same file? i.e. open + append + close? If so, you'll need to re-order the open & close lines –  Gagravarr May 7 '13 at 11:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.