Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
cocktail-party-server
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
cocktail-party
cocktail-party-server
Commits
1f0e7427
提交
1f0e7427
authored
7月 20, 2022
作者:
RuoYi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Excel注解支持backgroundColor属性设置背景色
上级
28b9fbb4
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
60 行增加
和
21 行删除
+60
-21
Excel.java
...mmon/src/main/java/com/ruoyi/common/annotation/Excel.java
+16
-1
ExcelUtil.java
...n/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
+44
-20
没有找到文件。
ruoyi-common/src/main/java/com/ruoyi/common/annotation/Excel.java
浏览文件 @
1f0e7427
...
...
@@ -109,7 +109,22 @@ public @interface Excel
public
ColumnType
cellType
()
default
ColumnType
.
STRING
;
/**
* 导出字体颜色
* 导出列头背景色
*/
public
IndexedColors
headerBackgroundColor
()
default
IndexedColors
.
GREY_50_PERCENT
;
/**
* 导出列头字体颜色
*/
public
IndexedColors
headerColor
()
default
IndexedColors
.
WHITE
;
/**
* 导出单元格背景色
*/
public
IndexedColors
backgroundColor
()
default
IndexedColors
.
WHITE
;
/**
* 导出单元格字体颜色
*/
public
IndexedColors
color
()
default
IndexedColors
.
BLACK
;
...
...
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
浏览文件 @
1f0e7427
...
...
@@ -649,20 +649,6 @@ public class ExcelUtil<T>
style
.
setFont
(
dataFont
);
styles
.
put
(
"data"
,
style
);
style
=
wb
.
createCellStyle
();
style
.
cloneStyleFrom
(
styles
.
get
(
"data"
));
style
.
setAlignment
(
HorizontalAlignment
.
CENTER
);
style
.
setVerticalAlignment
(
VerticalAlignment
.
CENTER
);
style
.
setFillForegroundColor
(
IndexedColors
.
GREY_50_PERCENT
.
getIndex
());
style
.
setFillPattern
(
FillPatternType
.
SOLID_FOREGROUND
);
Font
headerFont
=
wb
.
createFont
();
headerFont
.
setFontName
(
"Arial"
);
headerFont
.
setFontHeightInPoints
((
short
)
10
);
headerFont
.
setBold
(
true
);
headerFont
.
setColor
(
IndexedColors
.
WHITE
.
getIndex
());
style
.
setFont
(
headerFont
);
styles
.
put
(
"header"
,
style
);
style
=
wb
.
createCellStyle
();
style
.
setAlignment
(
HorizontalAlignment
.
CENTER
);
style
.
setVerticalAlignment
(
VerticalAlignment
.
CENTER
);
...
...
@@ -672,24 +658,60 @@ public class ExcelUtil<T>
style
.
setFont
(
totalFont
);
styles
.
put
(
"total"
,
style
);
styles
.
putAll
(
annotationStyles
(
wb
));
styles
.
putAll
(
annotationHeaderStyles
(
wb
,
styles
));
styles
.
putAll
(
annotationDataStyles
(
wb
));
return
styles
;
}
/**
* 根据Excel注解创建表格样式
* 根据Excel注解创建表格头样式
*
* @param wb 工作薄对象
* @return 自定义样式列表
*/
private
Map
<
String
,
CellStyle
>
annotationHeaderStyles
(
Workbook
wb
,
Map
<
String
,
CellStyle
>
styles
)
{
Map
<
String
,
CellStyle
>
headerStyles
=
new
HashMap
<
String
,
CellStyle
>();
for
(
Object
[]
os
:
fields
)
{
Excel
excel
=
(
Excel
)
os
[
1
];
String
key
=
StringUtils
.
format
(
"header_{}_{}"
,
excel
.
headerColor
(),
excel
.
headerBackgroundColor
());
if
(!
headerStyles
.
containsKey
(
key
))
{
CellStyle
style
=
wb
.
createCellStyle
();
style
=
wb
.
createCellStyle
();
style
.
cloneStyleFrom
(
styles
.
get
(
"data"
));
style
.
setAlignment
(
HorizontalAlignment
.
CENTER
);
style
.
setVerticalAlignment
(
VerticalAlignment
.
CENTER
);
style
.
setFillForegroundColor
(
excel
.
headerBackgroundColor
().
index
);
style
.
setFillPattern
(
FillPatternType
.
SOLID_FOREGROUND
);
Font
headerFont
=
wb
.
createFont
();
headerFont
.
setFontName
(
"Arial"
);
headerFont
.
setFontHeightInPoints
((
short
)
10
);
headerFont
.
setBold
(
true
);
headerFont
.
setColor
(
excel
.
headerColor
().
index
);
style
.
setFont
(
headerFont
);
headerStyles
.
put
(
key
,
style
);
}
}
return
headerStyles
;
}
/**
* 根据Excel注解创建表格列样式
*
* @param wb 工作薄对象
* @return 自定义样式列表
*/
private
Map
<
String
,
CellStyle
>
annotationStyles
(
Workbook
wb
)
private
Map
<
String
,
CellStyle
>
annotation
Data
Styles
(
Workbook
wb
)
{
Map
<
String
,
CellStyle
>
styles
=
new
HashMap
<
String
,
CellStyle
>();
for
(
Object
[]
os
:
fields
)
{
Excel
excel
=
(
Excel
)
os
[
1
];
String
key
=
"data_"
+
excel
.
align
()
+
"_"
+
excel
.
color
(
);
String
key
=
StringUtils
.
format
(
"data_{}_{}_{}"
,
excel
.
align
(),
excel
.
color
(),
excel
.
backgroundColor
()
);
if
(!
styles
.
containsKey
(
key
))
{
CellStyle
style
=
wb
.
createCellStyle
();
...
...
@@ -704,6 +726,8 @@ public class ExcelUtil<T>
style
.
setTopBorderColor
(
IndexedColors
.
GREY_50_PERCENT
.
getIndex
());
style
.
setBorderBottom
(
BorderStyle
.
THIN
);
style
.
setBottomBorderColor
(
IndexedColors
.
GREY_50_PERCENT
.
getIndex
());
style
.
setFillPattern
(
FillPatternType
.
SOLID_FOREGROUND
);
style
.
setFillForegroundColor
(
excel
.
backgroundColor
().
getIndex
());
Font
dataFont
=
wb
.
createFont
();
dataFont
.
setFontName
(
"Arial"
);
dataFont
.
setFontHeightInPoints
((
short
)
10
);
...
...
@@ -725,7 +749,7 @@ public class ExcelUtil<T>
// 写入列信息
cell
.
setCellValue
(
attr
.
name
());
setDataValidation
(
attr
,
row
,
column
);
cell
.
setCellStyle
(
styles
.
get
(
"header"
));
cell
.
setCellStyle
(
styles
.
get
(
StringUtils
.
format
(
"header_{}_{}"
,
attr
.
headerColor
(),
attr
.
headerBackgroundColor
())
));
return
cell
;
}
...
...
@@ -833,7 +857,7 @@ public class ExcelUtil<T>
{
// 创建cell
cell
=
row
.
createCell
(
column
);
cell
.
setCellStyle
(
styles
.
get
(
"data_"
+
attr
.
align
()
+
"_"
+
attr
.
color
(
)));
cell
.
setCellStyle
(
styles
.
get
(
StringUtils
.
format
(
"data_{}_{}_{}"
,
attr
.
align
(),
attr
.
color
(),
attr
.
backgroundColor
()
)));
// 用于读取对象中的属性
Object
value
=
getTargetValue
(
vo
,
field
,
attr
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论