当前位置:网站首页>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 .
边栏推荐
- Two implementation methods of delay queue
- Fabric. JS free draw rectangle
- Fabric. JS background is not affected by viewport transformation
- 7.1 Résumé du concours de simulation
- Centos8 installation mysql8.0.22 tutorial
- Sliding window on the learning road
- 黑马笔记---Set系列集合
- Gee series: Unit 2 explore datasets
- Global and Chinese market of hydrocyclone desander 2022-2028: Research Report on technology, participants, trends, market size and share
- 线程池概述
猜你喜欢

Centos8 installation mysql8.0.22 tutorial

Detailed explanation of Pointer use

Black Horse Notes - - set Series Collection

centos8安装mysql8.0.22教程

Fabric.js 居中元素

LeetCode 241. 为运算表达式设计优先级(分治/记忆化递归/动态规划)

No logic is executed after the El form is validated successfully

KMP idea and template code

【pyinstaller】_get_sysconfigdata_name() missing 1 required positional argument: ‘check_exists‘

Gee dataset: chirps pentad high resolution global grid rainfall dataset
随机推荐
Fabric. JS round brush
6.网络-基础
线程池批量处理数据
Disable access to external entities in XML parsing
Global and Chinese market of cell culture freezers 2022-2028: Research Report on technology, participants, trends, market size and share
【技术随记-08】
Mysql基础---查询(1天学会mysql基础)
Black Horse Notes - - set Series Collection
Fabric. JS free draw rectangle
Online English teaching app open source platform (customized)
Fabric.js 更换图片的3种方法(包括更换分组内的图片,以及存在缓存的情况)
LeetCode 1175. 质数排列(质数判断+组合数学)
Gee series: Unit 3 raster remote sensing image band characteristics and rendering visualization
Detailed explanation of Pointer use
Financial portal related information
Fabric.js 3个api设置画布宽高
Differential identities (help find mean, variance, and other moments)
Fabric.js 背景不受视口变换影响
php/js cookie共享跨域的问题
Fabric.js IText 上标和下标