Summary: | Unable to read excel 2007 with structure locked | ||
---|---|---|---|
Product: | POI | Reporter: | suresh babu <suresh54145> |
Component: | XSSF | Assignee: | POI Developers List <dev> |
Status: | RESOLVED WORKSFORME | ||
Severity: | normal | ||
Priority: | P2 | ||
Version: | 3.8-dev | ||
Target Milestone: | --- | ||
Hardware: | PC | ||
OS: | Windows Vista | ||
Attachments: | excel used to check the funtionality |
Description
suresh babu
2011-11-05 20:06:31 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 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 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 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
I am also getting same issue with file created/updated using Microsoft office 2007. Please let me know if you find any solution 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 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. |