I have a fairly simple workbook that I have successfully opened using POI. However, when trying a similar file with hyperlinks saved within, POI is unable to read it. This is the stacktrace I got on repeated attempts: java.lang.RuntimeException: Unexpected record type (org.apache.poi.hssf.record.HyperlinkRecord) at org.apache.poi.hssf.record.aggregates.RowRecordsAggregate.<init>(RowRecordsAggregate.java:107) at org.apache.poi.hssf.model.InternalSheet.<init>(InternalSheet.java:208) at org.apache.poi.hssf.model.InternalSheet.createSheet(InternalSheet.java:163) at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:298) at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:82) at excelproc.util.ExcelFileWrapper.<init>(ExcelFileWrapper.java:42) at excelproc.exec.InvoiceComparisonIndexBuilder.main(InvoiceComparisonIndexBuilder.java:46) The hyperlinks are internet URLs, if that makes a difference. Let me know if more info is needed. Thanks!
This is the code I'm using to attempt to open the workbook: public ExcelFileWrapper(String filename, Timestamp endDate) { this.filename = filename; this.endDate = endDate; final File f = new File(filename); try { excelFile = WorkbookFactory.create(f); } catch (Exception e) { log.error("Could not open Excel workbook for updating.", e); } }
Any chance you could supply the problem file? It looks like POI thinks the hyperlink applies to several rows, which isn't currently supported. We'll need the file to investigate why that is (to see the options on the hyperlink records, where they live in your file etc)
I tried manually creating each hyperlink separately in a reduced form of the target spreadsheet, and POI was able to operate on it successfully. I don't know exactly what the process is upstream; the developer generating the Excel file I receive may be doing something when creating her hyperlinks that POI doesn't like. I'd attach the spreadsheet, but it contains business data that probably shouldn't be shared. If there was a quick way to change the URLs in the hyperlinks without messing with whatever structure they're currently in, that would be sufficient to remove sensitive data and share the workbook. Thanks!
You could maybe go at it with a Hex Editor - you should be able to search for the hyperlink URL and text (assuming neither use accented or non-English characters they'll show up normally). Then, change those in the hex editor to something dummy but with the same size, and finally check in Excel that it can still open the files and sees the dummy text instead
Created attachment 29400 [details] file with hyperlink that repro's the exception
Hello, I am getting the same exception with Apache POI 3.8 and the file attached. Exception: java.lang.RuntimeException: Unexpected record type (org.apache.poi.hssf.record.HyperlinkRecord) at org.apache.poi.hssf.record.aggregates.RowRecordsAggregate.<init>(RowRecordsAggregate.java:107) at org.apache.poi.hssf.model.InternalSheet.<init>(InternalSheet.java:208) at org.apache.poi.hssf.model.InternalSheet.createSheet(InternalSheet.java:163) at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:296) at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:248) at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:192) at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:327) at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:308) at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:70) at com....MiscUnitTests.testExcelReader(MiscUnitTests.java:693) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at org.junit.runner.JUnitCore.run(JUnitCore.java:157) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:76) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:195) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:63) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120) Unit test: @Test public void testExcelReader() throws IOException, InvalidFormatException { InputStream stream = null; try { stream = this.getClass().getResourceAsStream("/sample_with_hyperlinks.xls"); WorkbookFactory.create(stream); } finally { stream.close(); } } I have not been able to create a simpler file that produces the exception. Thanks in advance.
Hi, I am currently facing the similar kind of issue will loading a file from this link: https://www.jse.co.za/_layouts/15/DownloadHandler.ashx?FileName=/Safex/All%20Contract%20Details.xls. If I open the file and enable editing,it size becomes almost double and it loads properly.But due to some restriction i cant done these changes in code. Thanks and Regards, Deepesh Ramrakhyani.
This is similar to the error reported in bug 57669
Seems to be caused by slightly corrupted Excel files, see bug 50426 and bug 53984 for similar issues where we could work around the problem somehow, although in this case it does not seem to be that easy as a simple fix similar to the previous bugs does not make it work...
Tested with 4.1.1 just in case, still fails
I found a way to support reading this file, see r1896552.
*** Bug 57669 has been marked as a duplicate of this bug. ***