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
401aa224
Commit
401aa224
authored
Oct 10, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接口文档的支持
parent
611d8c94
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
3 deletions
+14
-3
ExcelConsole.java
...-db/src/main/java/com/yanzuoguang/excel/ExcelConsole.java
+14
-3
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/excel/ExcelConsole.java
View file @
401aa224
...
...
@@ -67,6 +67,11 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
*/
private
Map
<
String
,
ExcelMergerData
>
mergerGroupData
;
/**
* 最大字节长度
*/
private
Map
<
Integer
,
Integer
>
columnBytes
;
/**
* 控制台输出Excel
*
...
...
@@ -160,6 +165,7 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
// 创建合并对象数据检测
mergerGroup
=
new
HashMap
<>();
mergerGroupData
=
new
HashMap
<>();
columnBytes
=
new
HashMap
<>();
// 创建工作簿对象
workbook
=
new
XSSFWorkbook
();
...
...
@@ -293,7 +299,11 @@ 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
);
String
columnName
=
column
.
getName
();
String
value
=
rowHandle
.
get
(
t
,
columnName
);
String
value
=
StringHelper
.
getFirst
(
rowHandle
.
get
(
t
,
columnName
));
// 获取字节数、用于设置最大宽度
int
maxBytes
=
Math
.
max
(
columnBytes
.
getOrDefault
(
columnPos
,
0
),
value
.
getBytes
().
length
);
columnBytes
.
put
(
columnPos
,
maxBytes
);
// 当不需要合并历史记录时,则创建新的内容
Cell
cell
=
createCell
(
row
,
columnPos
,
value
);
...
...
@@ -334,7 +344,6 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
if
(
workbook
==
null
)
{
return
this
;
}
// 合并数据配置
for
(
int
columnPos
=
0
;
columnPos
<
this
.
config
.
getColumns
().
size
();
columnPos
++)
{
ExportColumn
column
=
this
.
config
.
getColumns
().
get
(
columnPos
);
...
...
@@ -348,7 +357,9 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
}
}
if
(
column
.
getWidth
()
<
1
)
{
sheet
.
autoSizeColumn
(
columnPos
);
//设置单元格长度, 这里要乘上256
int
maxBytes
=
columnBytes
.
get
(
columnPos
);
sheet
.
setColumnWidth
(
columnPos
,
maxBytes
*
256
);
}
else
{
sheet
.
setColumnWidth
(
columnPos
,
getUnit
(
column
.
getWidth
()));
}
...
...
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