I am trying to hyperlink a .png file in a cell content of any .xlsx file. Following is the part of code and it is showing java.net.URISyntaxException exception (seems because of slash used in the address). However changing link.setAddress("test.png") is not showing any error, but it is not resolving my purpose. Please help me.
public static void main(String[]args) throws Exception{
XSSFWorkbook wb = new XSSFWorkbook();
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);
XSSFSheet sheet = wb.createSheet("Hyperlinks");
XSSFCell cell = sheet.createRow(1).createCell((short)0);
cell.setCellValue("File Link");
Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_FILE);
link.setAddress("H:\\Selenium\\XL\\src\\santosh\\xlwork\\test.png");
cell.setHyperlink(link);
cell.setCellStyle(hlink_style);
FileOutputStream out = new FileOutputStream("hyperlinks.xlsx");
wb.write(out);
out.close();
}
Ultimately what I need to do is to hyperlink a screenshot with any cell. The screenshot directory will be anywhere other than eclipse workspace.