poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]

简介: poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]

导入excel文件POI解析 时报错:

FileInputStream file = new FileInputStream(new File("G:\\TestData\\test.xls"));
//Create Workbook instance holding reference to .xlsx file
XSSFWorkbook workbook = new XSSFWorkbook(file);
//Get first/desired sheet from the workbook
XSSFSheet sheet = workbook.getSheetAt(0);
//Iterate through each rows one by one
Iterator<Row> rowIterator = sheet.iterator();
while (rowIterator.hasNext()){
  Row row = rowIterator.next();
  //For each row, iterate through all the columns
  Iterator<Cell> cellIterator = row.cellIterator();
  while (cellIterator.hasNext()){
     Cell cell = cellIterator.next();
     //Check the cell type and format accordingly
     switch (cell.getCellType()){
        case Cell.CELL_TYPE_NUMERIC:
            System.out.print(cell.getNumericCellValue() + "t");
            break;
        case Cell.CELL_TYPE_STRING:
            System.out.print(cell.getStringCellValue() + "t");
            break;
     }
  }
  System.out.println("");
}
file.close();         

报错:

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:218)


解决:


//Create Workbook instance holding reference to .xlsx file
XSSFWorkbook workbook = new XSSFWorkbook(file);


修改为


import org.apache.poi.ss.usermodel.Workbook; 
Workbook workbook = WorkbookFactory.create(file);


相关文章
|
4月前
Caused by: org.apache.ibatis.type.TypeException: Could not resolve type alias ‘order‘. Caus
Caused by: org.apache.ibatis.type.TypeException: Could not resolve type alias ‘order‘. Caus
68 0
|
2月前
|
XML 数据格式 Python
【Python】已解决:xml.parsers.expat.ExpatError: no element found: Line 1, column 0
【Python】已解决:xml.parsers.expat.ExpatError: no element found: Line 1, column 0
53 0
|
4月前
|
XML Java 数据库连接
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.forum.d
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.forum.d
50 1
|
3月前
|
Java
Found multiple occurrences of org.json.JSONObject on the class path:
Found multiple occurrences of org.json.JSONObject on the class path:
66 0
|
10月前
poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]
poi.openxml4j.exceptions.InvalidFormatException: Package should contain a content type part [M1.13]
251 0
|
4月前
|
Java
org.apache.jasper.JasperException...(line: 15, column: 16) quote symbol expected和处理办法
org.apache.jasper.JasperException...(line: 15, column: 16) quote symbol expected和处理办法
|
4月前
|
应用服务中间件 Linux
org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nes
org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nes
118 0
|
9月前
DeprecationWarning:current URL string parser is deprecated, and will be removed in a future version.
DeprecationWarning:current URL string parser is deprecated, and will be removed in a future version.
使用pageHelper报错 Type definition error: [simple type, classXXXX]
使用pageHelper报错 Type definition error: [simple type, classXXXX]
|
Kotlin
Program type already present: org.intellij.lang.annotations.Flow\Program type already present: org.i
Program type already present: org.intellij.lang.annotations.Flow\Program type already present: org.i
120 0
Program type already present: org.intellij.lang.annotations.Flow\Program type already present: org.i