poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Faraz Rozi" <frozi2...@gmail.com>
Subject Problem setting hyperlink to files outside of current directory
Date Fri, 14 Mar 2008 18:53:48 GMT
Hey everyone,

  I'm having issues with hyper links. I am trying to set a link in excel
using the new setHyperlink method from HSSFCell, which I got from SVN
checkout. I'm following online template for doing this but instead of simply
putting in the file name in String format I'm doing file.getAbsolutePath()
which also returns a String. For those wondering, using .getCanonicalPath()
produces the same results. This file variable holds the path to the file I
wish to link to. The problem is that while it looks like it creates the
hyper link in the excel sheet and displays the file name as the link label,
clicking on the link produces the following excel error message:

The address of this site is not valid. Check the address and try again.

Here's where it gets interesting. If I select the hyper link and choose
EDIT, it correctly displays the path in the new dialog window. If I choose
OK, without changing ANYTHING, it fixes the link and I can now click it and
it will take me to the file! This almost feels like my previous problem with
evaluating formulas, where I had to re-evaluate formulas to get appropriate
answers. Is there a similar method for hyper links? Thanks guys.

Here is the code:

public void setFileLinkValue(File file, int row, int col)
            HSSFCellStyle hlink_style = workBook.createCellStyle();
            HSSFFont hlink_font = workBook.createFont();
            HSSFRow sheetRow;
            HSSFCell cell;
            sheetRow = sheet.getRow(row);
            cell = sheetRow.getCell((short) col);
            HSSFHyperlink link = new HSSFHyperlink(HSSFHyperlink.LINK_FILE);

            //link to a file corresponding to row entry

            cell.setCellValue(new HSSFRichTextString(file.getName()));

            outputStream = new FileOutputStream("C:\\test.xls");
        catch (FileNotFoundException e)
            System.out.println("file not found\n");
        catch (IOException e)
            System.out.println("IO Exception\n");

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message