How to create Hypelink into Excel using openxml in Java
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开发者_Python百科 relationship tag is I am not getting. Kindly provide me sample code or any guidance as to how to achieve it.
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);
精彩评论