fuliqi
2025-01-15 69cd43d9303ed7cd985bd64379b4cc5b0aecef14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.ycl.handler;
 
import com.alibaba.excel.util.BooleanUtils;
import com.alibaba.excel.write.handler.RowWriteHandler;
import com.alibaba.excel.write.handler.context.RowWriteHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Comment;
import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
 
/**
 * 自定义拦截器.新增注释,第一行头加批注
 *
 * @author gonghl
 */
@Slf4j
public class CommentWriteHandler implements RowWriteHandler {
 
    @Override
    public void afterRowDispose(RowWriteHandlerContext context) {
        if (BooleanUtils.isTrue(context.getHead())) {
            Sheet sheet = context.getWriteSheetHolder().getSheet();
            Drawing<?> drawingPatriarch = sheet.createDrawingPatriarch();
 
            Comment comment1 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0,  5, 5,  4, 6));
            comment1.setString(new XSSFRichTextString("扣除相关镜头数量*0.1分"));
            sheet.getRow(0).getCell(1).setCellComment(comment1);
 
//            Comment comment2 = drawingPatriarch.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, 5, 8,  7, 9));
//            comment2.setString(new XSSFRichTextString("扣2分/12小时"));
//            sheet.getRow(0).getCell(1).setCellComment(comment2);
 
        }
    }
 
}