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
9be36a77
Commit
9be36a77
authored
Oct 10, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接口文档的支持
parent
5dd34078
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
15 deletions
+47
-15
ExcelConsole.java
...-db/src/main/java/com/yanzuoguang/excel/ExcelConsole.java
+47
-15
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/excel/ExcelConsole.java
View file @
9be36a77
...
...
@@ -3,6 +3,7 @@ package com.yanzuoguang.excel;
import
com.yanzuoguang.db.impl.DbRow
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.helper.CheckerHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.table.TableHead
;
import
com.yanzuoguang.util.table.TableHeadHelper
;
import
com.yanzuoguang.util.table.TableHeadItem
;
...
...
@@ -17,7 +18,9 @@ import java.io.File;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
...
...
@@ -51,10 +54,15 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
*/
private
int
rowIndex
;
/**
* 合并列表組
*/
private
Map
<
String
,
List
<
String
>>
mergerGroup
;
/**
* 是否需要合并单元格
*/
private
Map
<
Integer
,
ExcelMergerData
>
merger
Data
;
private
Map
<
String
,
ExcelMergerData
>
mergerGroup
Data
;
/**
* 控制台输出Excel
...
...
@@ -161,7 +169,8 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
rowIndex
+=
head
.
getTotalRow
();
// 创建合并对象数据检测
mergerData
=
new
HashMap
<>(
head
.
getTotalColumn
());
mergerGroup
=
new
HashMap
<>();
mergerGroupData
=
new
HashMap
<>();
}
/**
...
...
@@ -213,6 +222,18 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
sheet
.
addMergedRegion
(
region
);
}
}
// 合并数据配置
for
(
ExportColumn
column
:
this
.
config
.
getColumns
())
{
// 获取需要合并的組,不能为null
String
group
=
StringHelper
.
getFirst
(
column
.
getMegerGroup
());
if
(!
mergerGroup
.
containsKey
(
group
))
{
mergerGroup
.
put
(
group
,
new
ArrayList
<>());
mergerGroupData
.
put
(
group
,
new
ExcelMergerData
());
}
// 当前合并組中添加需要合并的列
mergerGroup
.
get
(
group
).
add
(
column
.
getName
());
}
}
/**
...
...
@@ -242,6 +263,7 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
Row
row
=
sheet
.
createRow
(
rowIndex
);
row
.
setHeight
(
getUnit
(
this
.
config
.
getRowHeight
()));
// 写入本行内容
for
(
int
columnPos
=
0
;
columnPos
<
this
.
config
.
getColumns
().
size
();
columnPos
++)
{
ExportColumn
column
=
this
.
config
.
getColumns
().
get
(
columnPos
);
...
...
@@ -250,22 +272,16 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
// 判断列是否需要合并
if
(
column
.
isMerger
())
{
// 获取合并历史记录配置
if
(!
mergerData
.
containsKey
(
columnPos
))
{
mergerData
.
put
(
columnPos
,
new
ExcelMergerData
());
}
ExcelMergerData
mergerColumn
=
mergerData
.
get
(
columnPos
);
ExcelMergerData
mergerData
=
mergerGroupData
.
get
(
column
.
getMegerGroup
());
// 判断是否需要合并历史记录
if
(
merger
Column
.
isMergerHistory
(
value
))
{
if
(
merger
Data
.
isMergerHistory
(
value
))
{
// 合并历史记录单元格
mergerData
(
merger
Column
,
columnPos
);
mergerData
(
merger
Data
,
columnPos
);
}
else
{
// 当不需要合并历史记录时,则创建新的内容
Cell
cell
=
row
.
createCell
(
columnPos
);
cell
.
setCellValue
(
value
);
}
// 更新合并内容
mergerColumn
.
updateMerger
(
rowIndex
,
value
);
}
else
{
// 不合并时直接写入单元格内容
Cell
cell
=
row
.
createCell
(
columnPos
);
...
...
@@ -273,6 +289,22 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
}
}
// 合并組数据处理
for
(
Map
.
Entry
<
String
,
List
<
String
>>
groupKvp
:
mergerGroup
.
entrySet
())
{
// 将当前組生成值密钥
StringBuilder
sb
=
new
StringBuilder
();
for
(
String
columnName
:
groupKvp
.
getValue
())
{
String
value
=
rowHandle
.
get
(
t
,
columnName
);
sb
.
append
(
value
.
replace
(
":"
,
"::"
));
sb
.
append
(
":"
);
}
String
groupValue
=
StringHelper
.
md5
(
sb
.
toString
());
// 更新合并内容
ExcelMergerData
mergerData
=
mergerGroupData
.
get
(
groupKvp
.
getKey
());
mergerData
.
updateMerger
(
rowIndex
,
groupValue
);
}
rowIndex
++;
}
...
...
@@ -300,10 +332,10 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
// 写入最后的合并内容
for
(
int
columnPos
=
0
;
columnPos
<
this
.
config
.
getColumns
().
size
();
columnPos
++)
{
ExportColumn
column
=
this
.
config
.
getColumns
().
get
(
columnPos
);
if
(
column
.
isMerger
()
&&
mergerData
.
containsKey
(
columnPos
)
)
{
ExcelMergerData
merger
Column
=
mergerData
.
get
(
columnPos
);
if
(
merger
Column
.
isMergerHistory
())
{
mergerData
(
merger
Column
,
columnPos
);
if
(
column
.
isMerger
())
{
ExcelMergerData
merger
Data
=
mergerGroupData
.
get
(
column
.
getMegerGroup
()
);
if
(
merger
Data
.
isMergerHistory
())
{
mergerData
(
merger
Data
,
columnPos
);
}
}
}
...
...
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