问题描述
我正在执行一个简单的任务:读取Excel文件并将其转换为对象.不过,我在读取Excel文件(.xls)时遇到了问题我将从外部系统接收它(也许他们自动生成了它).如果我打开它并进行简单保存(无论是否更改Excel文件中的任何内容),我的解析器逻辑就可以正常工作.但是,如果我不编辑并保存文件并尝试按原样解析原始文件,则在加载.xls文件时在此行会出现异常:
I am working on a simple task: Reading an Excel file and converting it to an object. Though, I am facing a problem in reading the Excel file (.xls)I will receive it from an external system (maybe they autogenerated it). If I open it and just do a simple save (with or without changing anything in the Excel file), my parser logic works fine. But if I don't edit and save the file and try to parse the original file as is, I get an exception at this line while loading the .xls file:
HSSFWorkbook xlsWorkbook = new HSSFWorkbook(inputDocument);
以下是例外:
java.lang.RuntimeException: Unexpected record type (org.apache.poi.hssf.record.HyperlinkRecord)
at org.apache.poi.hssf.record.aggregates.RowRecordsAggregate.<init>(RowRecordsAggregate.java:97)
at org.apache.poi.hssf.model.InternalSheet.<init>(InternalSheet.java:217)
at org.apache.poi.hssf.model.InternalSheet.createSheet(InternalSheet.java:156)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:337)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:289)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:224)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:382)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:364)
我在Google上搜索了可能的解决方案;但从未发现任何东西!有人可以引导我解决该问题吗?
I have googled for possible solutions; but never found any! Can somebody lead me a way to resolve it?
PS:我什至尝试用最新版本的POI(3.12)加载.xls,但没有成功!
PS: I even tried loading .xls with the recent versions of POI (3.12) but with no success!
谢谢
推荐答案
在上进行讨论https://bz.apache.org/bugzilla/show_bug.cgi?id=52447 表示这可能是由Microsoft Excel似乎可以正常处理的非标准Excel文件引起的,但Apache POI可能会阻塞.您可以尝试执行以下操作:
Discussion at https://bz.apache.org/bugzilla/show_bug.cgi?id=52447 indicates that this can be caused by non-standard Excel files that Microsoft Excel seems to handle gracefully, but Apache POI can choke on. You can try to following things:
- 请确保您使用的是最新版本的POI(3.13),因为其中存在许多可能与之相关的错误修正
- 向正在生成文件的应用程序报告问题,以尝试使其以更标准的方式提供文件
- 使用一个示例文件向您报告Apache POI失败
这篇关于POI:意外的记录类型org.apache.poi.hssf.record.HyperlinkRecord的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!