Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
clx-performance
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
姜武杰
clx-performance
Commits
4c04f0a1
提交
4c04f0a1
authored
10月 25, 2023
作者:
liruixin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Excel文件
上级
1f96de50
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
458 行增加
和
0 行删除
+458
-0
DataExcelTypeEnum.java
...va/com/clx/performance/utils/excel/DataExcelTypeEnum.java
+32
-0
ExcelData.java
.../main/java/com/clx/performance/utils/excel/ExcelData.java
+87
-0
ExcelField.java
...main/java/com/clx/performance/utils/excel/ExcelField.java
+36
-0
ExcelSheet.java
...main/java/com/clx/performance/utils/excel/ExcelSheet.java
+42
-0
ExcelUtil.java
.../main/java/com/clx/performance/utils/excel/ExcelUtil.java
+261
-0
没有找到文件。
performance-web/src/main/java/com/clx/performance/utils/excel/DataExcelTypeEnum.java
0 → 100644
浏览文件 @
4c04f0a1
package
com
.
clx
.
performance
.
utils
.
excel
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
/**
* 数据导出类型 0数据 1小计 2合计 3总计
*/
@Getter
@AllArgsConstructor
public
enum
DataExcelTypeEnum
{
DATA_TYPE
(
0
,
"数据"
),
SUBTOTAL
(
1
,
"小计"
),
EXCELLENT
(
2
,
"合计"
),
ALL_TOTAL
(
3
,
"总计"
),
;
private
int
value
;
private
String
desc
;
public
static
String
getDesc
(
int
value
)
{
for
(
DataExcelTypeEnum
c
:
DataExcelTypeEnum
.
values
())
{
if
(
c
.
getValue
()
==
value
)
{
return
c
.
desc
;
}
}
return
null
;
}
}
performance-web/src/main/java/com/clx/performance/utils/excel/ExcelData.java
0 → 100644
浏览文件 @
4c04f0a1
package
com
.
clx
.
performance
.
utils
.
excel
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.Getter
;
import
lombok.NoArgsConstructor
;
import
java.math.BigDecimal
;
@Data
@NoArgsConstructor
public
class
ExcelData
{
private
String
value
;
private
double
doubleValue
;
private
Integer
styleType
;
private
Integer
dataType
;
//数据类型:1字符串 2数字
@Getter
@AllArgsConstructor
public
enum
DataType
{
STRING
(
1
,
"字符串"
),
NUMERIC
(
2
,
"数字"
),
;
private
Integer
value
;
private
String
msg
;
}
public
ExcelData
(
String
value
)
{
this
(
value
,
null
);
}
public
ExcelData
(
String
value
,
String
defaultValue
)
{
this
.
value
=
value
;
this
.
dataType
=
DataType
.
STRING
.
value
;
}
public
ExcelData
(
Double
value
)
{
this
(
value
,
null
);
}
public
ExcelData
(
Double
value
,
String
defaultValue
)
{
if
(
null
!=
value
)
{
this
.
doubleValue
=
value
;
this
.
dataType
=
DataType
.
NUMERIC
.
value
;
}
else
{
this
.
value
=
defaultValue
;
this
.
dataType
=
DataType
.
STRING
.
value
;
}
}
public
ExcelData
(
Integer
value
)
{
this
(
value
,
null
);
}
public
ExcelData
(
Integer
value
,
String
defaultValue
)
{
if
(
null
!=
value
)
{
this
.
doubleValue
=
value
;
this
.
dataType
=
DataType
.
NUMERIC
.
value
;
}
else
{
this
.
value
=
defaultValue
;
this
.
dataType
=
DataType
.
STRING
.
value
;
}
}
public
ExcelData
(
BigDecimal
value
)
{
this
(
value
,
null
);
}
public
ExcelData
(
BigDecimal
value
,
String
defaultValue
)
{
if
(
null
!=
value
)
{
this
.
doubleValue
=
value
.
doubleValue
();
this
.
dataType
=
DataType
.
NUMERIC
.
value
;
}
else
{
this
.
value
=
defaultValue
;
this
.
dataType
=
DataType
.
STRING
.
value
;
}
}
public
double
getDoubleValue
()
{
return
doubleValue
;
}
public
String
getStringValue
()
{
return
value
;
}
}
performance-web/src/main/java/com/clx/performance/utils/excel/ExcelField.java
0 → 100644
浏览文件 @
4c04f0a1
package
com
.
clx
.
performance
.
utils
.
excel
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
/**
* @Author: aiqingguo
* @Description:
* @Date: 2022/8/18 14:25
* @Version: 1.0
*/
@Data
@NoArgsConstructor
public
class
ExcelField
{
private
Integer
column
;
private
String
fieldName
;
private
String
field
;
private
Integer
width
;
private
Integer
styleType
;
private
Integer
contentAlignment
;
public
ExcelField
(
String
fieldName
,
String
field
,
Integer
width
)
{
this
.
fieldName
=
fieldName
;
this
.
field
=
field
;
this
.
width
=
width
;
}
public
ExcelField
(
Integer
column
,
String
fieldName
,
String
field
,
Integer
width
)
{
this
.
column
=
column
;
this
.
fieldName
=
fieldName
;
this
.
field
=
field
;
this
.
width
=
width
;
}
}
performance-web/src/main/java/com/clx/performance/utils/excel/ExcelSheet.java
0 → 100644
浏览文件 @
4c04f0a1
package
com
.
clx
.
performance
.
utils
.
excel
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
java.util.List
;
/**
* @Author: aiqingguo
* @Description:
* @Date: 2022/8/19 9:53
* @Version: 1.0
*/
@Data
@NoArgsConstructor
public
class
ExcelSheet
{
private
String
name
;
private
String
title
;
private
String
time
;
private
Integer
timeStyleType
;
private
List
<
ExcelField
>
fieldList
;
private
List
<
List
<
ExcelData
>>
dataList
;
public
ExcelSheet
(
String
name
,
String
title
)
{
this
.
name
=
name
;
this
.
title
=
title
;
}
public
ExcelSheet
(
String
name
,
String
title
,
List
<
ExcelField
>
fieldList
)
{
this
.
name
=
name
;
this
.
title
=
title
;
this
.
fieldList
=
fieldList
;
}
public
ExcelSheet
(
String
name
,
String
title
,
List
<
ExcelField
>
fieldList
,
List
<
List
<
ExcelData
>>
dataList
)
{
this
.
name
=
name
;
this
.
title
=
title
;
this
.
fieldList
=
fieldList
;
this
.
dataList
=
dataList
;
}
}
performance-web/src/main/java/com/clx/performance/utils/excel/ExcelUtil.java
0 → 100644
浏览文件 @
4c04f0a1
package
com
.
clx
.
performance
.
utils
.
excel
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.poi.ss.usermodel.CellStyle
;
import
org.apache.poi.ss.usermodel.Font
;
import
org.apache.poi.ss.usermodel.HorizontalAlignment
;
import
org.apache.poi.ss.usermodel.VerticalAlignment
;
import
org.apache.poi.ss.util.CellRangeAddress
;
import
org.apache.poi.xssf.streaming.SXSSFCell
;
import
org.apache.poi.xssf.streaming.SXSSFRow
;
import
org.apache.poi.xssf.streaming.SXSSFSheet
;
import
org.apache.poi.xssf.streaming.SXSSFWorkbook
;
import
java.util.List
;
/**
* @Author: aiqingguo
* @Description:
* @Date: 2022/8/18 14:33
* @Version: 1.0
*/
public
class
ExcelUtil
{
@Getter
@AllArgsConstructor
public
enum
CellStyleType
{
CONTENT_CENTER
(
1
),
//内容居中
CONTENT_LEFT
(
2
),
//内容居左
CONTENT_RIGHT
(
3
),
//内容居右
TIME_LEFT
(
11
),
//时间左边
TIME_RIGHT
(
12
),
//时间右边
;
private
final
Integer
code
;
}
/**
* 创建excel
*/
public
static
SXSSFWorkbook
create
(
ExcelSheet
excelSheet
)
{
List
<
ExcelField
>
fieldList
=
excelSheet
.
getFieldList
();
List
<
List
<
ExcelData
>>
dataList
=
excelSheet
.
getDataList
();
SXSSFWorkbook
workbook
=
new
SXSSFWorkbook
();
//创建sheet
SXSSFSheet
sheet
=
workbook
.
createSheet
(
excelSheet
.
getName
());
int
fieldSize
=
fieldList
.
size
();
for
(
int
i
=
0
;
i
<
fieldSize
;
i
++)
{
sheet
.
setColumnWidth
(
i
,
fieldList
.
get
(
i
).
getWidth
());
}
//添加标题
int
row
=
0
;
CellRangeAddress
cellRangeAddress
=
new
CellRangeAddress
(
row
,
row
,
0
,
fieldSize
-
1
);
SXSSFRow
rowTitle
=
sheet
.
createRow
(
row
++);
sheet
.
addMergedRegion
(
cellRangeAddress
);
rowTitle
.
setHeightInPoints
(
30
);
SXSSFCell
titleCell
=
rowTitle
.
createCell
(
0
);
titleCell
.
setCellValue
(
excelSheet
.
getTitle
());
titleCell
.
setCellStyle
(
getTitleStyle
(
workbook
));
//时间
if
(
StringUtils
.
isNotBlank
(
excelSheet
.
getTime
()))
{
CellRangeAddress
timeCellRangeAddress
=
new
CellRangeAddress
(
row
,
row
,
0
,
fieldSize
-
1
);
SXSSFRow
rowTime
=
sheet
.
createRow
(
row
++);
sheet
.
addMergedRegion
(
timeCellRangeAddress
);
SXSSFCell
timeCell
=
rowTime
.
createCell
(
0
);
timeCell
.
setCellValue
(
excelSheet
.
getTime
());
Integer
styleType
=
excelSheet
.
getTimeStyleType
();
if
(
null
!=
styleType
)
{
timeCell
.
setCellStyle
(
getCellStyle
(
workbook
,
styleType
));
}
}
//添加表头
CellStyle
headCellStyle
=
getHeadStyle
(
workbook
);
SXSSFRow
rowHead
=
sheet
.
createRow
(
row
++);
for
(
int
i
=
0
;
i
<
fieldSize
;
i
++)
{
SXSSFCell
headCell
=
rowHead
.
createCell
(
i
);
headCell
.
setCellValue
(
fieldList
.
get
(
i
).
getFieldName
());
Integer
styleType
=
fieldList
.
get
(
i
).
getStyleType
();
if
(
null
!=
styleType
)
{
headCell
.
setCellStyle
(
getCellStyle
(
workbook
,
styleType
));
}
else
{
headCell
.
setCellStyle
(
headCellStyle
);
}
}
//内容
SXSSFRow
rowData
;
int
dataSize
=
dataList
.
size
();
for
(
int
i
=
0
;
i
<
dataSize
;
i
++)
{
rowData
=
sheet
.
createRow
(
row
++);
for
(
int
j
=
0
;
j
<
fieldSize
;
j
++)
{
SXSSFCell
dataCell
=
rowData
.
createCell
(
j
);
ExcelData
excelData
=
dataList
.
get
(
i
).
get
(
j
);
setCellValue
(
dataCell
,
excelData
);
Integer
styleType
=
dataList
.
get
(
i
).
get
(
j
).
getStyleType
();
if
(
null
!=
styleType
)
{
dataCell
.
setCellStyle
(
getCellStyle
(
workbook
,
styleType
));
}
}
}
return
workbook
;
}
/**
* 设置值
*/
private
static
void
setCellValue
(
SXSSFCell
dataCell
,
ExcelData
excelData
)
{
if
(
ExcelData
.
DataType
.
STRING
.
getValue
().
equals
(
excelData
.
getDataType
()))
{
String
stringValue
=
excelData
.
getStringValue
();
dataCell
.
setCellValue
(
stringValue
);
}
else
if
(
ExcelData
.
DataType
.
NUMERIC
.
getValue
().
equals
(
excelData
.
getDataType
()))
{
if
(
null
==
excelData
.
getStyleType
())
{
excelData
.
setStyleType
(
CellStyleType
.
CONTENT_RIGHT
.
getCode
());
}
dataCell
.
setCellValue
(
excelData
.
getDoubleValue
());
}
}
/**
* 设置标题字体
*/
private
static
Font
getTitleFont
(
SXSSFWorkbook
workbook
)
{
Font
ztFont
=
workbook
.
createFont
();
ztFont
.
setColor
(
Font
.
COLOR_NORMAL
);
ztFont
.
setFontHeightInPoints
((
short
)
22
);
return
ztFont
;
}
/**
* 设置标题样式
*/
private
static
CellStyle
getTitleStyle
(
SXSSFWorkbook
workbook
)
{
Font
font
=
getTitleFont
(
workbook
);
CellStyle
style
=
workbook
.
createCellStyle
();
style
.
setFont
(
font
);
style
.
setAlignment
(
HorizontalAlignment
.
CENTER
);
style
.
setVerticalAlignment
(
VerticalAlignment
.
CENTER
);
return
style
;
}
/**
* 设置格式
*/
private
static
Font
getHeadFont
(
SXSSFWorkbook
workbook
)
{
Font
ztFont
=
workbook
.
createFont
();
ztFont
.
setBold
(
true
);
return
ztFont
;
}
/**
* 设置表头样式
*/
private
static
CellStyle
getHeadStyle
(
SXSSFWorkbook
workbook
)
{
Font
headFont
=
getHeadFont
(
workbook
);
CellStyle
style
=
workbook
.
createCellStyle
();
style
.
setFont
(
headFont
);
style
.
setVerticalAlignment
(
VerticalAlignment
.
CENTER
);
style
.
setAlignment
(
HorizontalAlignment
.
CENTER
);
return
style
;
}
//获取单元格样式
private
static
CellStyle
getCellStyle
(
SXSSFWorkbook
workbook
,
Integer
cellStyleType
)
{
if
(
CellStyleType
.
CONTENT_CENTER
.
getCode
().
equals
(
cellStyleType
))
{
return
contentCenterStyle
(
workbook
);
}
if
(
CellStyleType
.
CONTENT_LEFT
.
getCode
().
equals
(
cellStyleType
))
{
return
contentLeftStyle
(
workbook
);
}
if
(
CellStyleType
.
CONTENT_RIGHT
.
getCode
().
equals
(
cellStyleType
))
{
return
contentRightStyle
(
workbook
);
}
if
(
CellStyleType
.
TIME_LEFT
.
getCode
().
equals
(
cellStyleType
))
{
return
timeLeftStyle
(
workbook
);
}
if
(
CellStyleType
.
TIME_RIGHT
.
getCode
().
equals
(
cellStyleType
))
{
return
timeRightStyle
(
workbook
);
}
return
workbook
.
createCellStyle
();
}
/**
* 内容居中
*/
private
static
CellStyle
contentCenterStyle
(
SXSSFWorkbook
workbook
)
{
CellStyle
cellStyle
=
workbook
.
createCellStyle
();
cellStyle
.
setAlignment
(
HorizontalAlignment
.
CENTER
);
return
cellStyle
;
}
/**
* 内容居右
*/
private
static
CellStyle
contentLeftStyle
(
SXSSFWorkbook
workbook
)
{
CellStyle
cellStyle
=
workbook
.
createCellStyle
();
cellStyle
.
setAlignment
(
HorizontalAlignment
.
LEFT
);
return
cellStyle
;
}
/**
* 内容居右
*/
private
static
CellStyle
contentRightStyle
(
SXSSFWorkbook
workbook
)
{
CellStyle
cellStyle
=
workbook
.
createCellStyle
();
cellStyle
.
setAlignment
(
HorizontalAlignment
.
RIGHT
);
return
cellStyle
;
}
/**
* 时间样式
*/
private
static
CellStyle
timeLeftStyle
(
SXSSFWorkbook
workbook
)
{
CellStyle
cellStyle
=
workbook
.
createCellStyle
();
cellStyle
.
setAlignment
(
HorizontalAlignment
.
LEFT
);
Font
font
=
workbook
.
createFont
();
font
.
setBold
(
true
);
font
.
setFontName
(
"宋体"
);
cellStyle
.
setFont
(
font
);
return
cellStyle
;
}
private
static
CellStyle
timeRightStyle
(
SXSSFWorkbook
workbook
)
{
CellStyle
cellStyle
=
workbook
.
createCellStyle
();
cellStyle
.
setAlignment
(
HorizontalAlignment
.
RIGHT
);
Font
font
=
workbook
.
createFont
();
font
.
setBold
(
true
);
font
.
setFontName
(
"宋体"
);
cellStyle
.
setFont
(
font
);
return
cellStyle
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论