1.看很多资料还是有问题 于是想到可以用转换器来实现
这是原来的方式
xml
@NumberFormat(value = "#.##%")
private BigDecimal proportion;
请看大屏幕
xml
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.alibaba.excel.util.NumberUtils;
import java.math.BigDecimal;
import java.text.ParseException;
public class BigDecimalAddPercentConverter implements Converter<BigDecimal> {
public BigDecimalAddPercentConverter() {
}
public Class<BigDecimal> supportJavaTypeKey() {
return BigDecimal.class;
}
public CellDataTypeEnum supportExcelTypeKey() {
return CellDataTypeEnum.STRING;
}
public BigDecimal convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws ParseException {
return NumberUtils.parseBigDecimal(cellData.getStringValue(), contentProperty);
}
public WriteCellData<?> convertToExcelData(BigDecimal value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
return new WriteCellData<>(value+"%");
}
}
其实也很简单哈
修改后的
xml
@ExcelProperty(converter = BigDecimalAddPercentConverter.class)
private BigDecimal proportion;