Search in sources :

Example 1 with ExcelComment

use of com.diboot.file.excel.annotation.ExcelComment in project diboot by dibo-software.

the class CommentWriteHandler method afterCellCreate.

/**
 * 头部批注处理
 */
@Override
public void afterCellCreate(CellWriteHandlerContext context) {
    Head head = context.getHeadData();
    List<String> headNames = head.getHeadNameList();
    int lastHeadIndex = headNames.size() - 1;
    Integer rowIndex = context.getRowIndex();
    if (!context.getHead() || rowIndex != lastHeadIndex && !headNames.get(rowIndex).equals(headNames.get(lastHeadIndex))) {
        return;
    }
    ExcelComment comment = AnnotationUtils.getAnnotation(head.getField(), ExcelComment.class);
    // 空批注不写入
    if (comment == null || V.isEmpty(comment.value())) {
        return;
    }
    Sheet sheet = context.getWriteSheetHolder().getSheet();
    Cell cell = context.getCell();
    cell.setCellComment(buildComment(sheet.createDrawingPatriarch(), cell.getColumnIndex(), sheet.getLastRowNum(), comment.value()));
}
Also used : ExcelComment(com.diboot.file.excel.annotation.ExcelComment) Head(com.alibaba.excel.metadata.Head) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell)

Aggregations

Head (com.alibaba.excel.metadata.Head)1 ExcelComment (com.diboot.file.excel.annotation.ExcelComment)1 Cell (org.apache.poi.ss.usermodel.Cell)1 Sheet (org.apache.poi.ss.usermodel.Sheet)1 XSSFRichTextString (org.apache.poi.xssf.usermodel.XSSFRichTextString)1