From 29c36380f636c0ae22d668c856c03a543bcca1c8 Mon Sep 17 00:00:00 2001
From: fwq <582742538@qq.com>
Date: 星期一, 23 十月 2023 19:25:23 +0800
Subject: [PATCH] 捕获异常判断2007

---
 src/main/java/com/hx/util/ExcelUtil.java |   55 ++++++++++++++++++++++++++++++-------------------------
 1 files changed, 30 insertions(+), 25 deletions(-)

diff --git a/src/main/java/com/hx/util/ExcelUtil.java b/src/main/java/com/hx/util/ExcelUtil.java
index ee0af02..ce1713f 100644
--- a/src/main/java/com/hx/util/ExcelUtil.java
+++ b/src/main/java/com/hx/util/ExcelUtil.java
@@ -3,6 +3,7 @@
 import com.hx.exception.TipsException;
 import com.monitorjbl.xlsx.StreamingReader;
 import org.apache.poi.hssf.usermodel.*;
+import org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException;
 import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.xssf.streaming.SXSSFWorkbook;
 import org.apache.poi.xssf.usermodel.XSSFCell;
@@ -884,7 +885,10 @@
 					.bufferSize(10240)
 					.open(new FileInputStream(file));
 			listData =readhandle(book);
-		}catch (Exception e){
+		}catch (OLE2NotOfficeXmlFileException ex){
+			ex.printStackTrace();
+			throw new RuntimeException("excel鐗堟湰涓嶄负2007鍙婁互涓�");
+		} catch (Exception e){
 			e.printStackTrace();
 			throw new RuntimeException(e.getMessage());
 		}
@@ -976,33 +980,34 @@
 					cell = row.getCell(j);
 					if (cell == null) {
 						arrayString.add("");
-					}
-					if (cell.getCellType() == CellType.NUMERIC) {
-						isData = true;
-						format = cell.getCellStyle().getDataFormat();
-						if (format == 14 || format == 31 || format == 57 || format == 58) {
-							//鏃ユ湡锛堜腑鏂囨椂闂存牸寮忕殑锛�
-							d = cell.getDateCellValue();
-							formater = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
-							arrayString.add(formater.format(d));
-						} else if (HSSFDateUtil.isCellDateFormatted(cell)) {
-							d = cell.getDateCellValue();
-							formater = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
-							arrayString.add(formater.format(d));
-						} else {
-							if (CellType.STRING == cell.getCellType()) {
-								arrayString.add(cell.getStringCellValue());
-							} else if (CellType.FORMULA == cell.getCellType()) {
-								arrayString.add(cell.getCellFormula());
+					}else{
+						if (cell.getCellType() == CellType.NUMERIC) {
+							isData = true;
+							format = cell.getCellStyle().getDataFormat();
+							if (format == 14 || format == 31 || format == 57 || format == 58) {
+								//鏃ユ湡锛堜腑鏂囨椂闂存牸寮忕殑锛�
+								d = cell.getDateCellValue();
+								formater = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
+								arrayString.add(formater.format(d));
+							} else if (HSSFDateUtil.isCellDateFormatted(cell)) {
+								d = cell.getDateCellValue();
+								formater = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
+								arrayString.add(formater.format(d));
 							} else {
-								arrayString.add(cell.getStringCellValue().trim());
+								if (CellType.STRING == cell.getCellType()) {
+									arrayString.add(cell.getStringCellValue());
+								} else if (CellType.FORMULA == cell.getCellType()) {
+									arrayString.add(cell.getCellFormula());
+								} else {
+									arrayString.add(cell.getStringCellValue().trim());
+								}
 							}
+						} else if (cell.getCellType() == CellType.BLANK) {
+							arrayString.add("");
+						} else { // 濡傛灉EXCEL琛ㄦ牸涓殑鏁版嵁绫诲瀷涓哄瓧绗︿覆鍨�
+							isData = true;
+							arrayString.add(cell.getStringCellValue().trim());
 						}
-					} else if (cell.getCellType() == CellType.BLANK) {
-						arrayString.add("");
-					} else { // 濡傛灉EXCEL琛ㄦ牸涓殑鏁版嵁绫诲瀷涓哄瓧绗︿覆鍨�
-						isData = true;
-						arrayString.add(cell.getStringCellValue().trim());
 					}
 				}
 				if (isData) {

--
Gitblit v1.8.0