0

I am using the apache poi package to generate excel workbooks. In the workbook I include cells with hyperlinks, using URLs containing fragments (#frag). In the resulting cells, the # character in the url has been encoded which makes it a different URL.

My question: Is there any way to preserve the URL provided as is?

My code:

        Cell cell = row.createCell(index);
        cell.setCellValue("the link");
        HSSFHyperlink link = workbook.getCreationHelper().createHyperlink(HSSFHyperlink.LINK_URL);
        link.setAddress("http://localhost:3000/#/search/pattern");
        cell.setHyperlink(link);

The url opened in the browser after clicking on the link in the generated spreadsheet

http://localhost:3000/%23/search/pattern

Any pointer appreciated.

jbelis
  • 575
  • 2
  • 6
  • 16
  • 2
    I have tried your code and Apache POI is not changing the `#` to `%23`. If you see the excel file and do 'Edit Hyperlink', you will see that the url does have a `#`. Its the browser that resolves `#` to `%23` – LittlePanda Apr 19 '15 at 15:12
  • You are correct the issue is not with the library. I now see that the excel replacement I am using has the correct link. – jbelis May 22 '15 at 09:23

1 Answers1

0

I have same issue about #value -> %23..

so i use this. "setCellFormula"

String link = "http://localhost:3000/#/search/pattern";
Cell cell = row.createCell(index);
cell.setCellFormula("HYPERLINK(\""+link+"\", \"link\")");
hoonzi
  • 1
  • 1