[英]Exception in thread “main” org.apache.poi.POIXMLException exception appearing while reading data from xlsx file using apache POI
[英]While Reading the data from Excel file with extension xlsx using apache poi it takes long time
使用apache poi读取扩展名为xlsx的excel文件时,识别扩展名需要花费很长时间。 您能帮忙为什么要花很长时间?
if (file.getExcelFile().getOriginalFilename().endsWith("xls"))
{
workbook = new HSSFWorkbook(file.getExcelFile().getInputStream());
} else if (file.getExcelFile().getOriginalFilename().endsWith("xlsx"))
{
workbook = new XSSFWorkbook(file.getExcelFile().getInputStream());
} else {
throw new IllegalArgumentException("Received file does not have a standard excel extension.");
}
在评论中添加评论-不要自己做,Apache POI内置了为您执行此操作的代码!
您应该使用WorkbookFactory.create(File)来做到这一点,例如
workbook = WorkbookFactory.create(file.getExcelFile());
如Apache POI文档中所述,直接使用File优先于InputStream来进行更快和更低的内存处理
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.