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
b0c1bc3f
Commit
b0c1bc3f
authored
May 08, 2020
by
陶光胜
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'developer' into 'master'
Developer See merge request
!3
parents
11ce7a31
306043ad
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
116 additions
and
0 deletions
+116
-0
ExcelExtensionEnum.java
...n/java/com/gic/download/constants/ExcelExtensionEnum.java
+20
-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/constants/ExcelExtensionEnum.java
View file @
b0c1bc3f
...
...
@@ -21,6 +21,26 @@ public enum ExcelExtensionEnum {
this
.
extension
=
extension
;
}
/**
* 根据code获取枚举对象,默认返回CSV
* @Title: getByCode
* @Description:
* @author guojuxing
* @param code
* @return com.gic.download.constants.ExcelExtensionEnum
*/
public
static
ExcelExtensionEnum
getByCode
(
Integer
code
)
{
if
(
code
==
null
)
{
return
ExcelExtensionEnum
.
CSV
;
}
for
(
ExcelExtensionEnum
extensionEnum
:
values
())
{
if
(
code
.
intValue
()
==
extensionEnum
.
getCode
())
{
return
extensionEnum
;
}
}
return
ExcelExtensionEnum
.
CSV
;
}
public
static
String
getExtensionByCode
(
Integer
code
)
{
if
(
code
==
null
)
{
return
".csv"
;
...
...
gic-enterprise-download/src/main/java/com/gic/download/qo/DownloadExcelQO.java
View file @
b0c1bc3f
package
com
.
gic
.
download
.
qo
;
import
java.io.Serializable
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* 下载导出文件参数列表类
...
...
@@ -50,6 +52,21 @@ public class DownloadExcelQO implements Serializable{
*/
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
()
{
return
tempPath
;
}
...
...
@@ -130,4 +147,31 @@ public class DownloadExcelQO implements Serializable{
this
.
columnWidth
=
columnWidth
;
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 @
b0c1bc3f
This diff is collapsed.
Click to expand it.
gic-enterprise-download/src/main/java/com/gic/download/utils/ExcelUtils.java
View file @
b0c1bc3f
...
...
@@ -144,6 +144,7 @@ public class ExcelUtils {
return
true
;
}
@Deprecated
public
static
boolean
setHeaderTitle
(
CellStyle
cellStyle
,
Sheet
sheet
,
List
<
Integer
>
columnWidth
,
List
<
HeaderQO
>
headerList
,
List
<?>
content
)
{
if
(
sheet
==
null
)
{
logger
.
info
(
"sheet is null"
);
...
...
@@ -193,6 +194,57 @@ public class ExcelUtils {
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
*
...
...
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