Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
金手指1668
easyexcel
提交
058df4d7
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,体验更适合开发者的 AI 搜索 >>
提交
058df4d7
编写于
7月 16, 2019
作者:
Z
zhuangjiaju
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
加入写excel支持注解
上级
17e20fb9
变更
69
显示空白变更内容
内联
并排
Showing
69 changed file
with
1671 addition
and
352 deletion
+1671
-352
src/main/java/com/alibaba/excel/EasyExcelFactory.java
src/main/java/com/alibaba/excel/EasyExcelFactory.java
+5
-4
src/main/java/com/alibaba/excel/analysis/BaseSaxAnalyser.java
...main/java/com/alibaba/excel/analysis/BaseSaxAnalyser.java
+3
-7
src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java
...ibaba/excel/analysis/v07/handlers/DefaultCellHandler.java
+12
-3
src/main/java/com/alibaba/excel/annotation/ExcelIgnore.java
src/main/java/com/alibaba/excel/annotation/ExcelIgnore.java
+17
-0
src/main/java/com/alibaba/excel/annotation/ExcelProperty.java
...main/java/com/alibaba/excel/annotation/ExcelProperty.java
+28
-16
src/main/java/com/alibaba/excel/annotation/format/DateTimeFormat.java
...a/com/alibaba/excel/annotation/format/DateTimeFormat.java
+36
-0
src/main/java/com/alibaba/excel/annotation/format/NumberFormat.java
...ava/com/alibaba/excel/annotation/format/NumberFormat.java
+37
-0
src/main/java/com/alibaba/excel/annotation/write/style/ColumnWidth.java
...com/alibaba/excel/annotation/write/style/ColumnWidth.java
+26
-0
src/main/java/com/alibaba/excel/annotation/write/style/ContentRowHeight.java
...libaba/excel/annotation/write/style/ContentRowHeight.java
+27
-0
src/main/java/com/alibaba/excel/annotation/write/style/ContentStyle.java
...om/alibaba/excel/annotation/write/style/ContentStyle.java
+31
-0
src/main/java/com/alibaba/excel/annotation/write/style/HeadRowHeight.java
...m/alibaba/excel/annotation/write/style/HeadRowHeight.java
+26
-0
src/main/java/com/alibaba/excel/annotation/write/style/HeadStyle.java
...a/com/alibaba/excel/annotation/write/style/HeadStyle.java
+27
-0
src/main/java/com/alibaba/excel/constant/ExcelXmlConstants.java
...in/java/com/alibaba/excel/constant/ExcelXmlConstants.java
+5
-3
src/main/java/com/alibaba/excel/context/AnalysisContext.java
src/main/java/com/alibaba/excel/context/AnalysisContext.java
+1
-1
src/main/java/com/alibaba/excel/context/AnalysisContextImpl.java
...n/java/com/alibaba/excel/context/AnalysisContextImpl.java
+1
-1
src/main/java/com/alibaba/excel/context/WriteContextImpl.java
...main/java/com/alibaba/excel/context/WriteContextImpl.java
+11
-16
src/main/java/com/alibaba/excel/converters/Converter.java
src/main/java/com/alibaba/excel/converters/Converter.java
+5
-5
src/main/java/com/alibaba/excel/converters/DefaultConverterLoader.java
.../com/alibaba/excel/converters/DefaultConverterLoader.java
+3
-3
src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalBooleanConverter.java
...cel/converters/bigdecimal/BigDecimalBooleanConverter.java
+3
-3
src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalNumberConverter.java
...xcel/converters/bigdecimal/BigDecimalNumberConverter.java
+3
-3
src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalStringConverter.java
...xcel/converters/bigdecimal/BigDecimalStringConverter.java
+14
-5
src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanBooleanConverter.java
.../converters/booleanconverter/BooleanBooleanConverter.java
+3
-3
src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanNumberConverter.java
...l/converters/booleanconverter/BooleanNumberConverter.java
+3
-3
src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanStringConverter.java
...l/converters/booleanconverter/BooleanStringConverter.java
+3
-3
src/main/java/com/alibaba/excel/converters/byteconverter/ByteBooleanConverter.java
.../excel/converters/byteconverter/ByteBooleanConverter.java
+3
-3
src/main/java/com/alibaba/excel/converters/byteconverter/ByteNumberConverter.java
...a/excel/converters/byteconverter/ByteNumberConverter.java
+3
-3
src/main/java/com/alibaba/excel/converters/byteconverter/ByteStringConverter.java
...a/excel/converters/byteconverter/ByteStringConverter.java
+3
-3
src/main/java/com/alibaba/excel/converters/date/DateNumberConverter.java
...om/alibaba/excel/converters/date/DateNumberConverter.java
+9
-5
src/main/java/com/alibaba/excel/converters/date/DateStringConverter.java
...om/alibaba/excel/converters/date/DateStringConverter.java
+14
-5
src/main/java/com/alibaba/excel/converters/doubleconverter/ByteBooleanConverter.java
...xcel/converters/doubleconverter/ByteBooleanConverter.java
+3
-3
src/main/java/com/alibaba/excel/converters/doubleconverter/DoubleNumberConverter.java
...cel/converters/doubleconverter/DoubleNumberConverter.java
+35
-0
src/main/java/com/alibaba/excel/converters/doubleconverter/DoubleStringConverter.java
...cel/converters/doubleconverter/DoubleStringConverter.java
+3
-3
src/main/java/com/alibaba/excel/converters/string/StringStringConverter.java
...libaba/excel/converters/string/StringStringConverter.java
+3
-3
src/main/java/com/alibaba/excel/enums/CellDataTypeEnum.java
src/main/java/com/alibaba/excel/enums/CellDataTypeEnum.java
+1
-5
src/main/java/com/alibaba/excel/event/ModelBuildEventListener.java
...java/com/alibaba/excel/event/ModelBuildEventListener.java
+12
-14
src/main/java/com/alibaba/excel/metadata/CellStyle.java
src/main/java/com/alibaba/excel/metadata/CellStyle.java
+13
-0
src/main/java/com/alibaba/excel/metadata/ExcelColumnProperty.java
.../java/com/alibaba/excel/metadata/ExcelColumnProperty.java
+0
-105
src/main/java/com/alibaba/excel/metadata/Head.java
src/main/java/com/alibaba/excel/metadata/Head.java
+24
-19
src/main/java/com/alibaba/excel/metadata/Workbook.java
src/main/java/com/alibaba/excel/metadata/Workbook.java
+16
-0
src/main/java/com/alibaba/excel/metadata/holder/AbstractConfigurationSelector.java
.../excel/metadata/holder/AbstractConfigurationSelector.java
+106
-1
src/main/java/com/alibaba/excel/metadata/holder/ConfigurationSelector.java
.../alibaba/excel/metadata/holder/ConfigurationSelector.java
+1
-1
src/main/java/com/alibaba/excel/metadata/holder/SheetHolder.java
...n/java/com/alibaba/excel/metadata/holder/SheetHolder.java
+9
-1
src/main/java/com/alibaba/excel/metadata/holder/TableHolder.java
...n/java/com/alibaba/excel/metadata/holder/TableHolder.java
+8
-1
src/main/java/com/alibaba/excel/metadata/holder/WorkbookHolder.java
...ava/com/alibaba/excel/metadata/holder/WorkbookHolder.java
+29
-4
src/main/java/com/alibaba/excel/metadata/property/CellStyleProperty.java
...om/alibaba/excel/metadata/property/CellStyleProperty.java
+84
-0
src/main/java/com/alibaba/excel/metadata/property/ColumnWidthProperty.java
.../alibaba/excel/metadata/property/ColumnWidthProperty.java
+31
-0
src/main/java/com/alibaba/excel/metadata/property/DateTimeFormatProperty.java
...ibaba/excel/metadata/property/DateTimeFormatProperty.java
+41
-0
src/main/java/com/alibaba/excel/metadata/property/ExcelContentProperty.java
...alibaba/excel/metadata/property/ExcelContentProperty.java
+62
-0
src/main/java/com/alibaba/excel/metadata/property/ExcelHeadProperty.java
...om/alibaba/excel/metadata/property/ExcelHeadProperty.java
+350
-0
src/main/java/com/alibaba/excel/metadata/property/NumberFormatProperty.java
...alibaba/excel/metadata/property/NumberFormatProperty.java
+43
-0
src/main/java/com/alibaba/excel/metadata/property/RowHeightProperty.java
...om/alibaba/excel/metadata/property/RowHeightProperty.java
+39
-0
src/main/java/com/alibaba/excel/util/StringUtils.java
src/main/java/com/alibaba/excel/util/StringUtils.java
+94
-0
src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java
src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java
+73
-22
src/main/java/com/alibaba/excel/write/builder/ExcelWriterBuilder.java
...a/com/alibaba/excel/write/builder/ExcelWriterBuilder.java
+18
-4
src/main/java/com/alibaba/excel/write/handler/CellWriteHandler.java
...ava/com/alibaba/excel/write/handler/CellWriteHandler.java
+13
-3
src/main/java/com/alibaba/excel/write/handler/DefaultWriteHandlerLoader.java
...libaba/excel/write/handler/DefaultWriteHandlerLoader.java
+2
-2
src/main/java/com/alibaba/excel/write/handler/RowWriteHandler.java
...java/com/alibaba/excel/write/handler/RowWriteHandler.java
+11
-3
src/main/java/com/alibaba/excel/write/handler/SheetWriteHandler.java
...va/com/alibaba/excel/write/handler/SheetWriteHandler.java
+5
-3
src/main/java/com/alibaba/excel/write/handler/WorkbookWriteHandler.java
...com/alibaba/excel/write/handler/WorkbookWriteHandler.java
+2
-4
src/main/java/com/alibaba/excel/write/merge/AbstractMergeStrategy.java
.../com/alibaba/excel/write/merge/AbstractMergeStrategy.java
+13
-0
src/main/java/com/alibaba/excel/write/style/AbstractCellStyleStrategy.java
.../alibaba/excel/write/style/AbstractCellStyleStrategy.java
+24
-0
src/main/java/com/alibaba/excel/write/style/AbstractColumnCellStyleStrategy.java
...ba/excel/write/style/AbstractColumnCellStyleStrategy.java
+29
-10
src/main/java/com/alibaba/excel/write/style/column/AbstractColumnWidthStyleStrategy.java
.../write/style/column/AbstractColumnWidthStyleStrategy.java
+3
-2
src/main/java/com/alibaba/excel/write/style/column/AbstractHeadColumnWidthStyleStrategy.java
...te/style/column/AbstractHeadColumnWidthStyleStrategy.java
+8
-3
src/main/java/com/alibaba/excel/write/style/column/SimpleColumnWidthStyleStrategy.java
...el/write/style/column/SimpleColumnWidthStyleStrategy.java
+5
-3
src/main/java/com/alibaba/excel/write/style/row/AbstractRowHeightStyleStrategy.java
...excel/write/style/row/AbstractRowHeightStyleStrategy.java
+23
-6
src/main/java/com/alibaba/excel/write/style/row/SimpleRowHeightStyleStrategy.java
...a/excel/write/style/row/SimpleRowHeightStyleStrategy.java
+33
-0
src/main/java/com/alibaba/excel/write/style/row/SimpleRowHighStyleStrategy.java
...aba/excel/write/style/row/SimpleRowHighStyleStrategy.java
+0
-29
src/test/java/com/alibaba/easyexcel/test/wirte/nohead/NoHeadData07Test.java
...alibaba/easyexcel/test/wirte/nohead/NoHeadData07Test.java
+40
-0
未找到文件。
src/main/java/com/alibaba/excel/EasyExcelFactory.java
浏览文件 @
058df4d7
...
...
@@ -81,7 +81,8 @@ public class EasyExcelFactory {
*/
@Deprecated
public
static
ExcelWriter
getWriter
(
OutputStream
outputStream
)
{
return
writerBuilder
().
outputFile
(
outputStream
).
autoCloseStream
(
Boolean
.
FALSE
).
build
();
return
writerBuilder
().
outputFile
(
outputStream
).
autoCloseStream
(
Boolean
.
FALSE
).
convertAllFiled
(
Boolean
.
FALSE
)
.
build
();
}
/**
...
...
@@ -99,7 +100,7 @@ public class EasyExcelFactory {
@Deprecated
public
static
ExcelWriter
getWriter
(
OutputStream
outputStream
,
ExcelTypeEnum
typeEnum
,
boolean
needHead
)
{
return
writerBuilder
().
outputFile
(
outputStream
).
excelType
(
typeEnum
).
needHead
(
needHead
)
.
autoCloseStream
(
Boolean
.
FALSE
).
build
();
.
autoCloseStream
(
Boolean
.
FALSE
).
convertAllFiled
(
Boolean
.
FALSE
).
build
();
}
/**
...
...
@@ -119,7 +120,7 @@ public class EasyExcelFactory {
public
static
ExcelWriter
getWriterWithTemp
(
InputStream
temp
,
OutputStream
outputStream
,
ExcelTypeEnum
typeEnum
,
boolean
needHead
)
{
return
writerBuilder
().
withTemplate
(
temp
).
outputFile
(
outputStream
).
excelType
(
typeEnum
).
needHead
(
needHead
)
.
autoCloseStream
(
Boolean
.
FALSE
).
build
();
.
autoCloseStream
(
Boolean
.
FALSE
).
convertAllFiled
(
Boolean
.
FALSE
).
build
();
}
/**
...
...
@@ -142,7 +143,7 @@ public class EasyExcelFactory {
public
static
ExcelWriter
getWriterWithTempAndHandler
(
InputStream
temp
,
OutputStream
outputStream
,
ExcelTypeEnum
typeEnum
,
boolean
needHead
,
WriteHandler
handler
)
{
return
writerBuilder
().
withTemplate
(
temp
).
outputFile
(
outputStream
).
excelType
(
typeEnum
).
needHead
(
needHead
)
.
registerWriteHandler
(
handler
).
autoCloseStream
(
Boolean
.
FALSE
).
build
();
.
registerWriteHandler
(
handler
).
autoCloseStream
(
Boolean
.
FALSE
).
convertAllFiled
(
Boolean
.
FALSE
).
build
();
}
public
static
ExcelWriterBuilder
writerBuilder
()
{
...
...
src/main/java/com/alibaba/excel/analysis/BaseSaxAnalyser.java
浏览文件 @
058df4d7
package
com.alibaba.excel.analysis
;
import
java.util.Collection
;
import
java.util.HashMap
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
...
...
@@ -11,14 +10,11 @@ import com.alibaba.excel.context.AnalysisContext;
import
com.alibaba.excel.converters.Converter
;
import
com.alibaba.excel.converters.ConverterKey
;
import
com.alibaba.excel.converters.ConverterRegistryCenter
;
import
com.alibaba.excel.converters.DefaultConverterBuilder
;
import
com.alibaba.excel.converters.bigdecimal.BigDecimalBooleanConverter
;
import
com.alibaba.excel.converters.bigdecimal.BigDecimalNumberConverter
;
import
com.alibaba.excel.converters.string.StringStringConverter
;
import
com.alibaba.excel.converters.DefaultConverterLoader
;
import
com.alibaba.excel.event.AnalysisEventListener
;
import
com.alibaba.excel.event.AnalysisEventRegistryCenter
;
import
com.alibaba.excel.event.AnalysisFinishEvent
;
import
com.alibaba.excel.metadata.ExcelHeadProperty
;
import
com.alibaba.excel.metadata.
property.
ExcelHeadProperty
;
import
com.alibaba.excel.metadata.Sheet
;
/**
...
...
@@ -56,7 +52,7 @@ public abstract class BaseSaxAnalyser implements ConverterRegistryCenter, Analys
}
private
void
registerDefaultConverters
()
{
converters
.
putAll
(
DefaultConverter
Buil
der
.
loadDefaultReadConverter
());
converters
.
putAll
(
DefaultConverter
Loa
der
.
loadDefaultReadConverter
());
}
@Override
...
...
src/main/java/com/alibaba/excel/analysis/v07/handlers/DefaultCellHandler.java
浏览文件 @
058df4d7
package
com.alibaba.excel.analysis.v07.handlers
;
import
static
com
.
alibaba
.
excel
.
constant
.
ExcelXmlConstants
.
CELL_FORMULA_TAG
;
import
static
com
.
alibaba
.
excel
.
constant
.
ExcelXmlConstants
.
CELL_INLINE_STRING_VALUE_TAG
;
import
static
com
.
alibaba
.
excel
.
constant
.
ExcelXmlConstants
.
CELL_TAG
;
import
static
com
.
alibaba
.
excel
.
constant
.
ExcelXmlConstants
.
CELL_VALUE_TAG
;
import
static
com
.
alibaba
.
excel
.
constant
.
ExcelXmlConstants
.
CELL_VALUE_TAG_1
;
import
static
com
.
alibaba
.
excel
.
constant
.
ExcelXmlConstants
.
CELL_VALUE_TYPE_TAG
;
import
java.util.Arrays
;
import
org.apache.poi.ss.usermodel.RichTextString
;
import
org.apache.poi.xssf.model.SharedStringsTable
;
import
org.apache.poi.xssf.usermodel.XSSFRichTextString
;
import
org.xml.sax.Attributes
;
import
com.alibaba.excel.analysis.v07.XlsxCellHandler
;
...
...
@@ -48,7 +49,7 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder
@Override
public
boolean
support
(
String
name
)
{
return
CELL_VALUE_TAG
.
equals
(
name
)
||
CELL_FORMULA_TAG
.
equals
(
name
)
||
CELL_
VALUE_TAG_1
.
equals
(
name
)
return
CELL_VALUE_TAG
.
equals
(
name
)
||
CELL_FORMULA_TAG
.
equals
(
name
)
||
CELL_
INLINE_STRING_VALUE_TAG
.
equals
(
name
)
||
CELL_TAG
.
equals
(
name
);
}
...
...
@@ -61,13 +62,14 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder
int
nextRow
=
PositionUtils
.
getRow
(
currentCellIndex
);
if
(
nextRow
>
curRow
)
{
curRow
=
nextRow
;
// endRow(ROW_TAG);
}
analysisContext
.
setCurrentRowNum
(
curRow
);
curCol
=
PositionUtils
.
getCol
(
currentCellIndex
);
// t="s" ,it's means String
// t="inlineStr" ,it's means String
// t="b" ,it's means Boolean
// t="e" ,it's means Error
// t is null ,it's means Empty or Number
CellDataTypeEnum
type
=
CellDataTypeEnum
.
buildFromCellType
(
attributes
.
getValue
(
CELL_VALUE_TYPE_TAG
));
currentCellData
=
new
CellData
(
type
);
...
...
@@ -89,6 +91,13 @@ public class DefaultCellHandler implements XlsxCellHandler, XlsxRowResultHolder
}
curRowContent
[
curCol
]
=
currentCellData
;
}
// This is a special form of string
if
(
CELL_INLINE_STRING_VALUE_TAG
.
equals
(
name
))
{
ensureSize
();
XSSFRichTextString
richTextString
=
new
XSSFRichTextString
(
currentCellData
.
getStringValue
());
currentCellData
.
setStringValue
(
richTextString
.
toString
());
curRowContent
[
curCol
]
=
currentCellData
;
}
}
private
void
ensureSize
()
{
...
...
src/main/java/com/alibaba/excel/annotation/Excel
ColumnNum
.java
→
src/main/java/com/alibaba/excel/annotation/Excel
Ignore
.java
浏览文件 @
058df4d7
...
...
@@ -7,28 +7,11 @@ import java.lang.annotation.RetentionPolicy;
import
java.lang.annotation.Target
;
/**
* Created by jipengfei on 17/3/19.
* Field column num at excel head
* Ignore convert excel
*
* @author
jipengfei
* @author
zhuangjiaju
*/
@Target
(
ElementType
.
FIELD
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Inherited
public
@interface
ExcelColumnNum
{
/**
* col num
* @return
*/
int
value
();
/**
*
* Default @see com.alibaba.excel.util.TypeUtil
* if default is not meet you can set format
*
* @return
*/
String
format
()
default
""
;
}
public
@interface
ExcelIgnore
{}
src/main/java/com/alibaba/excel/annotation/ExcelProperty.java
浏览文件 @
058df4d7
...
...
@@ -15,19 +15,31 @@ import java.lang.annotation.Target;
public
@interface
ExcelProperty
{
/**
* The name of the sheet header.
*
* <li>write: It automatically merges when you have more than one head
* <li>read: When you have multiple heads, take the first one
*
* @return
*/
String
[]
value
()
default
{
""
};
/**
* Index of column
*
* Read or write it on the index of column,If it's equal to -1, it's sorted by Java class
*
* @return
*/
int
index
()
default
99999
;
int
index
()
default
-
1
;
/**
*
* default @see com.alibaba.excel.util.TypeUtil
* if default is not meet you can set format
* default @see com.alibaba.excel.util.TypeUtil if default is not meet you can set format
*
* @return
* @deprecated please use {@link com.alibaba.excel.annotation.format.DateTimeFormat}
*/
@Deprecated
String
format
()
default
""
;
}
src/main/java/com/alibaba/excel/annotation/format/DateTimeFormat.java
0 → 100644
浏览文件 @
058df4d7
package
com.alibaba.excel.annotation.format
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Inherited
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
/**
* Convert date format.
*
* <li>write: It can be used on classes {@link java.util.Date}
* <li>read: It can be used on classes {@link String}
*
* @author zhuangjiaju
*/
@Target
(
ElementType
.
FIELD
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Inherited
public
@interface
DateTimeFormat
{
/**
*
* Specific format reference {@link java.text.SimpleDateFormat}
*
* @return
*/
String
value
()
default
""
;
/**
* true if date uses 1904 windowing, or false if using 1900 date windowing.
*
* @return
*/
boolean
use1904windowing
()
default
false
;
}
src/main/java/com/alibaba/excel/annotation/format/NumberFormat.java
0 → 100644
浏览文件 @
058df4d7
package
com.alibaba.excel.annotation.format
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Inherited
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
import
java.math.RoundingMode
;
/**
* Convert number format.
*
* <li>write: It can be used on classes that inherit {@link Number}
* <li>read: It can be used on classes {@link String}
*
* @author zhuangjiaju
*/
@Target
(
ElementType
.
FIELD
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Inherited
public
@interface
NumberFormat
{
/**
*
* Specific format reference {@link org.apache.commons.math3.fraction.BigFractionFormat}
*
* @return
*/
String
value
()
default
""
;
/**
* Rounded by default
*
* @return
*/
RoundingMode
roundingMode
()
default
RoundingMode
.
HALF_UP
;
}
src/main/java/com/alibaba/excel/annotation/write/style/ColumnWidth.java
0 → 100644
浏览文件 @
058df4d7
package
com.alibaba.excel.annotation.write.style
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Inherited
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
/**
* Set the width of the table
*
* @author zhuangjiaju
*/
@Target
({
ElementType
.
FIELD
,
ElementType
.
TYPE
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Inherited
public
@interface
ColumnWidth
{
/**
* Using the Calibri font as an example, the maximum digit width of 11 point font size is 7 pixels (at 96 dpi). If
* you set a column width to be 8 characters wide, e.g. <code>8*256</code>
*
* <p>
* -1 mean the auto set width
*/
int
value
()
default
-
1
;
}
src/main/java/com/alibaba/excel/annotation/write/style/ContentRowHeight.java
0 → 100644
浏览文件 @
058df4d7
package
com.alibaba.excel.annotation.write.style
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Inherited
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
/**
* Set the height of each table
*
* @author zhuangjiaju
*/
@Target
({
ElementType
.
TYPE
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Inherited
public
@interface
ContentRowHeight
{
/**
* Set the content height
* <p>
* -1 mean the auto set height
*
* @return
*/
short
value
()
default
-
1
;
}
src/main/java/com/alibaba/excel/annotation/write/style/ContentStyle.java
0 → 100644
浏览文件 @
058df4d7
package
com.alibaba.excel.annotation.write.style
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Inherited
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
import
org.apache.poi.ss.usermodel.IndexedColors
;
/**
* Convert number format.
*
* <li>write: It can be used on classes that inherit {@link Number}
* <li>read: It can be used on classes {@link String}
*
* @author zhuangjiaju
*/
@Target
({
ElementType
.
FIELD
,
ElementType
.
TYPE
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Inherited
public
@interface
ContentStyle
{
String
fontName
()
default
"宋体"
;
short
fontHeightInPoints
()
default
(
short
)
14
;
boolean
bold
()
default
true
;
IndexedColors
indexedColors
()
default
IndexedColors
.
WHITE1
;
}
src/main/java/com/alibaba/excel/annotation/write/style/HeadRowHeight.java
0 → 100644
浏览文件 @
058df4d7
package
com.alibaba.excel.annotation.write.style
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Inherited
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
/**
* Set the height of each table
*
* @author zhuangjiaju
*/
@Target
({
ElementType
.
TYPE
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Inherited
public
@interface
HeadRowHeight
{
/**
* Set the header height
* <p>
* -1 mean the auto set height
*
* @return
*/
short
value
()
default
-
1
;
}
src/main/java/com/alibaba/excel/annotation/write/style/HeadStyle.java
0 → 100644
浏览文件 @
058df4d7
package
com.alibaba.excel.annotation.write.style
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Inherited
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
import
java.lang.annotation.Target
;
import
org.apache.poi.ss.usermodel.IndexedColors
;
/**
* 配置
*
* @author zhuangjiaju
*/
@Target
({
ElementType
.
FIELD
,
ElementType
.
TYPE
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Inherited
public
@interface
HeadStyle
{
String
fontName
()
default
"宋体"
;
short
fontHeightInPoints
()
default
(
short
)
14
;
boolean
bold
()
default
true
;
IndexedColors
indexedColors
()
default
IndexedColors
.
GREY_25_PERCENT
;
}
src/main/java/com/alibaba/excel/constant/ExcelXmlConstants.java
浏览文件 @
058df4d7
...
...
@@ -10,10 +10,12 @@ public class ExcelXmlConstants {
public
static
final
String
ROW_TAG
=
"row"
;
public
static
final
String
CELL_TAG
=
"c"
;
public
static
final
String
CELL_VALUE_TYPE_TAG
=
"t"
;
public
static
final
String
CELL_FORMULA_TAG
=
"f"
;
public
static
final
String
CELL_VALUE_TAG
=
"v"
;
public
static
final
String
CELL_VALUE_TYPE_TAG
=
"t"
;
public
static
final
String
CELL_VALUE_TAG_1
=
"t"
;
/**
* When the data is "inlineStr" his tag is "t"
*/
public
static
final
String
CELL_INLINE_STRING_VALUE_TAG
=
"t"
;
}
src/main/java/com/alibaba/excel/context/AnalysisContext.java
浏览文件 @
058df4d7
...
...
@@ -4,7 +4,7 @@ import java.io.InputStream;
import
com.alibaba.excel.converters.ConverterRegistryCenter
;
import
com.alibaba.excel.event.AnalysisEventListener
;
import
com.alibaba.excel.metadata.ExcelHeadProperty
;
import
com.alibaba.excel.metadata.
property.
ExcelHeadProperty
;
import
com.alibaba.excel.metadata.Sheet
;
import
com.alibaba.excel.support.ExcelTypeEnum
;
...
...
src/main/java/com/alibaba/excel/context/AnalysisContextImpl.java
浏览文件 @
058df4d7
...
...
@@ -5,7 +5,7 @@ import java.io.InputStream;
import
com.alibaba.excel.converters.ConverterRegistryCenter
;
import
com.alibaba.excel.event.AnalysisEventListener
;
import
com.alibaba.excel.exception.ExcelAnalysisException
;
import
com.alibaba.excel.metadata.ExcelHeadProperty
;
import
com.alibaba.excel.metadata.
property.
ExcelHeadProperty
;
import
com.alibaba.excel.metadata.Sheet
;
import
com.alibaba.excel.support.ExcelTypeEnum
;
...
...
src/main/java/com/alibaba/excel/context/WriteContextImpl.java
浏览文件 @
058df4d7
...
...
@@ -2,6 +2,7 @@ package com.alibaba.excel.context;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.Row
;
...
...
@@ -11,13 +12,13 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
com.alibaba.excel.exception.ExcelGenerateException
;
import
com.alibaba.excel.metadata.ExcelHeadProperty
;
import
com.alibaba.excel.metadata.Head
;
import
com.alibaba.excel.metadata.Table
;
import
com.alibaba.excel.metadata.holder.ConfigurationSelector
;
import
com.alibaba.excel.metadata.holder.SheetHolder
;
import
com.alibaba.excel.metadata.holder.TableHolder
;
import
com.alibaba.excel.metadata.holder.WorkbookHolder
;
import
com.alibaba.excel.metadata.property.ExcelHeadProperty
;
import
com.alibaba.excel.util.WorkBookUtil
;
import
com.alibaba.excel.write.handler.CellWriteHandler
;
import
com.alibaba.excel.write.handler.RowWriteHandler
;
...
...
@@ -184,9 +185,6 @@ public class WriteContextImpl implements WriteContext {
}
currentSheetHolder
.
setSheet
(
currentSheet
);
// Initialization head
currentSheetHolder
.
setExcelHeadProperty
(
new
ExcelHeadProperty
(
currentSheetHolder
.
getClazz
(),
currentSheetHolder
.
getHead
()));
// Initialization head
initHead
(
currentSheetHolder
.
getExcelHeadProperty
());
}
...
...
@@ -203,7 +201,7 @@ public class WriteContextImpl implements WriteContext {
beforeRowCreate
(
rowIndex
,
relativeRowIndex
);
Row
row
=
WorkBookUtil
.
createRow
(
currentSheetHolder
.
getSheet
(),
i
);
afterRowCreate
(
row
,
relativeRowIndex
);
addOneRowOfHeadDataToExcel
(
row
,
excelHeadProperty
.
getHead
List
(),
relativeRowIndex
);
addOneRowOfHeadDataToExcel
(
row
,
excelHeadProperty
.
getHead
Map
(),
relativeRowIndex
);
}
}
...
...
@@ -237,18 +235,18 @@ public class WriteContextImpl implements WriteContext {
}
private
void
addMergedRegionToCurrentSheet
(
ExcelHeadProperty
excelHeadProperty
,
int
rowIndex
)
{
for
(
com
.
alibaba
.
excel
.
metadata
.
CellRange
cellRangeModel
:
excelHeadProperty
.
getCellRangeModels
())
{
for
(
com
.
alibaba
.
excel
.
metadata
.
CellRange
cellRangeModel
:
excelHeadProperty
.
headCellRangeList
())
{
currentSheetHolder
.
getSheet
().
addMergedRegion
(
new
CellRangeAddress
(
cellRangeModel
.
getFirstRow
()
+
rowIndex
,
cellRangeModel
.
getLastRow
()
+
rowIndex
,
cellRangeModel
.
getFirstCol
(),
cellRangeModel
.
getLastCol
()));
}
}
private
void
addOneRowOfHeadDataToExcel
(
Row
row
,
List
<
Head
>
headList
,
int
relativeRowIndex
)
{
for
(
int
i
=
0
;
i
<
headList
.
size
();
i
++
)
{
Head
head
=
headList
.
get
(
i
);
beforeCellCreate
(
row
,
head
List
.
get
(
i
)
,
relativeRowIndex
);
Cell
cell
=
WorkBookUtil
.
createCell
(
row
,
i
,
head
.
getHeadName
(
i
));
afterCellCreate
(
head
List
.
get
(
i
)
,
cell
,
relativeRowIndex
);
private
void
addOneRowOfHeadDataToExcel
(
Row
row
,
Map
<
Integer
,
Head
>
headMap
,
int
relativeRowIndex
)
{
for
(
Map
.
Entry
<
Integer
,
Head
>
entry
:
headMap
.
entrySet
()
)
{
Head
head
=
entry
.
getValue
(
);
beforeCellCreate
(
row
,
head
,
relativeRowIndex
);
Cell
cell
=
WorkBookUtil
.
createCell
(
row
,
entry
.
getKey
(),
head
.
getHeadNameList
().
get
(
relativeRowIndex
));
afterCellCreate
(
head
,
cell
,
relativeRowIndex
);
}
}
...
...
@@ -302,14 +300,11 @@ public class WriteContextImpl implements WriteContext {
return
;
}
initCurrentTableHolder
(
table
);
// Initialization head
currentTableHolder
.
setExcelHeadProperty
(
new
ExcelHeadProperty
(
currentTableHolder
.
getClazz
(),
currentTableHolder
.
getHead
()));
initHead
(
currentTableHolder
.
getExcelHeadProperty
());
}
private
void
initCurrentTableHolder
(
com
.
alibaba
.
excel
.
metadata
.
Table
table
)
{
currentTableHolder
=
new
TableHolder
(
table
,
currentSheetHolder
);
currentTableHolder
=
new
TableHolder
(
table
,
currentSheetHolder
,
currentWorkbookHolder
);
currentSheetHolder
.
getHasBeenInitializedTable
().
put
(
table
.
getTableNo
(),
currentTableHolder
);
currentConfigurationSelector
=
currentTableHolder
;
if
(
LOGGER
.
isDebugEnabled
())
{
...
...
src/main/java/com/alibaba/excel/converters/Converter.java
浏览文件 @
058df4d7
...
...
@@ -2,7 +2,7 @@ package com.alibaba.excel.converters;
import
com.alibaba.excel.enums.CellDataTypeEnum
;
import
com.alibaba.excel.metadata.CellData
;
import
com.alibaba.excel.metadata.
ExcelColumn
Property
;
import
com.alibaba.excel.metadata.
property.ExcelContent
Property
;
import
com.sun.istack.internal.NotNull
;
import
com.sun.istack.internal.Nullable
;
...
...
@@ -32,19 +32,19 @@ public interface Converter<T> {
* Convert excel objects to Java objects
*
* @param cellData
* @param co
lumn
Property
* @param co
ntent
Property
* @return
* @throws Exception
*/
T
convertToJavaData
(
@NotNull
CellData
cellData
,
@Nullable
ExcelCo
lumnProperty
column
Property
)
throws
Exception
;
T
convertToJavaData
(
@NotNull
CellData
cellData
,
@Nullable
ExcelCo
ntentProperty
content
Property
)
throws
Exception
;
/**
* Convert Java objects to excel objects
*
* @param value
* @param co
lumn
Property
* @param co
ntent
Property
* @return
* @throws Exception
*/
CellData
convertToExcelData
(
@NotNull
T
value
,
@Nullable
ExcelCo
lumnProperty
column
Property
)
throws
Exception
;
CellData
convertToExcelData
(
@NotNull
T
value
,
@Nullable
ExcelCo
ntentProperty
content
Property
)
throws
Exception
;
}
src/main/java/com/alibaba/excel/converters/DefaultConverter
Buil
der.java
→
src/main/java/com/alibaba/excel/converters/DefaultConverter
Loa
der.java
浏览文件 @
058df4d7
...
...
@@ -8,13 +8,13 @@ import com.alibaba.excel.converters.date.DateStringConverter;
import
com.alibaba.excel.converters.string.StringStringConverter
;
/**
*
Buil
d default handler
*
Loa
d default handler
*
* @author zhuangjiaju
*/
public
class
DefaultConverter
Buil
der
{
public
class
DefaultConverter
Loa
der
{
/**
* Load default w
ir
te converter
* Load default w
ri
te converter
*
* @return
*/
...
...
src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalBooleanConverter.java
浏览文件 @
058df4d7
...
...
@@ -5,7 +5,7 @@ import java.math.BigDecimal;
import
com.alibaba.excel.converters.Converter
;
import
com.alibaba.excel.enums.CellDataTypeEnum
;
import
com.alibaba.excel.metadata.CellData
;
import
com.alibaba.excel.metadata.
ExcelColumn
Property
;
import
com.alibaba.excel.metadata.
property.ExcelContent
Property
;
/**
* BigDecimal and boolean converter
...
...
@@ -25,7 +25,7 @@ public class BigDecimalBooleanConverter implements Converter<BigDecimal> {
}
@Override
public
BigDecimal
convertToJavaData
(
CellData
cellData
,
ExcelCo
lumnProperty
column
Property
)
{
public
BigDecimal
convertToJavaData
(
CellData
cellData
,
ExcelCo
ntentProperty
content
Property
)
{
if
(
cellData
.
getBooleanValue
())
{
return
BigDecimal
.
ONE
;
}
...
...
@@ -33,7 +33,7 @@ public class BigDecimalBooleanConverter implements Converter<BigDecimal> {
}
@Override
public
CellData
convertToExcelData
(
BigDecimal
value
,
ExcelCo
lumnProperty
column
Property
)
{
public
CellData
convertToExcelData
(
BigDecimal
value
,
ExcelCo
ntentProperty
content
Property
)
{
if
(
BigDecimal
.
ONE
.
equals
(
value
))
{
return
new
CellData
(
Boolean
.
TRUE
);
}
...
...
src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalNumberConverter.java
浏览文件 @
058df4d7
...
...
@@ -5,7 +5,7 @@ import java.math.BigDecimal;
import
com.alibaba.excel.converters.Converter
;
import
com.alibaba.excel.enums.CellDataTypeEnum
;
import
com.alibaba.excel.metadata.CellData
;
import
com.alibaba.excel.metadata.
ExcelColumn
Property
;
import
com.alibaba.excel.metadata.
property.ExcelContent
Property
;
/**
* BigDecimal and number converter
...
...
@@ -25,12 +25,12 @@ public class BigDecimalNumberConverter implements Converter<BigDecimal> {
}
@Override
public
BigDecimal
convertToJavaData
(
CellData
cellData
,
ExcelCo
lumnProperty
column
Property
)
{
public
BigDecimal
convertToJavaData
(
CellData
cellData
,
ExcelCo
ntentProperty
content
Property
)
{
return
new
BigDecimal
(
cellData
.
getDoubleValue
());
}
@Override
public
CellData
convertToExcelData
(
BigDecimal
value
,
ExcelCo
lumnProperty
column
Property
)
{
public
CellData
convertToExcelData
(
BigDecimal
value
,
ExcelCo
ntentProperty
content
Property
)
{
return
new
CellData
(
value
.
doubleValue
());
}
}
src/main/java/com/alibaba/excel/converters/bigdecimal/BigDecimalStringConverter.java
浏览文件 @
058df4d7
package
com.alibaba.excel.converters.bigdecimal
;
import
java.math.BigDecimal
;
import
java.math.RoundingMode
;
import
java.text.DecimalFormat
;
import
com.alibaba.excel.converters.Converter
;
import
com.alibaba.excel.enums.CellDataTypeEnum
;
import
com.alibaba.excel.metadata.CellData
;
import
com.alibaba.excel.metadata.
ExcelColumn
Property
;
import
com.alibaba.excel.metadata.
property.ExcelContent
Property
;
import
com.alibaba.excel.util.StringUtils
;
/**
...
...
@@ -27,15 +28,23 @@ public class BigDecimalStringConverter implements Converter<BigDecimal> {
}
@Override
public
BigDecimal
convertToJavaData
(
CellData
cellData
,
ExcelCo
lumnProperty
column
Property
)
{
public
BigDecimal
convertToJavaData
(
CellData
cellData
,
ExcelCo
ntentProperty
content
Property
)
{
return
new
BigDecimal
(
cellData
.
getStringValue
());
}
@Override
public
CellData
convertToExcelData
(
BigDecimal
value
,
ExcelColumnProperty
columnProperty
)
{
if
(
StringUtils
.
isEmpty
(
columnProperty
.
getFormat
()))
{
public
CellData
convertToExcelData
(
BigDecimal
value
,
ExcelContentProperty
contentProperty
)
{
String
format
=
null
;
RoundingMode
roundingMode
=
RoundingMode
.
HALF_UP
;
if
(
contentProperty
.
getNumberFormatProperty
()
!=
null
)
{
format
=
contentProperty
.
getNumberFormatProperty
().
getFormat
();
roundingMode
=
contentProperty
.
getNumberFormatProperty
().
getRoundingMode
();
}
if
(
StringUtils
.
isEmpty
(
format
))
{
return
new
CellData
(
value
.
toString
());
}
return
new
CellData
(
new
DecimalFormat
(
columnProperty
.
getFormat
()).
format
(
value
));
DecimalFormat
decimalFormat
=
new
DecimalFormat
(
format
);
decimalFormat
.
setRoundingMode
(
roundingMode
);
return
new
CellData
(
decimalFormat
.
format
(
value
));
}
}
src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanBooleanConverter.java
浏览文件 @
058df4d7
...
...
@@ -3,7 +3,7 @@ package com.alibaba.excel.converters.booleanconverter;
import
com.alibaba.excel.converters.Converter
;
import
com.alibaba.excel.enums.CellDataTypeEnum
;
import
com.alibaba.excel.metadata.CellData
;
import
com.alibaba.excel.metadata.
ExcelColumn
Property
;
import
com.alibaba.excel.metadata.
property.ExcelContent
Property
;
/**
* Boolean and boolean converter
...
...
@@ -23,12 +23,12 @@ public class BooleanBooleanConverter implements Converter<Boolean> {
}
@Override
public
Boolean
convertToJavaData
(
CellData
cellData
,
ExcelCo
lumnProperty
column
Property
)
{
public
Boolean
convertToJavaData
(
CellData
cellData
,
ExcelCo
ntentProperty
content
Property
)
{
return
cellData
.
getBooleanValue
();
}
@Override
public
CellData
convertToExcelData
(
Boolean
value
,
ExcelCo
lumnProperty
column
Property
)
{
public
CellData
convertToExcelData
(
Boolean
value
,
ExcelCo
ntentProperty
content
Property
)
{
return
new
CellData
(
value
);
}
...
...
src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanNumberConverter.java
浏览文件 @
058df4d7
...
...
@@ -3,7 +3,7 @@ package com.alibaba.excel.converters.booleanconverter;
import
com.alibaba.excel.converters.Converter
;
import
com.alibaba.excel.enums.CellDataTypeEnum
;
import
com.alibaba.excel.metadata.CellData
;
import
com.alibaba.excel.metadata.
ExcelColumn
Property
;
import
com.alibaba.excel.metadata.
property.ExcelContent
Property
;
/**
* Boolean and number converter
...
...
@@ -26,7 +26,7 @@ public class BooleanNumberConverter implements Converter<Boolean> {
}
@Override
public
Boolean
convertToJavaData
(
CellData
cellData
,
ExcelCo
lumnProperty
column
Property
)
{
public
Boolean
convertToJavaData
(
CellData
cellData
,
ExcelCo
ntentProperty
content
Property
)
{
if
(
ONE
.
equals
(
cellData
.
getDoubleValue
()))
{
return
Boolean
.
TRUE
;
}
...
...
@@ -34,7 +34,7 @@ public class BooleanNumberConverter implements Converter<Boolean> {
}
@Override
public
CellData
convertToExcelData
(
Boolean
value
,
ExcelCo
lumnProperty
column
Property
)
{
public
CellData
convertToExcelData
(
Boolean
value
,
ExcelCo
ntentProperty
content
Property
)
{
if
(
value
)
{
return
new
CellData
(
ONE
);
}
...
...
src/main/java/com/alibaba/excel/converters/booleanconverter/BooleanStringConverter.java
浏览文件 @
058df4d7
...
...
@@ -3,7 +3,7 @@ package com.alibaba.excel.converters.booleanconverter;
import
com.alibaba.excel.converters.Converter
;
import
com.alibaba.excel.enums.CellDataTypeEnum
;
import
com.alibaba.excel.metadata.CellData
;
import
com.alibaba.excel.metadata.
ExcelColumn
Property
;
import
com.alibaba.excel.metadata.
property.ExcelContent
Property
;
/**
* Boolean and string converter
...
...
@@ -23,12 +23,12 @@ public class BooleanStringConverter implements Converter<Boolean> {
}
@Override
public
Boolean
convertToJavaData
(
CellData
cellData
,
ExcelCo
lumnProperty
column
Property
)
{
public
Boolean
convertToJavaData
(
CellData
cellData
,
ExcelCo
ntentProperty
content
Property
)
{
return
Boolean
.
valueOf
(
cellData
.
getStringValue
());
}
@Override
public
CellData
convertToExcelData
(
Boolean
value
,
ExcelCo
lumnProperty
column
Property
)
{
public
CellData
convertToExcelData
(
Boolean
value
,
ExcelCo
ntentProperty
content
Property
)
{
return
new
CellData
(
value
.
toString
());
}
...
...
src/main/java/com/alibaba/excel/converters/byteconverter/ByteBooleanConverter.java
浏览文件 @
058df4d7
...
...
@@ -3,7 +3,7 @@ package com.alibaba.excel.converters.byteconverter;
import
com.alibaba.excel.converters.Converter
;
import
com.alibaba.excel.enums.CellDataTypeEnum
;
import
com.alibaba.excel.metadata.CellData
;
import
com.alibaba.excel.metadata.
ExcelColumn
Property
;
import
com.alibaba.excel.metadata.
property.ExcelContent
Property
;
/**
* Byte and boolean converter
...
...
@@ -25,7 +25,7 @@ public class ByteBooleanConverter implements Converter<Byte> {
}
@Override
public
Byte
convertToJavaData
(
CellData
cellData
,
ExcelCo
lumnProperty
column
Property
)
{
public
Byte
convertToJavaData
(
CellData
cellData
,
ExcelCo
ntentProperty
content
Property
)
{
if
(
cellData
.
getBooleanValue
())
{
return
ONE
;
}
...
...
@@ -33,7 +33,7 @@ public class ByteBooleanConverter implements Converter<Byte> {
}
@Override
public
CellData
convertToExcelData
(
Byte
value
,
ExcelCo
lumnProperty
column
Property
)
{
public
CellData
convertToExcelData
(
Byte
value
,
ExcelCo
ntentProperty
content
Property
)
{
if
(
ONE
.
equals
(
value
))
{
return
new
CellData
(
Boolean
.
TRUE
);
}
...
...
src/main/java/com/alibaba/excel/converters/byteconverter/ByteNumberConverter.java
浏览文件 @
058df4d7
...
...
@@ -3,7 +3,7 @@ package com.alibaba.excel.converters.byteconverter;
import
com.alibaba.excel.converters.Converter
;
import
com.alibaba.excel.enums.CellDataTypeEnum
;
import
com.alibaba.excel.metadata.CellData
;
import
com.alibaba.excel.metadata.
ExcelColumn
Property
;
import
com.alibaba.excel.metadata.
property.ExcelContent
Property
;
/**
* Byte and number converter
...
...
@@ -23,12 +23,12 @@ public class ByteNumberConverter implements Converter<Byte> {
}
@Override
public
Byte
convertToJavaData
(
CellData
cellData
,
ExcelCo
lumnProperty
column
Property
)
{
public
Byte
convertToJavaData
(
CellData
cellData
,
ExcelCo
ntentProperty
content
Property
)
{
return
cellData
.
getDoubleValue
().
byteValue
();
}
@Override
public
CellData
convertToExcelData
(
Byte
value
,
ExcelCo
lumnProperty
column
Property
)
{
public
CellData
convertToExcelData
(
Byte
value
,
ExcelCo
ntentProperty
content
Property
)
{
return
new
CellData
((
double
)
value
);
}
...
...
src/main/java/com/alibaba/excel/converters/byteconverter/ByteStringConverter.java
浏览文件 @
058df4d7
...
...
@@ -3,7 +3,7 @@ package com.alibaba.excel.converters.byteconverter;
import
com.alibaba.excel.converters.Converter
;
import
com.alibaba.excel.enums.CellDataTypeEnum
;
import
com.alibaba.excel.metadata.CellData
;
import
com.alibaba.excel.metadata.
ExcelColumn
Property
;
import
com.alibaba.excel.metadata.
property.ExcelContent
Property
;
/**
* Byte and string converter
...
...
@@ -23,12 +23,12 @@ public class ByteStringConverter implements Converter<Byte> {
}
@Override
public
Byte
convertToJavaData
(
CellData
cellData
,
ExcelCo
lumnProperty
column
Property
)
{
public
Byte
convertToJavaData
(
CellData
cellData
,
ExcelCo
ntentProperty
content
Property
)
{
return
Byte
.
valueOf
(
cellData
.
getStringValue
());
}
@Override
public
CellData
convertToExcelData
(
Byte
value
,
ExcelCo
lumnProperty
column
Property
)
{
public
CellData
convertToExcelData
(
Byte
value
,
ExcelCo
ntentProperty
content
Property
)
{
return
new
CellData
(
value
.
toString
());
}
...
...
src/main/java/com/alibaba/excel/converters/date/DateNumberConverter.java
浏览文件 @
058df4d7
...
...
@@ -7,7 +7,7 @@ import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import
com.alibaba.excel.converters.Converter
;
import
com.alibaba.excel.enums.CellDataTypeEnum
;
import
com.alibaba.excel.metadata.CellData
;
import
com.alibaba.excel.metadata.
ExcelColumn
Property
;
import
com.alibaba.excel.metadata.
property.ExcelContent
Property
;
/**
* Date and number converter
...
...
@@ -27,13 +27,17 @@ public class DateNumberConverter implements Converter<Date> {
}
@Override
public
Date
convertToJavaData
(
CellData
cellData
,
ExcelColumnProperty
columnProperty
)
{
return
HSSFDateUtil
.
getJavaDate
(
cellData
.
getDoubleValue
(),
columnProperty
.
getUse1904windowing
(),
columnProperty
.
getTimeZone
());
public
Date
convertToJavaData
(
CellData
cellData
,
ExcelContentProperty
contentProperty
)
{
if
(
contentProperty
.
getDateTimeFormatProperty
()
==
null
)
{
return
HSSFDateUtil
.
getJavaDate
(
cellData
.
getDoubleValue
(),
false
,
null
);
}
else
{
return
HSSFDateUtil
.
getJavaDate
(
cellData
.
getDoubleValue
(),
contentProperty
.
getDateTimeFormatProperty
().
getUse1904windowing
(),
null
);
}
}
@Override
public
CellData
convertToExcelData
(
Date
value
,
ExcelCo
lumnProperty
column
Property
)
{
public
CellData
convertToExcelData
(
Date
value
,
ExcelCo
ntentProperty
content
Property
)
{
return
new
CellData
((
double
)(
value
.
getTime
()));
}
}
src/main/java/com/alibaba/excel/converters/date/DateStringConverter.java
浏览文件 @
058df4d7
...
...
@@ -6,7 +6,7 @@ import java.util.Date;
import
com.alibaba.excel.converters.Converter
;
import
com.alibaba.excel.enums.CellDataTypeEnum
;
import
com.alibaba.excel.metadata.CellData
;
import
com.alibaba.excel.metadata.
ExcelColumn
Property
;
import
com.alibaba.excel.metadata.
property.ExcelContent
Property
;
import
com.alibaba.excel.util.DateUtils
;
/**
...
...
@@ -26,12 +26,21 @@ public class DateStringConverter implements Converter<Date> {
}
@Override
public
Date
convertToJavaData
(
CellData
cellData
,
ExcelColumnProperty
columnProperty
)
throws
ParseException
{
return
DateUtils
.
parseDate
(
cellData
.
getStringValue
(),
columnProperty
.
getFormat
());
public
Date
convertToJavaData
(
CellData
cellData
,
ExcelContentProperty
contentProperty
)
throws
ParseException
{
if
(
contentProperty
.
getDateTimeFormatProperty
()
==
null
)
{
return
DateUtils
.
parseDate
(
cellData
.
getStringValue
(),
null
);
}
else
{
return
DateUtils
.
parseDate
(
cellData
.
getStringValue
(),
contentProperty
.
getDateTimeFormatProperty
().
getFormat
());
}
}
@Override
public
CellData
convertToExcelData
(
Date
value
,
ExcelColumnProperty
columnProperty
)
{
return
new
CellData
(
DateUtils
.
format
(
value
,
columnProperty
.
getFormat
()));
public
CellData
convertToExcelData
(
Date
value
,
ExcelContentProperty
contentProperty
)
{
if
(
contentProperty
.
getDateTimeFormatProperty
()
==
null
)
{
return
new
CellData
(
DateUtils
.
format
(
value
,
null
));
}
else
{
return
new
CellData
(
DateUtils
.
format
(
value
,
contentProperty
.
getDateTimeFormatProperty
().
getFormat
()));
}
}
}
src/main/java/com/alibaba/excel/converters/doubleconverter/ByteBooleanConverter.java
浏览文件 @
058df4d7
...
...
@@ -3,7 +3,7 @@ package com.alibaba.excel.converters.doubleconverter;
import
com.alibaba.excel.converters.Converter
;
import
com.alibaba.excel.enums.CellDataTypeEnum
;
import
com.alibaba.excel.metadata.CellData
;
import
com.alibaba.excel.metadata.
ExcelColumn
Property
;
import
com.alibaba.excel.metadata.
property.ExcelContent
Property
;
/**
* Byte and boolean converter
...
...
@@ -25,7 +25,7 @@ public class ByteBooleanConverter implements Converter<Byte> {
}
@Override
public
Byte
convertToJavaData
(
CellData
cellData
,
ExcelCo
lumnProperty
column
Property
)
{
public
Byte
convertToJavaData
(
CellData
cellData
,
ExcelCo
ntentProperty
content
Property
)
{
if
(
cellData
.
getBooleanValue
())
{
return
ONE
;
}
...
...
@@ -33,7 +33,7 @@ public class ByteBooleanConverter implements Converter<Byte> {
}
@Override
public
CellData
convertToExcelData
(
Byte
value
,
ExcelCo
lumnProperty
column
Property
)
{
public
CellData
convertToExcelData
(
Byte
value
,
ExcelCo
ntentProperty
content
Property
)
{
if
(
ONE
.
equals
(
value
))
{
return
new
CellData
(
Boolean
.
TRUE
);
}
...
...
src/main/java/com/alibaba/excel/converters/doubleconverter/
Byt
eNumberConverter.java
→
src/main/java/com/alibaba/excel/converters/doubleconverter/
Doubl
eNumberConverter.java
浏览文件 @
058df4d7
...
...
@@ -3,18 +3,18 @@ package com.alibaba.excel.converters.doubleconverter;
import
com.alibaba.excel.converters.Converter
;
import
com.alibaba.excel.enums.CellDataTypeEnum
;
import
com.alibaba.excel.metadata.CellData
;
import
com.alibaba.excel.metadata.
ExcelColumn
Property
;
import
com.alibaba.excel.metadata.
property.ExcelContent
Property
;
/**
*
Byt
e and number converter
*
Doubl
e and number converter
*
* @author zhuangjiaju
*/
public
class
ByteNumberConverter
implements
Converter
<
Byt
e
>
{
public
class
DoubleNumberConverter
implements
Converter
<
Doubl
e
>
{
@Override
public
Class
supportJavaTypeKey
()
{
return
Byt
e
.
class
;
return
Doubl
e
.
class
;
}
@Override
...
...
@@ -23,13 +23,13 @@ public class ByteNumberConverter implements Converter<Byte> {
}
@Override
public
Byte
convertToJavaData
(
CellData
cellData
,
ExcelColumnProperty
columnProperty
)
{
return
cellData
.
getDoubleValue
()
.
byteValue
()
;
public
Double
convertToJavaData
(
CellData
cellData
,
ExcelContentProperty
contentProperty
)
throws
Exception
{
return
cellData
.
getDoubleValue
();
}
@Override
public
CellData
convertToExcelData
(
Byte
value
,
ExcelColumnProperty
columnProperty
)
{
return
new
CellData
(
(
double
)
value
);
public
CellData
convertToExcelData
(
Double
value
,
ExcelContentProperty
contentProperty
)
throws
Exception
{
return
new
CellData
(
value
);
}
}
src/main/java/com/alibaba/excel/converters/doubleconverter/DoubleStringConverter.java
浏览文件 @
058df4d7
...
...
@@ -3,7 +3,7 @@ package com.alibaba.excel.converters.doubleconverter;
import
com.alibaba.excel.converters.Converter
;
import
com.alibaba.excel.enums.CellDataTypeEnum
;
import
com.alibaba.excel.metadata.CellData
;
import
com.alibaba.excel.metadata.
ExcelColumn
Property
;
import
com.alibaba.excel.metadata.
property.ExcelContent
Property
;
/**
* Double and string converter
...
...
@@ -23,12 +23,12 @@ public class DoubleStringConverter implements Converter<Double> {
}
@Override
public
Double
convertToJavaData
(
CellData
cellData
,
ExcelCo
lumnProperty
column
Property
)
{
public
Double
convertToJavaData
(
CellData
cellData
,
ExcelCo
ntentProperty
content
Property
)
{
return
Double
.
valueOf
(
cellData
.
getStringValue
());
}
@Override
public
CellData
convertToExcelData
(
Double
value
,
ExcelCo
lumnProperty
column
Property
)
{
public
CellData
convertToExcelData
(
Double
value
,
ExcelCo
ntentProperty
content
Property
)
{
return
new
CellData
(
value
.
toString
());
}
}
src/main/java/com/alibaba/excel/converters/string/StringStringConverter.java
浏览文件 @
058df4d7
...
...
@@ -3,7 +3,7 @@ package com.alibaba.excel.converters.string;
import
com.alibaba.excel.converters.Converter
;
import
com.alibaba.excel.enums.CellDataTypeEnum
;
import
com.alibaba.excel.metadata.CellData
;
import
com.alibaba.excel.metadata.
ExcelColumn
Property
;
import
com.alibaba.excel.metadata.
property.ExcelContent
Property
;
/**
* String and string converter
...
...
@@ -22,12 +22,12 @@ public class StringStringConverter implements Converter<String> {
}
@Override
public
String
convertToJavaData
(
CellData
cellData
,
ExcelCo
lumnProperty
column
Property
)
{
public
String
convertToJavaData
(
CellData
cellData
,
ExcelCo
ntentProperty
content
Property
)
{
return
cellData
.
getStringValue
();
}
@Override
public
CellData
convertToExcelData
(
String
value
,
ExcelCo
lumnProperty
column
Property
)
{
public
CellData
convertToExcelData
(
String
value
,
ExcelCo
ntentProperty
content
Property
)
{
return
new
CellData
(
value
);
}
...
...
src/main/java/com/alibaba/excel/enums/CellDataTypeEnum.java
浏览文件 @
058df4d7
...
...
@@ -16,10 +16,6 @@ public enum CellDataTypeEnum {
* string
*/
STRING
,
/**
* inlineString
*/
INLINE_STRING
,
/**
* number
*/
...
...
@@ -40,7 +36,7 @@ public enum CellDataTypeEnum {
private
static
final
Map
<
String
,
CellDataTypeEnum
>
TYPE_ROUTING_MAP
=
new
HashMap
<
String
,
CellDataTypeEnum
>(
8
);
static
{
TYPE_ROUTING_MAP
.
put
(
"s"
,
STRING
);
TYPE_ROUTING_MAP
.
put
(
"inlineStr"
,
INLINE_
STRING
);
TYPE_ROUTING_MAP
.
put
(
"inlineStr"
,
STRING
);
TYPE_ROUTING_MAP
.
put
(
"e"
,
ERROR
);
TYPE_ROUTING_MAP
.
put
(
"b"
,
BOOLEAN
);
}
...
...
src/main/java/com/alibaba/excel/event/ModelBuildEventListener.java
浏览文件 @
058df4d7
...
...
@@ -11,8 +11,8 @@ import com.alibaba.excel.enums.CellDataTypeEnum;
import
com.alibaba.excel.exception.ExcelDataConvertException
;
import
com.alibaba.excel.exception.ExcelGenerateException
;
import
com.alibaba.excel.metadata.CellData
;
import
com.alibaba.excel.metadata.
ExcelColumn
Property
;
import
com.alibaba.excel.metadata.ExcelHeadProperty
;
import
com.alibaba.excel.metadata.
property.ExcelContent
Property
;
import
com.alibaba.excel.metadata.
property.
ExcelHeadProperty
;
import
net.sf.cglib.beans.BeanMap
;
...
...
@@ -21,6 +21,7 @@ import net.sf.cglib.beans.BeanMap;
*/
public
class
ModelBuildEventListener
extends
AnalysisEventListener
<
Object
>
{
private
final
Map
<
ConverterKey
,
Converter
>
converters
;
public
ModelBuildEventListener
(
Map
<
ConverterKey
,
Converter
>
converters
)
{
this
.
converters
=
converters
;
}
...
...
@@ -42,20 +43,17 @@ public class ModelBuildEventListener extends AnalysisEventListener<Object> {
private
Object
buildUserModel
(
AnalysisContext
context
,
List
<
CellData
>
cellDataList
)
throws
Exception
{
ExcelHeadProperty
excelHeadProperty
=
context
.
getExcelHeadProperty
();
Object
resultModel
=
excelHeadProperty
.
getHeadClazz
().
newInstance
();
if
(
excelHeadProperty
==
null
)
{
return
resultModel
;
}
Map
map
=
new
HashMap
();
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
for
(
int
i
=
0
;
i
<
cellDataList
.
size
();
i
++)
{
ExcelCo
lumnProperty
columnProperty
=
excelHeadProperty
.
getExcelColumnProperty
(
i
);
if
(
co
lumn
Property
!=
null
)
{
ExcelCo
ntentProperty
contentProperty
=
excelHeadProperty
.
getContentPropertyMap
().
get
(
i
);
if
(
co
ntent
Property
!=
null
)
{
CellData
cellData
=
cellDataList
.
get
(
i
);
if
(
cellData
.
getType
()
==
CellDataTypeEnum
.
EMPTY
)
{
continue
;
}
Object
value
=
convertValue
(
cellDataList
.
get
(
i
),
co
lumnProperty
.
getField
().
getClass
(),
column
Property
);
Object
value
=
convertValue
(
cellDataList
.
get
(
i
),
co
ntentProperty
.
getField
().
getClass
(),
content
Property
);
if
(
value
!=
null
)
{
map
.
put
(
co
lumn
Property
.
getField
().
getName
(),
value
);
map
.
put
(
co
ntent
Property
.
getField
().
getName
(),
value
);
}
}
}
...
...
@@ -63,14 +61,14 @@ public class ModelBuildEventListener extends AnalysisEventListener<Object> {
return
resultModel
;
}
private
Object
convertValue
(
CellData
cellData
,
Class
clazz
,
ExcelCo
lumnProperty
column
Property
)
{
private
Object
convertValue
(
CellData
cellData
,
Class
clazz
,
ExcelCo
ntentProperty
content
Property
)
{
Converter
converter
=
converters
.
get
(
ConverterKey
.
buildConverterKey
(
clazz
,
cellData
.
getType
()));
if
(
converter
==
null
)
{
throw
new
ExcelDataConvertException
(
"Converter not found, convert
e
"
+
cellData
.
getType
()
+
" to "
+
clazz
.
getName
());
"Converter not found, convert "
+
cellData
.
getType
()
+
" to "
+
clazz
.
getName
());
}
try
{
return
converter
.
convertToJavaData
(
cellData
,
co
lumn
Property
);
return
converter
.
convertToJavaData
(
cellData
,
co
ntent
Property
);
}
catch
(
Exception
e
)
{
throw
new
ExcelDataConvertException
(
"Convert data "
+
cellData
+
" to "
+
clazz
+
" error "
,
e
);
}
...
...
src/main/java/com/alibaba/excel/metadata/CellStyle.java
浏览文件 @
058df4d7
...
...
@@ -17,6 +17,19 @@ public class CellStyle {
*/
private
Font
font
;
public
CellStyle
()
{
}
public
CellStyle
(
String
fontName
,
Short
fontHeightInPoints
,
Boolean
bold
,
IndexedColors
indexedColors
)
{
Font
font
=
new
Font
();
font
.
setFontName
(
fontName
);
font
.
setFontHeightInPoints
(
fontHeightInPoints
);
font
.
setBold
(
bold
);
this
.
font
=
font
;
this
.
indexedColors
=
indexedColors
;
}
public
IndexedColors
getIndexedColors
()
{
return
indexedColors
;
}
...
...
src/main/java/com/alibaba/excel/metadata/ExcelColumnProperty.java
已删除
100644 → 0
浏览文件 @
17e20fb9
package
com.alibaba.excel.metadata
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.TimeZone
;
/**
* @author jipengfei
*/
public
class
ExcelColumnProperty
implements
Comparable
<
ExcelColumnProperty
>
{
/**
*/
private
Field
field
;
/**
*/
private
int
index
=
99999
;
/**
*/
private
List
<
String
>
head
=
new
ArrayList
<
String
>();
/**
*
*/
private
String
format
;
private
Boolean
use1904windowing
;
private
TimeZone
timeZone
;
private
int
scale
;
private
int
roundingMode
;
public
int
getScale
()
{
return
scale
;
}
public
void
setScale
(
int
scale
)
{
this
.
scale
=
scale
;
}
public
int
getRoundingMode
()
{
return
roundingMode
;
}
public
void
setRoundingMode
(
int
roundingMode
)
{
this
.
roundingMode
=
roundingMode
;
}
public
Boolean
getUse1904windowing
()
{
return
use1904windowing
;
}
public
void
setUse1904windowing
(
Boolean
use1904windowing
)
{
this
.
use1904windowing
=
use1904windowing
;
}
public
TimeZone
getTimeZone
()
{
return
timeZone
;
}
public
void
setTimeZone
(
TimeZone
timeZone
)
{
this
.
timeZone
=
timeZone
;
}
public
String
getFormat
()
{
return
format
;
}
public
void
setFormat
(
String
format
)
{
this
.
format
=
format
;
}
public
Field
getField
()
{
return
field
;
}
public
void
setField
(
Field
field
)
{
this
.
field
=
field
;
}
public
int
getIndex
()
{
return
index
;
}
public
void
setIndex
(
int
index
)
{
this
.
index
=
index
;
}
public
List
<
String
>
getHead
()
{
return
head
;
}
public
void
setHead
(
List
<
String
>
head
)
{
this
.
head
=
head
;
}
public
int
compareTo
(
ExcelColumnProperty
o
)
{
int
x
=
this
.
index
;
int
y
=
o
.
getIndex
();
return
(
x
<
y
)
?
-
1
:
((
x
==
y
)
?
0
:
1
);
}
}
src/main/java/com/alibaba/excel/metadata/Head.java
浏览文件 @
058df4d7
...
...
@@ -3,6 +3,9 @@ package com.alibaba.excel.metadata;
import
java.util.ArrayList
;
import
java.util.List
;
import
com.alibaba.excel.metadata.property.CellStyleProperty
;
import
com.alibaba.excel.metadata.property.ColumnWidthProperty
;
/**
* excel head
*
...
...
@@ -22,6 +25,15 @@ public class Head {
*/
private
List
<
String
>
headNameList
;
/**
* Cell style property
*/
private
CellStyleProperty
cellStyleProperty
;
/**
* column with
*/
private
ColumnWidthProperty
columnWidthProperty
;
public
Head
(
Integer
columnIndex
,
String
fieldName
,
String
headName
)
{
this
.
columnIndex
=
columnIndex
;
this
.
fieldName
=
fieldName
;
...
...
@@ -62,26 +74,19 @@ public class Head {
this
.
headNameList
=
headNameList
;
}
@Override
public
String
toString
()
{
return
"Head{"
+
"columnIndex="
+
columnIndex
+
", fieldName='"
+
fieldName
+
'\''
+
", headNameList="
+
headNameList
+
'}'
;
public
CellStyleProperty
getCellStyleProperty
()
{
return
cellStyleProperty
;
}
/**
* Get head name with index
*
* @param index
* @return
*/
public
String
getHeadName
(
int
index
)
{
if
(
headNameList
==
null
||
headNameList
.
isEmpty
())
{
return
null
;
public
void
setCellStyleProperty
(
CellStyleProperty
cellStyleProperty
)
{
this
.
cellStyleProperty
=
cellStyleProperty
;
}
if
(
index
>=
headNameList
.
size
())
{
return
headNameList
.
get
(
headNameList
.
size
()
-
1
);
}
else
{
return
headNameList
.
get
(
index
);
public
ColumnWidthProperty
getColumnWidthProperty
()
{
return
columnWidthProperty
;
}
public
void
setColumnWidthProperty
(
ColumnWidthProperty
columnWidthProperty
)
{
this
.
columnWidthProperty
=
columnWidthProperty
;
}
}
src/main/java/com/alibaba/excel/metadata/Workbook.java
浏览文件 @
058df4d7
...
...
@@ -28,6 +28,14 @@ public class Workbook extends BasicParameter {
* Default true
*/
private
Boolean
autoCloseStream
;
/**
* 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.
*
* @deprecated Just to be compatible with historical data, The default is always going to be convert all filed.
*/
@Deprecated
private
Boolean
convertAllFiled
;
/**
* Write handler
*
...
...
@@ -75,4 +83,12 @@ public class Workbook extends BasicParameter {
public
void
setAutoCloseStream
(
Boolean
autoCloseStream
)
{
this
.
autoCloseStream
=
autoCloseStream
;
}
public
Boolean
getConvertAllFiled
()
{
return
convertAllFiled
;
}
public
void
setConvertAllFiled
(
Boolean
convertAllFiled
)
{
this
.
convertAllFiled
=
convertAllFiled
;
}
}
src/main/java/com/alibaba/excel/metadata/holder/AbstractConfigurationSelector.java
浏览文件 @
058df4d7
...
...
@@ -8,15 +8,27 @@ import java.util.Map;
import
java.util.Set
;
import
java.util.TreeMap
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
com.alibaba.excel.converters.Converter
;
import
com.alibaba.excel.enums.HeadKindEnum
;
import
com.alibaba.excel.event.NotRepeatExecutor
;
import
com.alibaba.excel.event.Order
;
import
com.alibaba.excel.metadata.ExcelHeadProperty
;
import
com.alibaba.excel.metadata.CellStyle
;
import
com.alibaba.excel.metadata.Head
;
import
com.alibaba.excel.metadata.property.CellStyleProperty
;
import
com.alibaba.excel.metadata.property.ExcelContentProperty
;
import
com.alibaba.excel.metadata.property.ExcelHeadProperty
;
import
com.alibaba.excel.metadata.property.RowHeightProperty
;
import
com.alibaba.excel.write.handler.CellWriteHandler
;
import
com.alibaba.excel.write.handler.RowWriteHandler
;
import
com.alibaba.excel.write.handler.SheetWriteHandler
;
import
com.alibaba.excel.write.handler.WorkbookWriteHandler
;
import
com.alibaba.excel.write.handler.WriteHandler
;
import
com.alibaba.excel.write.style.AbstractColumnCellStyleStrategy
;
import
com.alibaba.excel.write.style.column.AbstractColumnWidthStyleStrategy
;
import
com.alibaba.excel.write.style.row.SimpleRowHeightStyleStrategy
;
/**
* sheet holder
...
...
@@ -191,6 +203,99 @@ public abstract class AbstractConfigurationSelector implements ConfigurationSele
return
result
;
}
protected
void
initAnnotationConfig
(
List
<
WriteHandler
>
handlerList
)
{
if
(!
HeadKindEnum
.
CLASS
.
equals
(
getExcelHeadProperty
().
getHeadKind
()))
{
return
;
}
Map
<
Integer
,
Head
>
headMap
=
getExcelHeadProperty
().
getHeadMap
();
Map
<
Integer
,
ExcelContentProperty
>
contentPropertyMap
=
getExcelHeadProperty
().
getContentPropertyMap
();
boolean
hasCellStyle
=
false
;
boolean
hasColumnWidth
=
false
;
for
(
Map
.
Entry
<
Integer
,
Head
>
entry
:
headMap
.
entrySet
())
{
if
(
entry
.
getValue
().
getCellStyleProperty
()
!=
null
)
{
hasCellStyle
=
true
;
}
if
(
entry
.
getValue
().
getColumnWidthProperty
()
!=
null
)
{
hasColumnWidth
=
true
;
}
ExcelContentProperty
excelContentProperty
=
contentPropertyMap
.
get
(
entry
.
getKey
());
if
(
excelContentProperty
.
getCellStyleProperty
()
!=
null
)
{
hasCellStyle
=
true
;
}
}
if
(
hasCellStyle
)
{
dealCellStyle
(
handlerList
,
contentPropertyMap
);
}
if
(
hasColumnWidth
)
{
dealColumnWidth
(
handlerList
);
}
dealRowHigh
(
handlerList
,
contentPropertyMap
);
}
private
void
dealRowHigh
(
List
<
WriteHandler
>
handlerList
,
Map
<
Integer
,
ExcelContentProperty
>
contentPropertyMap
)
{
RowHeightProperty
headRowHeightProperty
=
excelHeadProperty
.
getHeadRowHeightProperty
();
RowHeightProperty
contentRowHeightProperty
=
excelHeadProperty
.
getContentRowHeightProperty
();
if
(
headRowHeightProperty
==
null
&&
contentRowHeightProperty
==
null
)
{
return
;
}
Short
headRowHeight
=
null
;
if
(
headRowHeightProperty
!=
null
)
{
headRowHeight
=
headRowHeightProperty
.
getHeight
();
}
Short
contentRowHeight
=
null
;
if
(
contentRowHeightProperty
!=
null
)
{
contentRowHeight
=
contentRowHeightProperty
.
getHeight
();
}
handlerList
.
add
(
new
SimpleRowHeightStyleStrategy
(
headRowHeight
,
contentRowHeight
));
}
private
void
dealColumnWidth
(
List
<
WriteHandler
>
handlerList
)
{
WriteHandler
columnWidthStyleStrategy
=
new
AbstractColumnWidthStyleStrategy
()
{
@Override
protected
void
setColumnWidth
(
Sheet
sheet
,
Cell
cell
,
Head
head
)
{
if
(
head
==
null
)
{
return
;
}
if
(
head
.
getColumnWidthProperty
()
!=
null
)
{
sheet
.
setColumnWidth
(
head
.
getColumnIndex
(),
head
.
getColumnWidthProperty
().
getWidth
());
}
}
};
handlerList
.
add
(
columnWidthStyleStrategy
);
}
private
void
dealCellStyle
(
List
<
WriteHandler
>
handlerList
,
final
Map
<
Integer
,
ExcelContentProperty
>
contentPropertyMap
)
{
WriteHandler
columnCellStyleStrategy
=
new
AbstractColumnCellStyleStrategy
()
{
@Override
protected
CellStyle
headCellStyle
(
Head
head
)
{
if
(
head
==
null
||
head
.
getCellStyleProperty
()
==
null
)
{
return
null
;
}
CellStyleProperty
cellStyleProperty
=
head
.
getCellStyleProperty
();
return
new
CellStyle
(
cellStyleProperty
.
getFontName
(),
cellStyleProperty
.
getFontHeightInPoints
(),
cellStyleProperty
.
getBold
(),
cellStyleProperty
.
getIndexedColors
());
}
@Override
protected
CellStyle
contentCellStyle
(
Head
head
)
{
if
(
head
==
null
)
{
return
null
;
}
ExcelContentProperty
excelContentProperty
=
contentPropertyMap
.
get
(
head
.
getColumnIndex
());
if
(
excelContentProperty
==
null
||
excelContentProperty
.
getCellStyleProperty
()
==
null
)
{
return
null
;
}
CellStyleProperty
cellStyleProperty
=
excelContentProperty
.
getCellStyleProperty
();
return
new
CellStyle
(
cellStyleProperty
.
getFontName
(),
cellStyleProperty
.
getFontHeightInPoints
(),
cellStyleProperty
.
getBold
(),
cellStyleProperty
.
getIndexedColors
());
}
};
handlerList
.
add
(
columnCellStyleStrategy
);
}
@Override
public
Map
<
Class
<?
extends
WriteHandler
>,
List
<
WriteHandler
>>
writeHandlerMap
()
{
return
getWriteHandlerMap
();
...
...
src/main/java/com/alibaba/excel/metadata/holder/ConfigurationSelector.java
浏览文件 @
058df4d7
...
...
@@ -4,7 +4,7 @@ import java.util.List;
import
java.util.Map
;
import
com.alibaba.excel.converters.Converter
;
import
com.alibaba.excel.metadata.ExcelHeadProperty
;
import
com.alibaba.excel.metadata.
property.
ExcelHeadProperty
;
import
com.alibaba.excel.write.handler.WriteHandler
;
/**
...
...
src/main/java/com/alibaba/excel/metadata/holder/SheetHolder.java
浏览文件 @
058df4d7
...
...
@@ -11,6 +11,7 @@ import com.alibaba.excel.converters.Converter;
import
com.alibaba.excel.metadata.CellStyle
;
import
com.alibaba.excel.metadata.Head
;
import
com.alibaba.excel.metadata.TableStyle
;
import
com.alibaba.excel.metadata.property.ExcelHeadProperty
;
import
com.alibaba.excel.write.handler.WriteHandler
;
import
com.alibaba.excel.write.style.RowCellStyleStrategy
;
import
com.alibaba.excel.write.style.column.AbstractHeadColumnWidthStyleStrategy
;
...
...
@@ -21,6 +22,7 @@ import com.alibaba.excel.write.style.column.AbstractHeadColumnWidthStyleStrategy
* @author zhuangjiaju
*/
public
class
SheetHolder
extends
AbstractConfigurationSelector
{
/***
* poi sheet
*/
...
...
@@ -59,6 +61,9 @@ public class SheetHolder extends AbstractConfigurationSelector {
setHead
(
sheet
.
getHead
());
setClazz
(
sheet
.
getClazz
());
}
// Initialization property
setExcelHeadProperty
(
new
ExcelHeadProperty
(
getClazz
(),
getHead
(),
workbookHolder
.
getConvertAllFiled
()));
setNewInitialization
(
Boolean
.
TRUE
);
if
(
sheet
.
getNeedHead
()
==
null
)
{
setNeedHead
(
workbookHolder
.
needHead
());
...
...
@@ -76,6 +81,9 @@ public class SheetHolder extends AbstractConfigurationSelector {
if
(
sheet
.
getCustomWriteHandlerList
()
!=
null
&&
!
sheet
.
getCustomWriteHandlerList
().
isEmpty
())
{
handlerList
.
addAll
(
sheet
.
getCustomWriteHandlerList
());
}
// Initialization Annotation
initAnnotationConfig
(
handlerList
);
setWriteHandlerMap
(
sortAndClearUpHandler
(
handlerList
,
workbookHolder
.
getWriteHandlerMap
()));
Map
<
Class
,
Converter
>
converterMap
=
new
HashMap
<
Class
,
Converter
>(
workbookHolder
.
converterMap
());
if
(
sheet
.
getCustomConverterMap
()
!=
null
&&
!
sheet
.
getCustomConverterMap
().
isEmpty
())
{
...
...
@@ -97,7 +105,7 @@ public class SheetHolder extends AbstractConfigurationSelector {
}
sheet
.
getCustomWriteHandlerList
().
add
(
new
AbstractHeadColumnWidthStyleStrategy
()
{
@Override
protected
int
columnWidth
(
Head
head
)
{
protected
Integer
columnWidth
(
Head
head
)
{
if
(
columnWidthMap
.
containsKey
(
head
.
getColumnIndex
()))
{
columnWidthMap
.
get
(
head
.
getColumnIndex
());
}
...
...
src/main/java/com/alibaba/excel/metadata/holder/TableHolder.java
浏览文件 @
058df4d7
...
...
@@ -9,6 +9,7 @@ import com.alibaba.excel.converters.Converter;
import
com.alibaba.excel.metadata.CellStyle
;
import
com.alibaba.excel.metadata.Table
;
import
com.alibaba.excel.metadata.TableStyle
;
import
com.alibaba.excel.metadata.property.ExcelHeadProperty
;
import
com.alibaba.excel.write.handler.WriteHandler
;
import
com.alibaba.excel.write.style.RowCellStyleStrategy
;
...
...
@@ -31,7 +32,7 @@ public class TableHolder extends AbstractConfigurationSelector {
*/
private
com
.
alibaba
.
excel
.
metadata
.
Table
tableParam
;
public
TableHolder
(
com
.
alibaba
.
excel
.
metadata
.
Table
table
,
SheetHolder
sheetHolder
)
{
public
TableHolder
(
com
.
alibaba
.
excel
.
metadata
.
Table
table
,
SheetHolder
sheetHolder
,
WorkbookHolder
workbookHolder
)
{
super
();
this
.
tableParam
=
table
;
this
.
parentSheet
=
sheetHolder
;
...
...
@@ -46,6 +47,9 @@ public class TableHolder extends AbstractConfigurationSelector {
setClazz
(
table
.
getClazz
());
}
setNewInitialization
(
Boolean
.
TRUE
);
// Initialization property
setExcelHeadProperty
(
new
ExcelHeadProperty
(
getClazz
(),
getHead
(),
workbookHolder
.
getConvertAllFiled
()));
if
(
table
.
getNeedHead
()
==
null
)
{
setNeedHead
(
sheetHolder
.
needHead
());
}
else
{
...
...
@@ -62,6 +66,9 @@ public class TableHolder extends AbstractConfigurationSelector {
if
(
table
.
getCustomWriteHandlerList
()
!=
null
&&
!
table
.
getCustomWriteHandlerList
().
isEmpty
())
{
handlerList
.
addAll
(
table
.
getCustomWriteHandlerList
());
}
// Initialization Annotation
initAnnotationConfig
(
handlerList
);
setWriteHandlerMap
(
sortAndClearUpHandler
(
handlerList
,
sheetHolder
.
getWriteHandlerMap
()));
Map
<
Class
,
Converter
>
converterMap
=
new
HashMap
<
Class
,
Converter
>(
sheetHolder
.
converterMap
());
if
(
table
.
getCustomConverterMap
()
!=
null
&&
!
table
.
getCustomConverterMap
().
isEmpty
())
{
...
...
src/main/java/com/alibaba/excel/metadata/holder/WorkbookHolder.java
浏览文件 @
058df4d7
...
...
@@ -10,8 +10,8 @@ import java.util.Map;
import
org.apache.poi.ss.usermodel.Workbook
;
import
com.alibaba.excel.converters.Converter
;
import
com.alibaba.excel.converters.DefaultConverter
Buil
der
;
import
com.alibaba.excel.write.handler.DefaultWriteHandler
Buil
der
;
import
com.alibaba.excel.converters.DefaultConverter
Loa
der
;
import
com.alibaba.excel.write.handler.DefaultWriteHandler
Loa
der
;
import
com.alibaba.excel.write.handler.WriteHandler
;
/**
...
...
@@ -45,6 +45,15 @@ public class WorkbookHolder extends AbstractConfigurationSelector {
*/
private
Boolean
autoCloseStream
;
/**
* 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.
*
* @deprecated Just to be compatible with historical data, The default is always going to be convert all filed.
*/
@Deprecated
private
Boolean
convertAllFiled
;
/**
* Write handler
*
...
...
@@ -62,6 +71,11 @@ public class WorkbookHolder extends AbstractConfigurationSelector {
setHead
(
workbook
.
getHead
());
setClazz
(
workbook
.
getClazz
());
setNewInitialization
(
Boolean
.
TRUE
);
if
(
workbook
.
getConvertAllFiled
()
==
null
)
{
this
.
convertAllFiled
=
Boolean
.
TRUE
;
}
else
{
this
.
convertAllFiled
=
workbook
.
getConvertAllFiled
();
}
if
(
workbook
.
getAutoCloseStream
()
==
null
)
{
setAutoCloseStream
(
Boolean
.
TRUE
);
}
else
{
...
...
@@ -81,9 +95,12 @@ public class WorkbookHolder extends AbstractConfigurationSelector {
if
(
workbook
.
getCustomWriteHandlerList
()
!=
null
&&
!
workbook
.
getCustomWriteHandlerList
().
isEmpty
())
{
handlerList
.
addAll
(
workbook
.
getCustomWriteHandlerList
());
}
handlerList
.
addAll
(
DefaultWriteHandlerBuilder
.
loadDefaultHandler
());
// Initialization Annotation
initAnnotationConfig
(
handlerList
);
handlerList
.
addAll
(
DefaultWriteHandlerLoader
.
loadDefaultHandler
());
setWriteHandlerMap
(
sortAndClearUpHandler
(
handlerList
,
null
));
Map
<
Class
,
Converter
>
converterMap
=
DefaultConverter
Buil
der
.
loadDefaultWriteConverter
();
Map
<
Class
,
Converter
>
converterMap
=
DefaultConverter
Loa
der
.
loadDefaultWriteConverter
();
if
(
workbook
.
getCustomConverterMap
()
!=
null
&&
!
workbook
.
getCustomConverterMap
().
isEmpty
())
{
converterMap
.
putAll
(
workbook
.
getCustomConverterMap
());
}
...
...
@@ -146,4 +163,12 @@ public class WorkbookHolder extends AbstractConfigurationSelector {
public
void
setAutoCloseStream
(
Boolean
autoCloseStream
)
{
this
.
autoCloseStream
=
autoCloseStream
;
}
public
Boolean
getConvertAllFiled
()
{
return
convertAllFiled
;
}
public
void
setConvertAllFiled
(
Boolean
convertAllFiled
)
{
this
.
convertAllFiled
=
convertAllFiled
;
}
}
src/main/java/com/alibaba/excel/metadata/property/CellStyleProperty.java
0 → 100644
浏览文件 @
058df4d7
package
com.alibaba.excel.metadata.property
;
import
org.apache.poi.ss.usermodel.IndexedColors
;
import
com.alibaba.excel.annotation.write.style.ContentStyle
;
import
com.alibaba.excel.annotation.write.style.HeadStyle
;
/**
* Configuration from annotations
*
* @author zhuangjiaju
*/
public
class
CellStyleProperty
{
private
String
fontName
;
private
Short
fontHeightInPoints
;
private
Boolean
bold
;
private
IndexedColors
indexedColors
;
public
CellStyleProperty
(
String
fontName
,
Short
fontHeightInPoints
,
Boolean
bold
,
IndexedColors
indexedColors
)
{
this
.
fontName
=
fontName
;
this
.
fontHeightInPoints
=
fontHeightInPoints
;
this
.
bold
=
bold
;
this
.
indexedColors
=
indexedColors
;
}
public
static
CellStyleProperty
build
(
HeadStyle
headStyle
)
{
if
(
headStyle
==
null
)
{
return
null
;
}
boolean
isDefault
=
"宋体"
.
equals
(
headStyle
.
fontName
())
&&
headStyle
.
fontHeightInPoints
()
==
14
&&
headStyle
.
bold
()
&&
IndexedColors
.
GREY_25_PERCENT
.
equals
(
headStyle
.
indexedColors
());
if
(
isDefault
)
{
return
null
;
}
return
new
CellStyleProperty
(
headStyle
.
fontName
(),
headStyle
.
fontHeightInPoints
(),
headStyle
.
bold
(),
headStyle
.
indexedColors
());
}
public
static
CellStyleProperty
build
(
ContentStyle
contentStyle
)
{
if
(
contentStyle
==
null
)
{
return
null
;
}
boolean
isDefault
=
"宋体"
.
equals
(
contentStyle
.
fontName
())
&&
contentStyle
.
fontHeightInPoints
()
==
14
&&
contentStyle
.
bold
()
&&
IndexedColors
.
WHITE1
.
equals
(
contentStyle
.
indexedColors
());
if
(
isDefault
)
{
return
null
;
}
return
new
CellStyleProperty
(
contentStyle
.
fontName
(),
contentStyle
.
fontHeightInPoints
(),
contentStyle
.
bold
(),
contentStyle
.
indexedColors
());
}
public
String
getFontName
()
{
return
fontName
;
}
public
void
setFontName
(
String
fontName
)
{
this
.
fontName
=
fontName
;
}
public
Short
getFontHeightInPoints
()
{
return
fontHeightInPoints
;
}
public
void
setFontHeightInPoints
(
Short
fontHeightInPoints
)
{
this
.
fontHeightInPoints
=
fontHeightInPoints
;
}
public
Boolean
getBold
()
{
return
bold
;
}
public
void
setBold
(
Boolean
bold
)
{
this
.
bold
=
bold
;
}
public
IndexedColors
getIndexedColors
()
{
return
indexedColors
;
}
public
void
setIndexedColors
(
IndexedColors
indexedColors
)
{
this
.
indexedColors
=
indexedColors
;
}
}
src/main/java/com/alibaba/excel/metadata/property/ColumnWidthProperty.java
0 → 100644
浏览文件 @
058df4d7
package
com.alibaba.excel.metadata.property
;
import
com.alibaba.excel.annotation.write.style.ColumnWidth
;
/**
* Configuration from annotations
*
* @author zhuangjiaju
*/
public
class
ColumnWidthProperty
{
private
Integer
width
;
public
ColumnWidthProperty
(
Integer
width
)
{
this
.
width
=
width
;
}
public
static
ColumnWidthProperty
build
(
ColumnWidth
columnWidth
)
{
if
(
columnWidth
==
null
||
columnWidth
.
value
()
<
0
)
{
return
null
;
}
return
new
ColumnWidthProperty
(
columnWidth
.
value
());
}
public
Integer
getWidth
()
{
return
width
;
}
public
void
setWidth
(
Integer
width
)
{
this
.
width
=
width
;
}
}
src/main/java/com/alibaba/excel/metadata/property/DateTimeFormatProperty.java
0 → 100644
浏览文件 @
058df4d7
package
com.alibaba.excel.metadata.property
;
import
com.alibaba.excel.annotation.format.DateTimeFormat
;
/**
* Configuration from annotations
*
* @author zhuangjiaju
*/
public
class
DateTimeFormatProperty
{
private
String
format
;
private
Boolean
use1904windowing
;
public
DateTimeFormatProperty
(
String
format
,
Boolean
use1904windowing
)
{
this
.
format
=
format
;
this
.
use1904windowing
=
use1904windowing
;
}
public
static
DateTimeFormatProperty
build
(
DateTimeFormat
dateTimeFormat
)
{
if
(
dateTimeFormat
==
null
)
{
return
null
;
}
return
new
DateTimeFormatProperty
(
dateTimeFormat
.
value
(),
dateTimeFormat
.
use1904windowing
());
}
public
String
getFormat
()
{
return
format
;
}
public
void
setFormat
(
String
format
)
{
this
.
format
=
format
;
}
public
Boolean
getUse1904windowing
()
{
return
use1904windowing
;
}
public
void
setUse1904windowing
(
Boolean
use1904windowing
)
{
this
.
use1904windowing
=
use1904windowing
;
}
}
src/main/java/com/alibaba/excel/metadata/property/ExcelContentProperty.java
0 → 100644
浏览文件 @
058df4d7
package
com.alibaba.excel.metadata.property
;
import
java.lang.reflect.Field
;
import
com.alibaba.excel.metadata.Head
;
/**
* @author jipengfei
*/
public
class
ExcelContentProperty
{
/**
* Java filed
*/
private
Field
field
;
/**
* Excel head
*/
private
Head
head
;
private
CellStyleProperty
cellStyleProperty
;
private
DateTimeFormatProperty
dateTimeFormatProperty
;
private
NumberFormatProperty
numberFormatProperty
;
public
Field
getField
()
{
return
field
;
}
public
void
setField
(
Field
field
)
{
this
.
field
=
field
;
}
public
Head
getHead
()
{
return
head
;
}
public
void
setHead
(
Head
head
)
{
this
.
head
=
head
;
}
public
CellStyleProperty
getCellStyleProperty
()
{
return
cellStyleProperty
;
}
public
void
setCellStyleProperty
(
CellStyleProperty
cellStyleProperty
)
{
this
.
cellStyleProperty
=
cellStyleProperty
;
}
public
DateTimeFormatProperty
getDateTimeFormatProperty
()
{
return
dateTimeFormatProperty
;
}
public
void
setDateTimeFormatProperty
(
DateTimeFormatProperty
dateTimeFormatProperty
)
{
this
.
dateTimeFormatProperty
=
dateTimeFormatProperty
;
}
public
NumberFormatProperty
getNumberFormatProperty
()
{
return
numberFormatProperty
;
}
public
void
setNumberFormatProperty
(
NumberFormatProperty
numberFormatProperty
)
{
this
.
numberFormatProperty
=
numberFormatProperty
;
}
}
src/main/java/com/alibaba/excel/metadata/ExcelHeadProperty.java
→
src/main/java/com/alibaba/excel/metadata/
property/
ExcelHeadProperty.java
浏览文件 @
058df4d7
package
com.alibaba.excel.metadata
;
package
com.alibaba.excel.metadata
.property
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.TreeMap
;
import
com.alibaba.excel.annotation.ExcelColumnNum
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
com.alibaba.excel.annotation.ExcelIgnore
;
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.annotation.write.style.ContentRowHeight
;
import
com.alibaba.excel.annotation.write.style.ContentStyle
;
import
com.alibaba.excel.annotation.write.style.HeadRowHeight
;
import
com.alibaba.excel.annotation.write.style.HeadStyle
;
import
com.alibaba.excel.enums.HeadKindEnum
;
import
com.alibaba.excel.exception.ExcelGenerateException
;
import
com.alibaba.excel.metadata.CellRange
;
import
com.alibaba.excel.metadata.Head
;
/**
* Define the header attribute of excel
...
...
@@ -19,56 +31,56 @@ import com.alibaba.excel.enums.HeadKindEnum;
*/
public
class
ExcelHeadProperty
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ExcelHeadProperty
.
class
);
/**
* Custom class
*/
private
Class
headClazz
;
/**
*
A two-dimensional array describing the header
*
The types of head
*/
private
List
<
Head
>
headList
;
private
HeadKindEnum
headKind
;
/**
*
Attributes described by the header
*
The number of rows in the line with the most rows
*/
private
List
<
ExcelColumnProperty
>
columnPropertyList
=
new
ArrayList
<
ExcelColumnProperty
>()
;
private
int
headRowNumber
;
/**
* Attributes described by the header
*/
private
Map
<
Integer
,
ExcelColumnProperty
>
excelColumnPropertyMap1
=
new
HashMap
<
Integer
,
ExcelColumnProperty
>();
/**
* The types of head
* Configuration header information
*/
private
HeadKindEnum
headKind
;
private
Map
<
Integer
,
Head
>
headMap
;
/**
*
The number of rows in the line with the most rows
*
Configuration column information
*/
private
int
headRowNumber
;
private
Map
<
Integer
,
ExcelContentProperty
>
contentPropertyMap
;
private
RowHeightProperty
headRowHeightProperty
;
private
RowHeightProperty
contentRowHeightProperty
;
public
ExcelHeadProperty
(
Class
headClazz
,
List
<
List
<
String
>>
head
)
{
public
ExcelHeadProperty
(
Class
headClazz
,
List
<
List
<
String
>>
head
,
Boolean
convertAllFiled
)
{
this
.
headClazz
=
headClazz
;
headList
=
new
ArrayList
<
Head
>();
headMap
=
new
TreeMap
<
Integer
,
Head
>();
contentPropertyMap
=
new
TreeMap
<
Integer
,
ExcelContentProperty
>();
headKind
=
HeadKindEnum
.
NONE
;
headRowNumber
=
0
;
if
(
head
!=
null
&&
!
head
.
isEmpty
())
{
int
index
=
0
;
for
(
List
<
String
>
headData
:
head
)
{
headList
.
add
(
new
Head
(
index
++,
null
,
headData
)
);
for
(
int
i
=
0
;
i
<
head
.
size
();
i
++)
{
headMap
.
put
(
i
,
new
Head
(
i
,
null
,
head
.
get
(
i
)));
contentPropertyMap
.
put
(
i
,
null
);
}
headKind
=
HeadKindEnum
.
STRING
;
}
else
{
// convert headClazz to head
initColumnProperties
();
initColumnProperties
(
convertAllFiled
);
}
initHeadRowNumber
();
LOGGER
.
info
(
"The initialization sheet/table 'ExcelHeadProperty' is complete , head kind is {}"
,
headKind
);
}
public
static
ExcelHeadProperty
buildExcelHeadProperty
(
ExcelHeadProperty
excelHeadProperty
,
Class
clazz
,
List
<
String
>
headOneRow
)
{
if
(
excelHeadProperty
==
null
)
{
return
new
ExcelHeadProperty
(
clazz
,
new
ArrayList
<
List
<
String
>>());
return
new
ExcelHeadProperty
(
clazz
,
new
ArrayList
<
List
<
String
>>()
,
false
);
}
if
(
headOneRow
!=
null
)
{
excelHeadProperty
.
appendOneRow
(
headOneRow
);
...
...
@@ -78,20 +90,30 @@ public class ExcelHeadProperty {
private
void
initHeadRowNumber
()
{
headRowNumber
=
0
;
for
(
Head
head
:
head
List
)
{
for
(
Head
head
:
head
Map
.
values
()
)
{
List
<
String
>
list
=
head
.
getHeadNameList
();
if
(
list
!=
null
&&
list
.
size
()
>
headRowNumber
)
{
headRowNumber
=
list
.
size
();
}
}
for
(
Head
head
:
headMap
.
values
())
{
List
<
String
>
list
=
head
.
getHeadNameList
();
if
(
list
!=
null
&&
!
list
.
isEmpty
()
&&
list
.
size
()
<
headRowNumber
)
{
int
lack
=
headRowNumber
-
list
.
size
();
int
last
=
list
.
size
()
-
1
;
for
(
int
i
=
0
;
i
<
lack
;
i
++)
{
list
.
add
(
list
.
get
(
last
));
}
}
}
}
/**
*/
private
void
initColumnProperties
()
{
if
(
this
.
headClazz
!=
null
)
{
private
void
initColumnProperties
(
Boolean
convertAllFiled
)
{
if
(
headClazz
==
null
)
{
return
;
}
List
<
Field
>
fieldList
=
new
ArrayList
<
Field
>();
Class
tempClass
=
this
.
headClazz
;
Class
tempClass
=
headClazz
;
// When the parent class is null, it indicates that the parent class (Object class) has reached the top
// level.
while
(
tempClass
!=
null
)
{
...
...
@@ -99,79 +121,113 @@ public class ExcelHeadProperty {
// Get the parent class and give it to yourself
tempClass
=
tempClass
.
getSuperclass
();
}
for
(
Field
f
:
fieldList
)
{
initOneColumnProperty
(
f
);
// Screening of field
List
<
Field
>
defaultFieldList
=
new
ArrayList
<
Field
>();
Map
<
Integer
,
Field
>
customFiledMap
=
new
TreeMap
<
Integer
,
Field
>();
for
(
Field
field
:
fieldList
)
{
ExcelIgnore
excelIgnore
=
field
.
getAnnotation
(
ExcelIgnore
.
class
);
if
(
excelIgnore
!=
null
)
{
continue
;
}
ExcelProperty
excelProperty
=
field
.
getAnnotation
(
ExcelProperty
.
class
);
if
(
excelProperty
==
null
&&
!
convertAllFiled
)
{
continue
;
}
if
(
excelProperty
==
null
||
excelProperty
.
index
()
<
0
)
{
defaultFieldList
.
add
(
field
);
return
;
}
if
(
customFiledMap
.
containsKey
(
excelProperty
.
index
()))
{
throw
new
ExcelGenerateException
(
"The index of "
+
customFiledMap
.
get
(
excelProperty
.
index
()).
getName
()
+
" and "
+
field
.
getName
()
+
" must be inconsistent"
);
}
customFiledMap
.
put
(
excelProperty
.
index
(),
field
);
}
// 对列排序
Collections
.
sort
(
columnPropertyList
);
HeadStyle
headStyle
=
(
HeadStyle
)
headClazz
.
getAnnotation
(
HeadStyle
.
class
);
ContentStyle
contentStyle
=
(
ContentStyle
)
headClazz
.
getAnnotation
(
ContentStyle
.
class
);
ColumnWidth
columnWidth
=
(
ColumnWidth
)
headClazz
.
getAnnotation
(
ColumnWidth
.
class
);
this
.
headRowHeightProperty
=
RowHeightProperty
.
build
((
HeadRowHeight
)
headClazz
.
getAnnotation
(
HeadRowHeight
.
class
));
this
.
contentRowHeightProperty
=
RowHeightProperty
.
build
((
ContentRowHeight
)
headClazz
.
getAnnotation
(
ContentRowHeight
.
class
));
int
index
=
0
;
for
(
ExcelColumnProperty
excelColumnProperty
:
columnPropertyList
)
{
if
(
excelColumnProperty
.
getHead
()
!=
null
&&
excelColumnProperty
.
getHead
().
size
()
>
headRowNumber
)
{
headRowNumber
=
excelColumnProperty
.
getHead
().
size
();
for
(
Field
field
:
defaultFieldList
)
{
while
(
customFiledMap
.
containsKey
(
index
))
{
initOneColumnProperty
(
index
,
customFiledMap
.
get
(
index
),
headStyle
,
contentStyle
,
columnWidth
);
customFiledMap
.
remove
(
index
);
index
++;
}
headList
.
add
(
new
Head
(
index
++,
excelColumnProperty
.
getField
().
getName
(),
excelColumnProperty
.
getHead
()))
;
initOneColumnProperty
(
index
,
field
,
headStyle
,
contentStyle
,
columnWidth
);
index
++
;
}
headKind
=
HeadKindEnum
.
CLASS
;
for
(
Map
.
Entry
<
Integer
,
Field
>
entry
:
customFiledMap
.
entrySet
())
{
initOneColumnProperty
(
index
,
entry
.
getValue
(),
headStyle
,
contentStyle
,
columnWidth
);
index
++;
}
headKind
=
HeadKindEnum
.
CLASS
;
}
/**
* @param f
*/
private
void
initOneColumnProperty
(
Field
f
)
{
ExcelProperty
p
=
f
.
getAnnotation
(
ExcelProperty
.
class
);
ExcelColumnProperty
excelHeadProperty
=
null
;
if
(
p
!=
null
)
{
excelHeadProperty
=
new
ExcelColumnProperty
();
excelHeadProperty
.
setField
(
f
);
excelHeadProperty
.
setHead
(
Arrays
.
asList
(
p
.
value
()));
excelHeadProperty
.
setIndex
(
p
.
index
());
excelHeadProperty
.
setFormat
(
p
.
format
());
excelColumnPropertyMap1
.
put
(
p
.
index
(),
excelHeadProperty
);
private
void
initOneColumnProperty
(
int
index
,
Field
field
,
HeadStyle
parentHeadStyle
,
ContentStyle
parentContentStyle
,
ColumnWidth
parentColumnWidth
)
{
ExcelProperty
excelProperty
=
field
.
getAnnotation
(
ExcelProperty
.
class
);
List
<
String
>
tmpHeadList
=
new
ArrayList
<
String
>();
if
(
excelProperty
!=
null
)
{
tmpHeadList
=
Arrays
.
asList
(
excelProperty
.
value
());
}
else
{
ExcelColumnNum
columnNum
=
f
.
getAnnotation
(
ExcelColumnNum
.
class
);
if
(
columnNum
!=
null
)
{
excelHeadProperty
=
new
ExcelColumnProperty
();
excelHeadProperty
.
setField
(
f
);
excelHeadProperty
.
setIndex
(
columnNum
.
value
());
excelHeadProperty
.
setFormat
(
columnNum
.
format
());
excelColumnPropertyMap1
.
put
(
columnNum
.
value
(),
excelHeadProperty
);
tmpHeadList
.
add
(
field
.
getName
());
}
Head
head
=
new
Head
(
index
,
field
.
getName
(),
tmpHeadList
);
HeadStyle
headStyle
=
field
.
getAnnotation
(
HeadStyle
.
class
);
if
(
headStyle
==
null
)
{
headStyle
=
parentHeadStyle
;
}
head
.
setCellStyleProperty
(
CellStyleProperty
.
build
(
headStyle
));
ColumnWidth
columnWidth
=
field
.
getAnnotation
(
ColumnWidth
.
class
);
if
(
columnWidth
==
null
)
{
columnWidth
=
parentColumnWidth
;
}
if
(
excelHeadProperty
!=
null
)
{
this
.
columnPropertyList
.
add
(
excelHeadProperty
);
head
.
setColumnWidthProperty
(
ColumnWidthProperty
.
build
(
columnWidth
));
ExcelContentProperty
excelContentProperty
=
new
ExcelContentProperty
();
excelContentProperty
.
setHead
(
head
);
ContentStyle
contentStyle
=
field
.
getAnnotation
(
ContentStyle
.
class
);
if
(
contentStyle
==
null
)
{
contentStyle
=
parentContentStyle
;
}
excelContentProperty
.
setCellStyleProperty
(
CellStyleProperty
.
build
(
contentStyle
));
excelContentProperty
.
setDateTimeFormatProperty
(
DateTimeFormatProperty
.
build
(
field
.
getAnnotation
(
DateTimeFormat
.
class
)));
excelContentProperty
.
setNumberFormatProperty
(
NumberFormatProperty
.
build
(
field
.
getAnnotation
(
NumberFormat
.
class
)));
headMap
.
put
(
index
,
head
);
contentPropertyMap
.
put
(
index
,
excelContentProperty
);
}
/**
* Add one more head under the last head
*/
public
void
appendOneRow
(
List
<
String
>
row
)
{
int
headSize
=
headList
.
size
();
for
(
int
i
=
0
;
i
<
row
.
size
();
i
++)
{
String
rowData
=
row
.
get
(
i
);
// join
if
(
i
<=
headSize
)
{
head
List
.
get
(
i
).
getHeadNameList
().
add
(
rowData
);
if
(
headMap
.
containsKey
(
i
)
)
{
head
Map
.
get
(
i
).
getHeadNameList
().
add
(
rowData
);
}
else
{
// create and join
headList
.
add
(
new
Head
(
i
,
null
,
rowData
));
int
index
=
((
TreeMap
<
Integer
,
Head
>)
headMap
).
lastKey
()
+
1
;
headMap
.
put
(
index
,
new
Head
(
i
,
null
,
rowData
));
}
}
initHeadRowNumber
();
}
/**
* @param columnNum
* @return
*/
public
ExcelColumnProperty
getExcelColumnProperty
(
int
columnNum
)
{
return
excelColumnPropertyMap1
.
get
(
columnNum
);
}
public
Class
getHeadClazz
()
{
return
headClazz
;
}
...
...
@@ -180,22 +236,6 @@ public class ExcelHeadProperty {
this
.
headClazz
=
headClazz
;
}
public
List
<
ExcelColumnProperty
>
getColumnPropertyList
()
{
return
columnPropertyList
;
}
public
void
setColumnPropertyList
(
List
<
ExcelColumnProperty
>
columnPropertyList
)
{
this
.
columnPropertyList
=
columnPropertyList
;
}
public
List
<
Head
>
getHeadList
()
{
return
headList
;
}
public
void
setHeadList
(
List
<
Head
>
headList
)
{
this
.
headList
=
headList
;
}
public
HeadKindEnum
getHeadKind
()
{
return
headKind
;
}
...
...
@@ -216,37 +256,59 @@ public class ExcelHeadProperty {
this
.
headRowNumber
=
headRowNumber
;
}
public
Map
<
Integer
,
Head
>
getHeadMap
()
{
return
headMap
;
}
public
void
setHeadMap
(
Map
<
Integer
,
Head
>
headMap
)
{
this
.
headMap
=
headMap
;
}
public
Map
<
Integer
,
ExcelContentProperty
>
getContentPropertyMap
()
{
return
contentPropertyMap
;
}
public
void
setContentPropertyMap
(
Map
<
Integer
,
ExcelContentProperty
>
contentPropertyMap
)
{
this
.
contentPropertyMap
=
contentPropertyMap
;
}
public
RowHeightProperty
getHeadRowHeightProperty
()
{
return
headRowHeightProperty
;
}
public
void
setHeadRowHeightProperty
(
RowHeightProperty
headRowHeightProperty
)
{
this
.
headRowHeightProperty
=
headRowHeightProperty
;
}
public
RowHeightProperty
getContentRowHeightProperty
()
{
return
contentRowHeightProperty
;
}
public
void
setContentRowHeightProperty
(
RowHeightProperty
contentRowHeightProperty
)
{
this
.
contentRowHeightProperty
=
contentRowHeightProperty
;
}
/**
* Calculate all cells that need to be merged
*
* @return cells that need to be merged
*/
public
List
<
CellRange
>
getCellRangeModels
()
{
List
<
CellRange
>
cellRanges
=
new
ArrayList
<
CellRange
>();
for
(
int
i
=
0
;
i
<
headList
.
size
();
i
++)
{
List
<
String
>
columnValues
=
headList
.
get
(
i
).
getHeadNameList
();
public
List
<
CellRange
>
headCellRangeList
()
{
List
<
CellRange
>
cellRangeList
=
new
ArrayList
<
CellRange
>();
int
i
=
0
;
for
(
Map
.
Entry
<
Integer
,
Head
>
entry
:
headMap
.
entrySet
())
{
Head
head
=
entry
.
getValue
();
List
<
String
>
columnValues
=
head
.
getHeadNameList
();
for
(
int
j
=
0
;
j
<
columnValues
.
size
();
j
++)
{
int
lastRow
=
getLastRangNum
(
j
,
columnValues
.
get
(
j
),
columnValues
);
int
lastColumn
=
getLastRangNum
(
i
,
columnValues
.
get
(
j
),
getHeadByRowNum
(
j
));
int
lastColumn
=
getLastRangNum
(
i
,
columnValues
.
get
(
j
),
head
.
getHeadNameList
(
));
if
((
lastRow
>
j
||
lastColumn
>
i
)
&&
lastRow
>=
0
&&
lastColumn
>=
0
)
{
cellRange
s
.
add
(
new
CellRange
(
j
,
lastRow
,
i
,
lastColumn
));
cellRange
List
.
add
(
new
CellRange
(
j
,
lastRow
,
i
,
lastColumn
));
}
}
i
++;
}
return
cellRanges
;
}
public
List
<
String
>
getHeadByRowNum
(
int
rowNum
)
{
List
<
String
>
l
=
new
ArrayList
<
String
>(
headList
.
size
());
for
(
Head
head
:
headList
)
{
List
<
String
>
list
=
head
.
getHeadNameList
();
if
(
list
.
size
()
>
rowNum
)
{
l
.
add
(
list
.
get
(
rowNum
));
}
else
{
l
.
add
(
list
.
get
(
list
.
size
()
-
1
));
}
}
return
l
;
return
cellRangeList
;
}
/**
...
...
@@ -284,4 +346,5 @@ public class ExcelHeadProperty {
}
return
last
;
}
}
src/main/java/com/alibaba/excel/metadata/property/NumberFormatProperty.java
0 → 100644
浏览文件 @
058df4d7
package
com.alibaba.excel.metadata.property
;
import
java.math.RoundingMode
;
import
com.alibaba.excel.annotation.format.NumberFormat
;
/**
* Configuration from annotations
*
* @author zhuangjiaju
*/
public
class
NumberFormatProperty
{
private
String
format
;
private
RoundingMode
roundingMode
;
public
NumberFormatProperty
(
String
format
,
RoundingMode
roundingMode
)
{
this
.
format
=
format
;
this
.
roundingMode
=
roundingMode
;
}
public
static
NumberFormatProperty
build
(
NumberFormat
numberFormat
)
{
if
(
numberFormat
==
null
)
{
return
null
;
}
return
new
NumberFormatProperty
(
numberFormat
.
value
(),
numberFormat
.
roundingMode
());
}
public
String
getFormat
()
{
return
format
;
}
public
void
setFormat
(
String
format
)
{
this
.
format
=
format
;
}
public
RoundingMode
getRoundingMode
()
{
return
roundingMode
;
}
public
void
setRoundingMode
(
RoundingMode
roundingMode
)
{
this
.
roundingMode
=
roundingMode
;
}
}
src/main/java/com/alibaba/excel/metadata/property/RowHeightProperty.java
0 → 100644
浏览文件 @
058df4d7
package
com.alibaba.excel.metadata.property
;
import
com.alibaba.excel.annotation.write.style.ContentRowHeight
;
import
com.alibaba.excel.annotation.write.style.HeadRowHeight
;
/**
* Configuration from annotations
*
* @author zhuangjiaju
*/
public
class
RowHeightProperty
{
private
Short
height
;
public
RowHeightProperty
(
Short
height
)
{
this
.
height
=
height
;
}
public
static
RowHeightProperty
build
(
HeadRowHeight
headRowHeight
)
{
if
(
headRowHeight
==
null
||
headRowHeight
.
value
()
<
0
)
{
return
null
;
}
return
new
RowHeightProperty
(
headRowHeight
.
value
());
}
public
static
RowHeightProperty
build
(
ContentRowHeight
contentRowHeight
)
{
if
(
contentRowHeight
==
null
||
contentRowHeight
.
value
()
<
0
)
{
return
null
;
}
return
new
RowHeightProperty
(
contentRowHeight
.
value
());
}
public
Short
getHeight
()
{
return
height
;
}
public
void
setHeight
(
Short
height
)
{
this
.
height
=
height
;
}
}
src/main/java/com/alibaba/excel/util/StringUtils.java
浏览文件 @
058df4d7
...
...
@@ -32,6 +32,8 @@ import java.util.Set;
import
java.util.StringTokenizer
;
import
java.util.TimeZone
;
import
org.apache.commons.codec.binary.CharSequenceUtils
;
/**
* Miscellaneous {@link String} utility methods.
*
...
...
@@ -1218,4 +1220,96 @@ public abstract class StringUtils {
return
arrayToDelimitedString
(
arr
,
","
);
}
/**
* <p>Compares two CharSequences, returning {@code true} if they represent
* equal sequences of characters.</p>
*
* <p>{@code null}s are handled without exceptions. Two {@code null}
* references are considered to be equal. The comparison is case sensitive.</p>
*
* <pre>
* StringUtils.equals(null, null) = true
* StringUtils.equals(null, "abc") = false
* StringUtils.equals("abc", null) = false
* StringUtils.equals("abc", "abc") = true
* StringUtils.equals("abc", "ABC") = false
* </pre>
*
* @see Object#equals(Object)
* @param cs1 the first CharSequence, may be {@code null}
* @param cs2 the second CharSequence, may be {@code null}
* @return {@code true} if the CharSequences are equal (case-sensitive), or both {@code null}
* @since 3.0 Changed signature from equals(String, String) to equals(CharSequence, CharSequence)
*/
public
static
boolean
equals
(
final
CharSequence
cs1
,
final
CharSequence
cs2
)
{
if
(
cs1
==
cs2
)
{
return
true
;
}
if
(
cs1
==
null
||
cs2
==
null
)
{
return
false
;
}
if
(
cs1
.
length
()
!=
cs2
.
length
())
{
return
false
;
}
if
(
cs1
instanceof
String
&&
cs2
instanceof
String
)
{
return
cs1
.
equals
(
cs2
);
}
return
regionMatches
(
cs1
,
false
,
0
,
cs2
,
0
,
cs1
.
length
());
}
/**
* Green implementation of regionMatches.
*
* @param cs the {@code CharSequence} to be processed
* @param ignoreCase whether or not to be case insensitive
* @param thisStart the index to start on the {@code cs} CharSequence
* @param substring the {@code CharSequence} to be looked for
* @param start the index to start on the {@code substring} CharSequence
* @param length character length of the region
* @return whether the region matched
*/
static
boolean
regionMatches
(
final
CharSequence
cs
,
final
boolean
ignoreCase
,
final
int
thisStart
,
final
CharSequence
substring
,
final
int
start
,
final
int
length
)
{
if
(
cs
instanceof
String
&&
substring
instanceof
String
)
{
return
((
String
)
cs
).
regionMatches
(
ignoreCase
,
thisStart
,
(
String
)
substring
,
start
,
length
);
}
int
index1
=
thisStart
;
int
index2
=
start
;
int
tmpLen
=
length
;
// Extract these first so we detect NPEs the same as the java.lang.String version
final
int
srcLen
=
cs
.
length
()
-
thisStart
;
final
int
otherLen
=
substring
.
length
()
-
start
;
// Check for invalid parameters
if
(
thisStart
<
0
||
start
<
0
||
length
<
0
)
{
return
false
;
}
// Check that the regions are long enough
if
(
srcLen
<
length
||
otherLen
<
length
)
{
return
false
;
}
while
(
tmpLen
--
>
0
)
{
final
char
c1
=
cs
.
charAt
(
index1
++);
final
char
c2
=
substring
.
charAt
(
index2
++);
if
(
c1
==
c2
)
{
continue
;
}
if
(!
ignoreCase
)
{
return
false
;
}
// The same check as in String.regionMatches():
if
(
Character
.
toUpperCase
(
c1
)
!=
Character
.
toUpperCase
(
c2
)
&&
Character
.
toLowerCase
(
c1
)
!=
Character
.
toLowerCase
(
c2
))
{
return
false
;
}
}
return
true
;
}
}
src/main/java/com/alibaba/excel/write/ExcelBuilderImpl.java
浏览文件 @
058df4d7
package
com.alibaba.excel.write
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.Row
;
...
...
@@ -11,11 +12,11 @@ import com.alibaba.excel.context.WriteContextImpl;
import
com.alibaba.excel.converters.Converter
;
import
com.alibaba.excel.exception.ExcelDataConvertException
;
import
com.alibaba.excel.metadata.CellData
;
import
com.alibaba.excel.metadata.ExcelColumnProperty
;
import
com.alibaba.excel.metadata.Head
;
import
com.alibaba.excel.metadata.Sheet
;
import
com.alibaba.excel.metadata.Table
;
import
com.alibaba.excel.metadata.holder.ConfigurationSelector
;
import
com.alibaba.excel.metadata.property.ExcelContentProperty
;
import
com.alibaba.excel.util.CollectionUtils
;
import
com.alibaba.excel.util.POITempFile
;
import
com.alibaba.excel.util.WorkBookUtil
;
...
...
@@ -122,33 +123,83 @@ public class ExcelBuilderImpl implements ExcelBuilder {
if
(
CollectionUtils
.
isEmpty
(
oneRowData
))
{
return
;
}
List
<
Head
>
headList
=
context
.
currentConfigurationSelector
().
excelHeadProperty
().
getHeadList
();
for
(
int
i
=
0
;
i
<
oneRowData
.
size
();
i
++)
{
Head
head
=
i
<=
headList
.
size
()
?
headList
.
get
(
i
)
:
null
;
Map
<
Integer
,
Head
>
headMap
=
context
.
currentConfigurationSelector
().
excelHeadProperty
().
getHeadMap
();
int
dataIndex
=
0
;
int
cellIndex
=
0
;
for
(
Map
.
Entry
<
Integer
,
Head
>
entry
:
headMap
.
entrySet
())
{
if
(
dataIndex
>=
oneRowData
.
size
())
{
return
;
}
cellIndex
=
entry
.
getKey
();
Head
head
=
entry
.
getValue
();
doAddBasicTypeToExcel
(
oneRowData
,
head
,
row
,
relativeRowIndex
,
dataIndex
++,
cellIndex
);
}
// Finish
if
(
dataIndex
>=
oneRowData
.
size
())
{
return
;
}
if
(
cellIndex
!=
0
)
{
cellIndex
++;
}
for
(
int
i
=
0
;
i
<
oneRowData
.
size
()
-
dataIndex
;
i
++)
{
doAddBasicTypeToExcel
(
oneRowData
,
null
,
row
,
relativeRowIndex
,
dataIndex
++,
cellIndex
++);
}
}
private
void
doAddBasicTypeToExcel
(
List
<
Object
>
oneRowData
,
Head
head
,
Row
row
,
int
relativeRowIndex
,
int
dataIndex
,
int
cellIndex
)
{
beforeCellCreate
(
row
,
head
,
relativeRowIndex
);
Cell
cell
=
WorkBookUtil
.
createCell
(
row
,
i
);
Object
value
=
oneRowData
.
get
(
i
);
Cell
cell
=
WorkBookUtil
.
createCell
(
row
,
cellIndex
);
Object
value
=
oneRowData
.
get
(
dataIndex
);
converterAndSet
(
context
.
currentConfigurationSelector
(),
value
.
getClass
(),
cell
,
value
,
null
);
afterCellCreate
(
head
,
cell
,
relativeRowIndex
);
}
}
private
void
addJavaObjectToExcel
(
Object
oneRowData
,
Row
row
,
int
relativeRowIndex
)
{
ConfigurationSelector
currentConfigurationSelector
=
context
.
currentConfigurationSelector
();
int
i
=
0
;
BeanMap
beanMap
=
BeanMap
.
create
(
oneRowData
);
List
<
Head
>
headList
=
context
.
currentConfigurationSelector
().
excelHeadProperty
().
getHeadList
();
for
(
ExcelColumnProperty
excelHeadProperty
:
currentConfigurationSelector
.
excelHeadProperty
()
.
getColumnPropertyList
())
{
Head
head
=
i
<=
headList
.
size
()
?
headList
.
get
(
i
)
:
null
;
Map
<
Integer
,
Head
>
headMap
=
context
.
currentConfigurationSelector
().
excelHeadProperty
().
getHeadMap
();
Map
<
Integer
,
ExcelContentProperty
>
contentPropertyMap
=
context
.
currentConfigurationSelector
().
excelHeadProperty
().
getContentPropertyMap
();
int
cellIndex
=
0
;
for
(
Map
.
Entry
<
Integer
,
ExcelContentProperty
>
entry
:
contentPropertyMap
.
entrySet
())
{
cellIndex
=
entry
.
getKey
();
ExcelContentProperty
excelContentProperty
=
entry
.
getValue
();
String
name
=
excelContentProperty
.
getField
().
getName
();
if
(!
beanMap
.
containsKey
(
name
))
{
continue
;
}
Head
head
=
headMap
.
get
(
cellIndex
);
beforeCellCreate
(
row
,
head
,
relativeRowIndex
);
Cell
cell
=
WorkBookUtil
.
createCell
(
row
,
i
);
Object
value
=
beanMap
.
get
(
excelHeadProperty
.
getField
().
getName
()
);
converterAndSet
(
currentConfigurationSelector
,
excel
Head
Property
.
getField
().
getType
(),
cell
,
value
,
excel
Head
Property
);
Cell
cell
=
WorkBookUtil
.
createCell
(
row
,
cellIndex
);
Object
value
=
beanMap
.
get
(
name
);
converterAndSet
(
currentConfigurationSelector
,
excel
Content
Property
.
getField
().
getType
(),
cell
,
value
,
excel
Content
Property
);
afterCellCreate
(
head
,
cell
,
relativeRowIndex
);
i
++
;
beanMap
.
remove
(
name
)
;
}
// Finish
if
(
beanMap
.
isEmpty
())
{
return
;
}
if
(
cellIndex
!=
0
)
{
cellIndex
++;
}
for
(
Object
value
:
beanMap
.
values
())
{
beforeCellCreate
(
row
,
null
,
relativeRowIndex
);
Cell
cell
=
WorkBookUtil
.
createCell
(
row
,
cellIndex
++);
converterAndSet
(
currentConfigurationSelector
,
value
.
getClass
(),
cell
,
value
,
null
);
afterCellCreate
(
null
,
cell
,
relativeRowIndex
);
}
}
private
void
doAddJavaObjectToExcel
(
List
<
Object
>
oneRowData
,
Head
head
,
Row
row
,
int
relativeRowIndex
,
int
dataIndex
,
int
cellIndex
)
{
beforeCellCreate
(
row
,
head
,
relativeRowIndex
);
Cell
cell
=
WorkBookUtil
.
createCell
(
row
,
cellIndex
);
Object
value
=
oneRowData
.
get
(
dataIndex
);
converterAndSet
(
context
.
currentConfigurationSelector
(),
value
.
getClass
(),
cell
,
value
,
null
);
afterCellCreate
(
head
,
cell
,
relativeRowIndex
);
}
private
void
beforeCellCreate
(
Row
row
,
Head
head
,
int
relativeRowIndex
)
{
...
...
@@ -184,11 +235,11 @@ public class ExcelBuilderImpl implements ExcelBuilder {
}
private
void
converterAndSet
(
ConfigurationSelector
currentConfigurationSelector
,
Class
clazz
,
Cell
cell
,
Object
value
,
ExcelCo
lumnProperty
excelHead
Property
)
{
Object
value
,
ExcelCo
ntentProperty
excelContent
Property
)
{
if
(
value
==
null
)
{
return
;
}
Converter
converter
=
currentConfigurationSelector
.
converterMap
().
get
(
excelHeadProperty
.
getField
().
getType
()
);
Converter
converter
=
currentConfigurationSelector
.
converterMap
().
get
(
clazz
);
if
(
converter
==
null
)
{
throw
new
ExcelDataConvertException
(
"Can not find 'Converter' support class "
+
clazz
.
getSimpleName
()
+
"."
);
...
...
@@ -196,7 +247,7 @@ public class ExcelBuilderImpl implements ExcelBuilder {
CellData
cellData
;
try
{
cellData
=
converter
.
convertToExcelData
(
value
,
excel
Head
Property
);
cellData
=
converter
.
convertToExcelData
(
value
,
excel
Content
Property
);
}
catch
(
Exception
e
)
{
throw
new
ExcelDataConvertException
(
"Convert data:"
+
value
+
" error,at row:"
+
cell
.
getRow
().
getRowNum
(),
e
);
...
...
src/main/java/com/alibaba/excel/write/builder/ExcelWriterBuilder.java
浏览文件 @
058df4d7
...
...
@@ -60,8 +60,7 @@ public class ExcelWriterBuilder {
}
/**
* You can only choose one of the {@link ExcelWriterBuilder#head(List)} and
* {@link ExcelWriterBuilder#head(Class)}
* You can only choose one of the {@link ExcelWriterBuilder#head(List)} and {@link ExcelWriterBuilder#head(Class)}
*
* @param head
* @return
...
...
@@ -72,8 +71,7 @@ public class ExcelWriterBuilder {
}
/**
* You can only choose one of the {@link ExcelWriterBuilder#head(List)} and
* {@link ExcelWriterBuilder#head(Class)}
* You can only choose one of the {@link ExcelWriterBuilder#head(List)} and {@link ExcelWriterBuilder#head(Class)}
*
* @param clazz
* @return
...
...
@@ -102,6 +100,22 @@ public class ExcelWriterBuilder {
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.
* <p>
* Default true
*
* @param convertAllFiled
* @return
* @deprecated Just to be compatible with historical data, The default is always going to be convert all filed.
*/
@Deprecated
public
ExcelWriterBuilder
convertAllFiled
(
Boolean
convertAllFiled
)
{
workbook
.
setConvertAllFiled
(
convertAllFiled
);
return
this
;
}
/**
* Custom type conversions override the default.
*
...
...
src/main/java/com/alibaba/excel/write/handler/CellWriteHandler.java
浏览文件 @
058df4d7
...
...
@@ -18,7 +18,12 @@ public interface CellWriteHandler extends WriteHandler {
/**
* called before create the cell
*
* @param writeContext
* @param sheetHolder
* @param tableHolder
* @param row
* @param head
* @param relativeRowIndex
* @param isHead
*/
void
beforeCellCreate
(
SheetHolder
sheetHolder
,
@Nullable
TableHolder
tableHolder
,
Row
row
,
Head
head
,
int
relativeRowIndex
,
boolean
isHead
);
...
...
@@ -26,7 +31,12 @@ public interface CellWriteHandler extends WriteHandler {
/**
* called after the cell is created
*
* @param writeContext
* @param sheetHolder
* @param tableHolder
* @param cell
* @param head
* @param relativeRowIndex
* @param isHead
*/
void
afterCellCreate
(
SheetHolder
sheetHolder
,
@Nullable
TableHolder
tableHolder
,
Cell
cell
,
Head
head
,
int
relativeRowIndex
,
boolean
isHead
);
...
...
src/main/java/com/alibaba/excel/write/handler/DefaultWriteHandler
Buil
der.java
→
src/main/java/com/alibaba/excel/write/handler/DefaultWriteHandler
Loa
der.java
浏览文件 @
058df4d7
...
...
@@ -10,11 +10,11 @@ import com.alibaba.excel.metadata.Font;
import
com.alibaba.excel.write.style.RowCellStyleStrategy
;
/**
*
Buil
d default handler
*
Loa
d default handler
*
* @author zhuangjiaju
*/
public
class
DefaultWriteHandler
Buil
der
{
public
class
DefaultWriteHandler
Loa
der
{
/**
* Load default handler
...
...
src/main/java/com/alibaba/excel/write/handler/RowWriteHandler.java
浏览文件 @
058df4d7
...
...
@@ -16,7 +16,11 @@ public interface RowWriteHandler extends WriteHandler {
/**
* called before create the row
*
* @param writeContext
* @param sheetHolder
* @param tableHolder
* @param rowIndex
* @param relativeRowIndex
* @param isHead
*/
void
beforeRowCreate
(
SheetHolder
sheetHolder
,
@Nullable
TableHolder
tableHolder
,
int
rowIndex
,
int
relativeRowIndex
,
boolean
isHead
);
...
...
@@ -24,7 +28,11 @@ public interface RowWriteHandler extends WriteHandler {
/**
* called after the row is created
*
* @param writeContext
* @param sheetHolder
* @param tableHolder
* @param row
* @param relativeRowIndex
* @param isHead
*/
void
afterRowCreate
(
SheetHolder
sheetHolder
,
@Nullable
TableHolder
tableHolder
,
Row
row
,
int
relativeRowIndex
,
boolean
isHead
);
...
...
src/main/java/com/alibaba/excel/write/handler/SheetWriteHandler.java
浏览文件 @
058df4d7
...
...
@@ -13,14 +13,16 @@ public interface SheetWriteHandler extends WriteHandler {
/**
* called before create the sheet
*
* @param writeContext
* @param workbookHolder
* @param sheetHolder
*/
void
beforeSheetCreate
(
WorkbookHolder
workbookHolder
,
SheetHolder
sheetHolder
);
/**
* called after the sheet is created
*
* @param writeContext
* @param workbookHolder
* @param sheetHolder
*/
void
afterSheetCreate
(
WorkbookHolder
workbookHolder
,
SheetHolder
sheetHolder
);
}
src/main/java/com/alibaba/excel/write/handler/WorkbookWriteHandler.java
浏览文件 @
058df4d7
...
...
@@ -11,15 +11,13 @@ public interface WorkbookWriteHandler extends WriteHandler {
/**
* called before create the sheet
*
* @param writeContext
*/
void
beforeWorkbookCreate
();
/**
* called after the sheet is created
*
* @param w
riteContext
* @param w
orkbookHolder
*/
void
afterWorkbookCreate
(
WorkbookHolder
workbookHolder
);
}
src/main/java/com/alibaba/excel/write/merge/AbstractMergeStrategy.java
浏览文件 @
058df4d7
...
...
@@ -9,6 +9,11 @@ import com.alibaba.excel.metadata.holder.SheetHolder;
import
com.alibaba.excel.metadata.holder.TableHolder
;
import
com.alibaba.excel.write.handler.CellWriteHandler
;
/**
* Merge strategy
*
* @author zhuangjiaju
*/
public
abstract
class
AbstractMergeStrategy
implements
CellWriteHandler
{
@Override
...
...
@@ -24,5 +29,13 @@ public abstract class AbstractMergeStrategy implements CellWriteHandler {
merge
(
sheetHolder
.
getSheet
(),
cell
,
head
,
relativeRowIndex
);
}
/**
* merge
*
* @param sheet
* @param cell
* @param head
* @param relativeRowIndex
*/
protected
abstract
void
merge
(
Sheet
sheet
,
Cell
cell
,
Head
head
,
int
relativeRowIndex
);
}
src/main/java/com/alibaba/excel/write/style/AbstractCellStyleStrategy.java
浏览文件 @
058df4d7
...
...
@@ -12,6 +12,11 @@ import com.alibaba.excel.metadata.holder.WorkbookHolder;
import
com.alibaba.excel.write.handler.CellWriteHandler
;
import
com.alibaba.excel.write.handler.WorkbookWriteHandler
;
/**
* Cell style strategy
*
* @author zhuangjiaju
*/
public
abstract
class
AbstractCellStyleStrategy
implements
CellWriteHandler
,
WorkbookWriteHandler
,
NotRepeatExecutor
{
@Override
public
String
uniqueValue
()
{
...
...
@@ -41,10 +46,29 @@ public abstract class AbstractCellStyleStrategy implements CellWriteHandler, Wor
}
/**
* Initialization cell style
*
* @param workbook
*/
protected
abstract
void
initCellStyle
(
Workbook
workbook
);
/**
* Sets the cell style of header
*
* @param cell
* @param head
* @param relativeRowIndex
*/
protected
abstract
void
setHeadCellStyle
(
Cell
cell
,
Head
head
,
int
relativeRowIndex
);
/**
* Sets the cell style of content
*
* @param cell
* @param head
* @param relativeRowIndex
*/
protected
abstract
void
setContentCellStyle
(
Cell
cell
,
Head
head
,
int
relativeRowIndex
);
}
src/main/java/com/alibaba/excel/write/style/AbstractColumnCellStyleStrategy.java
浏览文件 @
058df4d7
...
...
@@ -9,6 +9,7 @@ import org.apache.poi.ss.usermodel.Workbook;
import
com.alibaba.excel.metadata.Head
;
import
com.alibaba.excel.util.StyleUtil
;
import
com.sun.istack.internal.Nullable
;
/**
*
...
...
@@ -31,23 +32,41 @@ public abstract class AbstractColumnCellStyleStrategy extends AbstractCellStyleS
protected
void
setHeadCellStyle
(
Cell
cell
,
Head
head
,
int
relativeRowIndex
)
{
int
columnIndex
=
head
.
getColumnIndex
();
if
(
headCellStyleCache
.
containsKey
(
columnIndex
))
{
cell
.
setCellStyle
(
headCellStyleCache
.
get
(
columnIndex
));
CellStyle
cellStyle
=
headCellStyleCache
.
get
(
columnIndex
);
if
(
cellStyle
!=
null
)
{
cell
.
setCellStyle
(
cellStyle
);
}
return
;
}
com
.
alibaba
.
excel
.
metadata
.
CellStyle
headCellStyle
=
headCellStyle
(
head
);
if
(
headCellStyle
==
null
)
{
headCellStyleCache
.
put
(
columnIndex
,
null
);
}
else
{
CellStyle
cellStyle
=
StyleUtil
.
buildHeadCellStyle
(
workbook
,
headCellStyle
(
head
));
headCellStyleCache
.
put
(
columnIndex
,
cellStyle
);
cell
.
setCellStyle
(
cellStyle
);
}
}
@Override
protected
void
setContentCellStyle
(
Cell
cell
,
Head
head
,
int
relativeRowIndex
)
{
int
columnIndex
=
head
.
getColumnIndex
();
if
(
contentCellStyleCache
.
containsKey
(
columnIndex
))
{
cell
.
setCellStyle
(
contentCellStyleCache
.
get
(
columnIndex
));
CellStyle
cellStyle
=
contentCellStyleCache
.
get
(
columnIndex
);
if
(
cellStyle
!=
null
)
{
cell
.
setCellStyle
(
cellStyle
);
}
return
;
}
com
.
alibaba
.
excel
.
metadata
.
CellStyle
contentCellStyle
=
contentCellStyle
(
head
);
if
(
contentCellStyle
==
null
)
{
contentCellStyleCache
.
put
(
columnIndex
,
null
);
}
else
{
CellStyle
cellStyle
=
StyleUtil
.
buildContentCellStyle
(
workbook
,
contentCellStyle
(
head
));
contentCellStyleCache
.
put
(
columnIndex
,
cellStyle
);
cell
.
setCellStyle
(
cellStyle
);
}
}
/**
* Returns the column width corresponding to each column head
...
...
@@ -55,7 +74,7 @@ public abstract class AbstractColumnCellStyleStrategy extends AbstractCellStyleS
* @param head
* @return
*/
protected
abstract
com
.
alibaba
.
excel
.
metadata
.
CellStyle
headCellStyle
(
Head
head
);
protected
abstract
com
.
alibaba
.
excel
.
metadata
.
CellStyle
headCellStyle
(
@Nullable
Head
head
);
/**
* Returns the column width corresponding to each column head
...
...
@@ -63,6 +82,6 @@ public abstract class AbstractColumnCellStyleStrategy extends AbstractCellStyleS
* @param head
* @return
*/
protected
abstract
com
.
alibaba
.
excel
.
metadata
.
CellStyle
contentCellStyle
(
Head
head
);
protected
abstract
com
.
alibaba
.
excel
.
metadata
.
CellStyle
contentCellStyle
(
@Nullable
Head
head
);
}
src/main/java/com/alibaba/excel/write/style/column/AbstractColumnWidthStyleStrategy.java
浏览文件 @
058df4d7
...
...
@@ -9,6 +9,7 @@ import com.alibaba.excel.metadata.Head;
import
com.alibaba.excel.metadata.holder.SheetHolder
;
import
com.alibaba.excel.metadata.holder.TableHolder
;
import
com.alibaba.excel.write.handler.CellWriteHandler
;
import
com.sun.istack.internal.Nullable
;
/**
* Column width style strategy
...
...
@@ -29,7 +30,7 @@ public abstract class AbstractColumnWidthStyleStrategy implements CellWriteHandl
@Override
public
void
afterCellCreate
(
SheetHolder
sheetHolder
,
TableHolder
tableHolder
,
Cell
cell
,
Head
head
,
int
relativeRowIndex
,
boolean
isHead
)
{
if
(!
isHead
)
{
if
(!
isHead
&&
relativeRowIndex
!=
0
)
{
return
;
}
setColumnWidth
(
sheetHolder
.
getSheet
(),
cell
,
head
);
...
...
@@ -42,6 +43,6 @@ public abstract class AbstractColumnWidthStyleStrategy implements CellWriteHandl
* @param cell
* @param head
*/
protected
abstract
void
setColumnWidth
(
Sheet
sheet
,
Cell
cell
,
Head
head
);
protected
abstract
void
setColumnWidth
(
Sheet
sheet
,
Cell
cell
,
@Nullable
Head
head
);
}
src/main/java/com/alibaba/excel/write/style/column/AbstractHeadColumnWidthStyleStrategy.java
浏览文件 @
058df4d7
...
...
@@ -4,6 +4,7 @@ import org.apache.poi.ss.usermodel.Cell;
import
org.apache.poi.ss.usermodel.Sheet
;
import
com.alibaba.excel.metadata.Head
;
import
com.sun.istack.internal.Nullable
;
/**
* Returns the column width according to each column header
...
...
@@ -13,17 +14,21 @@ import com.alibaba.excel.metadata.Head;
public
abstract
class
AbstractHeadColumnWidthStyleStrategy
extends
AbstractColumnWidthStyleStrategy
{
@Override
protected
void
setColumnWidth
(
Sheet
sheet
,
Cell
cell
,
Head
head
)
{
Integer
width
=
columnWidth
(
head
);
if
(
width
!=
null
)
{
sheet
.
setColumnWidth
(
cell
.
getColumnIndex
(),
columnWidth
(
head
));
}
}
/**
* Returns the column width corresponding to each column head.
*
* <li>if return null,ignore
*
* @param head
* @return the width in units of 1/256th of a character width . Using the Calibri font as an example, the maximum
* digit width of 11 point font size is 7 pixels (at 96 dpi). If you set a column width to be eight
* characters wide, e.g. you need return 8*256
*/
protected
abstract
int
columnWidth
(
Head
head
);
protected
abstract
Integer
columnWidth
(
@Nullable
Head
head
);
}
src/main/java/com/alibaba/excel/write/style/column/SimpleColumnWidthStyleStrategy.java
浏览文件 @
058df4d7
...
...
@@ -11,7 +11,7 @@ import com.alibaba.excel.metadata.Head;
* @author zhuangjiaju
*/
public
class
SimpleColumnWidthStyleStrategy
extends
AbstractColumnWidthStyleStrategy
{
private
int
columnWidth
;
private
Integer
columnWidth
;
/**
* Using the Calibri font as an example, the maximum digit width of 11 point font size is 7 pixels (at 96 dpi). * If
...
...
@@ -20,12 +20,14 @@ public class SimpleColumnWidthStyleStrategy extends AbstractColumnWidthStyleStra
* @param columnWidth
* the width in units of 1/256th of a character width
*/
public
SimpleColumnWidthStyleStrategy
(
int
columnWidth
)
{
public
SimpleColumnWidthStyleStrategy
(
Integer
columnWidth
)
{
this
.
columnWidth
=
columnWidth
;
}
@Override
protected
void
setColumnWidth
(
Sheet
sheet
,
Cell
cell
,
Head
head
)
{
if
(
columnWidth
!=
null
)
{
sheet
.
setColumnWidth
(
cell
.
getColumnIndex
(),
columnWidth
);
}
}
}
src/main/java/com/alibaba/excel/write/style/row/AbstractRowH
igh
StyleStrategy.java
→
src/main/java/com/alibaba/excel/write/style/row/AbstractRowH
eight
StyleStrategy.java
浏览文件 @
058df4d7
...
...
@@ -7,7 +7,12 @@ import com.alibaba.excel.metadata.holder.SheetHolder;
import
com.alibaba.excel.metadata.holder.TableHolder
;
import
com.alibaba.excel.write.handler.RowWriteHandler
;
public
abstract
class
AbstractRowHighStyleStrategy
implements
RowWriteHandler
,
NotRepeatExecutor
{
/**
* Set the row height strategy
*
* @author zhuangjiaju
*/
public
abstract
class
AbstractRowHeightStyleStrategy
implements
RowWriteHandler
,
NotRepeatExecutor
{
@Override
public
String
uniqueValue
()
{
...
...
@@ -24,14 +29,26 @@ public abstract class AbstractRowHighStyleStrategy implements RowWriteHandler, N
public
void
afterRowCreate
(
SheetHolder
sheetHolder
,
TableHolder
tableHolder
,
Row
row
,
int
relativeRowIndex
,
boolean
isHead
)
{
if
(
isHead
)
{
setHeadColumnH
igh
(
row
,
relativeRowIndex
);
setHeadColumnH
eight
(
row
,
relativeRowIndex
);
}
else
{
setContentColumnH
igh
(
row
,
relativeRowIndex
);
setContentColumnH
eight
(
row
,
relativeRowIndex
);
}
}
protected
abstract
void
setHeadColumnHigh
(
Row
row
,
int
relativeRowIndex
);
protected
abstract
void
setContentColumnHigh
(
Row
row
,
int
relativeRowIndex
);
/**
* Sets the height of header
*
* @param row
* @param relativeRowIndex
*/
protected
abstract
void
setHeadColumnHeight
(
Row
row
,
int
relativeRowIndex
);
/**
* Sets the height of content
*
* @param row
* @param relativeRowIndex
*/
protected
abstract
void
setContentColumnHeight
(
Row
row
,
int
relativeRowIndex
);
}
src/main/java/com/alibaba/excel/write/style/row/SimpleRowHeightStyleStrategy.java
0 → 100644
浏览文件 @
058df4d7
package
com.alibaba.excel.write.style.row
;
import
org.apache.poi.ss.usermodel.Row
;
/**
* Set the head column high and content column high
*
* @author zhuangjiaju
*/
public
class
SimpleRowHeightStyleStrategy
extends
AbstractRowHeightStyleStrategy
{
private
Short
headRowHeight
;
private
Short
contentRowHeight
;
public
SimpleRowHeightStyleStrategy
(
Short
headRowHeight
,
Short
contentRowHeight
)
{
this
.
headRowHeight
=
headRowHeight
;
this
.
contentRowHeight
=
contentRowHeight
;
}
@Override
protected
void
setHeadColumnHeight
(
Row
row
,
int
relativeRowIndex
)
{
if
(
headRowHeight
!=
null
)
{
row
.
setHeight
(
headRowHeight
);
}
}
@Override
protected
void
setContentColumnHeight
(
Row
row
,
int
relativeRowIndex
)
{
if
(
contentRowHeight
!=
null
)
{
row
.
setHeight
(
contentRowHeight
);
}
}
}
src/main/java/com/alibaba/excel/write/style/row/SimpleRowHighStyleStrategy.java
已删除
100644 → 0
浏览文件 @
17e20fb9
package
com.alibaba.excel.write.style.row
;
import
org.apache.poi.ss.usermodel.Row
;
/**
* Set the head column high and content column high
*
* @author zhuangjiaju
*/
public
class
SimpleRowHighStyleStrategy
extends
AbstractRowHighStyleStrategy
{
private
short
headColumnHigh
;
private
short
contentColumnHigh
;
public
SimpleRowHighStyleStrategy
(
short
headColumnHigh
,
short
contentColumnHigh
)
{
this
.
headColumnHigh
=
headColumnHigh
;
this
.
contentColumnHigh
=
contentColumnHigh
;
}
@Override
protected
void
setHeadColumnHigh
(
Row
row
,
int
relativeRowIndex
)
{
row
.
setHeight
(
headColumnHigh
);
}
@Override
protected
void
setContentColumnHigh
(
Row
row
,
int
relativeRowIndex
)
{
row
.
setHeight
(
contentColumnHigh
);
}
}
src/test/java/com/alibaba/easyexcel/test/wirte/nohead/NoHeadData07Test.java
0 → 100644
浏览文件 @
058df4d7
package
com.alibaba.easyexcel.test.wirte.nohead
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.junit.Test
;
import
com.alibaba.easyexcel.test.util.FileUtil
;
import
com.alibaba.easyexcel.test.wirte.order.OrderData
;
import
com.alibaba.excel.EasyExcelFactory
;
import
com.alibaba.excel.ExcelWriter
;
import
com.alibaba.excel.metadata.Sheet
;
/**
* Order data test
*
* @author zhuangjiaju
*/
public
class
NoHeadData07Test
{
@Test
public
void
simple
()
{
ExcelWriter
writer
=
EasyExcelFactory
.
writerBuilder
().
outputFile
(
FileUtil
.
createNewWriteFile
(
"order07.xlsx"
))
.
head
(
OrderData
.
class
).
build
();
Sheet
sheet
=
EasyExcelFactory
.
writerSheetBuilder
().
sheetNo
(
0
).
sheetName
(
"order"
).
build
();
writer
.
write
(
createData
(
10000
*
100
),
sheet
);
writer
.
finish
();
}
private
List
<
OrderData
>
createData
(
int
count
)
{
List
<
OrderData
>
list
=
new
ArrayList
<
OrderData
>();
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
OrderData
orderData
=
new
OrderData
();
orderData
.
setIndex1
(
"排序1:"
+
i
);
orderData
.
setIndex10
(
"排序10:"
+
i
);
list
.
add
(
orderData
);
}
return
list
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录