POI: Unexpected record type org.apache.poi.hssf.record.HyperlinkRecord

僤鯓⒐⒋嵵緔 提交于 2019-12-22 09:57:02

问题


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);

Below is the exception:

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)

I have googled for possible solutions; but never found any! Can somebody lead me a way to resolve it?

PS: I even tried loading .xls with the recent versions of POI (3.12) but with no success!

Thanks


回答1:


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:

  • Make sure you use the latest version of POI (3.13) as there were a number of bugfixes that may be related
  • Report an issue to the application that is producing the file to try to make it provide the file in a more standard way
  • Report an issue to Apache POI with a sample file that fails for you


来源:https://stackoverflow.com/questions/30785203/poi-unexpected-record-type-org-apache-poi-hssf-record-hyperlinkrecord

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!