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();