https://issues.apache.org/bugzilla/show_bug.cgi?id=47432
Summary: xlsx files generated with POI cannot be opened by
OpenOffice 3.x
Product: POI
Version: 3.5-dev
Platform: PC
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: XSSF
AssignedTo: [email protected]
ReportedBy: [email protected]
Created an attachment (id=23884)
--> (https://issues.apache.org/bugzilla/attachment.cgi?id=23884)
xlsx file generated by POI that cannot be opened by OpenOffice
After creating an xlsx file with the following sample code, and opening it with
OpenOffice 3.x, first it prompts me for the file type, then I choose Microsoft
Office 2007 XML, then I get a "General Error. General input/output error".
If you open the xlsx file with Excel 2007, then save it, it is then openable by
OpenOffice. Also, OpenOffice automatically detects the file type, so it opens
immediately.
I did some investigation, and found that after opening/saving the xlsx file
with Excel, the _rels/.rels file is changed (by Excel) to remove the leading
slashes from the Target property of the Relationship tag. If I take the file
generated by the code below, and manually remove the leading slashes from the
Target entries in the _rels/.rels file, the file is openable by OpenOffice.
When looking at the ECMA-376 docs, page 67, it shows the Relationship/Target
entries without leading slashes on them. So I believe POI is creating files
that aren't valid with respect to the Target tag. Excel seems to be lenient in
reading them, (and removing the badness when re-saving), and OpenOffice is just
failing completely upon trying to parse the files.
I will attach two xlsx files. One generated by the code below that cannot be
opened by OpenOffice (test-bad.xlsx) and one that has been manually fixed that
can be opened by OpenOffice (test-fixed.xlsx).
I looked into trying to fix POI to remove the leading slashes, but I quickly
ran into some issues with the code in openxml4j which has special checking to
make SURE these entries have leading slashes! (Line 391 in
org.apache.poi.openxlm4j.opc.PackagePartName.java)
Sample code to generate a workbook. (Every workbook I have generated with POI
3.5-beta6 cannot be opened by OpenOffice in my testing)
try {
XSSFWorkbook wb = new XSSFWorkbook();
Sheet sheet = wb.createSheet();
OutputStream out = new FileOutputStream(new File("test-bad.xlsx"));
wb.write(out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
_rels/.rels contents that OpenOffice errors parsing:
<?xml version="1.0" encoding="UTF-8"?>
<Relationships
xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Target="/xl/workbook.xml"
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"/>
<Relationship Id="rId2" Target="/docProps/core.xml"
Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"/>
</Relationships>
_rels/.rels contents that makes OpenOffice able to read files (only removed
leading slashes from Target entries):
<?xml version="1.0" encoding="UTF-8"?>
<Relationships
xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1" Target="xl/workbook.xml"
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"/>
<Relationship Id="rId2" Target="docProps/core.xml"
Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"/>
</Relationships>
Thanks,
--Leif
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]