Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
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
YZG
yzg-util
Commits
cfd43d84
Commit
cfd43d84
authored
Feb 28, 2023
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
EXCEL自定义列处理
parent
6c1f982f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
17 deletions
+18
-17
ExcelConsole.java
...-db/src/main/java/com/yanzuoguang/excel/ExcelConsole.java
+8
-15
ExportColumn.java
...-db/src/main/java/com/yanzuoguang/excel/ExportColumn.java
+10
-2
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/excel/ExcelConsole.java
View file @
cfd43d84
...
...
@@ -187,6 +187,7 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
String
[]
columns
=
new
String
[
this
.
config
.
getColumns
().
size
()];
int
pos
=
0
;
for
(
ExportColumn
column
:
this
.
config
.
getColumns
())
{
column
.
column
=
pos
;
columns
[
pos
++]
=
column
.
getTitle
();
}
return
TableHeadHelper
.
getTableHead
(
columns
);
...
...
@@ -278,13 +279,10 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
}
}
// 设置列宽度
int
columnPos
=
0
;
// 合并数据配置
for
(
ExportColumn
column
:
this
.
config
.
getColumns
())
{
sheet
.
setColumnWidth
(
columnPos
,
getUnit
(
column
.
getWidth
()));
columnPos
++;
sheet
.
setColumnWidth
(
column
.
column
,
getUnit
(
column
.
getWidth
()));
// 列样式
column
.
cellStyle
=
createColumnStyle
(
this
.
workbook
,
column
);
}
...
...
@@ -318,13 +316,12 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
private
void
writeDefineFormula
(
List
<
ExcelDefineRow
>
rows
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>(
this
.
config
.
getColumns
().
size
()
*
2
+
3
);
// 设置列别名
int
columnPos
=
0
;
for
(
ExportColumn
column
:
this
.
config
.
getColumns
())
{
map
.
put
(
column
.
getName
(),
String
.
format
(
"%s:%s"
,
CellReferenceUtil
.
getCoordName
(
column
Pos
,
this
.
startDataRowIndex
),
CellReferenceUtil
.
getCoordName
(
column
Pos
,
this
.
endDataRowIndex
)
CellReferenceUtil
.
getCoordName
(
column
.
column
,
this
.
startDataRowIndex
),
CellReferenceUtil
.
getCoordName
(
column
.
column
,
this
.
endDataRowIndex
)
));
map
.
put
(
column
.
getName
()
+
"_COL"
,
CellReferenceUtil
.
getColName
(
column
Pos
));
map
.
put
(
column
.
getName
()
+
"_COL"
,
CellReferenceUtil
.
getColName
(
column
.
column
));
}
// 数据行开始行号
map
.
put
(
"startDataRowIndex"
,
CellReferenceUtil
.
getRowName
(
this
.
startDataRowIndex
));
...
...
@@ -383,7 +380,6 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
// 将当前組生成值密钥
StringBuilder
sb
=
new
StringBuilder
();
// 写入本行内容
int
columnPos
=
0
;
for
(
ExportColumn
column
:
this
.
config
.
getColumns
())
{
String
columnName
=
column
.
getName
();
String
value
=
StringHelper
.
getFirst
(
rowHandle
.
get
(
t
,
columnName
));
...
...
@@ -404,10 +400,9 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
// 当前行行高
height
=
Math
.
max
(
nowCellHeight
,
height
);
// 当不需要合并历史记录时,则创建新的内容
createCell
(
row
,
column
Pos
,
value
,
column
.
cellStyle
);
createCell
(
row
,
column
.
column
,
value
,
column
.
cellStyle
);
// 合并列
mergerColumn
(
column
,
columnPos
,
false
);
columnPos
++;
mergerColumn
(
column
,
column
.
column
,
false
);
}
row
.
setHeight
((
short
)
Math
.
min
(
height
,
Short
.
MAX_VALUE
));
...
...
@@ -488,10 +483,8 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
// 合并数据配置
if
(
this
.
rowData
>
0
)
{
int
columnPos
=
0
;
for
(
ExportColumn
column
:
this
.
config
.
getColumns
())
{
mergerColumn
(
column
,
columnPos
,
true
);
columnPos
++;
mergerColumn
(
column
,
column
.
column
,
true
);
}
}
...
...
yzg-util-db/src/main/java/com/yanzuoguang/excel/ExportColumn.java
View file @
cfd43d84
...
...
@@ -44,9 +44,17 @@ public class ExportColumn {
*/
@ApiModelProperty
(
notes
=
"上下对其:0-居中,1-上对其,2-下对齐"
)
private
int
verticalAlignment
;
/**
* 列序号
*/
int
column
;
/**
* 合计列数据
*/
ExcelMergerData
groupData
=
new
ExcelMergerData
();
/**
* 列样式
*/
CellStyle
cellStyle
;
public
ExportColumn
()
{
...
...
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