Commit d1c10f6a authored by liqin's avatar liqin 💬

bug fixed

parent 82114029
......@@ -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>
......
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.setCellType(Cell.CELL_TYPE_STRING);
if (cell != null) {
cell.setCellFormula(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
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