|
@@ -19,10 +19,9 @@ import java.util.List;
|
|
public class ExcelUtil {
|
|
public class ExcelUtil {
|
|
|
|
|
|
|
|
|
|
- public static List<HashMap<Integer,String>> getExcelRowList(MultipartFile multipartFile) throws IOException {
|
|
|
|
|
|
+ public static List<HashMap<Integer,String>> getExcelRowList(Workbook workbook) throws IOException {
|
|
//行List,也是最终要返回的List
|
|
//行List,也是最终要返回的List
|
|
List<HashMap<Integer,String>> rowList=new ArrayList<>();
|
|
List<HashMap<Integer,String>> rowList=new ArrayList<>();
|
|
- Workbook workbook=getExcelWorkBook(multipartFile);
|
|
|
|
Sheet sheet = workbook.getSheetAt(0);
|
|
Sheet sheet = workbook.getSheetAt(0);
|
|
if (sheet == null) {
|
|
if (sheet == null) {
|
|
throw new IOException("创建Sheet失败!");
|
|
throw new IOException("创建Sheet失败!");
|
|
@@ -60,8 +59,15 @@ public class ExcelUtil {
|
|
return rowList;
|
|
return rowList;
|
|
}
|
|
}
|
|
|
|
|
|
- private static Workbook getExcelWorkBook(InputStream inputStream) throws IOException {
|
|
|
|
- return new XSSFWorkbook(inputStream);
|
|
|
|
|
|
+
|
|
|
|
+ public static List<HashMap<Integer,String>> getExcelRowList(MultipartFile multipartFile) throws IOException {
|
|
|
|
+ return getExcelRowList(getExcelWorkBook(multipartFile));
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public static List<HashMap<Integer,String>> getExcelRowList(InputStream inputStream) throws IOException {
|
|
|
|
+ return getExcelRowList(getExcelWorkBook(inputStream));
|
|
}
|
|
}
|
|
|
|
|
|
private static String fommartNum(String value){
|
|
private static String fommartNum(String value){
|
|
@@ -81,45 +87,8 @@ public class ExcelUtil {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- public static List<HashMap<Integer,String>> getExcelRowList(InputStream inputStream) throws IOException {
|
|
|
|
- //行List,也是最终要返回的List
|
|
|
|
- List<HashMap<Integer,String>> rowList=new ArrayList<>();
|
|
|
|
- Workbook workbook=getExcelWorkBook(inputStream);
|
|
|
|
- Sheet sheet = workbook.getSheetAt(0);
|
|
|
|
- if (sheet == null) {
|
|
|
|
- throw new IOException("创建Sheet失败!");
|
|
|
|
- }
|
|
|
|
- //开始遍历行
|
|
|
|
- for (int i=0;i<= sheet.getLastRowNum();i++){
|
|
|
|
- Row row = sheet.getRow(i);
|
|
|
|
- //列List
|
|
|
|
- HashMap<Integer,String> map = new HashMap<>();
|
|
|
|
- if(row == null){
|
|
|
|
- rowList.add(map);
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- //转换为List数组
|
|
|
|
- for (int cellNum=0;cellNum<= row.getLastCellNum();cellNum++){
|
|
|
|
- Cell cell = row.getCell(cellNum);
|
|
|
|
- if (cell != null && cell.getCellTypeEnum() != CellType.STRING && HSSFDateUtil.isCellDateFormatted(cell))
|
|
|
|
- {
|
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
- Date date = HSSFDateUtil.getJavaDate(cell.getNumericCellValue());
|
|
|
|
- String value = sdf.format(date);
|
|
|
|
- map.put(cellNum,value);
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- if(cell != null){
|
|
|
|
- DataFormatter formatter = new DataFormatter();
|
|
|
|
- String phoneNumber = formatter.formatCellValue(cell);
|
|
|
|
- String value = fommartNum(phoneNumber);
|
|
|
|
- map.put(cellNum,value);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- rowList.add(map);
|
|
|
|
- }
|
|
|
|
- return rowList;
|
|
|
|
|
|
+ private static Workbook getExcelWorkBook(InputStream inputStream) throws IOException {
|
|
|
|
+ return new XSSFWorkbook(inputStream);
|
|
}
|
|
}
|
|
|
|
|
|
private static Workbook getExcelWorkBook(MultipartFile multipartFile) throws IOException {
|
|
private static Workbook getExcelWorkBook(MultipartFile multipartFile) throws IOException {
|