Bug 61987 - Updating excel file opended with OPCPackage throws: OpenXML4JRuntimeException: Rule M2.4 exception
Summary: Updating excel file opended with OPCPackage throws: OpenXML4JRuntimeExceptio...
Status: RESOLVED DUPLICATE of bug 60102
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.16-FINAL
Hardware: PC All
: P2 blocker (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-10 13:30 UTC by raja
Modified: 2018-02-08 19:50 UTC (History)
0 users



Attachments
ExcelFileUpdateExample1.java (2.56 KB, text/plain)
2018-01-10 13:30 UTC, raja
Details
inputfile (3.39 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2018-01-10 13:36 UTC, raja
Details

Note You need to log in before you can comment on or make changes to this bug.
Description raja 2018-01-10 13:30:41 UTC
Created attachment 35669 [details]
ExcelFileUpdateExample1.java

Exception in thread "main" org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException: Rule M2.4 exception : this error should NEVER happen! If you can provide the triggering file, then please raise a bug at https://bz.apache.org/bugzilla/enter_bug.cgi?product=POI and attach the file that triggers it, thanks!
	at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.getContentType(ContentTypeManager.java:340)
	at org.apache.poi.openxml4j.opc.internal.ContentTypeManager.removeContentType(ContentTypeManager.java:253)
	at org.apache.poi.openxml4j.opc.OPCPackage.removePart(OPCPackage.java:1016)
	at org.apache.poi.openxml4j.opc.PackagePart.getOutputStream(PackagePart.java:526)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.commit(XSSFWorkbook.java:1832)
	at org.apache.poi.POIXMLDocumentPart.onSave(POIXMLDocumentPart.java:390)
	at org.apache.poi.POIXMLDocument.write(POIXMLDocument.java:242)
	at test.ExcelFileUpdateExample1.main(ExcelFileUpdateExample1.java:68)
Comment 1 raja 2018-01-10 13:36:01 UTC
Created attachment 35670 [details]
inputfile
Comment 2 Alain Fagot Bearez 2018-01-10 17:38:20 UTC
Take care about the order you are closing the resources:


            FileOutputStream outputStream = new FileOutputStream("JavaBooks.xlsx");
            workbook.write(outputStream);
            outputStream.close();
            workbook.close();

            //inputStream.close();
            pkg.close();
 

Otherwise you are trying to write into a package (document) that has been closed.

This is a classical duplicate of https://bz.apache.org/bugzilla/show_bug.cgi?id=60102
Comment 3 Dominik Stadler 2018-02-08 19:50:27 UTC
Closing as duplicate of bug 60102 as it seems the order of close/write is wrong here.

*** This bug has been marked as a duplicate of bug 60102 ***