GitHub user body2k created a discussion: 我想修改单元格里的文本,任意字符的的颜色。为什么不生效

`public class PartialRedTextHandler implements CellWriteHandler {

    @Override
    public void afterCellCreate(CellWriteHandlerContext context) {
        CellWriteHandler.super.afterCellCreate(context);
    }

    @Override
    public void afterCellDispose(CellWriteHandlerContext context) {
        Cell cell = context.getCell();
        // 拿到poi的workbook
        Workbook workbook = context.getWriteWorkbookHolder().getWorkbook();
        CellStyle baseCellStyle = getBaseCellStyle(workbook);
        int rowIndex = cell.getRowIndex();
        // 只处理非表头行
        if (rowIndex == 0) {
            return;
        }
        // 如果内容不是字符串类型
        if (cell.getCellType() == CellType.STRING) {
            String stringValue = cell.getStringCellValue();
            XSSFRichTextString richString = new XSSFRichTextString(stringValue);
            Font font = workbook.createFont();
            font.setColor(0,1IndexedColors.RED.getIndex());
            richString.applyFont(font);
            cell.setCellValue(richString);
        }
        cell.setCellStyle(baseCellStyle);
        context.getFirstCellData().setWriteCellStyle(null);
    }`

GitHub link: https://github.com/apache/fesod/discussions/894

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to