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
cec94096
Commit
cec94096
authored
Jan 08, 2021
by
liuxinben
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改通过excel批量取消邮寄的poi依赖
parent
b8190823
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
107 additions
and
70 deletions
+107
-70
pom.xml
pom.xml
+11
-0
PersonPostApi.java
src/main/java/com/yxproject/start/api/PersonPostApi.java
+2
-1
Excel.java
src/main/java/com/yxproject/start/utils/Excel.java
+93
-0
ExportExcel.java
src/main/java/com/yxproject/start/utils/ExportExcel.java
+1
-69
No files found.
pom.xml
View file @
cec94096
...
...
@@ -91,6 +91,17 @@
<version>
1.3.3
</version>
</dependency>
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi
</artifactId>
<version>
4.1.0
</version>
</dependency>
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi-ooxml
</artifactId>
<version>
4.1.0
</version>
</dependency>
</dependencies>
<build>
...
...
src/main/java/com/yxproject/start/api/PersonPostApi.java
View file @
cec94096
...
...
@@ -3,6 +3,7 @@ package com.yxproject.start.api;
import
com.yxproject.start.dto.ReadCardDto
;
import
com.yxproject.start.entity.PersonPostEntity
;
import
com.yxproject.start.service.PersonPostService
;
import
com.yxproject.start.utils.Excel
;
import
com.yxproject.start.utils.ExportExcel
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
...
...
@@ -149,7 +150,7 @@ public class PersonPostApi {
try
{
file
=
File
.
createTempFile
(
"prefix"
,
"_"
+
item
.
getOriginalFilename
());
item
.
transferTo
(
file
);
list
=
Ex
portEx
cel
.
rearXlsAndXlsx
(
file
,
filename
);
list
=
Excel
.
rearXlsAndXlsx
(
file
,
filename
);
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
Map
<
String
,
Object
>
noteMap
=
list
.
get
(
i
);
String
uploadNo
=
noteMap
.
get
(
"身份证受理号"
).
toString
();
...
...
src/main/java/com/yxproject/start/utils/Excel.java
0 → 100644
View file @
cec94096
package
com
.
yxproject
.
start
.
utils
;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook
;
import
org.apache.poi.ss.usermodel.Cell
;
import
org.apache.poi.ss.usermodel.Row
;
import
org.apache.poi.ss.usermodel.Sheet
;
import
org.apache.poi.ss.usermodel.Workbook
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
org.springframework.util.ObjectUtils
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.InputStream
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
public
class
Excel
{
/**
* 解析excel
* @param file
* @return
*/
public
static
List
<
Map
<
String
,
Object
>>
rearXlsAndXlsx
(
File
file
,
String
filePath
){
Workbook
wb
=
readExcel
(
file
,
filePath
);
List
<
Map
<
String
,
Object
>>
outerList
=
new
ArrayList
<>();
if
(
wb
!=
null
)
{
int
sheetSize
=
wb
.
getNumberOfSheets
();
for
(
int
index
=
0
;
index
<
sheetSize
;
index
++)
{
// 每个页签创建一个Sheet对象
Sheet
sheet
=
wb
.
getSheetAt
(
index
);
int
rowNum
=
sheet
.
getLastRowNum
();
int
headerNum
=
sheet
.
getRow
(
2
).
getLastCellNum
();
String
[]
s
=
new
String
[
headerNum
];
for
(
int
o
=
0
;
o
<
headerNum
;
o
++){
Cell
headerCell
=
sheet
.
getRow
(
2
).
getCell
(
o
);
// headerCell.setCellType(CellType.STRING);
s
[
o
]
=
headerCell
.
getStringCellValue
();
}
// sheet.getRows()返回该页的总行数
for
(
int
nowRowNum
=
3
;
nowRowNum
<=
rowNum
;
nowRowNum
++)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
Row
row
=
sheet
.
getRow
(
nowRowNum
);
// sheet.getColumns()返回该页的总列数
int
columnNum
=
row
.
getLastCellNum
();
for
(
int
nowColumnNum
=
0
;
nowColumnNum
<
columnNum
;
nowColumnNum
++)
{
Cell
columnCell
=
sheet
.
getRow
(
nowRowNum
).
getCell
(
nowColumnNum
);
// columnCell.setCellType(CellType.STRING);
if
(
ObjectUtils
.
isEmpty
(
columnCell
)){
continue
;
}
else
{
String
cellinfo
=
columnCell
.
getStringCellValue
();
if
(
cellinfo
.
isEmpty
()
||
cellinfo
.
equals
(
""
)){
continue
;
}
else
{
map
.
put
(
s
[
nowColumnNum
],
cellinfo
);
}
}
}
if
(!
ObjectUtils
.
isEmpty
(
map
)){
outerList
.
add
(
map
);
}
}
}
}
return
outerList
;
}
private
static
Workbook
readExcel
(
File
file
,
String
filePath
){
if
(
filePath
==
null
){
return
null
;
}
String
extString
=
filePath
.
substring
(
filePath
.
lastIndexOf
(
"."
));
try
{
@SuppressWarnings
(
"resource"
)
InputStream
is
=
new
FileInputStream
(
file
);
if
(
".xls"
.
equals
(
extString
)){
return
new
HSSFWorkbook
(
is
);
}
else
if
(
".xlsx"
.
equals
(
extString
)){
return
new
XSSFWorkbook
(
is
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
}
src/main/java/com/yxproject/start/utils/ExportExcel.java
View file @
cec94096
...
...
@@ -2,6 +2,7 @@ package com.yxproject.start.utils;
import
org.apache.poi.hssf.usermodel.*
;
import
org.apache.poi.ss.usermodel.*
;
import
org.apache.poi.hssf.usermodel.HSSFWorkbook
;
import
org.apache.poi.ss.util.CellRangeAddress
;
import
org.springframework.util.ObjectUtils
;
...
...
@@ -366,75 +367,6 @@ public class ExportExcel {
}
/**
* 解析excel
* @param file
* @return
*/
public
static
List
<
Map
<
String
,
Object
>>
rearXlsAndXlsx
(
File
file
,
String
filePath
){
Workbook
wb
=
readExcel
(
file
,
filePath
);
List
<
Map
<
String
,
Object
>>
outerList
=
new
ArrayList
<>();
if
(
wb
!=
null
)
{
int
sheetSize
=
wb
.
getNumberOfSheets
();
for
(
int
index
=
0
;
index
<
sheetSize
;
index
++)
{
// 每个页签创建一个Sheet对象
Sheet
sheet
=
wb
.
getSheetAt
(
index
);
int
rowNum
=
sheet
.
getLastRowNum
();
int
headerNum
=
sheet
.
getRow
(
2
).
getLastCellNum
();
String
[]
s
=
new
String
[
headerNum
];
for
(
int
o
=
0
;
o
<
headerNum
;
o
++){
Cell
headerCell
=
sheet
.
getRow
(
2
).
getCell
(
o
);
// headerCell.setCellType(CellType.STRING);
s
[
o
]
=
headerCell
.
getStringCellValue
();
}
// sheet.getRows()返回该页的总行数
for
(
int
nowRowNum
=
3
;
nowRowNum
<=
rowNum
;
nowRowNum
++)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
Row
row
=
sheet
.
getRow
(
nowRowNum
);
// sheet.getColumns()返回该页的总列数
int
columnNum
=
row
.
getLastCellNum
();
for
(
int
nowColumnNum
=
0
;
nowColumnNum
<
columnNum
;
nowColumnNum
++)
{
Cell
columnCell
=
sheet
.
getRow
(
nowRowNum
).
getCell
(
nowColumnNum
);
// columnCell.setCellType(CellType.STRING);
if
(
ObjectUtils
.
isEmpty
(
columnCell
)){
continue
;
}
else
{
String
cellinfo
=
columnCell
.
getStringCellValue
();
if
(
cellinfo
.
isEmpty
()
||
cellinfo
.
equals
(
""
)){
continue
;
}
else
{
map
.
put
(
s
[
nowColumnNum
],
cellinfo
);
}
}
}
if
(!
ObjectUtils
.
isEmpty
(
map
)){
outerList
.
add
(
map
);
}
}
}
}
return
outerList
;
}
private
static
Workbook
readExcel
(
File
file
,
String
filePath
){
if
(
filePath
==
null
){
return
null
;
}
String
extString
=
filePath
.
substring
(
filePath
.
lastIndexOf
(
"."
));
try
{
@SuppressWarnings
(
"resource"
)
InputStream
is
=
new
FileInputStream
(
file
);
if
(
".xls"
.
equals
(
extString
)){
return
new
HSSFWorkbook
(
is
);
}
else
if
(
".xlsx"
.
equals
(
extString
)){
throw
new
FileNotFoundException
();
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
null
;
}
}
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