Reputation: 81
I am trying to create hyperlink using apache poi which points to a URL. This URL returns a file which is a PDF file. I have written the code as below to create a link
HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_URL);
link.setAddress(cellValue);
cell.setHyperlink(link);
cell.setCellValue(cellValue);
I am getting the link in Excel sheet properly and able to open the link in every editor except Microsoft Excel. It throws an error Cannot open the link. I am able to open the link in Google Sheets, Open Office etc.
Please help me out as I am not sure this is a known issue or something I am missing
Upvotes: 2
Views: 1985
Reputation: 11
If you export excel in .xls format then use HSSFHyperlink. For .xlxs use XSSFHyperlink class. It is working in apache poi 3.10
cell.setCellValue("URL Link");
HSSFHyperlink link1 =(HSSFHyperlink)createHelper.createHyperlink(Hyperlink.LINK_URL);
link1.setAddress("http://www.google.com/");
cell.setHyperlink((HSSFHyperlink) link1);
cell.setCellStyle(hlink_style);
Upvotes: 1
Reputation: 21
I think it is the problem with Apache poi. If you have the hyperlinks that require login details, cookie will not be set in the excel which will lead to login page again. Hence, I tried working around by setting the cookies.
First I tried creating a URL along with the user details encoded Once in excel, if you click on the URL, I opened another page which will verify the user details and redirects to the required page.
Upvotes: 0
Reputation: 20142
I created Hyperlinks using this Example. I had to change to .xlsx
to .xls
to be able to open the file in MS Excel 2010 but the links are working fine.
But your code looks good as well.
Upvotes: 0