easypoi插入超链接

今天遇到个问题,在excel中插入超链接,用于直接打开表格链接的文件

1. 类似这种,ctrl+鼠标左键能直接打开,下面用easypoi来实现

《easypoi插入超链接》

2. 查看easypoi文档,字段@Excel注解属性 isHyperlink = true 打开超链接插入功能

《easypoi插入超链接》

3. 实际代码实现

  1. 实体类字段属性开启超链接
@Excel(name = "参数(input)", orderNum = "12", isHyperlink = true)
private String input;
@Excel(name = "返回值(returnInfo)", orderNum = "13", isHyperlink = true)
private String returnInfo;
  1. 编写属性拦截器
/**
 * @author :yepk
 * @version :1.0
 * @apiNote :用于导出
 * @date :2019-04-24-9:25
 */

public class ExcelDataHandler extends ExcelDataHandlerDefaultImpl<ShakerRequestLogInfo> {
    @Override
    public Hyperlink getHyperlink(CreationHelper creationHelper, ShakerRequestLogInfo obj, String name, Object value) {
        Hyperlink hyperlink = creationHelper.createHyperlink(HyperlinkType.FILE);
        hyperlink.setLabel(name);
        hyperlink.setAddress((String) value);
        return hyperlink;
    }
}
  1. 导出参数设置数据拦截器
ExportParams params = new ExportParams(String.format("%s-日志", date), last);
params.setDataHandler(new ExcelDataHandler());
  1. 给对应实体类字段添加 超链接
// 本例子采用绝对路径
String inputPath = "txt/" + System.currentTimeMillis() + "-input.txt";
// 具体逻辑自行书写
info.setInput(inputPath);
    原文作者:yepk
    原文地址: https://blog.csdn.net/u014764722/article/details/106850646
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞