Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
金手指1668
easyexcel
提交
5b695795
E
easyexcel
项目概览
金手指1668
/
easyexcel
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
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,发现更多精彩内容 >>
提交
5b695795
编写于
10月 24, 2019
作者:
庄家钜
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修复多个头的情况下会读取数据为空
上级
da2182de
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
50 addition
and
44 deletion
+50
-44
pom.xml
pom.xml
+4
-5
src/main/java/com/alibaba/excel/context/WriteContextImpl.java
...main/java/com/alibaba/excel/context/WriteContextImpl.java
+4
-11
src/main/java/com/alibaba/excel/metadata/CellData.java
src/main/java/com/alibaba/excel/metadata/CellData.java
+6
-0
src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java
...libaba/excel/read/metadata/holder/AbstractReadHolder.java
+2
-3
src/main/java/com/alibaba/excel/write/executor/AbstractExcelWriteExecutor.java
...baba/excel/write/executor/AbstractExcelWriteExecutor.java
+5
-2
src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java
.../alibaba/excel/write/executor/ExcelWriteFillExecutor.java
+16
-12
src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java
...te/style/column/LongestMatchColumnWidthStyleStrategy.java
+6
-1
src/test/java/com/alibaba/easyexcel/test/temp/simple/Wirte.java
...st/java/com/alibaba/easyexcel/test/temp/simple/Wirte.java
+2
-10
update.md
update.md
+5
-0
未找到文件。
pom.xml
浏览文件 @
5b695795
...
...
@@ -4,7 +4,7 @@
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.alibaba
</groupId>
<artifactId>
easyexcel
</artifactId>
<version>
2.1.0-beta
3
</version>
<version>
2.1.0-beta
4
</version>
<packaging>
jar
</packaging>
<name>
easyexcel
</name>
...
...
@@ -132,11 +132,11 @@
<build>
<plugins>
<!--
用pmd校验阿里的p3c规范
-->
<!--
code style
-->
<plugin>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-pmd-plugin
</artifactId>
<version>
3.
12.0
</version>
<version>
3.
8
</version>
<configuration>
<printFailingErrors>
true
</printFailingErrors>
<verbose>
true
</verbose>
...
...
@@ -157,7 +157,6 @@
</excludes>
</configuration>
<executions>
<!-- 绑定pmd:check到verify生命周期 -->
<execution>
<id>
pmd-check-verify
</id>
<phase>
validate
</phase>
...
...
@@ -170,7 +169,7 @@
<dependency>
<groupId>
com.alibaba.p3c
</groupId>
<artifactId>
p3c-pmd
</artifactId>
<version>
2.0.0
</version>
<version>
1.3.6
</version>
</dependency>
</dependencies>
</plugin>
...
...
src/main/java/com/alibaba/excel/context/WriteContextImpl.java
浏览文件 @
5b695795
package
com.alibaba.excel.context
;
import
com.alibaba.excel.support.ExcelTypeEnum
;
import
com.alibaba.excel.util.FileUtils
;
import
com.alibaba.excel.util.StringUtils
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.security.GeneralSecurityException
;
import
java.util.Map
;
import
java.util.UUID
;
import
org.apache.poi.hssf.record.crypto.Biff8EncryptionKey
;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook
;
import
org.apache.poi.openxml4j.opc.OPCPackage
;
import
org.apache.poi.openxml4j.opc.PackageAccess
;
import
org.apache.poi.poifs.crypt.Decryptor
;
import
org.apache.poi.poifs.crypt.EncryptionInfo
;
import
org.apache.poi.poifs.crypt.EncryptionMode
;
import
org.apache.poi.poifs.crypt.Encryptor
;
import
org.apache.poi.poifs.filesystem.DocumentOutputStream
;
import
org.apache.poi.poifs.filesystem.POIFSFileSystem
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.Row
;
...
...
@@ -36,6 +26,9 @@ import com.alibaba.excel.enums.WriteTypeEnum;
import
com.alibaba.excel.exception.ExcelGenerateException
;
import
com.alibaba.excel.metadata.CellData
;
import
com.alibaba.excel.metadata.Head
;
import
com.alibaba.excel.support.ExcelTypeEnum
;
import
com.alibaba.excel.util.FileUtils
;
import
com.alibaba.excel.util.StringUtils
;
import
com.alibaba.excel.util.WorkBookUtil
;
import
com.alibaba.excel.util.WriteHandlerUtils
;
import
com.alibaba.excel.write.metadata.WriteSheet
;
...
...
@@ -179,7 +172,7 @@ public class WriteContextImpl implements WriteContext {
Row
row
=
WorkBookUtil
.
createRow
(
writeSheetHolder
.
getSheet
(),
i
);
WriteHandlerUtils
.
afterRowCreate
(
this
,
row
,
relativeRowIndex
,
Boolean
.
TRUE
);
addOneRowOfHeadDataToExcel
(
row
,
excelWriteHeadProperty
.
getHeadMap
(),
relativeRowIndex
);
WriteHandlerUtils
.
afterRowDispose
(
this
,
row
,
relativeRowIndex
,
Boolean
.
FALS
E
);
WriteHandlerUtils
.
afterRowDispose
(
this
,
row
,
relativeRowIndex
,
Boolean
.
TRU
E
);
}
}
...
...
src/main/java/com/alibaba/excel/metadata/CellData.java
浏览文件 @
5b695795
...
...
@@ -202,6 +202,9 @@ public class CellData<T> {
* Ensure that the object does not appear null
*/
public
void
checkEmpty
()
{
if
(
type
==
null
)
{
type
=
CellDataTypeEnum
.
EMPTY
;
}
switch
(
type
)
{
case
STRING:
case
ERROR:
...
...
@@ -225,6 +228,9 @@ public class CellData<T> {
@Override
public
String
toString
()
{
if
(
type
==
null
)
{
return
"empty"
;
}
switch
(
type
)
{
case
NUMBER:
return
numberValue
.
toString
();
...
...
src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java
浏览文件 @
5b695795
...
...
@@ -158,7 +158,6 @@ public abstract class AbstractReadHolder extends AbstractHolder implements ReadH
if
(
currentheadRowNumber
==
rowIndex
+
1
)
{
buildHead
(
analysisContext
,
cellDataMap
);
}
// Now is header
for
(
ReadListener
readListener
:
analysisContext
.
currentReadHolder
().
readListenerList
())
{
try
{
...
...
@@ -206,8 +205,8 @@ public abstract class AbstractReadHolder extends AbstractHolder implements ReadH
tmpContentPropertyMap
.
put
(
entry
.
getKey
(),
contentPropertyMapData
.
get
(
entry
.
getKey
()));
continue
;
}
String
headName
=
headData
.
getHeadNameList
().
get
(
0
);
List
<
String
>
headNameList
=
headData
.
getHeadNameList
(
);
String
headName
=
headNameList
.
get
(
headNameList
.
size
()
-
1
);
for
(
Map
.
Entry
<
Integer
,
String
>
stringEntry
:
dataMap
.
entrySet
())
{
String
headString
=
stringEntry
.
getValue
();
Integer
stringKey
=
stringEntry
.
getKey
();
...
...
src/main/java/com/alibaba/excel/write/executor/AbstractExcelWriteExecutor.java
浏览文件 @
5b695795
...
...
@@ -31,7 +31,7 @@ public abstract class AbstractExcelWriteExecutor implements ExcelWriteExecutor {
protected
CellData
converterAndSet
(
WriteHolder
currentWriteHolder
,
Class
clazz
,
Cell
cell
,
Object
value
,
ExcelContentProperty
excelContentProperty
)
{
if
(
value
==
null
)
{
return
new
CellData
();
return
new
CellData
(
CellDataTypeEnum
.
EMPTY
);
}
if
(
value
instanceof
String
&&
currentWriteHolder
.
globalConfiguration
().
getAutoTrim
())
{
value
=
((
String
)
value
).
trim
();
...
...
@@ -40,6 +40,9 @@ public abstract class AbstractExcelWriteExecutor implements ExcelWriteExecutor {
if
(
cellData
.
getFormula
()
!=
null
&&
cellData
.
getFormula
())
{
cell
.
setCellFormula
(
cellData
.
getFormulaValue
());
}
if
(
cellData
.
getType
()
==
null
)
{
cellData
.
setType
(
CellDataTypeEnum
.
EMPTY
);
}
switch
(
cellData
.
getType
())
{
case
STRING:
cell
.
setCellValue
(
cellData
.
getStringValue
());
...
...
@@ -64,7 +67,7 @@ public abstract class AbstractExcelWriteExecutor implements ExcelWriteExecutor {
protected
CellData
convert
(
WriteHolder
currentWriteHolder
,
Class
clazz
,
Cell
cell
,
Object
value
,
ExcelContentProperty
excelContentProperty
)
{
if
(
value
==
null
)
{
return
new
CellData
();
return
new
CellData
(
CellDataTypeEnum
.
EMPTY
);
}
// This means that the user has defined the data.
if
(
value
instanceof
CellData
)
{
...
...
src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java
浏览文件 @
5b695795
...
...
@@ -14,6 +14,7 @@ import org.apache.poi.ss.usermodel.Row;
import
org.apache.poi.ss.usermodel.Sheet
;
import
com.alibaba.excel.context.WriteContext
;
import
com.alibaba.excel.enums.CellDataTypeEnum
;
import
com.alibaba.excel.enums.WriteDirectionEnum
;
import
com.alibaba.excel.enums.WriteTemplateAnalysisCellTypeEnum
;
import
com.alibaba.excel.exception.ExcelGenerateException
;
...
...
@@ -168,18 +169,21 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
CellData
cellData
=
convert
(
writeSheetHolder
,
value
==
null
?
null
:
value
.
getClass
(),
cell
,
value
,
fieldNameContentPropertyMap
.
get
(
variable
));
cellDataList
.
add
(
cellData
);
switch
(
cellData
.
getType
())
{
case
STRING:
cellValueBuild
.
append
(
cellData
.
getStringValue
());
break
;
case
BOOLEAN:
cellValueBuild
.
append
(
cellData
.
getBooleanValue
());
break
;
case
NUMBER:
cellValueBuild
.
append
(
cellData
.
getNumberValue
());
break
;
default
:
break
;
CellDataTypeEnum
type
=
cellData
.
getType
();
if
(
type
!=
null
)
{
switch
(
type
)
{
case
STRING:
cellValueBuild
.
append
(
cellData
.
getStringValue
());
break
;
case
BOOLEAN:
cellValueBuild
.
append
(
cellData
.
getBooleanValue
());
break
;
case
NUMBER:
cellValueBuild
.
append
(
cellData
.
getNumberValue
());
break
;
default
:
break
;
}
}
}
cellValueBuild
.
append
(
analysisCell
.
getPrepareDataList
().
get
(
index
));
...
...
src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java
浏览文件 @
5b695795
...
...
@@ -6,6 +6,7 @@ import java.util.Map;
import
org.apache.poi.ss.usermodel.Cell
;
import
com.alibaba.excel.enums.CellDataTypeEnum
;
import
com.alibaba.excel.metadata.CellData
;
import
com.alibaba.excel.metadata.Head
;
import
com.alibaba.excel.util.CollectionUtils
;
...
...
@@ -56,7 +57,11 @@ public class LongestMatchColumnWidthStyleStrategy extends AbstractColumnWidthSty
return
cell
.
getStringCellValue
().
getBytes
().
length
;
}
CellData
cellData
=
cellDataList
.
get
(
0
);
switch
(
cellData
.
getType
())
{
CellDataTypeEnum
type
=
cellData
.
getType
();
if
(
type
==
null
)
{
return
-
1
;
}
switch
(
type
)
{
case
STRING:
return
cellData
.
getStringValue
().
getBytes
().
length
;
case
BOOLEAN:
...
...
src/test/java/com/alibaba/easyexcel/test/temp/simple/Wirte.java
浏览文件 @
5b695795
package
com.alibaba.easyexcel.test.temp.simple
;
import
java.io.FileInputStream
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
...
...
@@ -13,14 +11,9 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
com.alibaba.easyexcel.test.core.large.LargeData
;
import
com.alibaba.easyexcel.test.core.simple.SimpleData
;
import
com.alibaba.easyexcel.test.demo.write.DemoData
;
import
com.alibaba.easyexcel.test.util.TestFileUtil
;
import
com.alibaba.excel.EasyExcel
;
import
com.alibaba.excel.ExcelWriter
;
import
com.alibaba.excel.write.metadata.WriteSheet
;
import
com.alibaba.excel.write.style.row.SimpleRowHeightStyleStrategy
;
import
com.alibaba.fastjson.JSON
;
import
net.sf.cglib.beans.BeanMap
;
...
...
@@ -50,8 +43,7 @@ public class Wirte {
String
fileName
=
TestFileUtil
.
getPath
()
+
"t22"
+
System
.
currentTimeMillis
()
+
".xlsx"
;
// 这里 需要指定写用哪个class去读,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
// 如果这里想使用03 则 传入excelType参数即可
EasyExcel
.
write
(
fileName
,
DemoData
.
class
)
.
registerWriteHandler
(
new
SimpleRowHeightStyleStrategy
((
short
)
150
,
(
short
)
120
)).
sheet
(
"模板"
).
doWrite
(
data
());
EasyExcel
.
write
(
fileName
,
DemoData
.
class
).
sheet
(
"模板"
).
doWrite
(
data
());
}
private
List
<
List
<
String
>>
head
()
{
...
...
@@ -74,7 +66,7 @@ public class Wirte {
DemoData
data
=
new
DemoData
();
data
.
setString
(
"字符串"
+
i
);
data
.
setDate
(
new
Date
());
data
.
setDoubleData
(
0.56
);
data
.
setDoubleData
(
null
);
list
.
add
(
data
);
}
return
list
;
...
...
update.md
浏览文件 @
5b695795
# 2.1.0-beta4
*
修改最长匹配策略会空指针的bug
[
Issue #747
](
https://github.com/alibaba/easyexcel/issues/747
)
*
修改afterRowDispose错误
[
Issue #751
](
https://github.com/alibaba/easyexcel/issues/751
)
*
修复多个头的情况下会读取数据为空
# 2.1.0-beta3
*
支持强行指定在内存处理,以支持备注、RichTextString等的写入
*
修复关闭流失败,可能会不删除临时文件的问题
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录