Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gic-enterprise-base
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
base_platform_enterprise
gic-enterprise-base
Commits
63e3bb66
Commit
63e3bb66
authored
Apr 14, 2020
by
guojuxing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
导出Excel二级表头添加
parent
071ff681
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
0 deletions
+96
-0
DownloadExcelQO.java
...ad/src/main/java/com/gic/download/qo/DownloadExcelQO.java
+44
-0
DownloadUtils.java
...d/src/main/java/com/gic/download/utils/DownloadUtils.java
+0
-0
ExcelUtils.java
...load/src/main/java/com/gic/download/utils/ExcelUtils.java
+52
-0
No files found.
gic-enterprise-download/src/main/java/com/gic/download/qo/DownloadExcelQO.java
View file @
63e3bb66
package
com
.
gic
.
download
.
qo
;
package
com
.
gic
.
download
.
qo
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
/**
/**
* 下载导出文件参数列表类
* 下载导出文件参数列表类
...
@@ -50,6 +52,21 @@ public class DownloadExcelQO implements Serializable{
...
@@ -50,6 +52,21 @@ public class DownloadExcelQO implements Serializable{
*/
*/
private
List
<
Integer
>
columnWidth
=
null
;
private
List
<
Integer
>
columnWidth
=
null
;
/**
* 二级表头标题中文,父子关联
*/
private
LinkedHashMap
<
String
,
List
<
String
>>
headerMap
;
/**
* 二级表头属性名称
*/
private
LinkedHashMap
<
String
,
List
<
String
>>
propertyNameMap
;
/**
* 二级表头需要加密的属性名称
*/
private
Map
<
String
,
List
<
String
>>
needEncryptFieldMap
;
public
String
getTempPath
()
{
public
String
getTempPath
()
{
return
tempPath
;
return
tempPath
;
}
}
...
@@ -130,4 +147,31 @@ public class DownloadExcelQO implements Serializable{
...
@@ -130,4 +147,31 @@ public class DownloadExcelQO implements Serializable{
this
.
columnWidth
=
columnWidth
;
this
.
columnWidth
=
columnWidth
;
return
this
;
return
this
;
}
}
public
LinkedHashMap
<
String
,
List
<
String
>>
getHeaderMap
()
{
return
headerMap
;
}
public
DownloadExcelQO
setHeaderMap
(
LinkedHashMap
<
String
,
List
<
String
>>
headerMap
)
{
this
.
headerMap
=
headerMap
;
return
this
;
}
public
LinkedHashMap
<
String
,
List
<
String
>>
getPropertyNameMap
()
{
return
propertyNameMap
;
}
public
DownloadExcelQO
setPropertyNameMap
(
LinkedHashMap
<
String
,
List
<
String
>>
propertyNameMap
)
{
this
.
propertyNameMap
=
propertyNameMap
;
return
this
;
}
public
Map
<
String
,
List
<
String
>>
getNeedEncryptFieldMap
()
{
return
needEncryptFieldMap
;
}
public
DownloadExcelQO
setNeedEncryptFieldMap
(
Map
<
String
,
List
<
String
>>
needEncryptFieldMap
)
{
this
.
needEncryptFieldMap
=
needEncryptFieldMap
;
return
this
;
}
}
}
gic-enterprise-download/src/main/java/com/gic/download/utils/DownloadUtils.java
View file @
63e3bb66
This diff is collapsed.
Click to expand it.
gic-enterprise-download/src/main/java/com/gic/download/utils/ExcelUtils.java
View file @
63e3bb66
...
@@ -144,6 +144,7 @@ public class ExcelUtils {
...
@@ -144,6 +144,7 @@ public class ExcelUtils {
return
true
;
return
true
;
}
}
@Deprecated
public
static
boolean
setHeaderTitle
(
CellStyle
cellStyle
,
Sheet
sheet
,
List
<
Integer
>
columnWidth
,
List
<
HeaderQO
>
headerList
,
List
<?>
content
)
{
public
static
boolean
setHeaderTitle
(
CellStyle
cellStyle
,
Sheet
sheet
,
List
<
Integer
>
columnWidth
,
List
<
HeaderQO
>
headerList
,
List
<?>
content
)
{
if
(
sheet
==
null
)
{
if
(
sheet
==
null
)
{
logger
.
info
(
"sheet is null"
);
logger
.
info
(
"sheet is null"
);
...
@@ -193,6 +194,57 @@ public class ExcelUtils {
...
@@ -193,6 +194,57 @@ public class ExcelUtils {
return
true
;
return
true
;
}
}
public
static
boolean
doubleHeaderTitle
(
CellStyle
cellStyle
,
Sheet
sheet
,
List
<
Integer
>
columnWidth
,
LinkedHashMap
<
String
,
List
<
String
>>
headerMap
,
List
<?>
content
)
{
if
(
sheet
==
null
)
{
logger
.
info
(
"sheet is null"
);
return
false
;
}
// 设置sheet格式
setSheetStyle
(
sheet
,
columnWidth
);
Row
row1
=
sheet
.
createRow
(
0
);
Row
row2
=
sheet
.
createRow
(
1
);
int
n
=
0
;
for
(
Map
.
Entry
<
String
,
List
<
String
>>
entry
:
headerMap
.
entrySet
())
{
Cell
cell1
=
row1
.
createCell
(
n
);
List
<
String
>
sonHeader
=
entry
.
getValue
();
String
value
=
entry
.
getKey
();
cell1
.
setCellValue
(
value
);
cell1
.
setCellStyle
(
cellStyle
);
//2层标题
if
(
CollectionUtils
.
isEmpty
(
sonHeader
))
{
//单标题
Cell
cell2
=
row2
.
createCell
(
n
);
cell2
.
setCellStyle
(
cellStyle
);
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
0
,
1
,
n
,
n
));
n
++;
continue
;
}
//创建第一行大标题
sheet
.
addMergedRegion
(
new
CellRangeAddress
(
0
,
0
,
n
,
(
n
+
sonHeader
.
size
()
-
1
)));
//赋值
for
(
int
j
=
0
,
sonLength
=
sonHeader
.
size
();
j
<
sonLength
;
j
++)
{
Cell
cell2
=
row2
.
createCell
(
n
++);
cell2
.
setCellStyle
(
cellStyle
);
cell2
.
setCellValue
(
sonHeader
.
get
(
j
));
}
}
// 如果内容为空 则退出
if
(
content
==
null
||
content
.
isEmpty
())
{
logger
.
info
(
"content is null,cannot write excel"
);
return
true
;
}
int
indexRow
=
2
;
for
(
Object
rowContent
:
content
)
{
Row
row
=
sheet
.
createRow
(
indexRow
++);
setRowInfo
(
row
,
rowContent
);
}
return
true
;
}
/**
/**
* 導出到excel
* 導出到excel
*
*
...
...
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