问题描述
我正在使用Apache POI生成包含多个工作表的excel工作簿。我想创建一个超链接从一张纸到另一张。如何完成这个我找到了建立超链接到网站,甚至其他excel文件,但不是在同一个工作簿中的其他工作表的解决方案。 Apache POI是否允许我们这样做?
I am using Apache POI to generate an excel workbook containing multiple sheets. I want to create a hyperlink from one sheet to another. How to accomplish this ? There are solutions I found for establishing hyperlinks to websites, even other excel files but not to other sheets within the same workbook. Does Apache POI allow us to do this ?
推荐答案
是的,Apache POI允许您创建一个超链接到另一张表工作簿。根据:
Yes, Apache POI allows you to create a hyperlink to another sheet in the same workbook. According to the Apache POI Quick Guide:
cell = sheet.createRow(3).createCell((short)0);
cell.setCellValue("Worksheet Link");
Hyperlink link2 = createHelper.createHyperlink(Hyperlink.LINK_DOCUMENT);
link2.setAddress("'Target Sheet'!A1");
cell.setHyperlink(link2);
cell.setCellStyle(hlink_style);
这将创建一个超级链接的单元格,类型为 LINK_DOCUMENT
,具有单元格引用的地址,可以在同一个表或另一个表中。然后,将单元格样式设置为现有单元格样式(在代码示例中创建),以使其看起来像超链接。
This creates a cell with a hyperlink in it of type LINK_DOCUMENT
, with an address of a cell reference, which can be in the same sheet or another sheet. Then it sets the cell style to an existing cell style (created earlier in the code sample), so that it looks like a hyperlink.
这篇关于使用apache poi超链接到同一工作簿中的不同工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!