使用poi异常:Package should contain a content type part [M1.13]

读写xls和xlsx格式时,HSSFWorkbook针对xls,XSSFWorkbook针对xlsx

根据上述原因做一下代码调整:

//HSSFWorkbook和XSSFWorkbook都实现了Workbook接口,tempPath是文件路径
Workbook workbook;
String suf = ".xls";
if (suffix.equals(suf)) {
    workbook = new HSSFWorkbook(new BufferedInputStream(new FileInputStream(tempPath)));
} else {
    workbook = new XSSFWorkbook(new BufferedInputStream(new FileInputStream(tempPath)));
}
Sheet sheet = workbook.getSheetAt(0);

参考链接:https://blog.csdn.net/llwan/article/details/8890190

你可能感兴趣的:(poi,M1.13)