Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
苏木力格
easyexcel
提交
f958af6f
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,发现更多精彩内容 >>
未验证
提交
f958af6f
编写于
10月 23, 2019
作者:
庄家钜
提交者:
GitHub
10月 23, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #745 from alibaba/2.1.x
2.1.x
上级
e8502bc9
8515b60c
变更
26
隐藏空白更改
内联
并排
Showing
26 changed file
with
451 addition
and
63 deletion
+451
-63
pom.xml
pom.xml
+1
-1
src/main/java/com/alibaba/excel/analysis/ExcelAnalyserImpl.java
...in/java/com/alibaba/excel/analysis/ExcelAnalyserImpl.java
+11
-9
src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java
.../java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java
+0
-2
src/main/java/com/alibaba/excel/context/WriteContextImpl.java
...main/java/com/alibaba/excel/context/WriteContextImpl.java
+13
-12
src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java
...om/alibaba/excel/metadata/property/ExcelHeadProperty.java
+37
-12
src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java
...libaba/excel/read/metadata/holder/AbstractReadHolder.java
+1
-1
src/main/java/com/alibaba/excel/read/metadata/property/ExcelReadHeadProperty.java
...a/excel/read/metadata/property/ExcelReadHeadProperty.java
+3
-2
src/main/java/com/alibaba/excel/util/WorkBookUtil.java
src/main/java/com/alibaba/excel/util/WorkBookUtil.java
+13
-4
src/main/java/com/alibaba/excel/write/builder/ExcelWriterBuilder.java
...a/com/alibaba/excel/write/builder/ExcelWriterBuilder.java
+43
-0
src/main/java/com/alibaba/excel/write/builder/ExcelWriterSheetBuilder.java
.../alibaba/excel/write/builder/ExcelWriterSheetBuilder.java
+33
-0
src/main/java/com/alibaba/excel/write/builder/ExcelWriterTableBuilder.java
.../alibaba/excel/write/builder/ExcelWriterTableBuilder.java
+34
-0
src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java
...m/alibaba/excel/write/executor/ExcelWriteAddExecutor.java
+7
-1
src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java
.../alibaba/excel/write/executor/ExcelWriteFillExecutor.java
+24
-12
src/main/java/com/alibaba/excel/write/metadata/WriteBasicParameter.java
...com/alibaba/excel/write/metadata/WriteBasicParameter.java
+49
-0
src/main/java/com/alibaba/excel/write/metadata/WriteWorkbook.java
.../java/com/alibaba/excel/write/metadata/WriteWorkbook.java
+15
-1
src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java
...baba/excel/write/metadata/holder/AbstractWriteHolder.java
+92
-2
src/main/java/com/alibaba/excel/write/metadata/holder/WriteHolder.java
.../com/alibaba/excel/write/metadata/holder/WriteHolder.java
+9
-0
src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java
...baba/excel/write/metadata/holder/WriteWorkbookHolder.java
+19
-0
src/main/java/com/alibaba/excel/write/property/ExcelWriteHeadProperty.java
.../alibaba/excel/write/property/ExcelWriteHeadProperty.java
+3
-2
src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java
...te/style/column/LongestMatchColumnWidthStyleStrategy.java
+1
-1
src/test/java/com/alibaba/easyexcel/test/core/fill/FillData.java
...t/java/com/alibaba/easyexcel/test/core/fill/FillData.java
+1
-0
src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java
...java/com/alibaba/easyexcel/test/demo/write/WriteTest.java
+31
-0
src/test/java/com/alibaba/easyexcel/test/temp/simple/Wirte.java
...st/java/com/alibaba/easyexcel/test/temp/simple/Wirte.java
+3
-1
src/test/resources/fill/simple.xls
src/test/resources/fill/simple.xls
+0
-0
src/test/resources/fill/simple.xlsx
src/test/resources/fill/simple.xlsx
+0
-0
update.md
update.md
+8
-0
未找到文件。
pom.xml
浏览文件 @
f958af6f
...
...
@@ -4,7 +4,7 @@
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.alibaba
</groupId>
<artifactId>
easyexcel
</artifactId>
<version>
2.1.0-beta
2
</version>
<version>
2.1.0-beta
3
</version>
<packaging>
jar
</packaging>
<name>
easyexcel
</name>
...
...
src/main/java/com/alibaba/excel/analysis/ExcelAnalyserImpl.java
浏览文件 @
f958af6f
...
...
@@ -129,26 +129,28 @@ public class ExcelAnalyserImpl implements ExcelAnalyser {
}
ReadWorkbookHolder
readWorkbookHolder
=
analysisContext
.
readWorkbookHolder
();
Throwable
throwable
=
null
;
try
{
if
(
readWorkbookHolder
.
getReadCache
()
!=
null
)
{
readWorkbookHolder
.
getReadCache
().
destroy
();
}
}
catch
(
Throwable
t
)
{
throw
CanNotCloseIo
(
t
)
;
throw
able
=
t
;
}
try
{
if
(
readWorkbookHolder
.
getOpcPackage
()
!=
null
)
{
readWorkbookHolder
.
getOpcPackage
().
revert
();
}
}
catch
(
Throwable
t
)
{
throw
CanNotCloseIo
(
t
)
;
throw
able
=
t
;
}
try
{
if
(
readWorkbookHolder
.
getPoifsFileSystem
()
!=
null
)
{
readWorkbookHolder
.
getPoifsFileSystem
().
close
();
}
}
catch
(
Throwable
t
)
{
throw
CanNotCloseIo
(
t
)
;
throw
able
=
t
;
}
try
{
if
(
analysisContext
.
readWorkbookHolder
().
getAutoCloseStream
()
...
...
@@ -156,17 +158,21 @@ public class ExcelAnalyserImpl implements ExcelAnalyser {
readWorkbookHolder
.
getInputStream
().
close
();
}
}
catch
(
Throwable
t
)
{
throw
CanNotCloseIo
(
t
)
;
throw
able
=
t
;
}
try
{
if
(
readWorkbookHolder
.
getTempFile
()
!=
null
)
{
FileUtils
.
delete
(
readWorkbookHolder
.
getTempFile
());
}
}
catch
(
Throwable
t
)
{
throw
CanNotCloseIo
(
t
)
;
throw
able
=
t
;
}
clearEncrypt03
();
if
(
throwable
!=
null
)
{
throw
new
ExcelAnalysisException
(
"Can not close IO"
,
throwable
);
}
}
private
void
clearEncrypt03
()
{
...
...
@@ -177,10 +183,6 @@ public class ExcelAnalyserImpl implements ExcelAnalyser {
Biff8EncryptionKey
.
setCurrentUserPassword
(
null
);
}
private
void
throwCanNotCloseIo
(
Throwable
t
)
{
throw
new
ExcelAnalysisException
(
"Can not close IO"
,
t
);
}
@Override
public
ExcelReadExecutor
excelExecutor
()
{
return
excelReadExecutor
;
...
...
src/main/java/com/alibaba/excel/analysis/v07/XlsxSaxAnalyser.java
浏览文件 @
f958af6f
...
...
@@ -15,7 +15,6 @@ import javax.xml.parsers.SAXParserFactory;
import
org.apache.poi.openxml4j.opc.OPCPackage
;
import
org.apache.poi.openxml4j.opc.PackageAccess
;
import
org.apache.poi.openxml4j.opc.PackagePart
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
org.apache.poi.xssf.eventusermodel.XSSFReader
;
import
org.apache.poi.xssf.model.StylesTable
;
import
org.apache.poi.xssf.usermodel.XSSFRelation
;
...
...
@@ -35,7 +34,6 @@ import com.alibaba.excel.read.metadata.holder.ReadWorkbookHolder;
import
com.alibaba.excel.util.CollectionUtils
;
import
com.alibaba.excel.util.FileUtils
;
import
com.alibaba.excel.util.SheetUtils
;
import
com.alibaba.excel.util.StringUtils
;
/**
*
...
...
src/main/java/com/alibaba/excel/context/WriteContextImpl.java
浏览文件 @
f958af6f
...
...
@@ -179,6 +179,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
.
FALSE
);
}
}
...
...
@@ -197,8 +198,7 @@ public class WriteContextImpl implements WriteContext {
Cell
cell
=
row
.
createCell
(
columnIndex
);
WriteHandlerUtils
.
afterCellCreate
(
this
,
cell
,
head
,
relativeRowIndex
,
Boolean
.
TRUE
);
cell
.
setCellValue
(
head
.
getHeadNameList
().
get
(
relativeRowIndex
));
CellData
cellData
=
null
;
WriteHandlerUtils
.
afterCellDispose
(
this
,
cellData
,
cell
,
head
,
relativeRowIndex
,
Boolean
.
TRUE
);
WriteHandlerUtils
.
afterCellDispose
(
this
,
(
CellData
)
null
,
cell
,
head
,
relativeRowIndex
,
Boolean
.
TRUE
);
}
}
...
...
@@ -261,12 +261,13 @@ public class WriteContextImpl implements WriteContext {
if
(
writeWorkbookHolder
==
null
)
{
return
;
}
Throwable
throwable
=
null
;
boolean
isOutputStreamEncrypt
=
false
;
try
{
isOutputStreamEncrypt
=
doOutputStreamEncrypt07
();
}
catch
(
Throwable
t
)
{
throw
CanNotCloseIo
(
t
)
;
throw
able
=
t
;
}
if
(!
isOutputStreamEncrypt
)
{
...
...
@@ -274,7 +275,7 @@ public class WriteContextImpl implements WriteContext {
writeWorkbookHolder
.
getWorkbook
().
write
(
writeWorkbookHolder
.
getOutputStream
());
writeWorkbookHolder
.
getWorkbook
().
close
();
}
catch
(
Throwable
t
)
{
throw
CanNotCloseIo
(
t
)
;
throw
able
=
t
;
}
}
...
...
@@ -284,7 +285,7 @@ public class WriteContextImpl implements WriteContext {
((
SXSSFWorkbook
)
workbook
).
dispose
();
}
}
catch
(
Throwable
t
)
{
throw
CanNotCloseIo
(
t
)
;
throw
able
=
t
;
}
try
{
...
...
@@ -292,14 +293,14 @@ public class WriteContextImpl implements WriteContext {
writeWorkbookHolder
.
getOutputStream
().
close
();
}
}
catch
(
Throwable
t
)
{
throw
CanNotCloseIo
(
t
)
;
throw
able
=
t
;
}
if
(!
isOutputStreamEncrypt
)
{
try
{
doFileEncrypt07
();
}
catch
(
Throwable
t
)
{
throw
CanNotCloseIo
(
t
)
;
throw
able
=
t
;
}
}
...
...
@@ -308,20 +309,20 @@ public class WriteContextImpl implements WriteContext {
writeWorkbookHolder
.
getTempTemplateInputStream
().
close
();
}
}
catch
(
Throwable
t
)
{
throw
CanNotCloseIo
(
t
)
;
throw
able
=
t
;
}
clearEncrypt03
();
if
(
throwable
!=
null
)
{
throw
new
ExcelGenerateException
(
"Can not close IO"
,
throwable
);
}
if
(
LOGGER
.
isDebugEnabled
())
{
LOGGER
.
debug
(
"Finished write."
);
}
}
private
void
throwCanNotCloseIo
(
Throwable
t
)
{
throw
new
ExcelGenerateException
(
"Can not close IO"
,
t
);
}
@Override
public
Sheet
getCurrentSheet
()
{
return
writeSheetHolder
.
getSheet
();
...
...
src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java
浏览文件 @
f958af6f
...
...
@@ -17,14 +17,15 @@ import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
import
com.alibaba.excel.annotation.ExcelProperty
;
import
com.alibaba.excel.annotation.format.DateTimeFormat
;
import
com.alibaba.excel.annotation.format.NumberFormat
;
import
com.alibaba.excel.annotation.write.style.ColumnWidth
;
import
com.alibaba.excel.converters.AutoConverter
;
import
com.alibaba.excel.converters.Converter
;
import
com.alibaba.excel.enums.HeadKindEnum
;
import
com.alibaba.excel.exception.ExcelCommonException
;
import
com.alibaba.excel.exception.ExcelGenerateException
;
import
com.alibaba.excel.metadata.Head
;
import
com.alibaba.excel.metadata.Holder
;
import
com.alibaba.excel.util.StringUtils
;
import
com.alibaba.excel.write.metadata.holder.AbstractWriteHolder
;
/**
* Define the header attribute of excel
...
...
@@ -46,7 +47,6 @@ public class ExcelHeadProperty {
* The number of rows in the line with the most rows
*/
private
int
headRowNumber
;
/**
* Configuration header information
*/
...
...
@@ -64,7 +64,7 @@ public class ExcelHeadProperty {
*/
private
Map
<
String
,
Field
>
ignoreMap
;
public
ExcelHeadProperty
(
Class
headClazz
,
List
<
List
<
String
>>
head
,
Boolean
convertAllFiled
)
{
public
ExcelHeadProperty
(
Holder
holder
,
Class
headClazz
,
List
<
List
<
String
>>
head
,
Boolean
convertAllFiled
)
{
this
.
headClazz
=
headClazz
;
headMap
=
new
TreeMap
<
Integer
,
Head
>();
contentPropertyMap
=
new
TreeMap
<
Integer
,
ExcelContentProperty
>();
...
...
@@ -73,14 +73,21 @@ public class ExcelHeadProperty {
headKind
=
HeadKindEnum
.
NONE
;
headRowNumber
=
0
;
if
(
head
!=
null
&&
!
head
.
isEmpty
())
{
int
headIndex
=
0
;
for
(
int
i
=
0
;
i
<
head
.
size
();
i
++)
{
headMap
.
put
(
i
,
new
Head
(
i
,
null
,
head
.
get
(
i
),
Boolean
.
FALSE
,
Boolean
.
TRUE
));
contentPropertyMap
.
put
(
i
,
null
);
if
(
holder
instanceof
AbstractWriteHolder
)
{
if
(((
AbstractWriteHolder
)
holder
).
ignore
(
null
,
i
))
{
continue
;
}
}
headMap
.
put
(
headIndex
,
new
Head
(
headIndex
,
null
,
head
.
get
(
i
),
Boolean
.
FALSE
,
Boolean
.
TRUE
));
contentPropertyMap
.
put
(
headIndex
,
null
);
headIndex
++;
}
headKind
=
HeadKindEnum
.
STRING
;
}
else
{
// convert headClazz to head
initColumnProperties
(
convertAllFiled
);
initColumnProperties
(
holder
,
convertAllFiled
);
}
initHeadRowNumber
();
if
(
LOGGER
.
isDebugEnabled
())
{
...
...
@@ -108,7 +115,7 @@ public class ExcelHeadProperty {
}
}
private
void
initColumnProperties
(
Boolean
convertAllFiled
)
{
private
void
initColumnProperties
(
Holder
holder
,
Boolean
convertAllFiled
)
{
if
(
headClazz
==
null
)
{
return
;
}
...
...
@@ -161,20 +168,37 @@ public class ExcelHeadProperty {
int
index
=
0
;
for
(
Field
field
:
defaultFieldList
)
{
while
(
customFiledMap
.
containsKey
(
index
))
{
initOneColumnProperty
(
index
,
customFiledMap
.
get
(
index
),
Boolean
.
TRUE
);
Field
customFiled
=
customFiledMap
.
get
(
index
);
customFiledMap
.
remove
(
index
);
if
(!
initOneColumnProperty
(
holder
,
index
,
customFiled
,
Boolean
.
TRUE
))
{
index
++;
}
}
if
(!
initOneColumnProperty
(
holder
,
index
,
field
,
Boolean
.
FALSE
))
{
index
++;
}
initOneColumnProperty
(
index
,
field
,
Boolean
.
FALSE
);
index
++;
}
for
(
Map
.
Entry
<
Integer
,
Field
>
entry
:
customFiledMap
.
entrySet
())
{
initOneColumnProperty
(
entry
.
getKey
(),
entry
.
getValue
(),
Boolean
.
TRUE
);
initOneColumnProperty
(
holder
,
entry
.
getKey
(),
entry
.
getValue
(),
Boolean
.
TRUE
);
}
headKind
=
HeadKindEnum
.
CLASS
;
}
private
void
initOneColumnProperty
(
int
index
,
Field
field
,
Boolean
forceIndex
)
{
/**
* Initialization column property
*
* @param holder
* @param index
* @param field
* @param forceIndex
* @return Ignore current field
*/
private
boolean
initOneColumnProperty
(
Holder
holder
,
int
index
,
Field
field
,
Boolean
forceIndex
)
{
if
(
holder
instanceof
AbstractWriteHolder
)
{
if
(((
AbstractWriteHolder
)
holder
).
ignore
(
field
.
getName
(),
index
))
{
return
true
;
}
}
ExcelProperty
excelProperty
=
field
.
getAnnotation
(
ExcelProperty
.
class
);
List
<
String
>
tmpHeadList
=
new
ArrayList
<
String
>();
boolean
notForceName
=
excelProperty
==
null
||
excelProperty
.
value
().
length
<=
0
...
...
@@ -206,6 +230,7 @@ public class ExcelHeadProperty {
headMap
.
put
(
index
,
head
);
contentPropertyMap
.
put
(
index
,
excelContentProperty
);
fieldNameContentPropertyMap
.
put
(
field
.
getName
(),
excelContentProperty
);
return
false
;
}
public
Class
getHeadClazz
()
{
...
...
src/main/java/com/alibaba/excel/read/metadata/holder/AbstractReadHolder.java
浏览文件 @
f958af6f
...
...
@@ -70,7 +70,7 @@ public abstract class AbstractReadHolder extends AbstractHolder implements ReadH
}
// Initialization property
this
.
excelReadHeadProperty
=
new
ExcelReadHeadProperty
(
getClazz
(),
getHead
(),
convertAllFiled
);
this
.
excelReadHeadProperty
=
new
ExcelReadHeadProperty
(
this
,
getClazz
(),
getHead
(),
convertAllFiled
);
if
(
readBasicParameter
.
getHeadRowNumber
()
==
null
)
{
if
(
parentAbstractReadHolder
==
null
)
{
if
(
excelReadHeadProperty
.
hasHead
())
{
...
...
src/main/java/com/alibaba/excel/read/metadata/property/ExcelReadHeadProperty.java
浏览文件 @
f958af6f
...
...
@@ -2,6 +2,7 @@ package com.alibaba.excel.read.metadata.property;
import
java.util.List
;
import
com.alibaba.excel.metadata.Holder
;
import
com.alibaba.excel.metadata.property.ExcelHeadProperty
;
/**
...
...
@@ -11,7 +12,7 @@ import com.alibaba.excel.metadata.property.ExcelHeadProperty;
*/
public
class
ExcelReadHeadProperty
extends
ExcelHeadProperty
{
public
ExcelReadHeadProperty
(
Class
headClazz
,
List
<
List
<
String
>>
head
,
Boolean
convertAllFiled
)
{
super
(
headClazz
,
head
,
convertAllFiled
);
public
ExcelReadHeadProperty
(
Holder
holder
,
Class
headClazz
,
List
<
List
<
String
>>
head
,
Boolean
convertAllFiled
)
{
super
(
h
older
,
h
eadClazz
,
head
,
convertAllFiled
);
}
}
src/main/java/com/alibaba/excel/util/WorkBookUtil.java
浏览文件 @
f958af6f
...
...
@@ -31,12 +31,21 @@ public class WorkBookUtil {
if
(
writeWorkbookHolder
.
getTempTemplateInputStream
()
!=
null
)
{
XSSFWorkbook
xssfWorkbook
=
new
XSSFWorkbook
(
writeWorkbookHolder
.
getTempTemplateInputStream
());
writeWorkbookHolder
.
setCachedWorkbook
(
xssfWorkbook
);
writeWorkbookHolder
.
setWorkbook
(
new
SXSSFWorkbook
(
xssfWorkbook
,
ROW_ACCESS_WINDOW_SIZE
));
if
(
writeWorkbookHolder
.
getInMemory
())
{
writeWorkbookHolder
.
setWorkbook
(
xssfWorkbook
);
}
else
{
writeWorkbookHolder
.
setWorkbook
(
new
SXSSFWorkbook
(
xssfWorkbook
,
ROW_ACCESS_WINDOW_SIZE
));
}
return
;
}
SXSSFWorkbook
sxssWorkbook
=
new
SXSSFWorkbook
(
ROW_ACCESS_WINDOW_SIZE
);
writeWorkbookHolder
.
setCachedWorkbook
(
sxssWorkbook
);
writeWorkbookHolder
.
setWorkbook
(
sxssWorkbook
);
Workbook
workbook
=
null
;
if
(
writeWorkbookHolder
.
getInMemory
())
{
workbook
=
new
XSSFWorkbook
();
}
else
{
workbook
=
new
SXSSFWorkbook
(
ROW_ACCESS_WINDOW_SIZE
);
}
writeWorkbookHolder
.
setCachedWorkbook
(
workbook
);
writeWorkbookHolder
.
setWorkbook
(
workbook
);
return
;
}
HSSFWorkbook
hssfWorkbook
;
...
...
src/main/java/com/alibaba/excel/write/builder/ExcelWriterBuilder.java
浏览文件 @
f958af6f
...
...
@@ -4,6 +4,7 @@ import java.io.File;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
import
com.alibaba.excel.ExcelWriter
;
...
...
@@ -103,6 +104,48 @@ public class ExcelWriterBuilder {
return
this
;
}
/**
* Write excel in memory. Default false,the cache file is created and finally written to excel.
* <p>
* Comment and RichTextString are only supported in memory mode.
*/
public
ExcelWriterBuilder
inMemory
(
Boolean
inMemory
)
{
writeWorkbook
.
setInMemory
(
inMemory
);
return
this
;
}
/**
* Ignore the custom columns.
*/
public
ExcelWriterBuilder
excludeColumnIndexes
(
Collection
<
Integer
>
excludeColumnIndexes
)
{
writeWorkbook
.
setExcludeColumnIndexes
(
excludeColumnIndexes
);
return
this
;
}
/**
* Ignore the custom columns.
*/
public
ExcelWriterBuilder
excludeColumnFiledNames
(
Collection
<
String
>
excludeColumnFiledNames
)
{
writeWorkbook
.
setExcludeColumnFiledNames
(
excludeColumnFiledNames
);
return
this
;
}
/**
* Only output the custom columns.
*/
public
ExcelWriterBuilder
includeColumnIndexes
(
Collection
<
Integer
>
includeColumnIndexes
)
{
writeWorkbook
.
setIncludeColumnIndexes
(
includeColumnIndexes
);
return
this
;
}
/**
* Only output the custom columns.
*/
public
ExcelWriterBuilder
includeColumnFiledNames
(
Collection
<
String
>
includeColumnFiledNames
)
{
writeWorkbook
.
setIncludeColumnFiledNames
(
includeColumnFiledNames
);
return
this
;
}
/**
* The default is all excel objects.if true , you can use {@link com.alibaba.excel.annotation.ExcelIgnore} ignore a
* field. if false , you must use {@link com.alibaba.excel.annotation.ExcelProperty} to use a filed.
...
...
src/main/java/com/alibaba/excel/write/builder/ExcelWriterSheetBuilder.java
浏览文件 @
f958af6f
package
com.alibaba.excel.write.builder
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
import
com.alibaba.excel.ExcelWriter
;
...
...
@@ -135,6 +136,38 @@ public class ExcelWriterSheetBuilder {
return
this
;
}
/**
* Ignore the custom columns.
*/
public
ExcelWriterSheetBuilder
excludeColumnIndexes
(
Collection
<
Integer
>
excludeColumnIndexes
)
{
writeSheet
.
setExcludeColumnIndexes
(
excludeColumnIndexes
);
return
this
;
}
/**
* Ignore the custom columns.
*/
public
ExcelWriterSheetBuilder
excludeColumnFiledNames
(
Collection
<
String
>
excludeColumnFiledNames
)
{
writeSheet
.
setExcludeColumnFiledNames
(
excludeColumnFiledNames
);
return
this
;
}
/**
* Only output the custom columns.
*/
public
ExcelWriterSheetBuilder
includeColumnIndexes
(
Collection
<
Integer
>
includeColumnIndexes
)
{
writeSheet
.
setIncludeColumnIndexes
(
includeColumnIndexes
);
return
this
;
}
/**
* Only output the custom columns.
*/
public
ExcelWriterSheetBuilder
includeColumnFiledNames
(
Collection
<
String
>
includeColumnFiledNames
)
{
writeSheet
.
setIncludeColumnFiledNames
(
includeColumnFiledNames
);
return
this
;
}
public
WriteSheet
build
()
{
return
writeSheet
;
}
...
...
src/main/java/com/alibaba/excel/write/builder/ExcelWriterTableBuilder.java
浏览文件 @
f958af6f
package
com.alibaba.excel.write.builder
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
import
com.alibaba.excel.ExcelWriter
;
...
...
@@ -128,6 +129,39 @@ public class ExcelWriterTableBuilder {
return
this
;
}
/**
* Ignore the custom columns.
*/
public
ExcelWriterTableBuilder
excludeColumnIndexes
(
Collection
<
Integer
>
excludeColumnIndexes
)
{
writeTable
.
setExcludeColumnIndexes
(
excludeColumnIndexes
);
return
this
;
}
/**
* Ignore the custom columns.
*/
public
ExcelWriterTableBuilder
excludeColumnFiledNames
(
Collection
<
String
>
excludeColumnFiledNames
)
{
writeTable
.
setExcludeColumnFiledNames
(
excludeColumnFiledNames
);
return
this
;
}
/**
* Only output the custom columns.
*/
public
ExcelWriterTableBuilder
includeColumnIndexes
(
Collection
<
Integer
>
includeColumnIndexes
)
{
writeTable
.
setIncludeColumnIndexes
(
includeColumnIndexes
);
return
this
;
}
/**
* Only output the custom columns.
*/
public
ExcelWriterTableBuilder
includeColumnFiledNames
(
Collection
<
String
>
includeColumnFiledNames
)
{
writeSheet
.
setIncludeColumnFiledNames
(
includeColumnFiledNames
);
return
this
;
}
public
WriteTable
build
()
{
return
writeTable
;
}
...
...
src/main/java/com/alibaba/excel/write/executor/ExcelWriteAddExecutor.java
浏览文件 @
f958af6f
...
...
@@ -98,6 +98,9 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor {
private
void
doAddBasicTypeToExcel
(
List
<
Object
>
oneRowData
,
Head
head
,
Row
row
,
int
relativeRowIndex
,
int
dataIndex
,
int
cellIndex
)
{
if
(
writeContext
.
currentWriteHolder
().
ignore
(
null
,
cellIndex
))
{
return
;
}
WriteHandlerUtils
.
beforeCellCreate
(
writeContext
,
row
,
head
,
cellIndex
,
relativeRowIndex
,
Boolean
.
FALSE
);
Cell
cell
=
WorkBookUtil
.
createCell
(
row
,
cellIndex
);
WriteHandlerUtils
.
afterCellCreate
(
writeContext
,
cell
,
head
,
relativeRowIndex
,
Boolean
.
FALSE
);
...
...
@@ -121,6 +124,9 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor {
cellIndex
=
entry
.
getKey
();
ExcelContentProperty
excelContentProperty
=
entry
.
getValue
();
String
name
=
excelContentProperty
.
getField
().
getName
();
if
(
writeContext
.
currentWriteHolder
().
ignore
(
name
,
cellIndex
))
{
continue
;
}
if
(!
beanMap
.
containsKey
(
name
))
{
continue
;
}
...
...
@@ -147,7 +153,7 @@ public class ExcelWriteAddExecutor extends AbstractExcelWriteExecutor {
for
(
Field
field
:
fieldList
)
{
String
filedName
=
field
.
getName
();
boolean
uselessData
=
!
beanMap
.
containsKey
(
filedName
)
||
beanMapHandledSet
.
contains
(
filedName
)
||
ignoreMap
.
containsKey
(
filedName
);
||
ignoreMap
.
containsKey
(
filedName
)
||
writeContext
.
currentWriteHolder
().
ignore
(
filedName
,
cellIndex
)
;
if
(
uselessData
)
{
continue
;
}
...
...
src/main/java/com/alibaba/excel/write/executor/ExcelWriteFillExecutor.java
浏览文件 @
f958af6f
...
...
@@ -9,6 +9,7 @@ import java.util.Map;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.CellStyle
;
import
org.apache.poi.ss.usermodel.CellType
;
import
org.apache.poi.ss.usermodel.Row
;
import
org.apache.poi.ss.usermodel.Sheet
;
...
...
@@ -141,6 +142,9 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
Cell
cell
=
getOneCell
(
analysisCell
,
fillConfig
);
if
(
analysisCell
.
getOnlyOneVariable
())
{
String
variable
=
analysisCell
.
getVariableList
().
get
(
0
);
if
(
writeContext
.
currentWriteHolder
().
ignore
(
variable
,
analysisCell
.
getColumnIndex
()))
{
continue
;
}
if
(!
dataMap
.
containsKey
(
variable
))
{
continue
;
}
...
...
@@ -154,6 +158,9 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
List
<
CellData
>
cellDataList
=
new
ArrayList
<
CellData
>();
for
(
String
variable
:
analysisCell
.
getVariableList
())
{
cellValueBuild
.
append
(
analysisCell
.
getPrepareDataList
().
get
(
index
++));
if
(
writeContext
.
currentWriteHolder
().
ignore
(
variable
,
analysisCell
.
getColumnIndex
()))
{
continue
;
}
if
(!
dataMap
.
containsKey
(
variable
))
{
continue
;
}
...
...
@@ -279,11 +286,10 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
if
(
cell
==
null
)
{
continue
;
}
boolean
needFill
=
prepareData
(
cell
.
getStringCellValue
(),
analysisCellList
,
collectionAnalysisCellList
,
i
,
j
);
String
preparedData
=
prepareData
(
cell
,
analysisCellList
,
collectionAnalysisCellList
,
i
,
j
);
// Prevent empty data from not being replaced
if
(
needFi
ll
)
{
cell
.
setCellValue
(
StringUtils
.
EMPTY
);
if
(
preparedData
!=
nu
ll
)
{
cell
.
setCellValue
(
preparedData
);
}
}
}
...
...
@@ -295,18 +301,23 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
/**
* To prepare data
*
* @param
value
* @param
cell
* @param analysisCellList
* @param collectionAnalysisCellList
* @param rowIndex
* @param columnIndex
* @return
Is a cell to be filled
* @return
Returns the data that the cell needs to replace
*/
private
boolean
prepareData
(
String
value
,
List
<
AnalysisCell
>
analysisCellList
,
private
String
prepareData
(
Cell
cell
,
List
<
AnalysisCell
>
analysisCellList
,
List
<
AnalysisCell
>
collectionAnalysisCellList
,
int
rowIndex
,
int
columnIndex
)
{
if
(!
CellType
.
STRING
.
equals
(
cell
.
getCellTypeEnum
()))
{
return
null
;
}
String
value
=
cell
.
getStringCellValue
();
if
(
StringUtils
.
isEmpty
(
value
))
{
return
false
;
return
null
;
}
StringBuilder
preparedData
=
new
StringBuilder
();
AnalysisCell
analysisCell
=
null
;
int
startIndex
=
0
;
int
length
=
value
.
length
();
...
...
@@ -354,8 +365,9 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
if
(
lastPrepareDataIndex
==
prefixIndex
)
{
analysisCell
.
getPrepareDataList
().
add
(
StringUtils
.
EMPTY
);
}
else
{
analysisCell
.
getPrepareDataList
()
.
add
(
convertPrepareData
(
value
.
substring
(
lastPrepareDataIndex
,
prefixIndex
)));
String
data
=
convertPrepareData
(
value
.
substring
(
lastPrepareDataIndex
,
prefixIndex
));
preparedData
.
append
(
data
);
analysisCell
.
getPrepareDataList
().
add
(
data
);
analysisCell
.
setOnlyOneVariable
(
Boolean
.
FALSE
);
}
lastPrepareDataIndex
=
suffixIndex
+
1
;
...
...
@@ -372,9 +384,9 @@ public class ExcelWriteFillExecutor extends AbstractExcelWriteExecutor {
}
else
{
collectionAnalysisCellList
.
add
(
analysisCell
);
}
return
true
;
return
preparedData
.
toString
()
;
}
return
false
;
return
null
;
}
private
AnalysisCell
initAnalysisCell
(
Integer
rowIndex
,
Integer
columnIndex
)
{
...
...
src/main/java/com/alibaba/excel/write/metadata/WriteBasicParameter.java
浏览文件 @
f958af6f
package
com.alibaba.excel.write.metadata
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.List
;
import
com.alibaba.excel.metadata.BasicParameter
;
...
...
@@ -28,6 +29,22 @@ public class WriteBasicParameter extends BasicParameter {
* Use the default style.Default is true.
*/
private
Boolean
useDefaultStyle
;
/**
* Ignore the custom columns.
*/
private
Collection
<
Integer
>
excludeColumnIndexes
;
/**
* Ignore the custom columns.
*/
private
Collection
<
String
>
excludeColumnFiledNames
;
/**
* Only output the custom columns.
*/
private
Collection
<
Integer
>
includeColumnIndexes
;
/**
* Only output the custom columns.
*/
private
Collection
<
String
>
includeColumnFiledNames
;
public
Integer
getRelativeHeadRowIndex
()
{
return
relativeHeadRowIndex
;
...
...
@@ -60,4 +77,36 @@ public class WriteBasicParameter extends BasicParameter {
public
void
setUseDefaultStyle
(
Boolean
useDefaultStyle
)
{
this
.
useDefaultStyle
=
useDefaultStyle
;
}
public
Collection
<
Integer
>
getExcludeColumnIndexes
()
{
return
excludeColumnIndexes
;
}
public
void
setExcludeColumnIndexes
(
Collection
<
Integer
>
excludeColumnIndexes
)
{
this
.
excludeColumnIndexes
=
excludeColumnIndexes
;
}
public
Collection
<
String
>
getExcludeColumnFiledNames
()
{
return
excludeColumnFiledNames
;
}
public
void
setExcludeColumnFiledNames
(
Collection
<
String
>
excludeColumnFiledNames
)
{
this
.
excludeColumnFiledNames
=
excludeColumnFiledNames
;
}
public
Collection
<
Integer
>
getIncludeColumnIndexes
()
{
return
includeColumnIndexes
;
}
public
void
setIncludeColumnIndexes
(
Collection
<
Integer
>
includeColumnIndexes
)
{
this
.
includeColumnIndexes
=
includeColumnIndexes
;
}
public
Collection
<
String
>
getIncludeColumnFiledNames
()
{
return
includeColumnFiledNames
;
}
public
void
setIncludeColumnFiledNames
(
Collection
<
String
>
includeColumnFiledNames
)
{
this
.
includeColumnFiledNames
=
includeColumnFiledNames
;
}
}
src/main/java/com/alibaba/excel/write/metadata/WriteWorkbook.java
浏览文件 @
f958af6f
...
...
@@ -43,7 +43,7 @@ public class WriteWorkbook extends WriteBasicParameter {
*/
private
File
templateFile
;
/**
* Default true
useDefaultStyle
* Default true
.
*/
private
Boolean
autoCloseStream
;
/**
...
...
@@ -57,6 +57,12 @@ public class WriteWorkbook extends WriteBasicParameter {
*
*/
private
String
password
;
/**
* Write excel in memory. Default false,the cache file is created and finally written to excel.
* <p>
* Comment and RichTextString are only supported in memory mode.
*/
private
Boolean
inMemory
;
/**
* The default is all excel objects.Default is true.
* <p>
...
...
@@ -155,4 +161,12 @@ public class WriteWorkbook extends WriteBasicParameter {
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
public
Boolean
getInMemory
()
{
return
inMemory
;
}
public
void
setInMemory
(
Boolean
inMemory
)
{
this
.
inMemory
=
inMemory
;
}
}
src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java
浏览文件 @
f958af6f
package
com.alibaba.excel.write.metadata.holder
;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
...
...
@@ -65,6 +66,22 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
* Use the default style.Default is true.
*/
private
Boolean
useDefaultStyle
;
/**
* Ignore the custom columns.
*/
private
Collection
<
Integer
>
excludeColumnIndexes
;
/**
* Ignore the custom columns.
*/
private
Collection
<
String
>
excludeColumnFiledNames
;
/**
* Only output the custom columns.
*/
private
Collection
<
Integer
>
includeColumnIndexes
;
/**
* Only output the custom columns.
*/
private
Collection
<
String
>
includeColumnFiledNames
;
public
AbstractWriteHolder
(
WriteBasicParameter
writeBasicParameter
,
AbstractWriteHolder
parentAbstractWriteHolder
,
Boolean
convertAllFiled
)
{
...
...
@@ -110,8 +127,29 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
this
.
useDefaultStyle
=
writeBasicParameter
.
getUseDefaultStyle
();
}
if
(
writeBasicParameter
.
getExcludeColumnFiledNames
()
==
null
&&
parentAbstractWriteHolder
!=
null
)
{
this
.
excludeColumnFiledNames
=
parentAbstractWriteHolder
.
getExcludeColumnFiledNames
();
}
else
{
this
.
excludeColumnFiledNames
=
writeBasicParameter
.
getExcludeColumnFiledNames
();
}
if
(
writeBasicParameter
.
getExcludeColumnIndexes
()
==
null
&&
parentAbstractWriteHolder
!=
null
)
{
this
.
excludeColumnIndexes
=
parentAbstractWriteHolder
.
getExcludeColumnIndexes
();
}
else
{
this
.
excludeColumnIndexes
=
writeBasicParameter
.
getExcludeColumnIndexes
();
}
if
(
writeBasicParameter
.
getIncludeColumnFiledNames
()
==
null
&&
parentAbstractWriteHolder
!=
null
)
{
this
.
includeColumnFiledNames
=
parentAbstractWriteHolder
.
getIncludeColumnFiledNames
();
}
else
{
this
.
includeColumnFiledNames
=
writeBasicParameter
.
getIncludeColumnFiledNames
();
}
if
(
writeBasicParameter
.
getIncludeColumnIndexes
()
==
null
&&
parentAbstractWriteHolder
!=
null
)
{
this
.
includeColumnIndexes
=
parentAbstractWriteHolder
.
getIncludeColumnIndexes
();
}
else
{
this
.
includeColumnIndexes
=
writeBasicParameter
.
getIncludeColumnIndexes
();
}
// Initialization property
this
.
excelWriteHeadProperty
=
new
ExcelWriteHeadProperty
(
getClazz
(),
getHead
(),
convertAllFiled
);
this
.
excelWriteHeadProperty
=
new
ExcelWriteHeadProperty
(
this
,
getClazz
(),
getHead
(),
convertAllFiled
);
// Compatible with old code
compatibleOldCode
(
writeBasicParameter
);
...
...
@@ -148,7 +186,6 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
getConverterMap
().
put
(
ConverterKeyBuild
.
buildKey
(
converter
.
supportJavaTypeKey
()),
converter
);
}
}
}
/**
...
...
@@ -343,6 +380,27 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
return
result
;
}
@Override
public
boolean
ignore
(
String
fieldName
,
Integer
columnIndex
)
{
if
(
fieldName
!=
null
)
{
if
(
includeColumnFiledNames
!=
null
&&
!
includeColumnFiledNames
.
contains
(
fieldName
))
{
return
true
;
}
if
(
excludeColumnFiledNames
!=
null
&&
excludeColumnFiledNames
.
contains
(
fieldName
))
{
return
true
;
}
}
if
(
columnIndex
!=
null
)
{
if
(
includeColumnIndexes
!=
null
&&
!
includeColumnIndexes
.
contains
(
columnIndex
))
{
return
true
;
}
if
(
excludeColumnIndexes
!=
null
&&
excludeColumnIndexes
.
contains
(
columnIndex
))
{
return
true
;
}
}
return
false
;
}
public
Boolean
getNeedHead
()
{
return
needHead
;
}
...
...
@@ -383,6 +441,38 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
this
.
useDefaultStyle
=
useDefaultStyle
;
}
public
Collection
<
Integer
>
getExcludeColumnIndexes
()
{
return
excludeColumnIndexes
;
}
public
void
setExcludeColumnIndexes
(
Collection
<
Integer
>
excludeColumnIndexes
)
{
this
.
excludeColumnIndexes
=
excludeColumnIndexes
;
}
public
Collection
<
String
>
getExcludeColumnFiledNames
()
{
return
excludeColumnFiledNames
;
}
public
void
setExcludeColumnFiledNames
(
Collection
<
String
>
excludeColumnFiledNames
)
{
this
.
excludeColumnFiledNames
=
excludeColumnFiledNames
;
}
public
Collection
<
Integer
>
getIncludeColumnIndexes
()
{
return
includeColumnIndexes
;
}
public
void
setIncludeColumnIndexes
(
Collection
<
Integer
>
includeColumnIndexes
)
{
this
.
includeColumnIndexes
=
includeColumnIndexes
;
}
public
Collection
<
String
>
getIncludeColumnFiledNames
()
{
return
includeColumnFiledNames
;
}
public
void
setIncludeColumnFiledNames
(
Collection
<
String
>
includeColumnFiledNames
)
{
this
.
includeColumnFiledNames
=
includeColumnFiledNames
;
}
@Override
public
ExcelWriteHeadProperty
excelWriteHeadProperty
()
{
return
getExcelWriteHeadProperty
();
...
...
src/main/java/com/alibaba/excel/write/metadata/holder/WriteHolder.java
浏览文件 @
f958af6f
...
...
@@ -28,6 +28,15 @@ public interface WriteHolder extends ConfigurationHolder {
*/
Map
<
Class
<?
extends
WriteHandler
>,
List
<
WriteHandler
>>
writeHandlerMap
();
/**
* Is to determine if a field needs to be ignored
*
* @param fieldName
* @param columnIndex
* @return
*/
boolean
ignore
(
String
fieldName
,
Integer
columnIndex
);
/**
* Whether a header is required for the currently operated cell
*
...
...
src/main/java/com/alibaba/excel/write/metadata/holder/WriteWorkbookHolder.java
浏览文件 @
f958af6f
...
...
@@ -97,6 +97,12 @@ public class WriteWorkbookHolder extends AbstractWriteHolder {
* Whether the encryption
*/
private
String
password
;
/**
* Write excel in memory. Default false,the cache file is created and finally written to excel.
* <p>
* Comment and RichTextString are only supported in memory mode.
*/
private
Boolean
inMemory
;
public
WriteWorkbookHolder
(
WriteWorkbook
writeWorkbook
)
{
super
(
writeWorkbook
,
null
,
writeWorkbook
.
getConvertAllFiled
());
...
...
@@ -137,6 +143,11 @@ public class WriteWorkbookHolder extends AbstractWriteHolder {
}
this
.
hasBeenInitializedSheet
=
new
HashMap
<
Integer
,
WriteSheetHolder
>();
this
.
password
=
writeWorkbook
.
getPassword
();
if
(
writeWorkbook
.
getInMemory
()
==
null
)
{
this
.
inMemory
=
Boolean
.
FALSE
;
}
else
{
this
.
inMemory
=
writeWorkbook
.
getInMemory
();
}
}
private
void
copyTemplate
()
throws
IOException
{
...
...
@@ -262,6 +273,14 @@ public class WriteWorkbookHolder extends AbstractWriteHolder {
this
.
password
=
password
;
}
public
Boolean
getInMemory
()
{
return
inMemory
;
}
public
void
setInMemory
(
Boolean
inMemory
)
{
this
.
inMemory
=
inMemory
;
}
@Override
public
HolderEnum
holderType
()
{
return
HolderEnum
.
WORKBOOK
;
...
...
src/main/java/com/alibaba/excel/write/property/ExcelWriteHeadProperty.java
浏览文件 @
f958af6f
...
...
@@ -17,6 +17,7 @@ import com.alibaba.excel.enums.CellDataTypeEnum;
import
com.alibaba.excel.enums.HeadKindEnum
;
import
com.alibaba.excel.metadata.CellRange
;
import
com.alibaba.excel.metadata.Head
;
import
com.alibaba.excel.metadata.Holder
;
import
com.alibaba.excel.metadata.property.ColumnWidthProperty
;
import
com.alibaba.excel.metadata.property.ExcelContentProperty
;
import
com.alibaba.excel.metadata.property.ExcelHeadProperty
;
...
...
@@ -31,8 +32,8 @@ public class ExcelWriteHeadProperty extends ExcelHeadProperty {
private
RowHeightProperty
headRowHeightProperty
;
private
RowHeightProperty
contentRowHeightProperty
;
public
ExcelWriteHeadProperty
(
Class
headClazz
,
List
<
List
<
String
>>
head
,
Boolean
convertAllFiled
)
{
super
(
headClazz
,
head
,
convertAllFiled
);
public
ExcelWriteHeadProperty
(
Holder
holder
,
Class
headClazz
,
List
<
List
<
String
>>
head
,
Boolean
convertAllFiled
)
{
super
(
h
older
,
h
eadClazz
,
head
,
convertAllFiled
);
if
(
getHeadKind
()
!=
HeadKindEnum
.
CLASS
)
{
return
;
}
...
...
src/main/java/com/alibaba/excel/write/style/column/LongestMatchColumnWidthStyleStrategy.java
浏览文件 @
f958af6f
...
...
@@ -21,7 +21,7 @@ import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
*/
public
class
LongestMatchColumnWidthStyleStrategy
extends
AbstractColumnWidthStyleStrategy
{
private
static
final
int
MAX_COLUMN_WIDTH
=
25
6
;
private
static
final
int
MAX_COLUMN_WIDTH
=
25
5
;
private
static
final
Map
<
Integer
,
Map
<
Integer
,
Integer
>>
CACHE
=
new
HashMap
<
Integer
,
Map
<
Integer
,
Integer
>>(
8
);
...
...
src/test/java/com/alibaba/easyexcel/test/core/fill/FillData.java
浏览文件 @
f958af6f
...
...
@@ -15,4 +15,5 @@ public class FillData {
@NumberFormat
(
"#"
)
@ExcelProperty
(
converter
=
DoubleStringConverter
.
class
)
private
double
number
;
private
String
empty
;
}
src/test/java/com/alibaba/easyexcel/test/demo/write/WriteTest.java
浏览文件 @
f958af6f
...
...
@@ -4,7 +4,9 @@ import java.io.File;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
org.apache.poi.ss.usermodel.FillPatternType
;
import
org.apache.poi.ss.usermodel.IndexedColors
;
...
...
@@ -62,6 +64,35 @@ public class WriteTest {
excelWriter
.
finish
();
}
/**
* 根据参数只导出指定列
* <p>
* 1. 创建excel对应的实体对象 参照{@link DemoData}
* <p>
* 2. 根据自己或者排除自己需要的列
* <p>
* 3. 直接写即可
*/
@Test
public
void
excludeOrIncludeWrite
()
{
String
fileName
=
TestFileUtil
.
getPath
()
+
"excludeOrIncludeWrite"
+
System
.
currentTimeMillis
()
+
".xlsx"
;
// 根据用户传入字段 假设我们要忽略 date
Set
<
String
>
excludeColumnFiledNames
=
new
HashSet
<
String
>();
excludeColumnFiledNames
.
add
(
"date"
);
// 这里 需要指定写用哪个class去读,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
EasyExcel
.
write
(
fileName
,
DemoData
.
class
).
excludeColumnFiledNames
(
excludeColumnFiledNames
).
sheet
(
"模板"
)
.
doWrite
(
data
());
fileName
=
TestFileUtil
.
getPath
()
+
"excludeOrIncludeWrite"
+
System
.
currentTimeMillis
()
+
".xlsx"
;
// 根据用户传入字段 假设我们只要导出 date
Set
<
String
>
includeColumnFiledNames
=
new
HashSet
<
String
>();
includeColumnFiledNames
.
add
(
"date"
);
// 这里 需要指定写用哪个class去读,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
EasyExcel
.
write
(
fileName
,
DemoData
.
class
).
includeColumnFiledNames
(
includeColumnFiledNames
).
sheet
(
"模板"
)
.
doWrite
(
data
());
}
/**
* 指定写入的列
* <p>
...
...
src/test/java/com/alibaba/easyexcel/test/temp/simple/Wirte.java
浏览文件 @
f958af6f
...
...
@@ -19,6 +19,7 @@ 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
;
...
...
@@ -49,7 +50,8 @@ public class Wirte {
String
fileName
=
TestFileUtil
.
getPath
()
+
"t22"
+
System
.
currentTimeMillis
()
+
".xlsx"
;
// 这里 需要指定写用哪个class去读,然后写到第一个sheet,名字为模板 然后文件流会自动关闭
// 如果这里想使用03 则 传入excelType参数即可
EasyExcel
.
write
(
fileName
,
DemoData
.
class
).
sheet
(
"模板"
).
doWrite
(
data
());
EasyExcel
.
write
(
fileName
,
DemoData
.
class
)
.
registerWriteHandler
(
new
SimpleRowHeightStyleStrategy
((
short
)
150
,
(
short
)
120
)).
sheet
(
"模板"
).
doWrite
(
data
());
}
private
List
<
List
<
String
>>
head
()
{
...
...
src/test/resources/fill/simple.xls
浏览文件 @
f958af6f
无法预览此类型文件
src/test/resources/fill/simple.xlsx
浏览文件 @
f958af6f
无法预览此类型文件
update.md
浏览文件 @
f958af6f
# 2.1.0-beta3
*
支持强行指定在内存处理,以支持备注、RichTextString等的写入
*
修复关闭流失败,可能会不删除临时文件的问题
*
支持根据参数自定义导出列
*
修改最长匹配策略的最大长度
[
Issue #734
](
https://github.com/alibaba/easyexcel/issues/734
)
*
修复策略头未生效的bug
[
Issue #735
](
https://github.com/alibaba/easyexcel/issues/735
)
*
修复填充的时候有数字会异常
# 2.1.0-beta2
*
修改模板通过流创建报错的bug
*
修复空数据未替换掉的bug
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录