2

I'm getting an exception while writing data into an XSSFWorkbook file:

java.io.IOException: Cannot write data, document seems to have been closed already
    at org.apache.poi.POIXMLDocument.write(POIXMLDocument.java:215)

Here's my code:

List<Object[]> rows = query.getResultList();

for (Object[] row : rows) {
{
    Row crow = sheet.createRow(rowNum++);

    for (int i = 0; i < row.length; i++) {
        crow.createCell(i).setCellValue(String.valueOf(row[i]));
    }
}

// Write the output to a file
FileOutputStream fileOut = new FileOutputStream(FilePath);
workbook.write(fileOut);
fileOut.close();
MTCoster
  • 5,868
  • 3
  • 28
  • 49
WASEEM
  • 207
  • 4
  • 18
  • 1
    this is a bit too brief. you need to indicate the troublesome line causing the problem, perhaps also linking to some docs. – oligofren Feb 08 '19 at 15:42
  • 2
    Is the extra `{` on the outer `for` loop just a transcription error? – MTCoster Feb 08 '19 at 15:43
  • 1
    Maybe this can help you: [https://stackoverflow.com/questions/14117617/apache-poi-unable-to-write-to-an-existing-workbook](https://stackoverflow.com/questions/14117617/apache-poi-unable-to-write-to-an-existing-workbook) – flaxel Feb 08 '19 at 15:46

0 Answers0