Bug 46419 - XSSFWorkbook.write() file format error
Summary: XSSFWorkbook.write() file format error
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.5-dev
Hardware: PC Windows XP
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
: 47432 (view as bug list)
Depends on:
Reported: 2008-12-19 04:45 UTC by Jose Miguel
Modified: 2009-07-28 03:07 UTC (History)
2 users (show)

Saved xlsx file using the specified code. Very simple xlsx file. Open Office 3.0 don't recognize it (7.93 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2008-12-19 04:45 UTC, Jose Miguel
Original xlsx fiel (before saving) (40.02 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2009-01-22 04:39 UTC, Jose Miguel
Saved file using Apache POI. No changes from the original file (34.18 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2009-01-22 04:41 UTC, Jose Miguel
OpenOfficeXlsxRepair.java - simple java class that works around OpenOffice issues - uses truezip: https://truezip.dev.java.net/ (2.97 KB, text/plain)
2009-07-23 07:42 UTC, Leif Nelson

Note You need to log in before you can comment on or make changes to this bug.
Description Jose Miguel 2008-12-19 04:45:19 UTC
Created attachment 23038 [details]
Saved xlsx file using the specified code. Very simple xlsx file. Open Office 3.0 don't recognize it

Using this code to load an xlsx file and save it in another path with o without changes.

Workbook xlsDocument=null;
try {
   xlsDocument = WorkbookFactory.create(new FileInputStream(pathOriginal));
} catch (FileNotFoundException ex) {
} catch (Exception ex) {
FileOutputStream fos = new FileOutputStream(pathTemp);

The saved file contains file format errors.

If the saved file is a complex file,
when you try to open it with excel, it says that the file is damaged but
sometimes can repair it. With simples files (including the most simple file,
only one cell with a simple text content) excel can open the file without
errors. But if you try to open the saved file using OpenOffice
3.0 which supports xlsx file format. OpenOffice 3.0 can open the original
xlsx file without problems, but the saved file isn't recognized by
OpenOffcie 3.0.

If you open the saved file with excel and save it again (usign save option
from excel), now OpenOffice can open it without problems, so I supose that
exists a save bug that causes a format problem that usually can be repaired
by excel, but never can be repaired by OpenOffice.
Comment 1 Yegor Kozlov 2008-12-20 05:43:29 UTC
Please attach the original file. 

Comment 2 Yegor Kozlov 2008-12-21 05:52:11 UTC
I think it is a bug in OpenOffice, not in POI. I files and issue, let's wait for feedback from OO guys:

OpenOffice can't read core OOXML relationships if a part name starts with a forward slash character '/'.
For example, if the main document part is referenced as "/xl/workbook.xml" then OpenOffice Calc fails to open it. If the main part is referenced as "xl/workbook.xml" (without the leading slash), then the file is opened OK.

The part name grammar implies the forward slash constraint. See OOXML Open Packaging Conventions, Package model conformance requirements:
M1.4 A part name shall start with a forward slash (“/”) character.

This constraint doesn't seem to be mandatory. Excel 2007 writes package part names without the leading slash and doesn't require it when reading files. Both "xl/workbook.xml" and "/xl/workbook.xml" part names seem to be valid, although only the first one is OK in OpenOffice 3.0. 

So, I think OO should support package part names starting with a forward slash.

Comment 3 Jose Miguel 2008-12-29 04:53:43 UTC
Sorry for not responding, but I was on holiday.

I agree that can exist an OpenOffice bug as you say, but I think that the bug I reported is a POI bug too. If I open an original file with MS Excel 2007 it works properly, but if I save this file without changes using POI the saved file not only can't be opened by OpenOffice but also presents problems to be opened with MS Excel 2007. Excel can open it, but it has to delete some registers, so I think that exists a problem with Apache POI too.

This is the messages reported by Excel 2007 when I try to open the saved file:

Registros quitados: Información de celda de /xl/worksheets/sheet6.xml parte
Registros quitados: Fórmula de /xl/calcChain.xml parte (Propiedades de cálculo)

The message is in spanish, in English it could be translated as:

Deleted registers: Cell information of /xl/worksheets/sheet6.xml part
Deleted registers: Formula of /xl/calcChain.xml part (Calculation of properties)

I can't attach my original file because it contains some private information, but I will try to modify this file to delete this private information and attach it. The file is protected so I can't modify it, when I get the password to unprotect  and modify it I will attach the file. Sorry.

J. Miguel
Comment 4 Jose Miguel 2009-01-22 04:39:33 UTC
Created attachment 23159 [details]
Original xlsx fiel (before saving)
Comment 5 Jose Miguel 2009-01-22 04:41:44 UTC
Created attachment 23160 [details]
Saved file using Apache POI. No changes from the original file

Open office can´t open this file.
Comment 6 Jose Miguel 2009-01-22 04:42:50 UTC
I attached the Original file and the saved file which I have the problem. I can open the saved file with Office Excel, but not with OpenOffice Calc. I only opened and saved the the file without changes and in a different path. 

Sorry but we had a lot of problems to can unprotect the file and publish it.

Comment 7 Leif Nelson 2009-06-26 08:14:49 UTC
*** Bug 47432 has been marked as a duplicate of this bug. ***
Comment 8 Leif Nelson 2009-07-23 07:40:42 UTC
I wrote a simple java class to work around this issue and make the xlsx files generated by POI compatible with OpenOffice.  We use it when generating all of our xlsx files as an interim solution while the OpenOffice bug sits there and does nothing :-)  It is attached as OpenOfficeXlsxRepair.java

Comment 9 Leif Nelson 2009-07-23 07:42:47 UTC
Created attachment 24027 [details]
OpenOfficeXlsxRepair.java - simple java class that works around OpenOffice issues - uses truezip: https://truezip.dev.java.net/
Comment 10 Leif Nelson 2009-07-23 07:45:43 UTC
(In reply to comment #9)
> Created an attachment (id=24027) [details]
> OpenOfficeXlsxRepair.java - simple java class that works around OpenOffice
> issues

FYI.  This class uses truezip to manipulate the contents of the xlsx zip file: https://truezip.dev.java.net/
Comment 11 Yegor Kozlov 2009-07-24 01:40:08 UTC
I fixed POI to produce files compatible with OpenOffice.
The fix was committed in r797350

Comment 12 Leif Nelson 2009-07-27 07:45:43 UTC
Thank you Yegor!  I will remove my workaround for around this :-)

Comment 13 Jose Miguel 2009-07-28 03:07:23 UTC
Thanks Yegor and Leif for solving the bug.