Bug 52447 - Unable to Open Excel XLS with hyperlink cells.
Summary: Unable to Open Excel XLS with hyperlink cells.
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.10-FINAL
Hardware: PC All
: P1 critical with 5 votes (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on: 50426 53984
Blocks: 57669
  Show dependency tree
 
Reported: 2012-01-10 22:46 UTC by Dave S.
Modified: 2019-01-06 13:17 UTC (History)
2 users (show)



Attachments
file with hyperlink that repro's the exception (53.50 KB, application/vnd.ms-excel)
2012-09-19 17:55 UTC, andrey
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dave S. 2012-01-10 22:46:12 UTC
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!
Comment 1 Dave S. 2012-01-10 22:47:42 UTC
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);
		}
	}
Comment 2 Nick Burch 2012-01-11 15:07:17 UTC
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)
Comment 3 Dave S. 2012-01-12 16:16:15 UTC
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!
Comment 4 Nick Burch 2012-01-13 11:03:26 UTC
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
Comment 5 andrey 2012-09-19 17:55:15 UTC
Created attachment 29400 [details]
file with hyperlink that repro's the exception
Comment 6 andrey 2012-09-19 18:01:29 UTC
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.
Comment 7 Deepesh Ramrakhyani 2014-05-12 06:46:55 UTC
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.
Comment 8 Dominik Stadler 2015-03-18 20:55:05 UTC
This is similar to the error reported in bug 57669
Comment 9 Dominik Stadler 2015-05-01 20:47:38 UTC
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...