0

I am writting some text say "Pass" into excel file using cell.setCellValue("Pass"). Now I have to create a link to an image which locates at directory (C:\Users\UserName\DeskTop\image\test.jpg) from an excel.

When I click on text pass from excel file, then it should open the test.jpg image.

Please guide me/share to JAVA code to achieve this.

Thanks, Md Ashfaq

Harshavardhan Konakanchi
  • 4,238
  • 6
  • 36
  • 54
mdashu
  • 225
  • 1
  • 6
  • 14

2 Answers2

1

Ashfaq...Following is a method you can user for hyperlink the screenshot with the cell.

 public static void hyperlinkScreenshot(XSSFCell cell, String FileAddress){
    XSSFWorkbook wb=cell.getRow().getSheet().getWorkbook();
    CreationHelper createHelper = wb.getCreationHelper();
    CellStyle hlink_style = wb.createCellStyle();
    Font hlink_font = wb.createFont();
    hlink_font.setUnderline(Font.U_SINGLE);
    hlink_font.setColor(IndexedColors.BLUE.getIndex());
    hlink_style.setFont(hlink_font);
    Hyperlink hp = createHelper.createHyperlink(Hyperlink.LINK_FILE);
    FileAddress=FileAddress.replace("\\", "/");
    hp.setAddress(FileAddress);
    cell.setHyperlink(hp);
    cell.setCellStyle(hlink_style);
}

for details check here.

Community
  • 1
  • 1
Sankumarsingh
  • 9,889
  • 11
  • 50
  • 74
0
Cell.Hyperlinks.Add Anchor:=Selection, Address:= _
        "C:\Users\UserName\DeskTop\image\test.jpg", TextToDisplay:="pass"

You can remove the setvalue as TextToDisplay can handle this...

Vasim
  • 3,052
  • 3
  • 35
  • 56
  • i used the same code but its giving errors in eclipse. I am new to this POI, can u re-write the complete code with more clarity. I am using cell = row.createCell(Colposition) to get the cell value – mdashu Jul 29 '13 at 10:03