Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
Y
YX_IDENT_beijing_auxiliary_YD
Project
Project
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
zhangyusheng
YX_IDENT_beijing_auxiliary_YD
Commits
e080ca89
Commit
e080ca89
authored
Mar 12, 2019
by
dahai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
下载公安网数据EXCEL
parent
237eef92
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
133 additions
and
4 deletions
+133
-4
ExportExcelApi.java
src/main/java/com/yxproject/start/api/ExportExcelApi.java
+28
-3
ExportExcel.java
src/main/java/com/yxproject/start/utils/ExportExcel.java
+105
-1
No files found.
src/main/java/com/yxproject/start/api/ExportExcelApi.java
View file @
e080ca89
...
@@ -3,10 +3,18 @@ package com.yxproject.start.api;
...
@@ -3,10 +3,18 @@ package com.yxproject.start.api;
import
com.yxproject.start.service.DetailReceiptListService
;
import
com.yxproject.start.service.DetailReceiptListService
;
import
com.yxproject.start.service.ReceiptService
;
import
com.yxproject.start.service.ReceiptService
;
import
com.yxproject.start.utils.ExportExcel
;
import
com.yxproject.start.utils.ExportExcel
;
import
org.apache.commons.lang.time.DateFormatUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -19,10 +27,27 @@ public class ExportExcelApi {
...
@@ -19,10 +27,27 @@ public class ExportExcelApi {
* 导出公安网数据
* 导出公安网数据
*/
*/
@RequestMapping
(
"printExcelData"
)
@RequestMapping
(
"printExcelData"
)
public
Byte
[]
printExcelData
(
String
dat
e
){
public
byte
[]
printExcelData
(
@RequestParam
(
"date"
)
String
date
,
HttpServletResponse
respons
e
){
List
<
Map
<
String
,
Object
>>
mapList
=
detailReceiptListService
.
selectPostDetails
(
replaceDate
(
date
));
List
<
Map
<
String
,
Object
>>
mapList
=
detailReceiptListService
.
selectPostDetails
(
replaceDate
(
date
));
response
.
setContentType
(
"application/x-download"
);
response
.
setCharacterEncoding
(
"UTF-8"
);
String
dateTime
=
DateFormatUtils
.
format
(
new
Date
(),
"yyyyMMddHH"
);
// //使用Servlet实现文件下载的时候,避免浏览器自动打开文件
String
fout
=
null
;
fout
=
ExportExcel
.
exportExcelDate
(
mapList
);
String
outFile
=
dateTime
+
"公安网数据"
;
try
{
FileInputStream
fis
=
new
FileInputStream
(
new
File
(
fout
));
byte
[]
b
=
new
byte
[
fis
.
available
()];
fis
.
read
(
b
);
fis
.
close
();
response
.
addHeader
(
"Content-Disposition"
,
"attachment;filename="
+
outFile
+
".xls"
);
return
b
;
}
catch
(
FileNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
return
null
;
return
null
;
}
}
/**
/**
...
...
src/main/java/com/yxproject/start/utils/ExportExcel.java
View file @
e080ca89
package
com
.
yxproject
.
start
.
utils
;
package
com
.
yxproject
.
start
.
utils
;
import
org.apache.poi.hssf.usermodel.*
;
import
org.apache.poi.hssf.usermodel.*
;
import
java.io.FileOutputStream
;
import
java.io.FileOutputStream
;
...
@@ -8,6 +7,7 @@ import java.io.IOException;
...
@@ -8,6 +7,7 @@ import java.io.IOException;
import
java.text.SimpleDateFormat
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
/**
/**
* @auther zhangyusheng
* @auther zhangyusheng
...
@@ -15,5 +15,109 @@ import java.util.List;
...
@@ -15,5 +15,109 @@ import java.util.List;
*/
*/
public
class
ExportExcel
{
public
class
ExportExcel
{
/**
* 导出公安网信息
* @param mapList 公安网信息
* @return
*/
public
static
String
exportExcelDate
(
List
<
Map
<
String
,
Object
>>
mapList
){
//第一步创建workbook
HSSFWorkbook
wb
=
new
HSSFWorkbook
();
SimpleDateFormat
simpleDateFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
HSSFSheet
sheet
=
wb
.
createSheet
(
"公安网信息表"
);
sheet
.
setColumnWidth
(
0
,
30
*
110
);
sheet
.
setColumnWidth
(
1
,
30
*
110
);
sheet
.
setColumnWidth
(
2
,
30
*
110
);
sheet
.
setColumnWidth
(
3
,
30
*
110
);
sheet
.
setColumnWidth
(
4
,
30
*
110
);
sheet
.
setColumnWidth
(
5
,
30
*
110
);
sheet
.
setColumnWidth
(
6
,
30
*
110
);
sheet
.
setColumnWidth
(
7
,
30
*
110
);
sheet
.
setColumnWidth
(
8
,
30
*
110
);
sheet
.
setColumnWidth
(
9
,
30
*
110
);
sheet
.
setColumnWidth
(
10
,
30
*
110
);
sheet
.
setColumnWidth
(
11
,
30
*
110
);
sheet
.
setColumnWidth
(
12
,
30
*
110
);
//第三步创建行row:添加表头0行
HSSFRow
row
=
sheet
.
createRow
(
0
);
HSSFCellStyle
style
=
wb
.
createCellStyle
();
//样式
style
.
setWrapText
(
true
);
//设置自动换行
HSSFFont
font
=
wb
.
createFont
();
font
.
setFontHeightInPoints
((
short
)
12
);
style
.
setFont
(
font
);
row
=
sheet
.
createRow
(
0
);
//创建下标为0的单元格
row
.
setHeightInPoints
(
Short
.
parseShort
(
"20"
));
//设置行高
HSSFCell
cell
=
row
.
createCell
(
0
);
//设定值
cell
.
setCellValue
(
"个人受理号"
);
cell
=
row
.
createCell
(
1
);
//设定值
cell
.
setCellValue
(
"受理号"
);
cell
=
row
.
createCell
(
2
);
//设定值
cell
.
setCellValue
(
"姓名"
);
cell
=
row
.
createCell
(
3
);
//设定值
cell
.
setCellValue
(
"性别"
);
cell
=
row
.
createCell
(
4
);
//设定值
cell
.
setCellValue
(
"派出所代码"
);
cell
=
row
.
createCell
(
5
);
//设定值
cell
.
setCellValue
(
"身份证号"
);
cell
=
row
.
createCell
(
6
);
//设定值
cell
.
setCellValue
(
"签发机关"
);
cell
=
row
.
createCell
(
7
);
//设定值
cell
.
setCellValue
(
"运单号"
);
cell
=
row
.
createCell
(
8
);
//设定值
cell
.
setCellValue
(
"制证类型"
);
cell
=
row
.
createCell
(
9
);
//设定值
cell
.
setCellValue
(
"原制证类型"
);
cell
=
row
.
createCell
(
10
);
//设定值
cell
.
setCellValue
(
"交接日期"
);
cell
=
row
.
createCell
(
11
);
//设定值
cell
.
setCellValue
(
"交接人"
);
cell
=
row
.
createCell
(
12
);
//设定值
cell
.
setCellValue
(
"备注"
);
for
(
int
i
=
0
;
i
<
mapList
.
size
();
i
++){
row
=
sheet
.
createRow
(
i
+
1
);
cell
=
row
.
createCell
(
0
);
//设定值
cell
.
setCellValue
(
"null"
.
equals
(
mapList
.
get
(
i
).
get
(
"UPLOAD_NO"
)+
""
)?
""
:
mapList
.
get
(
i
).
get
(
"UPLOAD_NO"
)+
""
);
cell
=
row
.
createCell
(
1
);
//设定值
cell
.
setCellValue
(
"null"
.
equals
(
mapList
.
get
(
i
).
get
(
"ACCEPT_NO"
)+
""
)?
""
:
mapList
.
get
(
i
).
get
(
"ACCEPT_NO"
)+
""
);
cell
=
row
.
createCell
(
2
);
//设定值
cell
.
setCellValue
(
"null"
.
equals
(
mapList
.
get
(
i
).
get
(
"NAME"
)+
""
)?
""
:
mapList
.
get
(
i
).
get
(
"NAME"
)+
""
);
cell
=
row
.
createCell
(
3
);
//设定值
cell
.
setCellValue
(
"null"
.
equals
(
mapList
.
get
(
i
).
get
(
"SEX"
)+
""
)?
""
:
mapList
.
get
(
i
).
get
(
"SEX"
)+
""
);
cell
=
row
.
createCell
(
4
);
//设定值
cell
.
setCellValue
(
"null"
.
equals
(
mapList
.
get
(
i
).
get
(
"POLICE_CODE"
)+
""
)?
""
:
mapList
.
get
(
i
).
get
(
"POLICE_CODE"
)+
""
);
cell
=
row
.
createCell
(
5
);
//设定值
cell
.
setCellValue
(
"null"
.
equals
(
mapList
.
get
(
i
).
get
(
"CARD_ID"
)+
""
)?
""
:
mapList
.
get
(
i
).
get
(
"CARD_ID"
)+
""
);
cell
=
row
.
createCell
(
6
);
//设定值
cell
.
setCellValue
(
"null"
.
equals
(
mapList
.
get
(
i
).
get
(
"SIGN_GOVT"
)+
""
)?
""
:
mapList
.
get
(
i
).
get
(
"SIGN_GOVT"
)+
""
);
cell
=
row
.
createCell
(
7
);
//设定值
cell
.
setCellValue
(
"null"
.
equals
(
mapList
.
get
(
i
).
get
(
"SIGN_GOVT"
)+
""
)?
""
:
mapList
.
get
(
i
).
get
(
"SIGN_GOVT"
)+
""
);
cell
=
row
.
createCell
(
8
);
//设定值
cell
.
setCellValue
(
"null"
.
equals
(
mapList
.
get
(
i
).
get
(
"CARD_TYPE_ID"
)+
""
)?
""
:
mapList
.
get
(
i
).
get
(
"CARD_TYPE_ID"
)+
""
);
cell
=
row
.
createCell
(
9
);
//设定值
cell
.
setCellValue
(
"null"
.
equals
(
mapList
.
get
(
i
).
get
(
"OLD_CARD_TYPE_ID"
)+
""
)?
""
:
mapList
.
get
(
i
).
get
(
"OLD_CARD_TYPE_ID"
)+
""
);
cell
=
row
.
createCell
(
10
);
//设定值
cell
.
setCellValue
(
"null"
.
equals
(
mapList
.
get
(
i
).
get
(
"CHECK_DATE"
)+
""
)?
""
:
mapList
.
get
(
i
).
get
(
"CHECK_DATE"
)+
""
);
cell
=
row
.
createCell
(
11
);
//设定值
cell
.
setCellValue
(
"null"
.
equals
(
mapList
.
get
(
i
).
get
(
"CHECK_NAME"
)+
""
)?
""
:
mapList
.
get
(
i
).
get
(
"CHECK_NAME"
)+
""
);
cell
=
row
.
createCell
(
12
);
//设定值
cell
.
setCellValue
(
"null"
.
equals
(
mapList
.
get
(
i
).
get
(
"NOTE"
)+
""
)?
""
:
mapList
.
get
(
i
).
get
(
"NOTE"
)+
""
);
}
//第六步将生成excel文件保存到指定路径下
FileOutputStream
fout
=
null
;
try
{
// fout = new FileOutputStream("E:\\Excel\\" + simpleDateFormat.format(new Date()) + countyInfoList.get(0).get("COUNTYNAME") + ".xls");
fout
=
new
FileOutputStream
(
"D:\\Excel\\"
+
simpleDateFormat
.
format
(
new
Date
())+
"公安网信息表"
+
".xls"
);
wb
.
write
(
fout
);
fout
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
System
.
out
.
println
(
"Excel文件生成成功..."
+
new
Date
());
// return "E:\\Excel\\" + simpleDateFormat.format(new Date()) +countyInfoList.get(0).get("COUNTYNAME") + ".xls";
return
"D:\\Excel\\"
+
simpleDateFormat
.
format
(
new
Date
())
+
"公安网信息表"
+
".xls"
;
}
}
}
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