使用 apache poi 超链接到同一工作簿中的不同工作表 [英] hyperlink to a different sheet within the same workbook using apache poi

查看:48
本文介绍了使用 apache poi 超链接到同一工作簿中的不同工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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 允许您创建指向同一工作簿中另一个工作表的超链接.根据 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 超链接到同一工作簿中的不同工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆