JXL read Hyperlink cell from Excel using Java -


i trying read hyperlink cell excel spreadsheet i'm unable so. when go spreadsheet , remove hyperlink reads fine. did come across solution below in question (how hyperlink address cell in excel using java?) gethyperlink method works sheet , not cell confusing me.

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()); } 

this code now

import jxl.cell; import jxl.sheet; import jxl.workbook; import jxl.read.biff.biffexception;  public string[] readusernamefromexcel() {         file src = new file("c:/filepath.xls");         string ex[] = new string[10];          try {              workbook wb = workbook.getworkbook(src);             sheet sh1 = wb.getsheet(0);              cell a3 = sh1.getcell(0, 2);             cell b3 = sh1.getcell(1,2);               cell c2 = sh1.getcell(2,1); //this cell want read hyperlink              ex[0] = a3.getcontents().trim();             ex[1] = b3.getcontents().trim();             ex[2] = c2.getcontents().trim();              system.out.println(ex[0]);             system.out.println(ex[1]);             system.out.println(ex[2]); 

so have tried is

hyperlink h = c2.gethyperlink();  

but gethyperlink not work when used cell.

enter image description here

and dont have option add gethyperlink() method

enter image description here

but when use sheet appear, although appears hyperlinks , array.

enter image description here

i feel though i'm close cant figure out i'm missing or doing wrong me on link appreciated, in advance!

i decided use apache poi instead that's gethyperlink method is. , works charm. i've posted code below in hope finds useful if find in same situation in trying change jxl apache poi! if you're using .xslx need use xssf instead of hssf (http://www.codejava.net/coding/how-to-read-excel-files-in-java-using-apache-poi)

 public string[] readusernamefromexcel() {         string ex[] = new string[10];         try {              fileinputstream fileinputstream = new fileinputstream("filepath.xls");             hssfworkbook workbook = new hssfworkbook(fileinputstream);             hssfsheet worksheet = workbook.getsheetat(0);             hssfrow row1 = worksheet.getrow(2);             hssfcell cella3 = row1.getcell(0);             ex[0] = string.valueof(cella3.getnumericcellvalue()).trim();              hssfrow row2 = worksheet.getrow(2);             hssfcell cellb3 = row2.getcell(1);             ex[1] = cellb3.getstringcellvalue();              hssfrow row3 = worksheet.getrow(1);              hssfcell cellc2 = row3.getcell(2);             hyperlink h = cellc2.gethyperlink();             ex[2] = h.getaddress();              system.out.println("a3: " + ex[0]);             system.out.println("b3: " + ex[1]);             system.out.println("c2: " + ex[2]);          }catch (filenotfoundexception e) {             e.printstacktrace();         }catch (ioexception e) {             e.printstacktrace();}   return ex;      } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -