读取 Excel 工作表时出现 BiffException
我有一个代码可以从旧格式(97-2003)的 Excel 工作表中读取。我对数据做了一些更改,最终得到了 2007 格式的 Excel 工作表。当我使用此 xlsx 工作表而不是 xls 工作表时,我得到以下信息:
jxl.read.biff.BiffException: Unable to recognize OLE stream
at jxl.read.biff.CompoundFile.<init>(CompoundFile.java:116)
at jxl.read.biff.File.<init>(File.java:127)
at jxl.Workbook.getWorkbook(Workbook.java:268)
at readexcel.ReadExcel.readContent(ReadExcel.java:50)
at readexcel.ReadExcel.init(ReadExcel.java:25)
at readexcel.ReadExcel.main(ReadExcel.java:183)
I have a code to read from an excel sheet which is in old format(97-2003). I made some changes to data and ended up a 2007 format excel sheet. When I used this xlsx sheet instead of xls sheet, I am getting this:
jxl.read.biff.BiffException: Unable to recognize OLE stream
at jxl.read.biff.CompoundFile.<init>(CompoundFile.java:116)
at jxl.read.biff.File.<init>(File.java:127)
at jxl.Workbook.getWorkbook(Workbook.java:268)
at readexcel.ReadExcel.readContent(ReadExcel.java:50)
at readexcel.ReadExcel.init(ReadExcel.java:25)
at readexcel.ReadExcel.main(ReadExcel.java:183)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
xls 格式(< Excel 2007)由 OLE 容器中的二进制 BIFF 数据组成。 xlsx 格式 (>= Excel 2007) 由 zip 容器中的 XML 文件组成。
Java Excel API 仅处理第一种格式,因此在未遇到 OLE 容器时会引发异常。
您需要将输入限制为仅 xls 文件,或者找到另一个可以处理这两种格式的工具。
The xls format (< Excel 2007) is comprised of binary BIFF data in an OLE container. The xlsx format (>= Excel 2007) is comprised of XML files in a zip container.
The Java Excel API only deals with the first format so it throws an exception when it doesn't encounter an OLE container.
You will need to restrict your input to xls files only or find another tool that handles both formats.
将您的工作簿“另存为”为“Excel 97-2003 工作簿”(Microsoft Excel 2007 中提供该选项),它将您的文件保存在 OLE 容器中。
"save as" your workbook as "Excel 97-2003 workbook" (option comes in Microsoft Excel 2007) it saves your file in OLE container.
我刚刚也遇到过同样的麻烦。项目是基于 Maven 的,以下指令的副作用是过滤 XLS 文件。
干净的解决方法是定义子文件夹“config”并允许过滤此特定文件夹,同时包含但不过滤其他子文件夹。
I just have had the same trouble. Project was Maven based and side effect of following directive was to filter XLS file.
Clean workaround solution was to define sub folder "config" and allow filtering on this specific folder, while including but not filtering on other sub-folders.
我在 Eclipse/Selenium 中遇到了同样的问题,并尝试“另存为”97-2000 (.xls),它解决了我的问题。
I was facing same issue in Eclipse/Selenium and tried to "Save As" 97-2000 (.xls) and it solved my problem.
我也遇到过同样的问题。
这是因为您使用的 Excel 扩展名 (.xlsx) 以及您用来加载的软件无法正确读取此格式。
因此,请使用旧版本的 Excel 扩展名(.xls),因为它们可能与您正在使用的工具兼容。
然后就可以理解并读取成功
I have also faced the same problem.
It is because the Excel you are using of extension (.xlsx) and this format is not correctly reading by the software you are using to load.
Hence Use the older versions of excel extension which is (.xls) as those may be compatible with the tool you are working.
Then it will understand and read successfully