使用apache poi创建超链接

时间:2021-01-02 20:23:50

I am trying to create a hyperlink using the following code

我正在尝试使用以下代码创建超链接

CreationHelper createHelper = wb.getCreationHelper();
cell.setCellValue("Click Here");
Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_FILE);

File f = new File("C:\\Test\\1.pdf");
link.setAddress(f.getCanonicalPath());
cell.setHyperlink((org.apache.poi.ss.usermodel.Hyperlink) link);

It works fine and it adds a link Click Here to the cell

它工作正常,它添加一个链接单击此处到单元格

But how i can set a partial text and a link using same type of code,
I mean the link need to be like your file is here, where only here is the link

但是我如何使用相同类型的代码设置部分文本和链接,我的意思是链接需要像你的文件在这里,这里只有链接

1 个解决方案

#1


4  

As far as I know I don't think it is possible, as it is not supported by Excel as well. To achieve that in Excel too there is no straight way and you have to do some tricks to achieve that. Something that is not supported right from Excel cannot be supported by Apache POI too.

据我所知,我不认为这是可能的,因为它也不支持Excel。要在Excel中实现这一点,也没有直接的方法,你必须做一些技巧来实现这一点。 Apache POI也不支持Excel中不支持的东西。

#1


4  

As far as I know I don't think it is possible, as it is not supported by Excel as well. To achieve that in Excel too there is no straight way and you have to do some tricks to achieve that. Something that is not supported right from Excel cannot be supported by Apache POI too.

据我所知,我不认为这是可能的,因为它也不支持Excel。要在Excel中实现这一点,也没有直接的方法,你必须做一些技巧来实现这一点。 Apache POI也不支持Excel中不支持的东西。