Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
苏木力格
easyexcel
提交
ad9544c4
E
easyexcel
项目概览
苏木力格
/
easyexcel
与 Fork 源项目一致
从无法访问的项目Fork
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
easyexcel
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ad9544c4
编写于
7月 30, 2019
作者:
Z
zhuangjiaju
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
扩充写的style
上级
a9f12c07
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
659 addition
and
379 deletion
+659
-379
src/main/java/com/alibaba/excel/annotation/write/style/ContentStyle.java
...om/alibaba/excel/annotation/write/style/ContentStyle.java
+0
-31
src/main/java/com/alibaba/excel/annotation/write/style/HeadStyle.java
...a/com/alibaba/excel/annotation/write/style/HeadStyle.java
+0
-27
src/main/java/com/alibaba/excel/metadata/CellStyle.java
src/main/java/com/alibaba/excel/metadata/CellStyle.java
+0
-48
src/main/java/com/alibaba/excel/metadata/Font.java
src/main/java/com/alibaba/excel/metadata/Font.java
+2
-0
src/main/java/com/alibaba/excel/metadata/Head.java
src/main/java/com/alibaba/excel/metadata/Head.java
+0
-13
src/main/java/com/alibaba/excel/metadata/property/CellStyleProperty.java
...om/alibaba/excel/metadata/property/CellStyleProperty.java
+0
-84
src/main/java/com/alibaba/excel/metadata/property/ExcelContentProperty.java
...alibaba/excel/metadata/property/ExcelContentProperty.java
+0
-9
src/main/java/com/alibaba/excel/util/StyleUtil.java
src/main/java/com/alibaba/excel/util/StyleUtil.java
+123
-58
src/main/java/com/alibaba/excel/write/handler/DefaultWriteHandlerLoader.java
...libaba/excel/write/handler/DefaultWriteHandlerLoader.java
+11
-11
src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java
...baba/excel/write/metadata/holder/AbstractWriteHolder.java
+34
-54
src/main/java/com/alibaba/excel/write/metadata/style/WriteCellStyle.java
...om/alibaba/excel/write/metadata/style/WriteCellStyle.java
+315
-0
src/main/java/com/alibaba/excel/write/metadata/style/WriteFont.java
...ava/com/alibaba/excel/write/metadata/style/WriteFont.java
+143
-0
src/main/java/com/alibaba/excel/write/property/ExcelWriteHeadProperty.java
.../alibaba/excel/write/property/ExcelWriteHeadProperty.java
+0
-15
src/main/java/com/alibaba/excel/write/style/AbstractColumnCellStyleStrategy.java
...ba/excel/write/style/AbstractColumnCellStyleStrategy.java
+7
-6
src/main/java/com/alibaba/excel/write/style/RowCellStyleStrategy.java
...a/com/alibaba/excel/write/style/RowCellStyleStrategy.java
+22
-21
src/main/java/com/alibaba/excel/write/style/column/AbstractColumnWidthStyleStrategy.java
.../write/style/column/AbstractColumnWidthStyleStrategy.java
+2
-2
未找到文件。
src/main/java/com/alibaba/excel/annotation/write/style/ContentStyle.java
已删除
100644 → 0
浏览文件 @
a9f12c07
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/HeadStyle.java
已删除
100644 → 0
浏览文件 @
a9f12c07
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/metadata/CellStyle.java
已删除
100644 → 0
浏览文件 @
a9f12c07
package
com.alibaba.excel.metadata
;
import
org.apache.poi.ss.usermodel.IndexedColors
;
/**
* Simple cell style
*
* @author zhuangjiaju
*/
public
class
CellStyle
{
/**
* 表头背景颜色
*/
private
IndexedColors
indexedColors
;
/**
* 表头字体样式
*/
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
;
}
public
void
setIndexedColors
(
IndexedColors
indexedColors
)
{
this
.
indexedColors
=
indexedColors
;
}
public
Font
getFont
()
{
return
font
;
}
public
void
setFont
(
Font
font
)
{
this
.
font
=
font
;
}
}
src/main/java/com/alibaba/excel/metadata/Font.java
浏览文件 @
ad9544c4
...
...
@@ -3,7 +3,9 @@ package com.alibaba.excel.metadata;
/**
*
* @author jipengfei
* @deprecated please use {@link com.alibaba.excel.write.metadata.style.WriteFont}
*/
@Deprecated
public
class
Font
{
/**
...
...
src/main/java/com/alibaba/excel/metadata/Head.java
浏览文件 @
ad9544c4
...
...
@@ -3,7 +3,6 @@ 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
;
/**
...
...
@@ -28,10 +27,6 @@ public class Head {
* Whether index is specified
*/
private
Boolean
forceIndex
;
/**
* Cell style property
*/
private
CellStyleProperty
cellStyleProperty
;
/**
* column with
*/
...
...
@@ -79,14 +74,6 @@ public class Head {
this
.
headNameList
=
headNameList
;
}
public
CellStyleProperty
getCellStyleProperty
()
{
return
cellStyleProperty
;
}
public
void
setCellStyleProperty
(
CellStyleProperty
cellStyleProperty
)
{
this
.
cellStyleProperty
=
cellStyleProperty
;
}
public
ColumnWidthProperty
getColumnWidthProperty
()
{
return
columnWidthProperty
;
}
...
...
src/main/java/com/alibaba/excel/metadata/property/CellStyleProperty.java
已删除
100644 → 0
浏览文件 @
a9f12c07
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/ExcelContentProperty.java
浏览文件 @
ad9544c4
...
...
@@ -21,7 +21,6 @@ public class ExcelContentProperty {
* Custom defined converters
*/
private
Converter
converter
;
private
CellStyleProperty
cellStyleProperty
;
private
DateTimeFormatProperty
dateTimeFormatProperty
;
private
NumberFormatProperty
numberFormatProperty
;
...
...
@@ -41,14 +40,6 @@ public class ExcelContentProperty {
this
.
head
=
head
;
}
public
CellStyleProperty
getCellStyleProperty
()
{
return
cellStyleProperty
;
}
public
void
setCellStyleProperty
(
CellStyleProperty
cellStyleProperty
)
{
this
.
cellStyleProperty
=
cellStyleProperty
;
}
public
DateTimeFormatProperty
getDateTimeFormatProperty
()
{
return
dateTimeFormatProperty
;
}
...
...
src/main/java/com/alibaba/excel/util/StyleUtil.java
浏览文件 @
ad9544c4
...
...
@@ -9,23 +9,20 @@ import org.apache.poi.ss.usermodel.IndexedColors;
import
org.apache.poi.ss.usermodel.VerticalAlignment
;
import
org.apache.poi.ss.usermodel.Workbook
;
import
com.alibaba.excel.write.metadata.style.WriteCellStyle
;
import
com.alibaba.excel.write.metadata.style.WriteFont
;
/**
* @author jipengfei
*/
public
class
StyleUtil
{
/**
*
* @param workbook
* @return
*/
public
static
CellStyle
buildDefaultCellStyle
(
Workbook
workbook
)
{
CellStyle
newCellStyle
=
workbook
.
createCellStyle
();
Font
font
=
workbook
.
createFont
();
font
.
setFontName
(
"宋体"
);
font
.
setFontHeightInPoints
((
short
)
14
);
font
.
setBold
(
true
);
newCellStyle
.
setFont
(
font
);
newCellStyle
.
setWrapText
(
true
);
newCellStyle
.
setVerticalAlignment
(
VerticalAlignment
.
CENTER
);
newCellStyle
.
setAlignment
(
HorizontalAlignment
.
CENTER
);
...
...
@@ -38,80 +35,148 @@ public class StyleUtil {
}
/**
* Build style
*
* Build
head cell
style
*
* @param workbook
* @param
cs
* @param
writeCellStyle
* @return
*/
public
static
CellStyle
buildHeadCellStyle
(
Workbook
workbook
,
com
.
alibaba
.
excel
.
metadata
.
CellStyle
cs
)
{
public
static
CellStyle
buildHeadCellStyle
(
Workbook
workbook
,
WriteCellStyle
writeCellStyle
)
{
CellStyle
cellStyle
=
buildDefaultCellStyle
(
workbook
);
if
(
cs
==
null
)
{
if
(
writeCellStyle
==
null
)
{
return
cellStyle
;
}
return
buildCellStyle
(
workbook
,
cellStyle
,
cs
.
getFont
(),
cs
.
getIndexedColors
());
}
/**
*
* @param workbook
* @param f
* @param indexedColors
* @return
*/
public
static
CellStyle
buildHeadCellStyle
(
Workbook
workbook
,
com
.
alibaba
.
excel
.
metadata
.
Font
f
,
IndexedColors
indexedColors
)
{
CellStyle
cellStyle
=
buildDefaultCellStyle
(
workbook
);
return
buildCellStyle
(
workbook
,
cellStyle
,
f
,
indexedColors
);
buildCellStyle
(
workbook
,
cellStyle
,
writeCellStyle
,
true
);
return
cellStyle
;
}
/**
* Build style
* Build
content cell
style
*
* @param workbook
* @param
cs
* @param
writeCellStyle
* @return
*/
public
static
CellStyle
buildContentCellStyle
(
Workbook
workbook
,
com
.
alibaba
.
excel
.
metadata
.
CellStyle
cs
)
{
public
static
CellStyle
buildContentCellStyle
(
Workbook
workbook
,
WriteCellStyle
writeCellStyle
)
{
CellStyle
cellStyle
=
workbook
.
createCellStyle
();
if
(
cs
==
null
)
{
if
(
writeCellStyle
==
null
)
{
return
cellStyle
;
}
return
buildCellStyle
(
workbook
,
cellStyle
,
cs
.
getFont
(),
cs
.
getIndexedColors
());
buildCellStyle
(
workbook
,
cellStyle
,
writeCellStyle
,
false
);
return
cellStyle
;
}
/**
*
* @param workbook
* @param f
* @param indexedColors
* @return
*/
public
static
CellStyle
buildContentCellStyle
(
Workbook
workbook
,
com
.
alibaba
.
excel
.
metadata
.
Font
f
,
IndexedColors
indexedColors
)
{
CellStyle
cellStyle
=
workbook
.
createCellStyle
();
return
buildCellStyle
(
workbook
,
cellStyle
,
f
,
indexedColors
);
private
static
void
buildCellStyle
(
Workbook
workbook
,
CellStyle
cellStyle
,
WriteCellStyle
writeCellStyle
,
boolean
isHead
)
{
buildFont
(
workbook
,
cellStyle
,
writeCellStyle
.
getWriteFont
(),
isHead
);
if
(
writeCellStyle
.
getDataFormat
()
!=
null
)
{
cellStyle
.
setDataFormat
(
writeCellStyle
.
getDataFormat
());
}
if
(
writeCellStyle
.
getHidden
()
!=
null
)
{
cellStyle
.
setHidden
(
writeCellStyle
.
getHidden
());
}
if
(
writeCellStyle
.
getLocked
()
!=
null
)
{
cellStyle
.
setLocked
(
writeCellStyle
.
getLocked
());
}
if
(
writeCellStyle
.
getQuotePrefix
()
!=
null
)
{
cellStyle
.
setQuotePrefixed
(
writeCellStyle
.
getQuotePrefix
());
}
if
(
writeCellStyle
.
getHorizontalAlignment
()
!=
null
)
{
cellStyle
.
setAlignment
(
writeCellStyle
.
getHorizontalAlignment
());
}
if
(
writeCellStyle
.
getWrapped
()
!=
null
)
{
cellStyle
.
setWrapText
(
writeCellStyle
.
getWrapped
());
}
if
(
writeCellStyle
.
getVerticalAlignment
()
!=
null
)
{
cellStyle
.
setVerticalAlignment
(
writeCellStyle
.
getVerticalAlignment
());
}
if
(
writeCellStyle
.
getRotation
()
!=
null
)
{
cellStyle
.
setRotation
(
writeCellStyle
.
getRotation
());
}
if
(
writeCellStyle
.
getIndent
()
!=
null
)
{
cellStyle
.
setIndention
(
writeCellStyle
.
getIndent
());
}
if
(
writeCellStyle
.
getBorderLeft
()
!=
null
)
{
cellStyle
.
setBorderLeft
(
writeCellStyle
.
getBorderLeft
());
}
if
(
writeCellStyle
.
getBorderRight
()
!=
null
)
{
cellStyle
.
setBorderRight
(
writeCellStyle
.
getBorderRight
());
}
if
(
writeCellStyle
.
getBorderTop
()
!=
null
)
{
cellStyle
.
setBorderTop
(
writeCellStyle
.
getBorderTop
());
}
if
(
writeCellStyle
.
getBorderBottom
()
!=
null
)
{
cellStyle
.
setBorderBottom
(
writeCellStyle
.
getBorderBottom
());
}
if
(
writeCellStyle
.
getLeftBorderColor
()
!=
null
)
{
cellStyle
.
setLeftBorderColor
(
writeCellStyle
.
getLeftBorderColor
());
}
if
(
writeCellStyle
.
getRightBorderColor
()
!=
null
)
{
cellStyle
.
setRightBorderColor
(
writeCellStyle
.
getRightBorderColor
());
}
if
(
writeCellStyle
.
getTopBorderColor
()
!=
null
)
{
cellStyle
.
setTopBorderColor
(
writeCellStyle
.
getTopBorderColor
());
}
if
(
writeCellStyle
.
getBottomBorderColor
()
!=
null
)
{
cellStyle
.
setBottomBorderColor
(
writeCellStyle
.
getBottomBorderColor
());
}
if
(
writeCellStyle
.
getFillPatternType
()
!=
null
)
{
cellStyle
.
setFillPattern
(
writeCellStyle
.
getFillPatternType
());
}
if
(
writeCellStyle
.
getFillBackgroundColor
()
!=
null
)
{
cellStyle
.
setFillBackgroundColor
(
writeCellStyle
.
getFillBackgroundColor
());
}
if
(
writeCellStyle
.
getFillForegroundColor
()
!=
null
)
{
cellStyle
.
setFillForegroundColor
(
writeCellStyle
.
getFillForegroundColor
());
}
if
(
writeCellStyle
.
getShrinkToFit
()
!=
null
)
{
cellStyle
.
setShrinkToFit
(
writeCellStyle
.
getShrinkToFit
());
}
}
/**
*
* @param workbook
* @param f
* @param indexedColors
* @return
*/
private
static
CellStyle
buildCellStyle
(
Workbook
workbook
,
CellStyle
cellStyle
,
com
.
alibaba
.
excel
.
metadata
.
Font
f
,
IndexedColors
indexedColors
)
{
if
(
f
!=
null
)
{
Font
font
=
workbook
.
createFont
();
font
.
setFontName
(
f
.
getFontName
());
font
.
setFontHeightInPoints
(
f
.
getFontHeightInPoints
());
font
.
setBold
(
f
.
isBold
());
private
static
void
buildFont
(
Workbook
workbook
,
CellStyle
cellStyle
,
WriteFont
writeFont
,
boolean
isHead
)
{
Font
font
=
null
;
if
(
isHead
)
{
font
=
workbook
.
createFont
();
font
.
setFontName
(
"宋体"
);
font
.
setFontHeightInPoints
((
short
)
14
);
font
.
setBold
(
true
);
cellStyle
.
setFont
(
font
);
}
if
(
indexedColors
!=
null
)
{
cellStyle
.
setFillForegroundColor
(
indexedColors
.
getIndex
());
if
(
writeFont
==
null
)
{
return
;
}
if
(!
isHead
)
{
font
=
workbook
.
createFont
();
cellStyle
.
setFont
(
font
);
}
if
(
writeFont
.
getFontName
()
!=
null
)
{
font
.
setFontName
(
writeFont
.
getFontName
());
}
if
(
writeFont
.
getFontHeightInPoints
()
!=
null
)
{
font
.
setFontHeightInPoints
(
writeFont
.
getFontHeightInPoints
());
}
if
(
writeFont
.
getItalic
()
!=
null
)
{
font
.
setItalic
(
writeFont
.
getItalic
());
}
if
(
writeFont
.
getStrikeout
()
!=
null
)
{
font
.
setStrikeout
(
writeFont
.
getStrikeout
());
}
if
(
writeFont
.
getColor
()
!=
null
)
{
font
.
setColor
(
writeFont
.
getColor
());
}
if
(
writeFont
.
getTypeOffset
()
!=
null
)
{
font
.
setTypeOffset
(
writeFont
.
getTypeOffset
());
}
if
(
writeFont
.
getUnderline
()
!=
null
)
{
font
.
setUnderline
(
writeFont
.
getUnderline
());
}
if
(
writeFont
.
getCharset
()
!=
null
)
{
font
.
setCharSet
(
writeFont
.
getCharset
());
}
if
(
writeFont
.
getBold
()
!=
null
)
{
font
.
setBold
(
writeFont
.
getBold
());
}
return
cellStyle
;
}
}
src/main/java/com/alibaba/excel/write/handler/DefaultWriteHandlerLoader.java
浏览文件 @
ad9544c4
...
...
@@ -5,13 +5,13 @@ import java.util.List;
import
org.apache.poi.ss.usermodel.IndexedColors
;
import
com.alibaba.excel.
metadata.
CellStyle
;
import
com.alibaba.excel.
metadata.
Font
;
import
com.alibaba.excel.
write.metadata.style.Write
CellStyle
;
import
com.alibaba.excel.
write.metadata.style.Write
Font
;
import
com.alibaba.excel.write.style.RowCellStyleStrategy
;
/**
* Load default handler
*
*
* @author zhuangjiaju
*/
public
class
DefaultWriteHandlerLoader
{
...
...
@@ -23,14 +23,14 @@ public class DefaultWriteHandlerLoader {
*/
public
static
List
<
WriteHandler
>
loadDefaultHandler
()
{
List
<
WriteHandler
>
handlerList
=
new
ArrayList
<
WriteHandler
>();
CellStyle
headCellStyle
=
new
CellStyle
();
Font
font
=
new
Font
(
);
headCellStyle
.
setFont
(
font
);
f
ont
.
setFontName
(
"宋体"
);
f
ont
.
setFontHeightInPoints
((
short
)
14
);
f
ont
.
setBold
(
true
);
head
CellStyle
.
setIndexedColors
(
IndexedColors
.
GREY_25_PERCENT
);
handlerList
.
add
(
new
RowCellStyleStrategy
(
head
CellStyle
,
new
ArrayList
<
CellStyle
>()));
WriteCellStyle
headWriteCellStyle
=
new
Write
CellStyle
();
headWriteCellStyle
.
setFillForegroundColor
(
IndexedColors
.
GREY_25_PERCENT
.
getIndex
()
);
WriteFont
headWriteFont
=
new
WriteFont
(
);
headWriteF
ont
.
setFontName
(
"宋体"
);
headWriteF
ont
.
setFontHeightInPoints
((
short
)
14
);
headWriteF
ont
.
setBold
(
true
);
head
WriteCellStyle
.
setWriteFont
(
headWriteFont
);
handlerList
.
add
(
new
RowCellStyleStrategy
(
head
WriteCellStyle
,
new
ArrayList
<
Write
CellStyle
>()));
return
handlerList
;
}
...
...
src/main/java/com/alibaba/excel/write/metadata/holder/AbstractWriteHolder.java
浏览文件 @
ad9544c4
...
...
@@ -9,6 +9,7 @@ import java.util.Set;
import
java.util.TreeMap
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.IndexedColors
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
com.alibaba.excel.converters.Converter
;
...
...
@@ -18,13 +19,13 @@ import com.alibaba.excel.enums.HeadKindEnum;
import
com.alibaba.excel.event.NotRepeatExecutor
;
import
com.alibaba.excel.event.Order
;
import
com.alibaba.excel.metadata.AbstractHolder
;
import
com.alibaba.excel.metadata.
CellStyle
;
import
com.alibaba.excel.metadata.
Font
;
import
com.alibaba.excel.metadata.Head
;
import
com.alibaba.excel.metadata.TableStyle
;
import
com.alibaba.excel.metadata.property.CellStyleProperty
;
import
com.alibaba.excel.metadata.property.ExcelContentProperty
;
import
com.alibaba.excel.metadata.property.RowHeightProperty
;
import
com.alibaba.excel.write.handler.CellWriteHandler
;
import
com.alibaba.excel.write.handler.DefaultWriteHandlerLoader
;
import
com.alibaba.excel.write.handler.RowWriteHandler
;
import
com.alibaba.excel.write.handler.SheetWriteHandler
;
import
com.alibaba.excel.write.handler.WorkbookWriteHandler
;
...
...
@@ -32,8 +33,9 @@ import com.alibaba.excel.write.handler.WriteHandler;
import
com.alibaba.excel.write.metadata.WriteBasicParameter
;
import
com.alibaba.excel.write.metadata.WriteSheet
;
import
com.alibaba.excel.write.metadata.WriteTable
;
import
com.alibaba.excel.write.metadata.style.WriteCellStyle
;
import
com.alibaba.excel.write.metadata.style.WriteFont
;
import
com.alibaba.excel.write.property.ExcelWriteHeadProperty
;
import
com.alibaba.excel.write.style.AbstractColumnCellStyleStrategy
;
import
com.alibaba.excel.write.style.RowCellStyleStrategy
;
import
com.alibaba.excel.write.style.column.AbstractColumnWidthStyleStrategy
;
import
com.alibaba.excel.write.style.column.AbstractHeadColumnWidthStyleStrategy
;
...
...
@@ -103,13 +105,19 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
compatibleOldCode
(
writeBasicParameter
);
// Set writeHandlerMap
List
<
WriteHandler
>
handlerList
=
new
ArrayList
<
WriteHandler
>();
List
<
WriteHandler
>
handlerList
;
if
(
parentAbstractWriteHolder
==
null
)
{
handlerList
=
DefaultWriteHandlerLoader
.
loadDefaultHandler
();
}
else
{
handlerList
=
new
ArrayList
<
WriteHandler
>();
}
// Initialization Annotation
initAnnotationConfig
(
handlerList
);
if
(
writeBasicParameter
.
getCustomWriteHandlerList
()
!=
null
&&
!
writeBasicParameter
.
getCustomWriteHandlerList
().
isEmpty
())
{
handlerList
.
addAll
(
writeBasicParameter
.
getCustomWriteHandlerList
());
}
// Initialization Annotation
initAnnotationConfig
(
handlerList
);
Map
<
Class
<?
extends
WriteHandler
>,
List
<
WriteHandler
>>
parentWriteHandlerMap
=
null
;
if
(
parentAbstractWriteHolder
!=
null
)
{
...
...
@@ -160,13 +168,25 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
if
(
writeBasicParameter
.
getCustomWriteHandlerList
()
==
null
)
{
writeBasicParameter
.
setCustomWriteHandlerList
(
new
ArrayList
<
WriteHandler
>());
}
CellStyle
headCellStyle
=
new
CellStyle
();
headCellStyle
.
setFont
(
tableStyle
.
getTableHeadFont
());
headCellStyle
.
setIndexedColors
(
tableStyle
.
getTableContentBackGroundColor
());
CellStyle
contentCellStyle
=
new
CellStyle
();
contentCellStyle
.
setFont
(
tableStyle
.
getTableContentFont
());
contentCellStyle
.
setIndexedColors
(
tableStyle
.
getTableContentBackGroundColor
());
writeBasicParameter
.
getCustomWriteHandlerList
().
add
(
new
RowCellStyleStrategy
(
headCellStyle
,
contentCellStyle
));
writeBasicParameter
.
getCustomWriteHandlerList
()
.
add
(
new
RowCellStyleStrategy
(
buildWriteCellStyle
(
tableStyle
.
getTableHeadFont
(),
tableStyle
.
getTableHeadBackGroundColor
()),
buildWriteCellStyle
(
tableStyle
.
getTableContentFont
(),
tableStyle
.
getTableContentBackGroundColor
())));
}
@Deprecated
private
WriteCellStyle
buildWriteCellStyle
(
Font
font
,
IndexedColors
indexedColors
)
{
WriteCellStyle
writeCellStyle
=
new
WriteCellStyle
();
if
(
indexedColors
!=
null
)
{
writeCellStyle
.
setFillForegroundColor
(
indexedColors
.
getIndex
());
}
if
(
font
!=
null
)
{
WriteFont
writeFont
=
new
WriteFont
();
writeFont
.
setFontName
(
font
.
getFontName
());
writeFont
.
setFontHeightInPoints
(
font
.
getFontHeightInPoints
());
writeFont
.
setBold
(
font
.
isBold
());
}
return
writeCellStyle
;
}
@Deprecated
...
...
@@ -196,24 +216,14 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
Map
<
Integer
,
Head
>
headMap
=
getExcelWriteHeadProperty
().
getHeadMap
();
Map
<
Integer
,
ExcelContentProperty
>
contentPropertyMap
=
getExcelWriteHeadProperty
().
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
;
break
;
}
}
if
(
hasCellStyle
)
{
dealCellStyle
(
handlerList
,
contentPropertyMap
);
}
if
(
hasColumnWidth
)
{
dealColumnWidth
(
handlerList
);
}
...
...
@@ -252,36 +262,6 @@ public abstract class AbstractWriteHolder extends AbstractHolder implements Writ
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
);
}
protected
Map
<
Class
<?
extends
WriteHandler
>,
List
<
WriteHandler
>>
sortAndClearUpHandler
(
List
<
WriteHandler
>
handlerList
,
Map
<
Class
<?
extends
WriteHandler
>,
List
<
WriteHandler
>>
parentHandlerMap
)
{
// add
...
...
src/main/java/com/alibaba/excel/write/metadata/style/WriteCellStyle.java
0 → 100644
浏览文件 @
ad9544c4
package
com.alibaba.excel.write.metadata.style
;
import
org.apache.poi.ss.usermodel.BorderStyle
;
import
org.apache.poi.ss.usermodel.BuiltinFormats
;
import
org.apache.poi.ss.usermodel.FillPatternType
;
import
org.apache.poi.ss.usermodel.HorizontalAlignment
;
import
org.apache.poi.ss.usermodel.IgnoredErrorType
;
import
org.apache.poi.ss.usermodel.IndexedColors
;
import
org.apache.poi.ss.usermodel.VerticalAlignment
;
/**
* Cell style when writing
*
* @author zhuangjiaju
*/
public
class
WriteCellStyle
{
/**
* Set the data format (must be a valid format). Built in formats are defined at {@link BuiltinFormats}.
*/
private
Short
dataFormat
;
/**
* Set the font for this style
*/
private
WriteFont
writeFont
;
/**
* Set the cell's using this style to be hidden
*/
private
Boolean
hidden
;
/**
* Set the cell's using this style to be locked
*/
private
Boolean
locked
;
/**
* Turn on or off "Quote Prefix" or "123 Prefix" for the style, which is used to tell Excel that the thing which
* looks like a number or a formula shouldn't be treated as on. Turning this on is somewhat (but not completely, see
* {@link IgnoredErrorType}) like prefixing the cell value with a ' in Excel
*/
private
Boolean
quotePrefix
;
/**
* Set the type of horizontal alignment for the cell
*/
private
HorizontalAlignment
horizontalAlignment
;
/**
* Set whether the text should be wrapped. Setting this flag to <code>true</code> make all content visible within a
* cell by displaying it on multiple lines
*
*/
private
Boolean
wrapped
;
/**
* Set the type of vertical alignment for the cell
*/
private
VerticalAlignment
verticalAlignment
;
/**
* Set the degree of rotation for the text in the cell.
*
* Note: HSSF uses values from -90 to 90 degrees, whereas XSSF uses values from 0 to 180 degrees. The
* implementations of this method will map between these two value-ranges accordingly, however the corresponding
* getter is returning values in the range mandated by the current type of Excel file-format that this CellStyle is
* applied to.
*/
private
Short
rotation
;
/**
* Set the number of spaces to indent the text in the cell
*/
private
Short
indent
;
/**
* Set the type of border to use for the left border of the cell
*/
private
BorderStyle
borderLeft
;
/**
* Set the type of border to use for the right border of the cell
*/
private
BorderStyle
borderRight
;
/**
* Set the type of border to use for the top border of the cell
*/
private
BorderStyle
borderTop
;
/**
* Set the type of border to use for the bottom border of the cell
*/
private
BorderStyle
borderBottom
;
/**
* Set the color to use for the left border
*
* @see IndexedColors
*/
private
Short
leftBorderColor
;
/**
* Set the color to use for the right border
*
* @see IndexedColors
*
*/
private
Short
rightBorderColor
;
/**
* Set the color to use for the top border
*
* @see IndexedColors
*
*/
private
Short
topBorderColor
;
/**
* Set the color to use for the bottom border
*
* @see IndexedColors
*
*/
private
Short
bottomBorderColor
;
/**
* Setting to one fills the cell with the foreground color... No idea about other values
*
* @see FillPatternType#SOLID_FOREGROUND
*/
private
FillPatternType
fillPatternType
;
/**
* Set the background fill color.
*
* @see IndexedColors
*
*/
private
Short
fillBackgroundColor
;
/**
* Set the foreground fill color <i>Note: Ensure Foreground color is set prior to background color.</i>
*
* @see IndexedColors
*
*/
private
Short
fillForegroundColor
;
/**
* Controls if the Cell should be auto-sized to shrink to fit if the text is too long
*/
private
Boolean
shrinkToFit
;
public
Short
getDataFormat
()
{
return
dataFormat
;
}
public
void
setDataFormat
(
Short
dataFormat
)
{
this
.
dataFormat
=
dataFormat
;
}
public
WriteFont
getWriteFont
()
{
return
writeFont
;
}
public
void
setWriteFont
(
WriteFont
writeFont
)
{
this
.
writeFont
=
writeFont
;
}
public
Boolean
getHidden
()
{
return
hidden
;
}
public
void
setHidden
(
Boolean
hidden
)
{
this
.
hidden
=
hidden
;
}
public
Boolean
getLocked
()
{
return
locked
;
}
public
void
setLocked
(
Boolean
locked
)
{
this
.
locked
=
locked
;
}
public
Boolean
getQuotePrefix
()
{
return
quotePrefix
;
}
public
void
setQuotePrefix
(
Boolean
quotePrefix
)
{
this
.
quotePrefix
=
quotePrefix
;
}
public
HorizontalAlignment
getHorizontalAlignment
()
{
return
horizontalAlignment
;
}
public
void
setHorizontalAlignment
(
HorizontalAlignment
horizontalAlignment
)
{
this
.
horizontalAlignment
=
horizontalAlignment
;
}
public
Boolean
getWrapped
()
{
return
wrapped
;
}
public
void
setWrapped
(
Boolean
wrapped
)
{
this
.
wrapped
=
wrapped
;
}
public
VerticalAlignment
getVerticalAlignment
()
{
return
verticalAlignment
;
}
public
void
setVerticalAlignment
(
VerticalAlignment
verticalAlignment
)
{
this
.
verticalAlignment
=
verticalAlignment
;
}
public
Short
getRotation
()
{
return
rotation
;
}
public
void
setRotation
(
Short
rotation
)
{
this
.
rotation
=
rotation
;
}
public
Short
getIndent
()
{
return
indent
;
}
public
void
setIndent
(
Short
indent
)
{
this
.
indent
=
indent
;
}
public
BorderStyle
getBorderLeft
()
{
return
borderLeft
;
}
public
void
setBorderLeft
(
BorderStyle
borderLeft
)
{
this
.
borderLeft
=
borderLeft
;
}
public
BorderStyle
getBorderRight
()
{
return
borderRight
;
}
public
void
setBorderRight
(
BorderStyle
borderRight
)
{
this
.
borderRight
=
borderRight
;
}
public
BorderStyle
getBorderTop
()
{
return
borderTop
;
}
public
void
setBorderTop
(
BorderStyle
borderTop
)
{
this
.
borderTop
=
borderTop
;
}
public
BorderStyle
getBorderBottom
()
{
return
borderBottom
;
}
public
void
setBorderBottom
(
BorderStyle
borderBottom
)
{
this
.
borderBottom
=
borderBottom
;
}
public
Short
getLeftBorderColor
()
{
return
leftBorderColor
;
}
public
void
setLeftBorderColor
(
Short
leftBorderColor
)
{
this
.
leftBorderColor
=
leftBorderColor
;
}
public
Short
getRightBorderColor
()
{
return
rightBorderColor
;
}
public
void
setRightBorderColor
(
Short
rightBorderColor
)
{
this
.
rightBorderColor
=
rightBorderColor
;
}
public
Short
getTopBorderColor
()
{
return
topBorderColor
;
}
public
void
setTopBorderColor
(
Short
topBorderColor
)
{
this
.
topBorderColor
=
topBorderColor
;
}
public
Short
getBottomBorderColor
()
{
return
bottomBorderColor
;
}
public
void
setBottomBorderColor
(
Short
bottomBorderColor
)
{
this
.
bottomBorderColor
=
bottomBorderColor
;
}
public
FillPatternType
getFillPatternType
()
{
return
fillPatternType
;
}
public
void
setFillPatternType
(
FillPatternType
fillPatternType
)
{
this
.
fillPatternType
=
fillPatternType
;
}
public
Short
getFillBackgroundColor
()
{
return
fillBackgroundColor
;
}
public
void
setFillBackgroundColor
(
Short
fillBackgroundColor
)
{
this
.
fillBackgroundColor
=
fillBackgroundColor
;
}
public
Short
getFillForegroundColor
()
{
return
fillForegroundColor
;
}
public
void
setFillForegroundColor
(
Short
fillForegroundColor
)
{
this
.
fillForegroundColor
=
fillForegroundColor
;
}
public
Boolean
getShrinkToFit
()
{
return
shrinkToFit
;
}
public
void
setShrinkToFit
(
Boolean
shrinkToFit
)
{
this
.
shrinkToFit
=
shrinkToFit
;
}
}
src/main/java/com/alibaba/excel/write/metadata/style/WriteFont.java
0 → 100644
浏览文件 @
ad9544c4
package
com.alibaba.excel.write.metadata.style
;
import
org.apache.poi.common.usermodel.fonts.FontCharset
;
import
org.apache.poi.hssf.usermodel.HSSFPalette
;
import
org.apache.poi.ss.usermodel.Font
;
import
org.apache.poi.ss.usermodel.IndexedColors
;
/**
* Font when writing
*
* @author jipengfei
*/
public
class
WriteFont
{
/**
* The name for the font (i.e. Arial)
*/
private
String
fontName
;
/**
* Height in the familiar unit of measure - points
*/
private
Short
fontHeightInPoints
;
/**
* Whether to use italics or not
*/
private
Boolean
italic
;
/**
* Whether to use a strikeout horizontal line through the text or not
*/
private
Boolean
strikeout
;
/**
* The color for the font
*
* @see Font#COLOR_NORMAL
* @see Font#COLOR_RED
* @see HSSFPalette#getColor(short)
* @see IndexedColors
*/
private
Short
color
;
/**
* Set normal,super or subscript.
*
* @see Font#SS_NONE
* @see Font#SS_SUPER
* @see Font#SS_SUB
*/
private
Short
typeOffset
;
/**
* set type of text underlining to use
*
* @see Font#U_NONE
* @see Font#U_SINGLE
* @see Font#U_DOUBLE
* @see Font#U_SINGLE_ACCOUNTING
* @see Font#U_DOUBLE_ACCOUNTING
*/
private
Byte
underline
;
/**
* Set character-set to use.
*
* @see FontCharset
* @see Font#ANSI_CHARSET
* @see Font#DEFAULT_CHARSET
* @see Font#SYMBOL_CHARSET
*/
private
Integer
charset
;
/**
* Bold
*/
private
Boolean
bold
;
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
getItalic
()
{
return
italic
;
}
public
void
setItalic
(
Boolean
italic
)
{
this
.
italic
=
italic
;
}
public
Boolean
getStrikeout
()
{
return
strikeout
;
}
public
void
setStrikeout
(
Boolean
strikeout
)
{
this
.
strikeout
=
strikeout
;
}
public
Short
getColor
()
{
return
color
;
}
public
void
setColor
(
Short
color
)
{
this
.
color
=
color
;
}
public
Short
getTypeOffset
()
{
return
typeOffset
;
}
public
void
setTypeOffset
(
Short
typeOffset
)
{
this
.
typeOffset
=
typeOffset
;
}
public
Byte
getUnderline
()
{
return
underline
;
}
public
void
setUnderline
(
Byte
underline
)
{
this
.
underline
=
underline
;
}
public
Integer
getCharset
()
{
return
charset
;
}
public
void
setCharset
(
Integer
charset
)
{
this
.
charset
=
charset
;
}
public
Boolean
getBold
()
{
return
bold
;
}
public
void
setBold
(
Boolean
bold
)
{
this
.
bold
=
bold
;
}
}
src/main/java/com/alibaba/excel/write/property/ExcelWriteHeadProperty.java
浏览文件 @
ad9544c4
...
...
@@ -7,13 +7,10 @@ import java.util.Map;
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.metadata.CellRange
;
import
com.alibaba.excel.metadata.Head
;
import
com.alibaba.excel.metadata.property.CellStyleProperty
;
import
com.alibaba.excel.metadata.property.ColumnWidthProperty
;
import
com.alibaba.excel.metadata.property.ExcelContentProperty
;
import
com.alibaba.excel.metadata.property.ExcelHeadProperty
;
...
...
@@ -38,29 +35,17 @@ public class ExcelWriteHeadProperty extends ExcelHeadProperty {
this
.
contentRowHeightProperty
=
RowHeightProperty
.
build
((
ContentRowHeight
)
headClazz
.
getAnnotation
(
ContentRowHeight
.
class
));
HeadStyle
parentHeadStyle
=
(
HeadStyle
)
headClazz
.
getAnnotation
(
HeadStyle
.
class
);
ContentStyle
parentContentStyle
=
(
ContentStyle
)
headClazz
.
getAnnotation
(
ContentStyle
.
class
);
ColumnWidth
parentColumnWidth
=
(
ColumnWidth
)
headClazz
.
getAnnotation
(
ColumnWidth
.
class
);
for
(
Map
.
Entry
<
Integer
,
ExcelContentProperty
>
entry
:
getContentPropertyMap
().
entrySet
())
{
Integer
index
=
entry
.
getKey
();
ExcelContentProperty
excelContentPropertyData
=
entry
.
getValue
();
Field
field
=
excelContentPropertyData
.
getField
();
Head
headData
=
getHeadMap
().
get
(
index
);
HeadStyle
headStyle
=
field
.
getAnnotation
(
HeadStyle
.
class
);
if
(
headStyle
==
null
)
{
headStyle
=
parentHeadStyle
;
}
headData
.
setCellStyleProperty
(
CellStyleProperty
.
build
(
headStyle
));
ColumnWidth
columnWidth
=
field
.
getAnnotation
(
ColumnWidth
.
class
);
if
(
columnWidth
==
null
)
{
columnWidth
=
parentColumnWidth
;
}
headData
.
setColumnWidthProperty
(
ColumnWidthProperty
.
build
(
columnWidth
));
ContentStyle
contentStyle
=
field
.
getAnnotation
(
ContentStyle
.
class
);
if
(
contentStyle
==
null
)
{
contentStyle
=
parentContentStyle
;
}
excelContentPropertyData
.
setCellStyleProperty
(
CellStyleProperty
.
build
(
contentStyle
));
}
}
...
...
src/main/java/com/alibaba/excel/write/style/AbstractColumnCellStyleStrategy.java
浏览文件 @
ad9544c4
...
...
@@ -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.alibaba.excel.write.metadata.style.WriteCellStyle
;
import
com.sun.istack.internal.Nullable
;
/**
...
...
@@ -38,11 +39,11 @@ public abstract class AbstractColumnCellStyleStrategy extends AbstractCellStyleS
}
return
;
}
com
.
alibaba
.
excel
.
metadata
.
CellStyle
headCellStyle
=
headCellStyle
(
head
);
Write
CellStyle
headCellStyle
=
headCellStyle
(
head
);
if
(
headCellStyle
==
null
)
{
headCellStyleCache
.
put
(
columnIndex
,
null
);
}
else
{
CellStyle
cellStyle
=
StyleUtil
.
buildHeadCellStyle
(
workbook
,
headCellStyle
(
head
)
);
CellStyle
cellStyle
=
StyleUtil
.
buildHeadCellStyle
(
workbook
,
headCellStyle
);
headCellStyleCache
.
put
(
columnIndex
,
cellStyle
);
cell
.
setCellStyle
(
cellStyle
);
}
...
...
@@ -58,11 +59,11 @@ public abstract class AbstractColumnCellStyleStrategy extends AbstractCellStyleS
}
return
;
}
com
.
alibaba
.
excel
.
metadata
.
CellStyle
contentCellStyle
=
contentCellStyle
(
head
);
Write
CellStyle
contentCellStyle
=
contentCellStyle
(
head
);
if
(
contentCellStyle
==
null
)
{
contentCellStyleCache
.
put
(
columnIndex
,
null
);
}
else
{
CellStyle
cellStyle
=
StyleUtil
.
buildContentCellStyle
(
workbook
,
contentCellStyle
(
head
)
);
CellStyle
cellStyle
=
StyleUtil
.
buildContentCellStyle
(
workbook
,
contentCellStyle
);
contentCellStyleCache
.
put
(
columnIndex
,
cellStyle
);
cell
.
setCellStyle
(
cellStyle
);
}
...
...
@@ -74,7 +75,7 @@ public abstract class AbstractColumnCellStyleStrategy extends AbstractCellStyleS
* @param head
* @return
*/
protected
abstract
com
.
alibaba
.
excel
.
metadata
.
CellStyle
headCellStyle
(
@Nullable
Head
head
);
protected
abstract
Write
CellStyle
headCellStyle
(
@Nullable
Head
head
);
/**
* Returns the column width corresponding to each column head
...
...
@@ -82,6 +83,6 @@ public abstract class AbstractColumnCellStyleStrategy extends AbstractCellStyleS
* @param head
* @return
*/
protected
abstract
com
.
alibaba
.
excel
.
metadata
.
CellStyle
contentCellStyle
(
@Nullable
Head
head
);
protected
abstract
Write
CellStyle
contentCellStyle
(
@Nullable
Head
head
);
}
src/main/java/com/alibaba/excel/write/style/RowCellStyleStrategy.java
浏览文件 @
ad9544c4
...
...
@@ -4,11 +4,12 @@ import java.util.ArrayList;
import
java.util.List
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.CellStyle
;
import
org.apache.poi.ss.usermodel.Workbook
;
import
com.alibaba.excel.metadata.CellStyle
;
import
com.alibaba.excel.metadata.Head
;
import
com.alibaba.excel.util.StyleUtil
;
import
com.alibaba.excel.write.metadata.style.WriteCellStyle
;
/**
*
...
...
@@ -18,50 +19,50 @@ import com.alibaba.excel.util.StyleUtil;
*/
public
class
RowCellStyleStrategy
extends
AbstractCellStyleStrategy
{
private
WriteCellStyle
headWriteCellStyle
;
private
List
<
WriteCellStyle
>
contentWriteCellStyleList
;
private
CellStyle
headCellStyle
;
private
List
<
CellStyle
>
contentCellStyleList
;
private
org
.
apache
.
poi
.
ss
.
usermodel
.
CellStyle
poiHeadCellStyle
;
private
List
<
org
.
apache
.
poi
.
ss
.
usermodel
.
CellStyle
>
poiContentCellStyleList
;
public
RowCellStyleStrategy
(
CellStyle
headCellStyle
,
List
<
CellStyle
>
contentCellStyleList
)
{
this
.
headCellStyle
=
headCellStyle
;
this
.
contentCellStyleList
=
contentCellStyleList
;
public
RowCellStyleStrategy
(
WriteCellStyle
headWriteCellStyle
,
List
<
WriteCellStyle
>
contentWriteCellStyleList
)
{
this
.
headWriteCellStyle
=
headWriteCellStyle
;
this
.
contentWriteCellStyleList
=
contentWriteCellStyleList
;
}
public
RowCellStyleStrategy
(
CellStyle
headCellStyle
,
CellStyle
content
CellStyle
)
{
this
.
head
CellStyle
=
head
CellStyle
;
content
CellStyleList
=
new
ArrayList
<
CellStyle
>();
content
CellStyleList
.
add
(
content
CellStyle
);
public
RowCellStyleStrategy
(
WriteCellStyle
headWriteCellStyle
,
WriteCellStyle
contentWrite
CellStyle
)
{
this
.
head
WriteCellStyle
=
headWrite
CellStyle
;
content
WriteCellStyleList
=
new
ArrayList
<
Write
CellStyle
>();
content
WriteCellStyleList
.
add
(
contentWrite
CellStyle
);
}
@Override
protected
void
initCellStyle
(
Workbook
workbook
)
{
if
(
headCellStyle
!=
null
)
{
poiHeadCellStyle
=
StyleUtil
.
buildHeadCellStyle
(
workbook
,
head
CellStyle
);
if
(
head
Write
CellStyle
!=
null
)
{
headCellStyle
=
StyleUtil
.
buildHeadCellStyle
(
workbook
,
headWrite
CellStyle
);
}
if
(
content
CellStyleList
!=
null
&&
!
content
CellStyleList
.
isEmpty
())
{
poiContentCellStyleList
=
new
ArrayList
<
org
.
apache
.
poi
.
ss
.
usermodel
.
CellStyle
>();
for
(
CellStyle
cellStyle
:
content
CellStyleList
)
{
poiContentCellStyleList
.
add
(
StyleUtil
.
buildContentCellStyle
(
workbook
,
c
ellStyle
));
if
(
content
WriteCellStyleList
!=
null
&&
!
contentWrite
CellStyleList
.
isEmpty
())
{
contentCellStyleList
=
new
ArrayList
<
CellStyle
>();
for
(
WriteCellStyle
writeCellStyle
:
contentWrite
CellStyleList
)
{
contentCellStyleList
.
add
(
StyleUtil
.
buildContentCellStyle
(
workbook
,
writeC
ellStyle
));
}
}
}
@Override
protected
void
setHeadCellStyle
(
Cell
cell
,
Head
head
,
int
relativeRowIndex
)
{
if
(
poiH
eadCellStyle
==
null
)
{
if
(
h
eadCellStyle
==
null
)
{
return
;
}
cell
.
setCellStyle
(
poiH
eadCellStyle
);
cell
.
setCellStyle
(
h
eadCellStyle
);
}
@Override
protected
void
setContentCellStyle
(
Cell
cell
,
Head
head
,
int
relativeRowIndex
)
{
if
(
poiContentCellStyleList
==
null
||
poiC
ontentCellStyleList
.
isEmpty
())
{
if
(
contentCellStyleList
==
null
||
c
ontentCellStyleList
.
isEmpty
())
{
return
;
}
cell
.
setCellStyle
(
poiContentCellStyleList
.
get
(
relativeRowIndex
%
poiC
ontentCellStyleList
.
size
()));
cell
.
setCellStyle
(
contentCellStyleList
.
get
(
relativeRowIndex
%
c
ontentCellStyleList
.
size
()));
}
}
src/main/java/com/alibaba/excel/write/style/column/AbstractColumnWidthStyleStrategy.java
浏览文件 @
ad9544c4
...
...
@@ -13,7 +13,7 @@ import com.sun.istack.internal.Nullable;
/**
* Column width style strategy
*
*
* @author zhuangjiaju
*/
public
abstract
class
AbstractColumnWidthStyleStrategy
implements
CellWriteHandler
,
NotRepeatExecutor
{
...
...
@@ -40,7 +40,7 @@ public abstract class AbstractColumnWidthStyleStrategy implements CellWriteHandl
/**
* Sets the column width when head create
*
*
* @param sheet
* @param cell
* @param head
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录