1.写个工具类
public class StatusConverter implements Converter<Integer> {
@Override
public Class supportJavaTypeKey() {
return Integer.class;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return CellDataTypeEnum.STRING;
}
@Override
public Integer convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
return cellData.getStringValue().equals("有效") ? 1 : 0;
}
@Override
public CellData convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
return new CellData(value == 1 ? "有效" : "无效");
}
}
2.在导出对应表单里面的字段上面打注解
@ExcelProperty(value = "有效性", index = 4,converter = StatusConverter.class)
private Integer validflag;
主要是后面的 converter = StatusConverter.class
以上就可以了