Search in sources :

Example 1 with BaseExcelModel

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

the class CommentWriteHandler method afterCellDispose.

/**
 * 数据批注处理
 * <p>
 * 包含回写异常数据
 */
@Override
public void afterCellDispose(CellWriteHandlerContext context) {
    int dataIndex = context.getRelativeRowIndex();
    if (context.getHead() || V.isEmpty(dataList) || dataList.size() <= dataIndex) {
        return;
    }
    BaseExcelModel excelModel = dataList.get(dataIndex);
    String fieldName = context.getHeadData().getFieldName();
    Cell cell = context.getCell();
    // 批注写入
    String comment = S.join(excelModel.getComment().get(fieldName), ";\n");
    if (V.notEmpty(comment)) {
        Sheet sheet = context.getWriteSheetHolder().getSheet();
        cell.setCellComment(buildComment(sheet.createDrawingPatriarch(), cell.getColumnIndex(), sheet.getLastRowNum(), comment));
    }
    // 回写无效值
    Map<String, String> field2InvalidValueMap = excelModel.getField2InvalidValueMap();
    if (field2InvalidValueMap.containsKey(fieldName)) {
        cell.setCellValue(field2InvalidValueMap.get(fieldName));
    }
}
Also used : BaseExcelModel(com.diboot.file.excel.BaseExcelModel) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) Cell(org.apache.poi.ss.usermodel.Cell) Sheet(org.apache.poi.ss.usermodel.Sheet)

Aggregations

BaseExcelModel (com.diboot.file.excel.BaseExcelModel)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