Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
sts网站
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
liyang
sts网站
Commits
6efceac4
Commit
6efceac4
authored
Dec 03, 2024
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Excel注解支持wrapText是否允许内容换行
parent
77a63504
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
3 deletions
+9
-3
Excel.java
...mmon/src/main/java/com/ruoyi/common/annotation/Excel.java
+5
-0
ExcelUtil.java
...n/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
+4
-3
No files found.
ruoyi-common/src/main/java/com/ruoyi/common/annotation/Excel.java
View file @
6efceac4
...
...
@@ -83,6 +83,11 @@ public @interface Excel
*/
public
String
prompt
()
default
""
;
/**
* 是否允许内容换行
*/
public
boolean
wrapText
()
default
false
;
/**
* 设置只能选择不能输入的列内容.
*/
...
...
ruoyi-common/src/main/java/com/ruoyi/common/utils/poi/ExcelUtil.java
View file @
6efceac4
...
...
@@ -950,7 +950,7 @@ public class ExcelUtil<T>
*/
public
void
annotationDataStyles
(
Map
<
String
,
CellStyle
>
styles
,
Field
field
,
Excel
excel
)
{
String
key
=
StringUtils
.
format
(
"data_{}_{}_{}_{}
"
,
excel
.
align
(),
excel
.
color
(),
excel
.
backgroundColor
(),
excel
.
cellType
());
String
key
=
StringUtils
.
format
(
"data_{}_{}_{}_{}
_{}"
,
excel
.
align
(),
excel
.
color
(),
excel
.
backgroundColor
(),
excel
.
cellType
(),
excel
.
wrapText
());
if
(!
styles
.
containsKey
(
key
))
{
CellStyle
style
=
wb
.
createCellStyle
();
...
...
@@ -966,6 +966,7 @@ public class ExcelUtil<T>
style
.
setBottomBorderColor
(
IndexedColors
.
GREY_50_PERCENT
.
getIndex
());
style
.
setFillPattern
(
FillPatternType
.
SOLID_FOREGROUND
);
style
.
setFillForegroundColor
(
excel
.
backgroundColor
().
getIndex
());
style
.
setWrapText
(
excel
.
wrapText
());
Font
dataFont
=
wb
.
createFont
();
dataFont
.
setFontName
(
"Arial"
);
dataFont
.
setFontHeightInPoints
((
short
)
10
);
...
...
@@ -994,7 +995,7 @@ public class ExcelUtil<T>
if
(
isSubList
())
{
// 填充默认样式,防止合并单元格样式失效
sheet
.
setDefaultColumnStyle
(
column
,
styles
.
get
(
StringUtils
.
format
(
"data_{}_{}_{}_{}
"
,
attr
.
align
(),
attr
.
color
(),
attr
.
backgroundColor
(),
attr
.
cellType
())));
sheet
.
setDefaultColumnStyle
(
column
,
styles
.
get
(
StringUtils
.
format
(
"data_{}_{}_{}_{}
_{}"
,
attr
.
align
(),
attr
.
color
(),
attr
.
backgroundColor
(),
attr
.
cellType
(),
attr
.
wrapText
())));
if
(
attr
.
needMerge
())
{
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
rownum
-
1
,
rownum
,
column
,
column
));
...
...
@@ -1137,7 +1138,7 @@ public class ExcelUtil<T>
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
subMergedFirstRowNum
,
subMergedLastRowNum
,
column
,
column
));
}
}
cell
.
setCellStyle
(
styles
.
get
(
StringUtils
.
format
(
"data_{}_{}_{}_{}
"
,
attr
.
align
(),
attr
.
color
(),
attr
.
backgroundColor
(),
attr
.
cellType
())));
cell
.
setCellStyle
(
styles
.
get
(
StringUtils
.
format
(
"data_{}_{}_{}_{}
_{}"
,
attr
.
align
(),
attr
.
color
(),
attr
.
backgroundColor
(),
attr
.
cellType
(),
attr
.
wrapText
())));
// 用于读取对象中的属性
Object
value
=
getTargetValue
(
vo
,
field
,
attr
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment