Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
苏木力格
easyexcel
提交
ae63dd2a
E
easyexcel
项目概览
苏木力格
/
easyexcel
与 Fork 源项目一致
从无法访问的项目Fork
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
easyexcel
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ae63dd2a
编写于
4月 22, 2020
作者:
庄家钜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
新增支持自定义转换器 入参可以为空 #1084
上级
a7db3cf0
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
26 addition
and
15 deletion
+26
-15
src/main/java/com/alibaba/excel/converters/NullableObjectConverter.java
...com/alibaba/excel/converters/NullableObjectConverter.java
+11
-0
src/main/java/com/alibaba/excel/write/executor/AbstractExcelWriteExecutor.java
...baba/excel/write/executor/AbstractExcelWriteExecutor.java
+8
-8
src/test/java/com/alibaba/easyexcel/test/temp/read/HeadListener.java
...va/com/alibaba/easyexcel/test/temp/read/HeadListener.java
+2
-2
src/test/java/com/alibaba/easyexcel/test/temp/read/HeadReadData.java
...va/com/alibaba/easyexcel/test/temp/read/HeadReadData.java
+2
-3
src/test/java/com/alibaba/easyexcel/test/temp/read/HeadReadTest.java
...va/com/alibaba/easyexcel/test/temp/read/HeadReadTest.java
+2
-2
update.md
update.md
+1
-0
未找到文件。
src/main/java/com/alibaba/excel/converters/NullableObjectConverter.java
0 → 100644
浏览文件 @
ae63dd2a
package
com.alibaba.excel.converters
;
/**
* When implementing <code>convertToExcelData</code> method, pay attention to the reference <code>value</code> may be
* null
*
* @author JiaJu Zhuang
**/
public
interface
NullableObjectConverter
<
T
>
extends
Converter
<
T
>
{
}
src/main/java/com/alibaba/excel/write/executor/AbstractExcelWriteExecutor.java
浏览文件 @
ae63dd2a
...
@@ -10,6 +10,7 @@ import org.apache.poi.ss.usermodel.Sheet;
...
@@ -10,6 +10,7 @@ import org.apache.poi.ss.usermodel.Sheet;
import
com.alibaba.excel.context.WriteContext
;
import
com.alibaba.excel.context.WriteContext
;
import
com.alibaba.excel.converters.Converter
;
import
com.alibaba.excel.converters.Converter
;
import
com.alibaba.excel.converters.ConverterKeyBuild
;
import
com.alibaba.excel.converters.ConverterKeyBuild
;
import
com.alibaba.excel.converters.NullableObjectConverter
;
import
com.alibaba.excel.enums.CellDataTypeEnum
;
import
com.alibaba.excel.enums.CellDataTypeEnum
;
import
com.alibaba.excel.exception.ExcelDataConvertException
;
import
com.alibaba.excel.exception.ExcelDataConvertException
;
import
com.alibaba.excel.metadata.CellData
;
import
com.alibaba.excel.metadata.CellData
;
...
@@ -32,11 +33,10 @@ public abstract class AbstractExcelWriteExecutor implements ExcelWriteExecutor {
...
@@ -32,11 +33,10 @@ public abstract class AbstractExcelWriteExecutor implements ExcelWriteExecutor {
protected
CellData
converterAndSet
(
WriteHolder
currentWriteHolder
,
Class
clazz
,
Cell
cell
,
Object
value
,
protected
CellData
converterAndSet
(
WriteHolder
currentWriteHolder
,
Class
clazz
,
Cell
cell
,
Object
value
,
ExcelContentProperty
excelContentProperty
,
Head
head
,
Integer
relativeRowIndex
)
{
ExcelContentProperty
excelContentProperty
,
Head
head
,
Integer
relativeRowIndex
)
{
if
(
value
==
null
)
{
boolean
needTrim
=
return
new
CellData
(
CellDataTypeEnum
.
EMPTY
);
value
!=
null
&&
(
value
instanceof
String
&&
currentWriteHolder
.
globalConfiguration
().
getAutoTrim
());
}
if
(
needTrim
)
{
if
(
value
instanceof
String
&&
currentWriteHolder
.
globalConfiguration
().
getAutoTrim
())
{
value
=
((
String
)
value
).
trim
();
value
=
((
String
)
value
).
trim
();
}
}
CellData
cellData
=
convert
(
currentWriteHolder
,
clazz
,
cell
,
value
,
excelContentProperty
);
CellData
cellData
=
convert
(
currentWriteHolder
,
clazz
,
cell
,
value
,
excelContentProperty
);
if
(
cellData
.
getFormula
()
!=
null
&&
cellData
.
getFormula
())
{
if
(
cellData
.
getFormula
()
!=
null
&&
cellData
.
getFormula
())
{
...
@@ -70,9 +70,6 @@ public abstract class AbstractExcelWriteExecutor implements ExcelWriteExecutor {
...
@@ -70,9 +70,6 @@ public abstract class AbstractExcelWriteExecutor implements ExcelWriteExecutor {
protected
CellData
convert
(
WriteHolder
currentWriteHolder
,
Class
clazz
,
Cell
cell
,
Object
value
,
protected
CellData
convert
(
WriteHolder
currentWriteHolder
,
Class
clazz
,
Cell
cell
,
Object
value
,
ExcelContentProperty
excelContentProperty
)
{
ExcelContentProperty
excelContentProperty
)
{
if
(
value
==
null
)
{
return
new
CellData
(
CellDataTypeEnum
.
EMPTY
);
}
// This means that the user has defined the data.
// This means that the user has defined the data.
if
(
value
instanceof
CellData
)
{
if
(
value
instanceof
CellData
)
{
CellData
cellDataValue
=
(
CellData
)
value
;
CellData
cellDataValue
=
(
CellData
)
value
;
...
@@ -110,6 +107,9 @@ public abstract class AbstractExcelWriteExecutor implements ExcelWriteExecutor {
...
@@ -110,6 +107,9 @@ public abstract class AbstractExcelWriteExecutor implements ExcelWriteExecutor {
new
CellData
(
CellDataTypeEnum
.
EMPTY
),
excelContentProperty
,
new
CellData
(
CellDataTypeEnum
.
EMPTY
),
excelContentProperty
,
"Can not find 'Converter' support class "
+
clazz
.
getSimpleName
()
+
"."
);
"Can not find 'Converter' support class "
+
clazz
.
getSimpleName
()
+
"."
);
}
}
if
(
value
==
null
&&
!(
converter
instanceof
NullableObjectConverter
))
{
return
new
CellData
(
CellDataTypeEnum
.
EMPTY
);
}
CellData
cellData
;
CellData
cellData
;
try
{
try
{
cellData
=
cellData
=
...
...
src/test/java/com/alibaba/easyexcel/test/temp/read/HeadListener.java
浏览文件 @
ae63dd2a
...
@@ -14,7 +14,7 @@ import com.alibaba.fastjson.JSON;
...
@@ -14,7 +14,7 @@ import com.alibaba.fastjson.JSON;
*
*
* @author Jiaju Zhuang
* @author Jiaju Zhuang
*/
*/
public
class
HeadListener
extends
AnalysisEventListener
<
Map
<
Integer
,
String
>
>
{
public
class
HeadListener
extends
AnalysisEventListener
<
HeadReadData
>
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
HeadListener
.
class
);
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
HeadListener
.
class
);
/**
/**
* 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收
* 每隔5条存储数据库,实际使用中可以3000条,然后清理list ,方便内存回收
...
@@ -29,7 +29,7 @@ public class HeadListener extends AnalysisEventListener<Map<Integer,String>> {
...
@@ -29,7 +29,7 @@ public class HeadListener extends AnalysisEventListener<Map<Integer,String>> {
}
}
@Override
@Override
public
void
invoke
(
Map
<
Integer
,
String
>
data
,
AnalysisContext
context
)
{
public
void
invoke
(
HeadReadData
data
,
AnalysisContext
context
)
{
LOGGER
.
info
(
"index:{}"
,
context
.
readRowHolder
().
getRowIndex
());
LOGGER
.
info
(
"index:{}"
,
context
.
readRowHolder
().
getRowIndex
());
LOGGER
.
info
(
"解析到一条数据:{}"
,
JSON
.
toJSONString
(
data
));
LOGGER
.
info
(
"解析到一条数据:{}"
,
JSON
.
toJSONString
(
data
));
}
}
...
...
src/test/java/com/alibaba/easyexcel/test/temp/read/HeadReadData.java
浏览文件 @
ae63dd2a
...
@@ -11,10 +11,9 @@ import lombok.experimental.Accessors;
...
@@ -11,10 +11,9 @@ import lombok.experimental.Accessors;
* @author Jiaju Zhuang
* @author Jiaju Zhuang
**/
**/
@Data
@Data
@Accessors
(
chain
=
true
)
public
class
HeadReadData
{
public
class
HeadReadData
{
@ExcelProperty
(
"头1"
)
@ExcelProperty
(
{
"主标题"
,
"数据1"
}
)
private
String
h1
;
private
String
h1
;
@ExcelProperty
({
"
头"
,
"头
2"
})
@ExcelProperty
({
"
主标题"
,
"数据
2"
})
private
String
h2
;
private
String
h2
;
}
}
src/test/java/com/alibaba/easyexcel/test/temp/read/HeadReadTest.java
浏览文件 @
ae63dd2a
...
@@ -32,8 +32,8 @@ public class HeadReadTest {
...
@@ -32,8 +32,8 @@ public class HeadReadTest {
@Test
@Test
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
File
file
=
TestFileUtil
.
readUserHomeFile
(
"test/t
1
.xlsx"
);
File
file
=
TestFileUtil
.
readUserHomeFile
(
"test/t
2
.xlsx"
);
EasyExcel
.
read
(
file
,
null
,
new
HeadListener
()).
ignoreEmptyRow
(
false
).
sheet
(
0
).
doRead
();
EasyExcel
.
read
(
file
,
HeadReadData
.
class
,
new
HeadListener
()).
ignoreEmptyRow
(
false
).
sheet
(
0
).
doRead
();
}
}
...
...
update.md
浏览文件 @
ae63dd2a
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
*
发布正式版
*
发布正式版
*
修复第一行为空不会调用
`invokeHeadMap`
的bug
[
Issue #993
](
https://github.com/alibaba/easyexcel/issues/993
)
*
修复第一行为空不会调用
`invokeHeadMap`
的bug
[
Issue #993
](
https://github.com/alibaba/easyexcel/issues/993
)
*
当类的属性没有按照ExcelProperty的属性index顺序排序的时候,写数据出现错乱
[
Issue #1046
](
https://github.com/alibaba/easyexcel/issues/1046
)
*
当类的属性没有按照ExcelProperty的属性index顺序排序的时候,写数据出现错乱
[
Issue #1046
](
https://github.com/alibaba/easyexcel/issues/1046
)
*
新增支持自定义转换器 入参可以为空 实现
`NullableObjectConverter`
即可
[
Issue #1084
](
https://github.com/alibaba/easyexcel/issues/1084
)
# 2.2.0-beta2
# 2.2.0-beta2
*
修复最长匹配策略不同表格会有影响的bug
[
Issue #1010
](
https://github.com/alibaba/easyexcel/issues/1010
)
*
修复最长匹配策略不同表格会有影响的bug
[
Issue #1010
](
https://github.com/alibaba/easyexcel/issues/1010
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录