当前位置:网站首页>Here comes a new chapter in the series of data conversion when exporting with easyexcel!
Here comes a new chapter in the series of data conversion when exporting with easyexcel!
2022-07-02 05:27:00 【It snows at night when the boat is moored, and he can expect it】
Come on. ~ Use EasyExcel A new chapter in a series of data conversion when exporting !
A synopsis of antecedents
Before using EasyExcel When performing data export function , Type conversion processing ( Payment type 、 men and women 、 Other types, etc ) It's all for if else Judgment processing , Recently used Map To process , Record it here .
Code implementation
// Mode one
public class DemoTypeConverter implements Converter<String> {
public static final Map<String,String> DEMO_TYPE_MAP = ImmutableMap.<String,String>builder()
.put(" type 1","01")
.put(" type 2","02")
.put(" type 3","03")
.put(" type 4","04")
.put(" type 5","05")
.put(" type 6","06")
.put(" type 7","07").build();
@Override
public Class supportJavaTypeKey() {
return String.class;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return CellDataTypeEnum.STRING;
}
@Override
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
if (StringUtils.isBlank(cellData.getStringValue())){
return "";
}
return DEMO_TYPE_MAP.getOrDefault(cellData.getStringValue(),"");
}
@Override
public CellData convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
return null;
}
}
// Mode two
public class DemoTypeConverter implements Converter<String> {
public static final Map<String,String> DEMO_TYPE_MAP = ImmutableMap.<String,String> of(
" type 1","01",
" type 2","02",
" type 3","03",
" type 4","04"
);
@Override
public Class supportJavaTypeKey() {
return String.class;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return CellDataTypeEnum.STRING;
}
@Override
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
if (StringUtils.isBlank(cellData.getStringValue())){
return "";
}
return DEMO_TYPE_MAP.getOrDefault(cellData.getStringValue(),"");
}
@Override
public CellData convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
return null;
}
}
summary
As can be seen from the above code , The difference between the two methods is only Map Are constructed in different ways , Other code logic is the same . If there are many types, it is recommended to adopt method 1 , Less than or equal to 4 Method 2 .
边栏推荐
- 【pyinstaller】_get_sysconfigdata_name() missing 1 required positional argument: ‘check_exists‘
- Set the default style of scroll bar Google browser
- Fabric. JS upload local image to canvas background
- Php/js cookie sharing across domains
- kmp思想及模板代码
- 摆正元素(带过渡动画)
- Fabric. JS centered element
- php/js cookie共享跨域的问题
- Gee: remote sensing image composite and mosaic
- [technical notes-08]
猜你喜欢
随机推荐
Nodejs (03) -- custom module
Briefly introduce chown command
【pyinstaller】_get_sysconfigdata_name() missing 1 required positional argument: ‘check_exists‘
Principle and implementation of parallax effect
Visual Studio導入
Gee data set: export the distribution and installed capacity of hydropower stations in the country to CSV table
Fabric. JS centered element
Record sentry's path of stepping on the pit
Fabric.js IText 手动设置斜体
paddle: ValueError:quality setting only supported for ‘jpeg‘ compression
Implementation of go language for deleting duplicate items in sorting array
7. Eleven state sets of TCP
LeetCode 1175. Prime number arrangement (prime number judgment + Combinatorial Mathematics)
Dark horse notes -- map set system
Implementation of leetcode two number addition go
Gee series: Unit 1 Introduction to Google Earth engine
brew install * 失败,解决方法
金融门户相关信息
Mysql基础---查询(1天学会mysql基础)
Pyechart1.19 national air quality exhibition








