This code fragment raises an org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.WorkbookFactory; File file = new File(...); Workbook workbook = WorkbookFactory.create(file, "", false); workbook.close(); File outfile = new File(...); FileOutputStream outputStream = new FileOutputStream(outfile); // exception in following line workbook.write(outputStream);
I think this is more or less a duplicate of Bug 59634 where we discuss the exact contract of the close(). The discussion there currently tends to state "do not use the Workbook after closing" which is consistent with many other Java classes that implement the Closeable interface. So you can easily fix this by deferring the close() call to after the Workbook is written out. Bug 59634 might also adjust the code to provide a more meaningful error message. *** This bug has been marked as a duplicate of bug 59634 ***