1

I'm using poi 3.7 , upload the file is .xlsx

The console show:

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:186)
    at poi.POITest.ReadAndPrintExcelFile(POITest.java:15)
    at poi.POITest.main(POITest.java:59)
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:147)
    at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:592)
    at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:222)
    at org.apache.poi.util.PackageHelper.open(PackageHelper.java:39)
    ... 3 more
Philipp Reichart
  • 20,771
  • 6
  • 58
  • 65
jptiancai
  • 23
  • 1
  • 1
  • 8

5 Answers5

12

Just use org.apache.poi.ss.usermodel.WorkbookFactory instead of creating instances : new HSSFWorkbook() or new XSSFWorkbook().

Workbook exWorkBook = WorkbookFactory.create(excelInputStream);
Sergei
  • 145
  • 1
  • 5
3

Not the answer you may want to hear. But i found i get this error when the password is wrong. Check if the call to Decryptor.verifyPassword() returns true in your code. If so password should be fine.

For me I got a false, and the code ignored and try to read the file anyway.Then i got the "Package should contain a content type part [M1.13]" error. Once i typed in the correct password, i got true returned and the file was decrypted.

Hope this helps

codester
  • 117
  • 2
  • 9
1

I use POI, and sometimes when this happens you just have to experiment to pinpoint the problem. Here are things I have done in the past to help figure out what the problem is:

  1. Convert the file to .xls format and see if it loads. If it does, resave as .xlsx and try again.

  2. If the file has multiple sheets, try saving each sheet as a separate file and see if they can load,

  3. If you narrow it down to a specific sheet, load parts of the sheet and see which part causes the problem.

Usually, if you use this "divide and conquer" approach, you can figure out the problem pretty quickly.

Formulas and macros can be particularly problematic.

Adam Mihalcin
  • 14,242
  • 4
  • 36
  • 52
Howard Schutzman
  • 2,115
  • 1
  • 15
  • 8
0

If you are using open office and trying to save the file in xlsx format still you get the error; also using xssf does'nt solve the purpose.you need to use Microsoft Office Excel sheet to avoid the error.

0

I found that I had corrupted my xlsx file and so had to delete it and recreate it.

Jack
  • 2,891
  • 11
  • 48
  • 65