Question

I am using Apache POI to generate excel sheets (.xls format). On the first sheet I have created several hyperlinks that will link to different sheets in the same document.

HSSFSheet summarySheet = workbook.createSheet(rs.getString(1));    
Hyperlink targetLink = createHelper.createHyperlink(Hyperlink.LINK_DOCUMENT);
targetLink.setAddress("'"+rs.getString(1)+"'");

I am using the above code snippet to create sheets and Hyperlinks to those sheets. As you can see the number of sheets varies as I'm setting the address dynamically from the database. This approach was working fine but I've encountered a problem now.

As I said, each link will open a different sheet in the same document except for the last link. When I click this, Open Office throws a pop-up saying "Invalid Range". Now, I don't know if the problem is with the code or if it is not related to the code. I just wanted to check if anybody has encountered a similar problem or if someone knows why Open Office throws such an error. If any of you feel the question is not contructive or if it is asked at the wrong place, please do guide me before downvoting etc. Thanks.

Edit: Now that I've checked it has got something to do with the Target Sheet that I'm setting in the setLinkAddress(). Can anyone tell me what is the correct format that I should use to specify the name of the target sheet?

Was it helpful?

Solution

I have figured out the solution for this problem. As I had doubted it has to do with the format of the name of the target sheet. There is some specific length for the name of the target sheet beyond which "Invalid Range" error will thrown in Open office. We can reduce the length of the sheet name while we are creating it. I do not know the exact length but from what I've seen it should only be long enough so that it can be displayed completely in the sheet tab at the bottom of the open office screen.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top