Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_879456671
easyexcel
提交
bdba8a41
E
easyexcel
项目概览
qq_879456671
/
easyexcel
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
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,发现更多精彩内容 >>
提交
bdba8a41
编写于
9月 15, 2021
作者:
庄家钜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改代码为jdk8
上级
6407a8ab
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
40 addition
and
53 deletion
+40
-53
src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java
.../alibaba/excel/write/executor/ExcelWriteFillExecutor.java
+39
-52
src/test/java/com/alibaba/easyexcel/test/temp/dataformat/DataFormatter1.java
...libaba/easyexcel/test/temp/dataformat/DataFormatter1.java
+1
-1
未找到文件。
src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java
浏览文件 @
bdba8a41
...
...
@@ -18,6 +18,8 @@ import com.alibaba.excel.metadata.data.WriteCellData;
import
com.alibaba.excel.metadata.property.ExcelContentProperty
;
import
com.alibaba.excel.util.BeanMapUtils
;
import
com.alibaba.excel.util.FieldUtils
;
import
com.alibaba.excel.util.ListUtils
;
import
com.alibaba.excel.util.MapUtils
;
import
com.alibaba.excel.util.StringUtils
;
import
com.alibaba.excel.util.WriteHandlerUtils
;
import
com.alibaba.excel.write.metadata.fill.AnalysisCell
;
...
...
@@ -48,32 +50,25 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
/**
* Fields to replace in the template
*/
private
final
Map
<
String
,
List
<
AnalysisCell
>>
templateAnalysisCache
=
new
HashMap
<
String
,
List
<
AnalysisCell
>>(
8
);
private
final
Map
<
String
,
List
<
AnalysisCell
>>
templateAnalysisCache
=
MapUtils
.
newHashMap
(
);
/**
* Collection fields to replace in the template
*/
private
final
Map
<
String
,
List
<
AnalysisCell
>>
templateCollectionAnalysisCache
=
new
HashMap
<
String
,
List
<
AnalysisCell
>>(
8
);
private
final
Map
<
String
,
List
<
AnalysisCell
>>
templateCollectionAnalysisCache
=
MapUtils
.
newHashMap
();
/**
* Style cache for collection fields
*/
private
final
Map
<
String
,
Map
<
AnalysisCell
,
CellStyle
>>
collectionFieldStyleCache
=
new
HashMap
<
String
,
Map
<
AnalysisCell
,
CellStyle
>>(
8
);
private
final
Map
<
String
,
Map
<
AnalysisCell
,
CellStyle
>>
collectionFieldStyleCache
=
MapUtils
.
newHashMap
();
/**
* Row height cache for collection
*/
private
final
Map
<
String
,
Short
>
collectionRowHeightCache
=
new
HashMap
<
String
,
Short
>(
8
);
private
final
Map
<
String
,
Short
>
collectionRowHeightCache
=
MapUtils
.
newHashMap
(
);
/**
* Last index cache for collection fields
*/
private
final
Map
<
String
,
Map
<
AnalysisCell
,
Integer
>>
collectionLastIndexCache
=
new
HashMap
<
String
,
Map
<
AnalysisCell
,
Integer
>>(
8
);
private
final
Map
<
String
,
Map
<
AnalysisCell
,
Integer
>>
collectionLastIndexCache
=
MapUtils
.
newHashMap
();
private
final
Map
<
String
,
Integer
>
relativeRowIndexMap
=
new
HashMap
<
String
,
Integer
>(
8
);
/**
* The data prefix that is populated this time
*/
private
String
currentDataPrefix
;
private
final
Map
<
String
,
Integer
>
relativeRowIndexMap
=
MapUtils
.
newHashMap
();
/**
* The unique data encoding for this fill
*/
...
...
@@ -93,6 +88,9 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
fillConfig
.
init
();
Object
realData
;
// The data prefix that is populated this time
String
currentDataPrefix
;
if
(
data
instanceof
FillWrapper
)
{
FillWrapper
fillWrapper
=
(
FillWrapper
)
data
;
currentDataPrefix
=
fillWrapper
.
getName
();
...
...
@@ -106,11 +104,11 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
// processing data
if
(
realData
instanceof
Collection
)
{
List
<
AnalysisCell
>
analysisCellList
=
readTemplateData
(
templateCollectionAnalysisCache
);
Collection
collectionData
=
(
Collection
)
realData
;
Collection
<?>
collectionData
=
(
Collection
<?>
)
realData
;
if
(
CollectionUtils
.
isEmpty
(
collectionData
))
{
return
;
}
Iterator
iterator
=
collectionData
.
iterator
();
Iterator
<?>
iterator
=
collectionData
.
iterator
();
if
(
WriteDirectionEnum
.
VERTICAL
.
equals
(
fillConfig
.
getDirection
())
&&
fillConfig
.
getForceNewRow
())
{
shiftRows
(
collectionData
.
size
(),
analysisCellList
);
}
...
...
@@ -182,9 +180,9 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
if
(
CollectionUtils
.
isEmpty
(
analysisCellList
))
{
return
;
}
Map
dataMap
;
Map
<?,
?>
dataMap
;
if
(
oneRowData
instanceof
Map
)
{
dataMap
=
(
Map
)
oneRowData
;
dataMap
=
(
Map
<?,
?>
)
oneRowData
;
}
else
{
dataMap
=
BeanMapUtils
.
create
(
oneRowData
);
}
...
...
@@ -259,11 +257,9 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
}
Sheet
sheet
=
writeContext
.
writeSheetHolder
().
getSheet
();
Map
<
AnalysisCell
,
Integer
>
collectionLastIndexMap
=
collectionLastIndexCache
.
get
(
currentUniqueDataFlag
);
if
(
collectionLastIndexMap
==
null
)
{
collectionLastIndexMap
=
new
HashMap
<
AnalysisCell
,
Integer
>(
16
);
collectionLastIndexCache
.
put
(
currentUniqueDataFlag
,
collectionLastIndexMap
);
}
Map
<
AnalysisCell
,
Integer
>
collectionLastIndexMap
=
collectionLastIndexCache
.
computeIfAbsent
(
currentUniqueDataFlag
,
key
->
MapUtils
.
newHashMap
());
boolean
isOriginalCell
=
false
;
Integer
lastRowIndex
;
Integer
lastColumnIndex
;
...
...
@@ -297,11 +293,9 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
Row
row
=
createRowIfNecessary
(
sheet
,
cachedSheet
,
lastRowIndex
,
fillConfig
,
analysisCell
,
isOriginalCell
);
Cell
cell
=
createCellIfNecessary
(
row
,
lastColumnIndex
);
Map
<
AnalysisCell
,
CellStyle
>
collectionFieldStyleMap
=
collectionFieldStyleCache
.
get
(
currentUniqueDataFlag
);
if
(
collectionFieldStyleMap
==
null
)
{
collectionFieldStyleMap
=
new
HashMap
<
AnalysisCell
,
CellStyle
>(
16
);
collectionFieldStyleCache
.
put
(
currentUniqueDataFlag
,
collectionFieldStyleMap
);
}
Map
<
AnalysisCell
,
CellStyle
>
collectionFieldStyleMap
=
collectionFieldStyleCache
.
computeIfAbsent
(
currentUniqueDataFlag
,
key
->
MapUtils
.
newHashMap
());
if
(
isOriginalCell
)
{
collectionFieldStyleMap
.
put
(
analysisCell
,
cell
.
getCellStyle
());
}
else
{
...
...
@@ -373,7 +367,7 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
return
analysisCellList
;
}
Sheet
sheet
=
writeContext
.
writeSheetHolder
().
getCachedSheet
();
Map
<
String
,
Set
<
Integer
>>
firstRowCache
=
new
HashMap
<
String
,
Set
<
Integer
>>
(
8
);
Map
<
String
,
Set
<
Integer
>>
firstRowCache
=
MapUtils
.
newHashMapWithExpectedSize
(
8
);
for
(
int
i
=
0
;
i
<=
sheet
.
getLastRowNum
();
i
++)
{
Row
row
=
sheet
.
getRow
(
i
);
if
(
row
==
null
)
{
...
...
@@ -397,14 +391,14 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
/**
* To prepare data
*
* @param cell
* @param rowIndex
* @param columnIndex
* @param firstRowCache
* @param cell
cell
* @param rowIndex
row index
* @param columnIndex
column index
* @param firstRowCache
first row cache
* @return Returns the data that the cell needs to replace
*/
private
String
prepareData
(
Cell
cell
,
int
rowIndex
,
int
columnIndex
,
Map
<
String
,
Set
<
Integer
>>
firstRowCache
)
{
if
(!
CellType
.
STRING
.
equals
(
cell
.
getCellType
Enum
()))
{
if
(!
CellType
.
STRING
.
equals
(
cell
.
getCellType
()))
{
return
null
;
}
String
value
=
cell
.
getStringCellValue
();
...
...
@@ -421,7 +415,7 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
while
(
startIndex
<
length
)
{
int
prefixIndex
=
value
.
indexOf
(
FILL_PREFIX
,
startIndex
);
if
(
prefixIndex
<
0
)
{
break
out
;
break
;
}
if
(
prefixIndex
!=
0
)
{
char
prefixPrefixChar
=
value
.
charAt
(
prefixIndex
-
1
);
...
...
@@ -491,28 +485,21 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
}
String
uniqueDataFlag
=
uniqueDataFlag
(
writeContext
.
writeSheetHolder
(),
analysisCell
.
getPrefix
());
if
(
WriteTemplateAnalysisCellTypeEnum
.
COMMON
.
equals
(
analysisCell
.
getCellType
()))
{
List
<
AnalysisCell
>
analysisCellList
=
templateAnalysisCache
.
get
(
uniqueDataFlag
);
if
(
analysisCellList
==
null
)
{
analysisCellList
=
new
ArrayList
<
AnalysisCell
>();
templateAnalysisCache
.
put
(
uniqueDataFlag
,
analysisCellList
);
}
List
<
AnalysisCell
>
analysisCellList
=
templateAnalysisCache
.
computeIfAbsent
(
uniqueDataFlag
,
key
->
ListUtils
.
newArrayList
());
analysisCellList
.
add
(
analysisCell
);
}
else
{
Set
<
Integer
>
uniqueFirstRowCache
=
firstRowCache
.
get
(
uniqueDataFlag
);
if
(
uniqueFirstRowCache
==
null
)
{
uniqueFirstRowCache
=
new
HashSet
<
Integer
>();
firstRowCache
.
put
(
uniqueDataFlag
,
uniqueFirstRowCache
);
}
Set
<
Integer
>
uniqueFirstRowCache
=
firstRowCache
.
computeIfAbsent
(
uniqueDataFlag
,
key
->
new
HashSet
<>());
if
(!
uniqueFirstRowCache
.
contains
(
rowIndex
))
{
analysisCell
.
setFirstRow
(
Boolean
.
TRUE
);
uniqueFirstRowCache
.
add
(
rowIndex
);
}
List
<
AnalysisCell
>
collectionAnalysisCellList
=
templateCollectionAnalysisCache
.
get
(
uniqueDataFlag
);
if
(
collectionAnalysisCellList
==
null
)
{
collectionAnalysisCellList
=
new
ArrayList
<
AnalysisCell
>();
templateCollectionAnalysisCache
.
put
(
uniqueDataFlag
,
collectionAnalysisCellList
);
}
List
<
AnalysisCell
>
collectionAnalysisCellList
=
templateCollectionAnalysisCache
.
computeIfAbsent
(
uniqueDataFlag
,
key
->
ListUtils
.
newArrayList
());
collectionAnalysisCellList
.
add
(
analysisCell
);
}
return
preparedData
.
toString
();
...
...
@@ -525,9 +512,9 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
analysisCell
.
setRowIndex
(
rowIndex
);
analysisCell
.
setColumnIndex
(
columnIndex
);
analysisCell
.
setOnlyOneVariable
(
Boolean
.
TRUE
);
List
<
String
>
variableList
=
new
ArrayList
<
String
>
();
List
<
String
>
variableList
=
ListUtils
.
newArrayList
();
analysisCell
.
setVariableList
(
variableList
);
List
<
String
>
prepareDataList
=
new
ArrayList
<
String
>
();
List
<
String
>
prepareDataList
=
ListUtils
.
newArrayList
();
analysisCell
.
setPrepareDataList
(
prepareDataList
);
analysisCell
.
setCellType
(
WriteTemplateAnalysisCellTypeEnum
.
COMMON
);
analysisCell
.
setFirstRow
(
Boolean
.
FALSE
);
...
...
@@ -545,7 +532,7 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
if
(
writeSheetHolder
.
getSheetNo
()
!=
null
)
{
prefix
=
writeSheetHolder
.
getSheetNo
().
toString
();
}
else
{
prefix
=
writeSheetHolder
.
getSheetName
()
.
toString
()
;
prefix
=
writeSheetHolder
.
getSheetName
();
}
if
(
StringUtils
.
isEmpty
(
wrapperName
))
{
return
prefix
+
"-"
;
...
...
src/test/java/com/alibaba/easyexcel/test/temp/dataformat/DataFormatter1.java
浏览文件 @
bdba8a41
...
...
@@ -968,7 +968,7 @@ public class DataFormatter1 implements Observer {
return
""
;
}
CellType
cellType
=
cell
.
getCellType
Enum
();
CellType
cellType
=
cell
.
getCellType
();
if
(
cellType
==
CellType
.
FORMULA
)
{
if
(
evaluator
==
null
)
{
return
cell
.
getCellFormula
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录