Bug 57181 - Unable to read Excel 2007 xlsm file
Summary: Unable to read Excel 2007 xlsm file
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.13-dev
Hardware: PC All
: P2 blocker (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-11-04 11:17 UTC by Suyog
Modified: 2015-08-03 07:43 UTC (History)
2 users (show)



Attachments
Example-File which fails to open (326.88 KB, application/vnd.ms-excel.sheet.macroEnabled.12)
2015-07-30 15:00 UTC, Martin G
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Suyog 2014-11-04 11:17:05 UTC
Hi 

Below is the code base to read xlsm file :

             Sheet sheet = null;
		try
		{
			byte[] filedata = attachmentValue.getFileData();
			InputStream inputFileStream = new ByteArrayInputStream(filedata);
	         
                        //Create Workbook instance for xlsm file input stream
	                 Workbook workbook = null;
	       
                       if(attachmentValue.getFileName().toLowerCase().endsWith("xlsm") ){
	                       workbook = new XSSFWorkbook(inputFileStream);
	                }
	        
	                  sheet = workbook.getSheetAt(0);
		}
		catch (Exception e) {
                }

      
The above highlighted code is working fine with the xlsm file created with Microsoft Office 2010 but throwing below exception with Microsoft office 2007 :

[11/3/14 23:09:26:424 SGT] 0000019e SystemErr     R org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]
[11/3/14 23:09:26:425 SGT] 0000019e SystemErr     R 	at org.apache.poi.util.PackageHelper.open(PackageHelper.java:41)
[11/3/14 23:09:26:426 SGT] 0000019e SystemErr     R 	at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:204)

Please suggest if anyone has identified & fixed same kind of issues.
Comment 1 Nick Burch 2014-11-04 11:20:07 UTC
3.9 is a little old, can you please re-test with 3.11 beta 2, or even better, a recent nightly build? (3.11 beta 3 should be out in a few days)
Comment 2 Suyog 2014-11-04 11:30:23 UTC
Tried with poi-bin-3.10-FINAL, but getting same issue
Comment 3 Suyog 2014-11-04 11:32:35 UTC
xlsm files created with Microsoft 2010 are working fine but issue is with files created/updtaed on 2007.

Even if we open the file in 2010 & just without any chnage, those are working fine
Comment 4 Suyog 2014-11-04 11:34:59 UTC
xlsm files created with Microsoft 2010 are working fine but issue is with files created/updtaed on 2007.

Even if we open the 2007 updtaed/creted file which is failling in 2010 & just save it without any chnage, those are working fine
Comment 5 Nick Burch 2014-11-04 11:38:17 UTC
Try with a recent nightly build / build from svn?
Comment 6 Dominik Stadler 2014-11-09 19:27:45 UTC
Also can you attach two such files, one created with Excel 2007 and one with Excel 2010?
Comment 7 Emanuele 2014-12-01 17:06:15 UTC
Hello,
I read xlsm file properly but have the same problem when add "Protect Workbook" on Revision tab. I use 3.11 beta 3 version
Comment 8 Martin G 2015-07-30 15:00:33 UTC
Created attachment 32946 [details]
Example-File which fails to open
Comment 9 Martin G 2015-07-30 15:03:10 UTC
I am using POI 3.12.

Opening attached File raises the following Exception.

org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:62)
at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:456)
at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:461)
at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:162)
at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:271)
Comment 10 Nick Burch 2015-07-30 15:05:45 UTC
Can you try with 3.13 beta 1?
Comment 11 Martin G 2015-07-30 15:21:22 UTC
Yes, I did.

Resulted basically in the same Exception.

org.apache.poi.POIXMLException: java.lang.reflect.InvocationTargetException
  at org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:62)
  at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:456)
  at org.apache.poi.POIXMLDocumentPart.read(POIXMLDocumentPart.java:461)
  at org.apache.poi.POIXMLDocument.load(POIXMLDocument.java:163)
  at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:279)
Comment 12 Nick Burch 2015-08-01 00:26:35 UTC
I've just tried the attached file on trunk, and it opens just fine. Unit test which shows that added in r1693676. Do we need to do something different to what's in that unit test to trigger the problem? Or is it already fixed?
Comment 13 Martin G 2015-08-03 07:43:05 UTC
It works and has been my fault from the beginning.
I did no included the ooxml-schemas lib.
But in my stack-trace I saw this hint not before I used the nightly.
Going back to 3.12 I fond out, that it opens xlsm well and I am able to access the content.

Thanks anyway!