Bug 47432

Summary: xlsx files generated with POI cannot be opened by OpenOffice 3.x
Product: POI Reporter: Leif Nelson <lnelson>
Component: XSSFAssignee: POI Developers List <dev>
Severity: normal    
Priority: P2    
Version: 3.5-dev   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: xlsx file generated by POI that cannot be opened by OpenOffice
xlsx file that has been "fixed" to be readable by OpenOffice

Description Leif Nelson 2009-06-25 17:33:41 UTC
Created attachment 23884 [details]
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"));
  } catch (Exception e) {

_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"/>

_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"/>

Comment 1 Leif Nelson 2009-06-25 17:34:17 UTC
Created attachment 23885 [details]
xlsx file that has been "fixed" to be readable by OpenOffice
Comment 2 Leif Nelson 2009-06-26 08:14:49 UTC

*** This bug has been marked as a duplicate of bug 46419 ***
Comment 3 Yegor Kozlov 2009-06-27 04:43:54 UTC

I suggest you vote for this bug on openoffice.org: http://www.openoffice.org/issues/show_bug.cgi?id=97460

According to their rules, additional vote should prioritize this bug to an upper level. I hope it will influence OO developers to fix it.

Comment 4 Leif Nelson 2009-06-29 07:51:48 UTC

I added as many votes as I could for the OpenOffice issue.