Hutool 生成excel 批注

  • • 发表于2019-02-25 16:34:44.0
  • • 作者 小徐同学
  • • 187 次浏览
  • • 0 条评论
  • • 最后编辑时间 2019-03-01 09:52:32.0
  • • 来自 [笔 记]

原创声明:本文为作者原创,未经允许不得转载,经授权转载需注明作者和出处

public static void main(String[] args) {
        //标题
        List<String> row1 = CollUtil.newArrayList("姓名", "性别", "昵称", "哈哈");

        List<String> row2 = CollUtil.newArrayList("aa1", "bb1", "cc1", "dd1");
        List<String> row3 = CollUtil.newArrayList("aa2", "bb2", "cc2", "dd2");
        List<String> row4 = CollUtil.newArrayList("aa3", "bb3", "cc3", "dd3");
        List<String> row5 = CollUtil.newArrayList("aa4", "bb4", "cc4", "dd4");

        List<List<String>> rows = CollUtil.newArrayList(row1, row2, row3, row4, row5);

        // 通过工具类创建writer
        ExcelWriter writer = ExcelUtil.getWriter("C:\\temp\\temp.xlsx");

        // 一次性写出内容
        writer.write(rows);

        Sheet sheet = writer.getSheet();

        //批注
        Drawing<?> patr = sheet.createDrawingPatriarch();
        ClientAnchor anchor = patr.createAnchor(0, 0, 0,0, 3, 3, 5, 6);

        Comment cellComment = patr.createCellComment(anchor);
        cellComment.setString(new XSSFRichTextString("SBSB"));
        sheet.getRow(0).getCell(0).setCellComment(cellComment);

        Comment cellComment2 = patr.createCellComment(anchor);
        cellComment2.setString(new XSSFRichTextString("SBSB2"));
        sheet.getRow(0).getCell(1).setCellComment(cellComment2);

        // 关闭writer,释放内存
        writer.close();
    }
评论区(共0条评论)
0条评论
Ctrl+Enter
作者

Michael

小徐同学

帖子:34 回复:0

全栈搬运工

作者详情》
Top