How to get hyperlink address from a cell in excel by using java? -
i know how use javaexcelapi (jxl) or apache poi read string information of cell in excel file writing java code. got problem:
a cell contains string hyperlink on it. can read string in cell, don't know how read hyperlink address through java.
the method you're looking cell.gethyperlink(), returns either null (cell has no hyperlink) or hyperlink object
if wanted fetch hyperlink url of cell b2 of test.xls, you'd like:
workbook wb = workbookfactory.create(new file("test.xls")); sheet s = wb.getsheetat(0); row r2 = s.getrow(1); // rows in poi 0 based cell cb2 = r2.getcell(1); // cells 0 based hyperlink h = cb2.gethyperlink(); if (h == null) { system.err.println("cell b2 didn't have hyperlink!"); } else { system.out.println("b2 : " + h.getlabel() + " -> " + h.getaddress()); }
Comments
Post a Comment