關於poi讀寫.xlsx檔案的錯誤
程式碼:
private static Workbook openSXSSFExcel(String excelPath){
// if(excelPath.endsWith(".xls")){
// throw new RuntimeException("不支援.xls格式的檔案");
// }
File file = new File(excelPath);
XSSFWorkbook workbook = null;
if(!file.exists()){
createNewExcel(excelPath);
}
try {
FileInputStream fs = new FileInputStream(file);
workbook = new XSSFWorkbook(fs);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return workbook;
}
報錯:
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:218)
at parseUtils.Parse.openSXSSFExcel(Parse.java:242)
at parseUtils.Parse.main(Parse.java:416)
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:199)
at org.apache.poi.openxml4j.opc.OPCPackage.getParts(OPCPackage.java:665)
at org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:274)
at org.apache.poi.util.PackageHelper.open(PackageHelper.java:39)
... 3 more
求大神解決!!!