少言少语

静以修身,俭以养德

  menu
39 文章
12543 浏览
0 当前访客
ღゝ◡╹)ノ❤️

EasyPoi导出字段为超链接

wallhavenymwj9d.jpg

看文档 http://easypoi.mydoc.io/

步骤一

  • 字段上面开启超链接
@Excel(name = "地址", isHyperlink = true)
private String path;

步骤二

  • 实现拦截类

image.png

  • 代码实现
public class ExcelDataHandler extends ExcelDataHandlerDefaultImpl<Object> {
    @Override
    public Hyperlink getHyperlink(CreationHelper creationHelper, Object obj, String name, Object value) {
        Hyperlink hyperlink = creationHelper.createHyperlink(HyperlinkType.URL);
        hyperlink.setLabel(name);
        hyperlink.setAddress((String) value);
        return hyperlink;
    }
}

Object为操作类

步骤三

  • 将拦截类加载导出方法
ExportParams exportParams = new ExportParams(title, sheetName);
        exportParams.setDataHandler(new ExcelDataHandler());
        ExportExcelUtil.exportExcel(list, Object.class, fileName, response, exportParams);

Object操作模板

结束


标题:EasyPoi导出字段为超链接
作者:JssDream
地址:https://www.hjava.cn/articles/2020/06/17/1592396658708.html