Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
leaf-hlcm
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
hlcm
leaf-hlcm
Commits
172fae59
Commit
172fae59
authored
Mar 16, 2021
by
李贺贺
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
对账单打印格式优化
parent
83d6fe57
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
37 deletions
+57
-37
ConExportServiceImpl.java
...hand/hls/hlcm/cont/service/impl/ConExportServiceImpl.java
+52
-32
ExcelFormatUtil.java
...ain/java/com/hand/hls/hlcm/cont/util/ExcelFormatUtil.java
+5
-5
No files found.
src/main/java/com/hand/hls/hlcm/cont/service/impl/ConExportServiceImpl.java
View file @
172fae59
...
...
@@ -15,8 +15,6 @@ import java.math.BigDecimal;
import
java.net.URL
;
import
java.net.URLEncoder
;
import
java.text.DecimalFormat
;
import
java.text.DecimalFormatSymbols
;
import
java.text.NumberFormat
;
import
java.text.ParseException
;
import
java.util.*
;
...
...
@@ -27,14 +25,12 @@ import javax.servlet.http.HttpServletResponse;
import
com.hand.hls.hlcm.cont.util.ExcelFormatUtil
;
import
org.apache.poi.hssf.usermodel.HSSFCellStyle
;
import
org.apache.poi.hssf.usermodel.HSSF
DataFormat
;
import
org.apache.poi.hssf.usermodel.HSSF
PrintSetup
;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook
;
import
org.apache.poi.ss.usermodel.*
;
import
org.apache.poi.ss.util.CellRangeAddress
;
import
org.apache.poi.xssf.streaming.*
;
import
org.apache.poi.xssf.usermodel.XSSFClientAnchor
;
import
org.apache.poi.xssf.usermodel.XSSFDataFormat
;
import
org.codehaus.jackson.annotate.JsonSubTypes
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -91,11 +87,15 @@ public class ConExportServiceImpl implements ConExportService {
SXSSFDrawing
patriarch
=
sheet
.
createDrawingPatriarch
();
//Drawing patriarch = sheet.createDrawingPatriarch();
//anchor主要用于设置图片的属性
XSSFClientAnchor
anchor
=
new
XSSFClientAnchor
(
0
,
0
,
255
,
255
,
(
short
)
3
,
0
,
(
short
)
7
,
3
);
//dx1 :距离开始单元格左侧的距离 dy1:距离开始单元格上侧的距离
//dx2 :距离结束单元格左侧的距离 dy2:距离开始单元格上侧的距离
//col1:起始单元格列序号,row1:起始单元格行序号
//col2:结束单元格列序号,row2:结束单元格行序号
XSSFClientAnchor
anchor
=
new
XSSFClientAnchor
(
25
*
10000
,
0
,
25
*
10000
,
0
,
(
short
)
2
,
0
,
(
short
)
6
,
3
);
anchor
.
setAnchorType
(
ClientAnchor
.
AnchorType
.
byId
(
3
));
//插入图片
patriarch
.
createPicture
(
anchor
,
wb
.
addPicture
(
byteArrayOut
.
toByteArray
(),
HSSFWorkbook
.
PICTURE_TYPE_JPEG
));
CellRangeAddress
regionTitle0
=
new
CellRangeAddress
(
0
,
2
,
0
,
9
);
CellRangeAddress
regionTitle0
=
new
CellRangeAddress
(
0
,
2
,
0
,
7
);
//删除最后一列
sheet
.
addMergedRegion
(
regionTitle0
);
CellStyle
content
=
ExcelFormatUtil
.
contentStyle
(
wb
);
// 黑体居左显示
...
...
@@ -104,35 +104,35 @@ public class ConExportServiceImpl implements ConExportService {
String
contentTitle
=
"96 Ying Chun Road, Pudong New Area Shanghai, China 200127"
;
SXSSFRow
rowTitle
=
sheet
.
createRow
(
3
);
SXSSFCell
cellTitle
=
rowTitle
.
createCell
(
3
);
SXSSFCell
cellTitle
=
rowTitle
.
createCell
(
0
);
cellTitle
.
setCellValue
(
contentTitle
);
cellTitle
.
setCellStyle
(
ExcelFormatUtil
.
contentCenterStyle
(
wb
));
// 黑体居中
CellRangeAddress
regionTitle
=
new
CellRangeAddress
(
3
,
3
,
3
,
6
);
CellRangeAddress
regionTitle
=
new
CellRangeAddress
(
3
,
3
,
0
,
7
);
sheet
.
addMergedRegion
(
regionTitle
);
contentTitle
=
"中国上海市浦东新区迎春路96号"
;
SXSSFRow
rowTitle1
=
sheet
.
createRow
(
4
);
SXSSFCell
cellTitle1
=
rowTitle1
.
createCell
(
3
);
SXSSFCell
cellTitle1
=
rowTitle1
.
createCell
(
0
);
cellTitle1
.
setCellValue
(
contentTitle
);
cellTitle1
.
setCellStyle
(
ExcelFormatUtil
.
contentCenterStyle
(
wb
));
// 黑体居中
CellRangeAddress
regionTitle1
=
new
CellRangeAddress
(
4
,
4
,
3
,
6
);
CellRangeAddress
regionTitle1
=
new
CellRangeAddress
(
4
,
4
,
0
,
7
);
sheet
.
addMergedRegion
(
regionTitle1
);
contentTitle
=
"Tel:+86-(0)21-5056-3050\tFax:+86-(0)21-5056-3077"
;
SXSSFRow
rowTitle2
=
sheet
.
createRow
(
5
);
SXSSFCell
cellTitle2
=
rowTitle2
.
createCell
(
3
);
SXSSFCell
cellTitle2
=
rowTitle2
.
createCell
(
0
);
cellTitle2
.
setCellValue
(
contentTitle
);
cellTitle2
.
setCellStyle
(
ExcelFormatUtil
.
contentCenterStyle
(
wb
));
// 黑体居中
CellRangeAddress
regionTitle2
=
new
CellRangeAddress
(
5
,
5
,
3
,
6
);
CellRangeAddress
regionTitle2
=
new
CellRangeAddress
(
5
,
5
,
0
,
7
);
sheet
.
addMergedRegion
(
regionTitle2
);
SXSSFRow
rowTitle3
=
sheet
.
createRow
(
6
);
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
for
(
int
i
=
0
;
i
<
8
;
i
++)
{
SXSSFCell
cellTitle3
=
rowTitle3
.
createCell
(
i
);
cellTitle3
.
setCellValue
(
""
);
cellTitle3
.
setCellStyle
(
contentLine
);
}
CellRangeAddress
regionTitle3
=
new
CellRangeAddress
(
6
,
6
,
0
,
9
);
CellRangeAddress
regionTitle3
=
new
CellRangeAddress
(
6
,
6
,
0
,
7
);
//删除最后一列
sheet
.
addMergedRegion
(
regionTitle3
);
ExcelFormatUtil
.
initTitle
(
sheet
,
ExcelFormatUtil
.
headSytle
(
wb
),
"对账单"
,
7
,
0
);
...
...
@@ -163,20 +163,35 @@ public class ConExportServiceImpl implements ConExportService {
cellBpValue3
.
setCellStyle
(
contentLine
);
SXSSFCell
cellBpValue4
=
rowBpName
.
createCell
(
4
);
cellBpValue4
.
setCellValue
(
"
:
"
);
cellBpValue4
.
setCellStyle
(
content
);
cellBpValue4
.
setCellValue
(
""
);
cellBpValue4
.
setCellStyle
(
content
Line
);
CellRangeAddress
region
=
new
CellRangeAddress
(
10
,
10
,
0
,
3
);
sheet
.
addMergedRegion
(
region
);
SXSSFCell
cellBpValue5
=
rowBpName
.
createCell
(
5
);
cellBpValue5
.
setCellValue
(
":"
);
cellBpValue5
.
setCellStyle
(
content
);
contentExcel
=
" 依据您与宏菱融资租赁(上海)有限公司签订的《融资租赁合同》,(合同号:"
+
map
.
get
(
"CONTRACT_NUMBER"
)
+
";机号:"
+
map
.
get
(
"MACHINE_NUMBER"
)
+
")"
;
ExcelFormatUtil
.
initContent
(
sheet
,
content
,
contentExcel
,
12
,
0
);
CellRangeAddress
region
=
new
CellRangeAddress
(
10
,
10
,
0
,
4
);
sheet
.
addMergedRegion
(
region
);
contentExcel
=
"我公司已经按约向您交付了租赁物,截止"
+
map
.
get
(
"TODAY"
)
+
",您已支付我公司以下性质和金额的款项:"
;
contentExcel
=
" 依据您与宏菱融资租赁(上海)有限公司签订的《融资租赁合同》(合同号:"
+
map
.
get
(
"CONTRACT_NUMBER"
)
+
";机号:"
+
map
.
get
(
"MACHINE_NUMBER"
)
+
")我公司已经按约向您交付了租赁物,截止"
+
map
.
get
(
"TODAY"
)
+
",您已支付我公司以下性质和金额的款项:"
;
// ExcelFormatUtil.initContent(sheet, content, contentExcel, 12, 1);
SXSSFRow
row1
=
sheet
.
createRow
(
12
);
SXSSFCell
cell1
=
row1
.
createCell
(
0
);
//设置每一列的字段名
cell1
.
setCellValue
(
contentExcel
);
content
.
setWrapText
(
true
);
cell1
.
setCellStyle
(
content
);
CellRangeAddress
region1
=
new
CellRangeAddress
(
12
,
16
,
0
,
7
);
sheet
.
addMergedRegion
(
region1
);
/* contentExcel = "机号:" + map.get("MACHINE_NUMBER") + ") 我公司已经按约向您交付了租赁物,截止" +
map.get("TODAY") + ",您已支付";
ExcelFormatUtil.initContent(sheet, content, contentExcel, 14, 0);
contentExcel = "我公司以下性质和金额的款项:";
ExcelFormatUtil.initContent(sheet, content, contentExcel, 16, 0);*/
sheet
.
setColumnWidth
(
9
,
3000
);
if
(
list
!=
null
&&
list
.
size
()
>
1
)
{
//logger.info(">>>>>>>>>>>>>>>>>>>>开始遍历数据组装单元格内容>>>>>>>>>>");
...
...
@@ -189,13 +204,14 @@ public class ConExportServiceImpl implements ConExportService {
int
[]
ints
=
new
int
[]{
2500
,
1800
,
3000
,
3000
,
3000
,
3000
,
3000
,
3000
};
// 设置表头样式
ExcelFormatUtil
.
initColumn
(
sheet
,
contentTable
,
strs
,
ints
,
16
);
//修改表头起始行,原16
ExcelFormatUtil
.
initColumn
(
sheet
,
contentTable
,
strs
,
ints
,
18
);
//logger.info(">>>>>>>>>>>>>>>>>>>>表头样式设置完成>>>>>>>>>>");
double
amount
=
0
;
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
LinkedHashMap
<
String
,
Object
>
map1
=
(
LinkedHashMap
<
String
,
Object
>)
list
.
get
(
i
);
SXSSFRow
row
=
sheet
.
createRow
(
i
+
1
7
);
int
j
=
1
;
SXSSFRow
row
=
sheet
.
createRow
(
i
+
1
9
);
int
j
=
0
;
SXSSFCell
cell
=
row
.
createCell
(
j
++);
if
(
map1
.
get
(
"CF_ITEM_N"
)
!=
null
)
{
...
...
@@ -330,19 +346,23 @@ public class ConExportServiceImpl implements ConExportService {
//logger.info(">>>>>>>>>>>>>>>>>>>>结束遍历数据组装单元格内容>>>>>>>>>>");
contentExcel
=
"由于入账处理需要时间,以上还款金额可能未包含最近一次的还款记录。"
;
ExcelFormatUtil
.
initContent
(
sheet
,
content
,
contentExcel
,
list
.
size
()
+
1
6
+
2
,
1
);
ExcelFormatUtil
.
initContent
(
sheet
,
content
,
contentExcel
,
list
.
size
()
+
1
8
+
2
,
0
);
contentExcel
=
"请参考。"
;
ExcelFormatUtil
.
initContent
(
sheet
,
content
,
contentExcel
,
list
.
size
()
+
1
6
+
4
,
1
);
ExcelFormatUtil
.
initContent
(
sheet
,
content
,
contentExcel
,
list
.
size
()
+
1
8
+
4
,
0
);
contentExcel
=
"宏菱融资租赁(上海)有限公司"
;
ExcelFormatUtil
.
initContent
(
sheet
,
ExcelFormatUtil
.
contentCenterStyle
(
wb
),
contentExcel
,
list
.
size
()
+
1
6
+
6
,
6
);
ExcelFormatUtil
.
initContent
(
sheet
,
ExcelFormatUtil
.
contentCenterStyle
(
wb
),
contentExcel
,
list
.
size
()
+
1
8
+
6
,
4
);
contentExcel
=
"(公章)"
;
ExcelFormatUtil
.
initContent
(
sheet
,
ExcelFormatUtil
.
contentCenterStyle
(
wb
),
contentExcel
,
list
.
size
()
+
1
6
+
8
,
6
);
ExcelFormatUtil
.
initContent
(
sheet
,
ExcelFormatUtil
.
contentCenterStyle
(
wb
),
contentExcel
,
list
.
size
()
+
1
8
+
8
,
4
);
contentExcel
=
(
String
)
map
.
get
(
"TODAY"
);
ExcelFormatUtil
.
initContent
(
sheet
,
ExcelFormatUtil
.
contentCenterStyle
(
wb
),
contentExcel
,
list
.
size
()
+
16
+
10
,
6
);
ExcelFormatUtil
.
initContent
(
sheet
,
ExcelFormatUtil
.
contentCenterStyle
(
wb
),
contentExcel
,
list
.
size
()
+
18
+
10
,
4
);
//调整打印格式
PrintSetup
ps
=
sheet
.
getPrintSetup
();
ps
.
setFitWidth
((
short
)
0
);
sheet
.
setFitToPage
(
true
);
try
{
outputResponse
(
response
,
wb
,
"对账单("
+
(
String
)
map
.
get
(
"BP_NAME"
)
+
(
String
)
map
.
get
(
"CONTRACT_NUMBER"
)
+
").xlsx"
);
}
catch
(
Exception
e
)
{
...
...
src/main/java/com/hand/hls/hlcm/cont/util/ExcelFormatUtil.java
View file @
172fae59
...
...
@@ -61,7 +61,7 @@ public class ExcelFormatUtil {
Font
font1
=
wb
.
createFont
();
font1
.
setFontName
(
"黑体"
);
style1
.
setFont
(
font1
);
//
style1.setWrapText(true);
style1
.
setWrapText
(
true
);
style1
.
setAlignment
(
HorizontalAlignment
.
LEFT
);
style1
.
setVerticalAlignment
(
VerticalAlignment
.
CENTER
);
return
style1
;
...
...
@@ -117,7 +117,7 @@ public class ExcelFormatUtil {
//设置每一列的字段名
cell
.
setCellValue
(
title
);
cell
.
setCellStyle
(
header
);
CellRangeAddress
region
=
new
CellRangeAddress
(
firstRow
,
firstRow
+
1
,
firstrCol
,
9
);
CellRangeAddress
region
=
new
CellRangeAddress
(
firstRow
,
firstRow
+
1
,
firstrCol
,
7
);
sheet
.
addMergedRegion
(
region
);
}
...
...
@@ -130,7 +130,7 @@ public class ExcelFormatUtil {
//设置每一列的字段名
cell
.
setCellValue
(
content
);
cell
.
setCellStyle
(
contentType
);
CellRangeAddress
region
=
new
CellRangeAddress
(
firstRow
,
firstRow
,
firstrCol
,
9
);
CellRangeAddress
region
=
new
CellRangeAddress
(
firstRow
,
firstRow
,
firstrCol
,
7
);
//删除最后一列
sheet
.
addMergedRegion
(
region
);
}
...
...
@@ -139,11 +139,11 @@ public class ExcelFormatUtil {
SXSSFRow
row
=
sheet
.
createRow
(
firstRow
);
for
(
int
j
=
1
;
j
<=
title
.
length
;
j
++)
{
SXSSFCell
cell
=
row
.
createCell
(
j
);
SXSSFCell
cell
=
row
.
createCell
(
j
-
1
);
//设置每一列的字段名
cell
.
setCellValue
(
title
[
j
-
1
]);
cell
.
setCellStyle
(
contentTable
);
sheet
.
setColumnWidth
(
j
,
titleLength
[
j
-
1
]);
sheet
.
setColumnWidth
(
j
-
1
,
titleLength
[
j
-
1
]);
}
}
...
...
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