Home » excel » excel – POI: Unexpected record type org.apache.poi.hssf.record.HyperlinkRecord

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

Posted by: admin April 23, 2020 Leave a comment

Questions:

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

How to&Answers:

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