[alibaba/easyexcel]03格式公式类型单元格无法获取DataFormatData

2024-05-10 767 views
9

03格式excel,单元格为公式,并设置单元格格式为数值,2位小数。

触发Bug的代码

   public class XLSBigDecimalConverter implements Converter<BigDecimal> {

    public Class<?> supportJavaTypeKey() {
        return BigDecimal.class;
    }

    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.NUMBER;
    }

    public BigDecimal convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        BigDecimal val = cellData.getNumberValue();

        if (cellData.getDataFormatData() != null) {
            String format = cellData.getDataFormatData().getFormat();
            System.out.println(format);           
         }
        return val;
    }

    public WriteCellData<?> convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return null;
    }

}

cellData.getDataFormatData() 为空。代码错误应该在 FormulaRecordHandler 没有将DataFormat设置给tempCellData

回答

4

hello, please give me some time to fix it, thanks. If you have more detailed information, you can contact me or comment here.

1

@Melody0321 我也遇到了这个问题,表现是03版Excel, 单元格格式是 日期,公式是: Date(2022,5,6),排查下来, 是否可以修改类:FormulaRecordHandler, 在 ln: 63 增加如下代码: tempCellData.setDataFormatData(dataFormatData);

0

该问题已经在3.1.0+版本里面解决,最新版本:Maven central