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