Commit d1c10f6a authored by liqin's avatar liqin 💬

bug fixed

parent 82114029
...@@ -120,12 +120,12 @@ ...@@ -120,12 +120,12 @@
<dependency> <dependency>
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId> <artifactId>poi</artifactId>
<version>3.17</version> <version>5.0.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.poi</groupId> <groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId> <artifactId>poi-ooxml</artifactId>
<version>3.17</version> <version>5.0.0</version>
</dependency> </dependency>
<!-- Swagger2 Document --> <!-- Swagger2 Document -->
...@@ -257,7 +257,7 @@ ...@@ -257,7 +257,7 @@
<dependency> <dependency>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId> <artifactId>hutool-all</artifactId>
<version>5.6.0</version> <version>5.6.2</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.projectlombok</groupId> <groupId>org.projectlombok</groupId>
......
package cn.wisenergy.chnmuseum.party.common.util; package cn.wisenergy.chnmuseum.party.common.util;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.*;
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.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.InputStream; import java.io.InputStream;
...@@ -27,10 +23,10 @@ public class ImportExcelUtil { ...@@ -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); boolean ret = isXls(fileName);
Workbook workbook = null; Workbook workbook;
// 根据文件后缀创建不同的对象 // 根据文件后缀创建不同的对象
if (ret) { if (ret) {
workbook = new HSSFWorkbook(is); workbook = new HSSFWorkbook(is);
...@@ -45,30 +41,28 @@ public class ImportExcelUtil { ...@@ -45,30 +41,28 @@ public class ImportExcelUtil {
//列数 //列数
int lastCellNum = titleRow.getLastCellNum(); 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++) { for (int i = 1; i <= lastRowNum; i++) {
ArrayList<String> list1 = new ArrayList<>(); ArrayList<String> list1 = new ArrayList<>();
HashMap<String,String> map = new HashMap<>(); HashMap<String, String> map = new HashMap<>();
//获取行数据 //获取行数据
Row row = sheet.getRow(i); Row row = sheet.getRow(i);
for (int j = 0; j < lastCellNum; j++) { for (int j = 0; j < lastCellNum; j++) {
//获取单元格 //获取单元格
Cell cell = row.getCell(j); Cell cell = row.getCell(j);
if (cell!=null) { if (cell != null) {
cell.setCellType(Cell.CELL_TYPE_STRING); cell.setCellFormula(CellType.STRING.name());
//获取单元格数据 //获取单元格数据
list1.add(cell.getStringCellValue()); list1.add(cell.getStringCellValue());
//列名 :数据 //列名 :数据
map.put(titleRow.getCell(j).getStringCellValue(), cell.getStringCellValue()); map.put(titleRow.getCell(j).getStringCellValue(), cell.getStringCellValue());
}else {
continue;
} }
} }
list.add(map); list.add(map);
} }
is.close(); is.close();
return list; return list;
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment