Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
hp-smart
Overview
Overview
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
platform
hp-smart
Commits
6ac8ee7e
Commit
6ac8ee7e
authored
Apr 11, 2024
by
宋祥
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.导出错乱问题修复
parent
6a1981bb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
39 deletions
+50
-39
CKExcelTools.java
...main/java/com/baosight/hpjx/hp/kc/tools/CKExcelTools.java
+50
-39
No files found.
src/main/java/com/baosight/hpjx/hp/kc/tools/CKExcelTools.java
View file @
6ac8ee7e
...
...
@@ -101,24 +101,26 @@ public class CKExcelTools {
sheet
.
setColumnWidth
(
1
,
30
*
256
);
sheet
.
setColumnWidth
(
5
,
15
*
256
);
sheet
.
setColumnWidth
(
6
,
15
*
256
);
// startRow:索引,从0开始
int
startRow
=
0
;
// 第1行
buildRow1
(
workbook
,
sheet
,
dataMap
);
startRow
=
buildRow1
(
workbook
,
sheet
,
startRow
,
dataMap
);
// 第2行:标题栏
buildRow2
(
workbook
,
sheet
);
startRow
=
buildRow2
(
workbook
,
sheet
,
startRow
);
// 第2行:标题栏
startRow
=
buildRow3
(
workbook
,
sheet
,
startRow
);
// 遍历数据行,excel行从第3行开始
int
headRow
=
2
;
int
lastRow
=
2
;
Map
<
String
,
List
<
HPKC004
>>
childrenMap
=
(
Map
<
String
,
List
<
HPKC004
>>)
dataMap
.
get
(
Field
.
CHILDREN
);
for
(
Map
.
Entry
<
String
,
List
<
HPKC004
>>
childrenEntry
:
childrenMap
.
entrySet
())
{
String
key
=
childrenEntry
.
getKey
();
List
<
HPKC004
>
values
=
childrenEntry
.
getValue
();
// 组名称
lastRow
=
buildGroupRow
(
workbook
,
sheet
,
key
,
lastRow
,
head
Row
);
startRow
=
buildGroupRow
(
workbook
,
sheet
,
key
,
start
Row
);
// 明细数据,返回末尾行数
lastRow
=
buildChildRow
(
workbook
,
sheet
,
values
,
lastRow
,
head
Row
);
startRow
=
buildChildRow
(
workbook
,
sheet
,
values
,
start
Row
);
}
// 页脚
buildFoot
(
workbook
,
sheet
,
las
tRow
);
buildFoot
(
workbook
,
sheet
,
star
tRow
);
return
workbook
;
}
...
...
@@ -127,12 +129,11 @@ public class CKExcelTools {
*
* @param workbook
* @param sheet
* @param
las
tRow
* @param
star
tRow
*/
private
static
void
buildFoot
(
HSSFWorkbook
workbook
,
HSSFSheet
sheet
,
int
las
tRow
)
{
private
static
void
buildFoot
(
HSSFWorkbook
workbook
,
HSSFSheet
sheet
,
int
star
tRow
)
{
// 页脚第一行
int
currRow
=
lastRow
+
1
;
HSSFRow
row1
=
sheet
.
createRow
(
currRow
);
HSSFRow
row1
=
sheet
.
createRow
(
startRow
);
row1
.
setHeight
((
short
)
(
20
*
20
));
// 1.1
HSSFCell
cell1_1
=
row1
.
createCell
(
0
);
...
...
@@ -143,11 +144,11 @@ public class CKExcelTools {
cell1_2
.
setCellValue
(
"承运车号:"
);
cell1_2
.
setCellStyle
(
getCellStyle
(
workbook
,
HorizontalAlignment
.
LEFT
,
VerticalAlignment
.
CENTER
,
true
,
false
));
// 合并单元格
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
currRow
,
curr
Row
,
0
,
1
));
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
currRow
,
curr
Row
,
2
,
4
));
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
startRow
,
start
Row
,
0
,
1
));
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
startRow
,
start
Row
,
2
,
4
));
// 页脚第二行
currRow
=
curr
Row
+
1
;
HSSFRow
row2
=
sheet
.
createRow
(
curr
Row
);
startRow
=
start
Row
+
1
;
HSSFRow
row2
=
sheet
.
createRow
(
start
Row
);
row2
.
setHeight
((
short
)
(
20
*
20
));
// 1.1
HSSFCell
cell2_1
=
row2
.
createCell
(
0
);
...
...
@@ -158,8 +159,8 @@ public class CKExcelTools {
cell2_2
.
setCellValue
(
"发货人签字:"
);
cell2_2
.
setCellStyle
(
getCellStyle
(
workbook
,
HorizontalAlignment
.
LEFT
,
VerticalAlignment
.
CENTER
,
true
,
false
));
// 合并单元格
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
currRow
,
curr
Row
,
0
,
1
));
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
currRow
,
curr
Row
,
2
,
4
));
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
startRow
,
start
Row
,
0
,
1
));
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
startRow
,
start
Row
,
2
,
4
));
}
/**
...
...
@@ -168,20 +169,16 @@ public class CKExcelTools {
* @param workbook
* @param sheet
* @param values
* @param lastRow
* @param headRow
* @param startRow
*/
private
static
int
buildChildRow
(
HSSFWorkbook
workbook
,
HSSFSheet
sheet
,
List
<
HPKC004
>
values
,
int
lastRow
,
int
headRow
)
{
int
currRow
=
lastRow
+
1
;
private
static
int
buildChildRow
(
HSSFWorkbook
workbook
,
HSSFSheet
sheet
,
List
<
HPKC004
>
values
,
int
startRow
)
{
for
(
int
i
=
0
;
i
<
values
.
size
();
i
++)
{
HPKC004
valueMap
=
values
.
get
(
i
);
currRow
=
currRow
+
i
;
HSSFRow
row
=
sheet
.
createRow
(
currRow
);
HSSFRow
row
=
sheet
.
createRow
(
startRow
);
row
.
setHeight
((
short
)
(
20
*
20
));
// 序号
HSSFCell
cell1_0
=
row
.
createCell
(
0
);
cell1_0
.
setCellValue
(
currRow
-
headRow
);
cell1_0
.
setCellValue
(
startRow
-
2
);
cell1_0
.
setCellStyle
(
getCellStyle
(
workbook
));
// 名称
HSSFCell
cell1_1
=
row
.
createCell
(
1
);
...
...
@@ -211,8 +208,9 @@ public class CKExcelTools {
HSSFCell
cell1_6
=
row
.
createCell
(
6
);
cell1_6
.
setCellValue
(
valueMap
.
getRemark
());
cell1_6
.
setCellStyle
(
getCellStyle
(
workbook
));
++
startRow
;
}
return
curr
Row
;
return
start
Row
;
}
/**
...
...
@@ -220,17 +218,14 @@ public class CKExcelTools {
*
* @param workbook
* @param sheet
* @param lastRow
* @param headRow
* @param startRow
*/
private
static
int
buildGroupRow
(
HSSFWorkbook
workbook
,
HSSFSheet
sheet
,
String
groupName
,
int
lastRow
,
int
headRow
)
{
int
currRow
=
lastRow
+
1
;
HSSFRow
row
=
sheet
.
createRow
(
currRow
);
private
static
int
buildGroupRow
(
HSSFWorkbook
workbook
,
HSSFSheet
sheet
,
String
groupName
,
int
startRow
)
{
HSSFRow
row
=
sheet
.
createRow
(
startRow
);
row
.
setHeight
((
short
)
(
20
*
20
));
// 序号
HSSFCell
cell1_0
=
row
.
createCell
(
0
);
cell1_0
.
setCellValue
(
currRow
-
headRow
);
cell1_0
.
setCellValue
(
startRow
-
2
);
cell1_0
.
setCellStyle
(
getCellStyle
(
workbook
));
// 名称
HSSFCell
cell1_1
=
row
.
createCell
(
1
);
...
...
@@ -248,8 +243,8 @@ public class CKExcelTools {
HSSFCell
cell1_6
=
row
.
createCell
(
6
);
cell1_6
.
setCellStyle
(
getCellStyle
(
workbook
));
// 合并单元格
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
currRow
,
curr
Row
,
1
,
6
));
return
currRow
;
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
startRow
,
start
Row
,
1
,
6
));
return
startRow
+
1
;
}
/**
...
...
@@ -257,11 +252,12 @@ public class CKExcelTools {
*
* @param workbook
* @param sheet
* @param startRow
* @param dataMap
*/
private
static
void
buildRow1
(
HSSFWorkbook
workbook
,
HSSFSheet
sheet
,
Map
dataMap
)
{
private
static
int
buildRow1
(
HSSFWorkbook
workbook
,
HSSFSheet
sheet
,
int
startRow
,
Map
dataMap
)
{
// 在sheet中添加第0行,注意老版本poi对Excel的行数列数有限制short
HSSFRow
row1
=
sheet
.
createRow
(
0
);
HSSFRow
row1
=
sheet
.
createRow
(
startRow
);
row1
.
setHeight
((
short
)
(
20
*
20
));
// 1.1、表头:项目名
HSSFCell
cell1_1
=
row1
.
createCell
(
0
);
...
...
@@ -274,6 +270,7 @@ public class CKExcelTools {
// 合并单元格
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
0
,
0
,
0
,
4
));
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
0
,
0
,
5
,
6
));
return
startRow
+
1
;
}
/**
...
...
@@ -281,10 +278,11 @@ public class CKExcelTools {
*
* @param workbook
* @param sheet
* @param startRow
*/
private
static
void
buildRow2
(
HSSFWorkbook
workbook
,
HSSFSheet
sheet
)
{
private
static
int
buildRow2
(
HSSFWorkbook
workbook
,
HSSFSheet
sheet
,
int
startRow
)
{
// 2.第2行标题行
HSSFRow
row2
=
sheet
.
createRow
(
1
);
HSSFRow
row2
=
sheet
.
createRow
(
startRow
);
row2
.
setHeight
((
short
)
(
20
*
20
));
// 2.0、序号
HSSFCell
cell2_0
=
row2
.
createCell
(
0
);
...
...
@@ -316,6 +314,17 @@ public class CKExcelTools {
cell2_6
.
setCellValue
(
"备注"
);
cell2_6
.
setCellStyle
(
getCellStyle
(
workbook
,
HorizontalAlignment
.
CENTER
,
VerticalAlignment
.
CENTER
,
true
,
true
));
return
startRow
+
1
;
}
/**
* 构建第2~3行
*
* @param workbook
* @param sheet
* @param startRow
*/
private
static
int
buildRow3
(
HSSFWorkbook
workbook
,
HSSFSheet
sheet
,
int
startRow
)
{
// 3.第3行标题行
HSSFRow
row3
=
sheet
.
createRow
(
2
);
row3
.
setHeight
((
short
)
(
20
*
20
));
...
...
@@ -350,8 +359,10 @@ public class CKExcelTools {
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
1
,
1
,
2
,
4
));
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
1
,
2
,
5
,
5
));
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
1
,
2
,
6
,
6
));
return
startRow
+
1
;
}
/**
* 默认:居中+边框
*
...
...
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