Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
chnmuseum-party
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
liqin
chnmuseum-party
Commits
d1c10f6a
Commit
d1c10f6a
authored
Apr 01, 2021
by
liqin
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fixed
parent
82114029
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
17 deletions
+11
-17
pom.xml
pom.xml
+3
-3
ImportExcelUtil.java
...isenergy/chnmuseum/party/common/util/ImportExcelUtil.java
+8
-14
No files found.
pom.xml
View file @
d1c10f6a
...
...
@@ -120,12 +120,12 @@
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi
</artifactId>
<version>
3.17
</version>
<version>
5.0.0
</version>
</dependency>
<dependency>
<groupId>
org.apache.poi
</groupId>
<artifactId>
poi-ooxml
</artifactId>
<version>
3.17
</version>
<version>
5.0.0
</version>
</dependency>
<!-- Swagger2 Document -->
...
...
@@ -257,7 +257,7 @@
<dependency>
<groupId>
cn.hutool
</groupId>
<artifactId>
hutool-all
</artifactId>
<version>
5.6.
0
</version>
<version>
5.6.
2
</version>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
...
...
src/main/java/cn/wisenergy/chnmuseum/party/common/util/ImportExcelUtil.java
View file @
d1c10f6a
package
cn
.
wisenergy
.
chnmuseum
.
party
.
common
.
util
;
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.ss.usermodel.*
;
import
org.apache.poi.xssf.usermodel.XSSFWorkbook
;
import
java.io.InputStream
;
...
...
@@ -27,10 +23,10 @@ public class ImportExcelUtil {
}
}
public
static
List
<
Map
<
String
,
String
>>
readExcel
(
String
fileName
,
InputStream
is
)
throws
Exception
{
public
static
List
<
Map
<
String
,
String
>>
readExcel
(
String
fileName
,
InputStream
is
)
throws
Exception
{
boolean
ret
=
isXls
(
fileName
);
Workbook
workbook
=
null
;
Workbook
workbook
;
// 根据文件后缀创建不同的对象
if
(
ret
)
{
workbook
=
new
HSSFWorkbook
(
is
);
...
...
@@ -45,30 +41,28 @@ public class ImportExcelUtil {
//列数
int
lastCellNum
=
titleRow
.
getLastCellNum
();
List
<
Map
<
String
,
String
>>
list
=
new
ArrayList
<>();
List
<
Map
<
String
,
String
>>
list
=
new
ArrayList
<>();
for
(
int
i
=
1
;
i
<=
lastRowNum
;
i
++)
{
ArrayList
<
String
>
list1
=
new
ArrayList
<>();
HashMap
<
String
,
String
>
map
=
new
HashMap
<>();
HashMap
<
String
,
String
>
map
=
new
HashMap
<>();
//获取行数据
Row
row
=
sheet
.
getRow
(
i
);
for
(
int
j
=
0
;
j
<
lastCellNum
;
j
++)
{
//获取单元格
Cell
cell
=
row
.
getCell
(
j
);
if
(
cell
!=
null
)
{
cell
.
setCell
Type
(
Cell
.
CELL_TYPE_STRING
);
if
(
cell
!=
null
)
{
cell
.
setCell
Formula
(
CellType
.
STRING
.
name
()
);
//获取单元格数据
list1
.
add
(
cell
.
getStringCellValue
());
//列名 :数据
map
.
put
(
titleRow
.
getCell
(
j
).
getStringCellValue
(),
cell
.
getStringCellValue
());
}
else
{
continue
;
}
}
list
.
add
(
map
);
}
is
.
close
();
return
list
;
}
}
\ No newline at end of file
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