Supports obtaining current row data object during writing

Search before asking

  • I searched in the issues and found nothing similar.

Motivation

在写入excel文件时,准备好数据后,写入文件对数据进行二次转换或者简单业务逻辑处理。不想再循环进行处理。可以在数据写入单元格的时候进行二次转换或者简单业务逻辑处理,此时,业务可能需要依赖行级完整对象数据。
示例:

class Data {
    private int a;
    private int b;
    private int c;
    private String text;
}

在生成text单元格内容,可能需要结合数据a、b、c进行逻辑判断。

Solution

希望在converter(WriteConverterContext)或handler(CellWriteHandlerContext)中传入 oneRowData

Cell cell = WorkBookUtil.createCell(row, columnIndex);
cellWriteHandlerContext.setCell(cell);

WriteHandlerUtils.afterCellCreate(cellWriteHandlerContext);

cellWriteHandlerContext.setOriginalRecord(oneRowData); // 传入当前行级数据
cellWriteHandlerContext.setOriginalValue(beanMap.get(name));
cellWriteHandlerContext.setOriginalFieldClass(head.getField().getType());
converterAndSet(cellWriteHandlerContext);

WriteHandlerUtils.afterCellDispose(cellWriteHandlerContext);

beanMapHandledSet.add(name);

Alternatives

No response

Anything else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!