Reputation: 1
I am trying to add hyperlink to excel file from OpenXML, which I am not able to. Have read somewhere that need to add relationships tag for hyperlink and then refer that id with hyperlink tag, but how to add this relationship tag is I am not getting. Kindly provide me sample code or any guidance as to how to achieve it.
Upvotes: 0
Views: 1388
Reputation: 48376
You don't need to worry about the relationships or anything like that, POI will take care of it all for you.
The code to add a hyperlink is the same for HSSF (.xls) and XSSF (.xlsx), and is included on the POI website: http://poi.apache.org/spreadsheet/quick-guide.html#Hyperlinks
The code is basically something like:
Workbook wb = new XSSFWorkbook();
CreationHelper createHelper = wb.getCreationHelper();
Sheet sheet = wb.createSheet("Hyperlinks");
cell = sheet.createRow(0).createCell(Cell.CELL_TYPE_STRING);
cell.setCellValue("URL Link");
Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL);
link.setAddress("http://poi.apache.org/");
cell.setHyperlink(link);
Upvotes: 1