参考:常见api
java.text.DecimalFormat用法详解
使用场景:
比如Long 数字,身份证号码,如果直接导出excel,数字后面会变成0,这个时候需要把数字转成字符串才可以不失真。
这个注解最后还是数字格式,并不能把数字转字符串
@NumberFormat(value = "#.##%")
使用自定义转换器
参考:
EasyExcel自定义转换器
@ExcelProperty(converter = TjEasyExcelLongConverter.class)
package com.tj.utils.easyExcel;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
public class TjEasyExcelLongConverter implements Converter<Long> {
@Override
public WriteCellData<?> convertToExcelData(Long value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
String res = String.valueOf(value); //把Long转成字符串
return new WriteCellData<String>(res);
}
}