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
efe320d2
Commit
efe320d2
authored
Feb 28, 2023
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
设置单元格的值
parent
e3e05ae0
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
13 deletions
+73
-13
ExcelConsole.java
...-db/src/main/java/com/yanzuoguang/excel/ExcelConsole.java
+54
-4
ExcelDefineCell.java
.../src/main/java/com/yanzuoguang/excel/ExcelDefineCell.java
+17
-7
ExportData.java
...il-db/src/main/java/com/yanzuoguang/excel/ExportData.java
+2
-2
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/excel/ExcelConsole.java
View file @
efe320d2
...
...
@@ -18,6 +18,7 @@ import java.io.File;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.util.List
;
import
java.util.regex.Pattern
;
/**
...
...
@@ -66,7 +67,14 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
* 行数据
*/
private
int
rowData
;
/**
* 开始数据行
*/
private
int
startDataRowIndex
=
Integer
.
MAX_VALUE
;
/**
* 结束数据行
*/
private
int
endDataRowIndex
=
Integer
.
MIN_VALUE
;
/**
* 缓存行数
*/
...
...
@@ -213,6 +221,8 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
writeHead
(
head
);
rowIndex
+=
head
.
getTotalRow
();
// 写入自定义行
writeDefineRow
(
this
.
config
.
getStartRows
());
}
/**
...
...
@@ -290,6 +300,22 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
return
this
;
}
private
void
writeDefineRow
(
List
<
ExcelDefineRow
>
rows
)
{
// 创建行
for
(
ExcelDefineRow
row
:
rows
)
{
Row
sheetRow
=
sheet
.
createRow
(
rowIndex
);
sheetRow
.
setHeight
(
getUnit
(
row
.
getHeight
()));
for
(
ExcelDefineCell
cell
:
row
.
getCells
())
{
cell
.
cellStyle
=
createCellStyle
(
cell
);
cell
.
cell
=
createCell
(
sheetRow
,
cell
.
getColumn
(),
cell
.
getValue
(),
cell
.
cellStyle
);
}
rowIndex
++;
}
}
private
void
writeDefineFormula
(
List
<
ExcelDefineRow
>
rows
)
{
}
/**
* 循环处理单行数据
*
...
...
@@ -297,6 +323,11 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
*/
@Override
public
void
handle
(
T
t
)
{
// 数据开始行
this
.
startDataRowIndex
=
Math
.
min
(
this
.
startDataRowIndex
,
this
.
rowIndex
);
// 数据结束行
this
.
endDataRowIndex
=
Math
.
max
(
this
.
endDataRowIndex
,
this
.
rowIndex
);
ExcelRow
<
T
>
rowHandle
=
this
.
getRowHandle
();
// 创建一行
Row
row
=
sheet
.
createRow
(
rowIndex
);
...
...
@@ -417,6 +448,11 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
}
}
// 写入自定义行
writeDefineRow
(
this
.
config
.
getEndRows
());
writeDefineFormula
(
this
.
config
.
getStartRows
());
writeDefineFormula
(
this
.
config
.
getEndRows
());
String
fileNameTemp
=
this
.
getFileNameTemp
();
// 保存为临时文件
try
(
OutputStream
out
=
new
FileOutputStream
(
fileNameTemp
))
{
...
...
@@ -538,8 +574,21 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
private
CellStyle
createColumnStyle
(
SXSSFWorkbook
wb
,
ExportColumn
column
)
{
CellStyle
style
=
this
.
createStyle
(
wb
,
false
);
setAlignment
(
style
,
column
.
getAlignment
());
setVerticalAlignment
(
style
,
column
.
getVerticalAlignment
());
return
style
;
}
private
CellStyle
createCellStyle
(
ExcelDefineCell
cell
)
{
CellStyle
style
=
this
.
createStyle
(
this
.
workbook
,
false
);
setAlignment
(
style
,
cell
.
getAlignment
());
setVerticalAlignment
(
style
,
cell
.
getVerticalAlignment
());
return
style
;
}
private
void
setAlignment
(
CellStyle
style
,
int
alignment
)
{
// 左右居中
switch
(
column
.
getAlignment
()
)
{
switch
(
alignment
)
{
case
1
:
style
.
setAlignment
(
CellStyle
.
ALIGN_LEFT
);
break
;
...
...
@@ -551,9 +600,11 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
style
.
setAlignment
(
CellStyle
.
ALIGN_CENTER
);
break
;
}
}
private
void
setVerticalAlignment
(
CellStyle
style
,
int
verticalAlignment
)
{
// 上下居中
switch
(
column
.
getVerticalAlignment
()
)
{
switch
(
verticalAlignment
)
{
case
1
:
style
.
setVerticalAlignment
(
CellStyle
.
VERTICAL_TOP
);
break
;
...
...
@@ -565,7 +616,6 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
style
.
setVerticalAlignment
(
CellStyle
.
VERTICAL_CENTER
);
break
;
}
return
style
;
}
private
void
setDefaultStyle
(
CellRangeAddress
region
,
CellStyle
cellStyle
)
{
...
...
yzg-util-db/src/main/java/com/yanzuoguang/excel/ExcelDefineCell.java
View file @
efe320d2
package
com
.
yanzuoguang
.
excel
;
import
io.swagger.annotations.ApiModelProperty
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.CellStyle
;
/**
* 单元格
...
...
@@ -12,7 +14,7 @@ public class ExcelDefineCell {
* 第几列
*/
@ApiModelProperty
(
notes
=
"第几列"
)
private
short
column
Pos
;
private
short
column
;
/**
* 横合并
*/
...
...
@@ -39,17 +41,25 @@ public class ExcelDefineCell {
@ApiModelProperty
(
notes
=
"文字内容"
)
private
String
value
;
/**
* 公式,如:SUM(C2:C3),或者SUM(
columnName
),columnName=数据列名称,公式优先
* 公式,如:SUM(C2:C3),或者SUM(
{columnName}
),columnName=数据列名称,公式优先
*/
@ApiModelProperty
(
notes
=
" 公式,如:SUM(C2:C3),或者SUM(
columnName),columnName=数据列名称,公式优先.不能SUM(columnA/columnB)
"
)
@ApiModelProperty
(
notes
=
" 公式,如:SUM(C2:C3),或者SUM(
{columnName}),columnName=数据列名称,公式优先.不能SUM(columnA/columnB),当前行={rowIndex}
"
)
private
String
formula
;
/**
* 当前单元格样式
*/
CellStyle
cellStyle
;
/**
* 单元格
*/
Cell
cell
;
public
short
getColumn
Pos
()
{
return
column
Pos
;
public
short
getColumn
()
{
return
column
;
}
public
void
setColumn
Pos
(
short
columnPos
)
{
this
.
column
Pos
=
columnPos
;
public
void
setColumn
(
short
column
)
{
this
.
column
=
column
;
}
public
short
getWidthSize
()
{
...
...
yzg-util-db/src/main/java/com/yanzuoguang/excel/ExportData.java
View file @
efe320d2
...
...
@@ -7,11 +7,11 @@ import java.util.ArrayList;
import
java.util.List
;
/**
* 订单导出数据
* 订单导出数据
配置信息,需要注意,多线程导出时配置不能共用同一个对象
*
* @author 颜佐光
*/
@ApiModel
(
description
=
"订单导出数据配置信息"
)
@ApiModel
(
description
=
"订单导出数据配置信息
,需要注意,多线程导出时配置不能共用同一个对象
"
)
public
class
ExportData
{
@ApiModelProperty
(
notes
=
"普通导出模式"
)
...
...
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