Apache poi workbookfactory 从 xlsx 创建 HSSFWorkbook,但我希望 XSSFWorkbook

问题描述

我正在尝试通过以下调用从 file.xlsx 创建 XSSFWorkbook:

1. XSSFWorkbookFactory.create(file) -> return hssfWorkbook
2. WorkbookFactory.createXSSFWorkbook(file) -> While trying to invoke 'createWorkbook' on factory org.apache.poi.xssf.usermodel.XSSFWorkbookFactory and arguments [path to file.xlsx]
3. OPCPackage.open(file) -> The supplied data appears to be in the OLE2 Format. You are calling the part of POI that deals with OOXML (Office Open XML) Documents. You need to call a different part of POI to process this data (eg hssf instead of XSSF)
   XSSFWorkbook wb = new XSSFWorkbook(pkg);
4. XSSFWorkbookFactory.createWorkbook(new FileInputStream(file)) -> The supplied data appears to be in the OLE2 Format. You are calling the part of POI that deals with OOXML (Office Open XML) Documents. You need to call a different part of POI to process this data (eg hssf instead of XSSF)

我需要将文件读取为 XSSFWorkbook 以读取和设置图表的新参数。 任何想法,为什么我会发现此错误以及为什么从第 1 项开始返回 hssfWorkbook

我检查了几次,文件的扩展名为 .xlsx。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)