Monday, 15 June 2015

Unable to open hyperlinked files in Excel with JAVA using Apache POI -



Unable to open hyperlinked files in Excel with JAVA using Apache POI -

i'm trying open files linked in excel sheet using apache poi. i've got:

fileinputstream inputstream = new fileinputstream(file); workbook = new hssfworkbook(inputstream); hssfsheet sheet = workbook.getsheetat(0); log("processing sheet: " + sheet.getsheetname()); iterator rowiterator = sheet.iterator(); while (rowiterator.hasnext()) { hssfrow row = (hssfrow) rowiterator.next(); iterator celliterator = row.celliterator(); while (celliterator.hasnext()) { hssfcell cell = (hssfcell) celliterator.next(); if(cell.gethyperlink() != null){ hssfhyperlink hyperlink = cell.gethyperlink(); log("hyperlink found: " + hyperlink.getaddress()); try{ fileinputstream fs = new fileinputstream(hyperlink.getaddress()); }catch(exception ex){ log(ex.getmessage()); } } } }

but hyperlink.getaddress() doesn't homecoming right path, looks returns relative path without ../.

i tried using getdirectoryroot() method on workbook. returns /. have path excel file without base of operations path excel uses or ../'s in attachments path, i'm not able right path.

instead can utilize 1 easier way: take file relative address , absolute path of file.

e.g.

system.out.println(new file(hyperlink.getaddress()).getabsolutepath());

java excel apache apache-poi

No comments:

Post a Comment