Bug 52142 - Unable to read excel 2007 with structure locked
Summary: Unable to read excel 2007 with structure locked
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.8-dev
Hardware: PC Windows Vista
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-05 20:06 UTC by suresh babu
Modified: 2016-07-26 19:48 UTC (History)
0 users



Attachments
excel used to check the funtionality (12.81 KB, application/zip)
2011-11-08 16:12 UTC, suresh babu
Details

Note You need to log in before you can comment on or make changes to this bug.
Description suresh babu 2011-11-05 20:06:31 UTC
I am able to open the excel 2007 but when I protect it with structure locking..I am not able to open it. I am using poi-3.8.beta4.

I dont think something is wrong with excel sheet.

Code:

 XSSFWorkbook workbook=null;
			InputStream inputStream = null;

				inputStream = new FileInputStream(new File("G:\\test.xlsx"));

			workbook=	 new XSSFWorkbook(inputStream);


Error:


Exception in thread "main" org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]
	at org.apache.poi.util.PackageHelper.open(PackageHelper.java:41)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:178)
	at com.poi.xssf.XSSFWorkBook.main(XSSFWorkBook.java:97)
Caused by: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]
	at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:148)
	at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:615)
	at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:229)
	at org.apache.poi.util.PackageHelper.open(PackageHelper.java:39)
	... 2 more
Comment 1 Yegor Kozlov 2011-11-07 07:18:14 UTC
It is hard to tell what is wrong without a sample file.

Please post the initial file (not locked), the locked file and detailed instructions how you created it in Excel, i.e. what operations you did to produce content that POI cannot read.

Yegor
Comment 2 Yegor Kozlov 2011-11-07 07:19:14 UTC
It is hard to tell what is wrong without a sample file.

Please post the initial file (not locked), the locked file and detailed instructions how you created it in Excel, i.e. what operations you did to produce content that POI cannot read.

Yegor
Comment 3 suresh babu 2011-11-07 15:12:46 UTC
I have created test.xlsx sheet and added text 'test' in the first cell. I have added the latest jar files of poi 3.8 beta 4 version on build path.

Below is the code used to read the sheet.

		   XSSFWorkbook workbook=null;
	            InputStream inputStream = null;

	                inputStream = new FileInputStream(new File("G:\\test.xlsx"));

	            workbook=     new XSSFWorkbook(inputStream);
	            XSSFSheet sheet=workbook.getSheetAt(0);
	            XSSFRow row=sheet.getRow(0);
	            XSSFCell cell=row.getCell(0);
	            System.out.println("cell value is--"+cell.toString());

output:

cell value is--test

I used the review-->protect workbook-->protect structure and windows..then gave 'suresh' as password and save the excel sheet as 'test_structure_locked.xlsx'.

then I tried to read this new file with the below code. It seems it is not able to read the excel sheet whose structure is locked.

 XSSFWorkbook workbook=null;
	            InputStream inputStream = null;

	                inputStream = new FileInputStream(new File("G:\\test_structure_locked.xlsx"));

	            workbook=     new XSSFWorkbook(inputStream);
	            XSSFSheet sheet=workbook.getSheetAt(0);
	            XSSFRow row=sheet.getRow(0);
	            XSSFCell cell=row.getCell(0);
	            System.out.println("cell value is--"+cell.toString());

Error:
Exception in thread "main" org.apache.poi.POIXMLException: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]
	at org.apache.poi.util.PackageHelper.open(PackageHelper.java:41)
	at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:178)
	at com.poi.xssf.XSSFWorkBook.main(XSSFWorkBook.java:98)
Caused by: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]
	at org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:148)
	at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:615)
	at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:229)
	at org.apache.poi.util.PackageHelper.open(PackageHelper.java:39)
	... 2 more





(In reply to comment #0)
> I am able to open the excel 2007 but when I protect it with structure
> locking..I am not able to open it. I am using poi-3.8.beta4.
> 
> I dont think something is wrong with excel sheet.
> 
> Code:
> 
>  XSSFWorkbook workbook=null;
>             InputStream inputStream = null;
> 
>                 inputStream = new FileInputStream(new File("G:\\test.xlsx"));
> 
>             workbook=     new XSSFWorkbook(inputStream);
> 
> 
> Error:
> 
> 
> Exception in thread "main" org.apache.poi.POIXMLException:
> org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should
> contain a content type part [M1.13]
>     at org.apache.poi.util.PackageHelper.open(PackageHelper.java:41)
>     at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:178)
>     at com.poi.xssf.XSSFWorkBook.main(XSSFWorkBook.java:97)
> Caused by: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package
> should contain a content type part [M1.13]
>     at
> org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:148)
>     at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:615)
>     at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:229)
>     at org.apache.poi.util.PackageHelper.open(PackageHelper.java:39)
>     ... 2 more

(In reply to comment #0)
> I am able to open the excel 2007 but when I protect it with structure
> locking..I am not able to open it. I am using poi-3.8.beta4.
> 
> I dont think something is wrong with excel sheet.
> 
> Code:
> 
>  XSSFWorkbook workbook=null;
>             InputStream inputStream = null;
> 
>                 inputStream = new FileInputStream(new File("G:\\test.xlsx"));
> 
>             workbook=     new XSSFWorkbook(inputStream);
> 
> 
> Error:
> 
> 
> Exception in thread "main" org.apache.poi.POIXMLException:
> org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package should
> contain a content type part [M1.13]
>     at org.apache.poi.util.PackageHelper.open(PackageHelper.java:41)
>     at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:178)
>     at com.poi.xssf.XSSFWorkBook.main(XSSFWorkBook.java:97)
> Caused by: org.apache.poi.openxml4j.exceptions.InvalidFormatException: Package
> should contain a content type part [M1.13]
>     at
> org.apache.poi.openxml4j.opc.ZipPackage.getPartsImpl(ZipPackage.java:148)
>     at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:615)
>     at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:229)
>     at org.apache.poi.util.PackageHelper.open(PackageHelper.java:39)
>     ... 2 more
Comment 4 suresh babu 2011-11-08 16:12:07 UTC
Created attachment 27910 [details]
excel used to check the funtionality

Hi,

I have added the excel sheets used to test the code mentioned in the previous post.

Thanks,
Suresh A
Comment 5 Suyog 2014-11-04 11:21:59 UTC
I am also getting same issue with file created/updated using Microsoft office 2007.

Please let me know if you find any solution
Comment 6 Nick Burch 2016-03-15 12:43:52 UTC
We've added some more descriptive exceptions in 3.15 beta 1 for the most common incorrect file types. If you pass in a .ODS or a .XLS, for example, the exception will not tell you that you've done that.

So, it might be worth re-testing for this case with a nightly build / 3.15 beta 1 when released
Comment 7 Dominik Stadler 2016-07-26 19:48:47 UTC
Latest trunk reports this as follows

org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException: The supplied data appears to be in the OLE2 Format. You are calling the part of POI that deals with OOXML (Office Open XML) Documents. You need to call a different part of POI to process this data (eg HSSF instead of XSSF)

So I think we can close this as WORKSFORME, you seem to have an xls file with a .xlsx extension which means you actually need HSSF.... classes to work with such files. Alternatively you can use WorkbookFactory and the underlying base interfaces (Workbook, Sheet, Row, Cell, ...) to make your code independent of the actual file-format.