当前位置:网站首页>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 .
边栏推荐
- Installation du tutoriel MySQL 8.0.22 par centos8
- Php/js cookie sharing across domains
- Implementation of go language for deleting duplicate items in sorting array
- Gee series: Unit 2 explore datasets
- Global and Chinese market of cell culture freezers 2022-2028: Research Report on technology, participants, trends, market size and share
- php/js cookie共享跨域的问题
- Reflection of the soul of the frame (important knowledge)
- Fabric. JS gradient
- Essence and physical meaning of convolution (deep and brief understanding)
- Visual studio import
猜你喜欢

Dark horse notes -- Set Series Collection

Youth training camp -- database operation project

Nodejs (03) -- custom module

LeetCode 1175. 质数排列(质数判断+组合数学)

Fabric. JS iText set italics manually
![[technical notes-08]](/img/52/0aff21b01ba7adbfcdb597d1aa85f9.png)
[technical notes-08]

【pyinstaller】_ get_ sysconfigdata_ name() missing 1 required positional argument: ‘check_ exists‘

Record sentry's path of stepping on the pit

Disable access to external entities in XML parsing

Using QA band and bit mask in Google Earth engine
随机推荐
Splice characters in {{}}
Sliding window on the learning road
centos8安装mysql8.0.22教程
Fabric. JS background is not affected by viewport transformation
Operator details
Fabric.js IText 上标和下标
The reason why sizeof (ARR) / sizeof (arr[0]) is used in the function to calculate the length of the array is incorrect
Gee: explore the characteristics of precipitation change in the Yellow River Basin in the past 10 years [pixel by pixel analysis]
LeetCode 241. 为运算表达式设计优先级(分治/记忆化递归/动态规划)
php/js cookie共享跨域的问题
指针使用详解
Gee series: Unit 2 explore datasets
How matlab marks' a 'in the figure and how matlab marks points and solid points in the figure
Disable access to external entities in XML parsing
Ubuntu 20.04 installing mysql8
LeetCode 1175. Prime number arrangement (prime number judgment + Combinatorial Mathematics)
Fabric.js 基础笔刷
MySQL foundation --- query (learn MySQL foundation in 1 day)
Global and Chinese market of insulin pens 2022-2028: Research Report on technology, participants, trends, market size and share
Leetcode 18 problem [sum of four numbers] recursive solution