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
78851199
Commit
78851199
authored
Feb 22, 2023
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
导出Excel边框
parent
67c38588
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
7 deletions
+23
-7
ExcelConsole.java
...-db/src/main/java/com/yanzuoguang/excel/ExcelConsole.java
+23
-7
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/excel/ExcelConsole.java
View file @
78851199
...
...
@@ -11,6 +11,7 @@ import com.yanzuoguang.util.table.TableHeadItem;
import
org.apache.poi.hssf.util.HSSFColor
;
import
org.apache.poi.ss.usermodel.*
;
import
org.apache.poi.ss.util.CellRangeAddress
;
import
org.apache.poi.ss.util.RegionUtil
;
import
org.apache.poi.xssf.streaming.SXSSFWorkbook
;
import
java.io.File
;
...
...
@@ -402,9 +403,9 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
}
CellRangeAddress
region
=
new
CellRangeAddress
(
rowStart
,
rowEnd
,
columnPos
,
columnPos
);
setStyle
(
region
);
sheet
.
addMergedRegion
(
region
);
// 设置合并后的单元格样式
sheet
.
getRow
(
rowStart
).
getCell
(
columnPos
).
setCellStyle
(
style
);
}
/**
...
...
@@ -520,22 +521,37 @@ public class ExcelConsole<T extends Object> implements DbRow<T> {
font
.
setFontName
(
"宋体"
);
font
.
setFontHeightInPoints
((
short
)
10
);
cellStyle
.
setFont
(
font
);
// 左右居中
cellStyle
.
setAlignment
(
CellStyle
.
ALIGN_CENTER
);
// 上下居中
cellStyle
.
setVerticalAlignment
(
CellStyle
.
VERTICAL_CENTER
);
// 设置自动换行
cellStyle
.
setWrapText
(
true
);
// 设置单元格的边框颜色.
cellStyle
.
setTopBorderColor
(
HSSFColor
.
BLACK
.
index
);
cellStyle
.
setLeftBorderColor
(
HSSFColor
.
BLACK
.
index
);
cellStyle
.
setBorderLeft
((
short
)
1
);
cellStyle
.
setRightBorderColor
(
HSSFColor
.
BLACK
.
index
);
cellStyle
.
setBo
rderRight
((
short
)
1
);
cellStyle
.
setBo
ttomBorderColor
(
HSSFColor
.
BLACK
.
index
);
// 设置单元格的边框为粗体
cellStyle
.
setBorderTop
(
CellStyle
.
BORDER_THIN
);
cellStyle
.
setBorderLeft
(
CellStyle
.
BORDER_THIN
);
cellStyle
.
setBorderRight
(
CellStyle
.
BORDER_THIN
);
cellStyle
.
setBorderBottom
(
CellStyle
.
BORDER_THIN
);
// 设置单元格的边框颜色.
cellStyle
.
setBottomBorderColor
(
HSSFColor
.
BLACK
.
index
);
// 设置单元格的背景颜色.
cellStyle
.
setFillForegroundColor
(
HSSFColor
.
WHITE
.
index
);
return
cellStyle
;
}
private
void
setStyle
(
CellRangeAddress
region
)
{
// 使用RegionUtil类为合并后的单元格添加边框
RegionUtil
.
setBorderTop
(
style
.
getBorderTop
(),
region
,
sheet
,
this
.
workbook
);
RegionUtil
.
setBorderLeft
(
style
.
getBorderLeft
(),
region
,
sheet
,
this
.
workbook
);
RegionUtil
.
setBorderRight
(
style
.
getBorderRight
(),
region
,
sheet
,
this
.
workbook
);
RegionUtil
.
setBorderBottom
(
style
.
getBorderBottom
(),
region
,
sheet
,
this
.
workbook
);
RegionUtil
.
setTopBorderColor
(
style
.
getTopBorderColor
(),
region
,
sheet
,
this
.
workbook
);
RegionUtil
.
setLeftBorderColor
(
style
.
getLeftBorderColor
(),
region
,
sheet
,
this
.
workbook
);
RegionUtil
.
setRightBorderColor
(
style
.
getRightBorderColor
(),
region
,
sheet
,
this
.
workbook
);
RegionUtil
.
setBottomBorderColor
(
style
.
getBottomBorderColor
(),
region
,
sheet
,
this
.
workbook
);
}
}
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