触发场景描述
直接产生异常处:
对应的调用报错栈
java.lang.NullPointerException
at com.alibaba.excel.write.style.row.AbstractRowHeightStyleStrategy.afterRowDispose(AbstractRowHeightStyleStrategy.java:22)
at com.alibaba.excel.write.handler.chain.RowHandlerExecutionChain.afterRowDispose(RowHandlerExecutionChain.java:47)
at com.alibaba.excel.util.WriteHandlerUtils.afterRowDispose(WriteHandlerUtils.java:178)
at com.alibaba.excel.write.executor.ExcelWriteFillExecutor.doFill(ExcelWriteFillExecutor.java:297)
at com.alibaba.excel.write.executor.ExcelWriteFillExecutor.fill(ExcelWriteFillExecutor.java:130)
at com.alibaba.excel.write.ExcelBuilderImpl.fill(ExcelBuilderImpl.java:82)
at com.alibaba.excel.ExcelWriter.fill(ExcelWriter.java:110)
at com.alibaba.excel.ExcelWriter.fill(ExcelWriter.java:98)
图示:
触发Bug的代码
@Test
public void testDemo() {
WriteSheet writeSheet = EasyExcelFactory.writerSheet("Sheet1").build();
ExcelWriter excelWriter = EasyExcel.write(fileName)
// 加入拦截就会出现问题
.registerWriteHandler(new CustomCellWriteHeightConfig())
.withTemplate(testTemplate)
.build();
// 这里 会填充到第一个sheet, 然后文件流会自动关闭
FillData fillData = new FillData();
fillData.setName("张三");
fillData.setNumber(5.2);
excelWriter.fill(fillData,writeSheet);
excelWriter.finish();
}
个人想法
doFill(readTemplateData(templateAnalysisCache), realData, fillConfig, null);
RowWriteHandlerContext rowWriteHandlerContext = WriteHandlerUtils.createRowWriteHandlerContext(writeContext,
null, relativeRowIndex, Boolean.FALSE);
并且其中的 relativeRowIndex
和 head
属性都是上下文固定传入的,在 AbstractRowHeightStyleStrategy
类中的方法setHeadColumnHeight
和 setContentColumnHeight
if (context.getHead()) {
setHeadColumnHeight(context.getRow(), context.getRelativeRowIndex());
} else {
setContentColumnHeight(context.getRow(), context.getRelativeRowIndex());
}
用的是基类int接收参数null是不允许的。
考虑是否能换成包装类型接收,若有不能空的逻辑则再做判空处理。
2条答案
按热度按时间fzsnzjdm1#
这个bug到现在没修复吗?遇到同样问题了
mtb9vblg2#
同样的问题,使用doFill()出现,更新至 4.0.2仍然存在,这是我的报错: