Procházet zdrojové kódy

修改数据类型的兼容性

luoguangyi před 3 roky
rodič
revize
eea9d41465

+ 16 - 1
src/main/java/com/persagy/util/ExcelUtil.java

@@ -264,7 +264,8 @@ public class ExcelUtil {
 			switch (cell.getCellType()) {
 			case Cell.CELL_TYPE_NUMERIC:
 				short format = cell.getCellStyle().getDataFormat();
-				if (format == 14 || format == 22 || format == 31 || format == 57 || format == 58 || format == 176 || format == 177 || format == 178) {
+				if (isDateType(cell,format)) {
+					//format == 14 || format == 22 || format == 31 || format == 57 || format == 58 || format == 176 || format == 177 || format == 178
 					Date date = cell.getDateCellValue();
 					long floor = date.getTime() / (1000L * 60) * (1000L * 60);
 					long ceiling = floor + (1000L * 60);
@@ -301,4 +302,18 @@ public class ExcelUtil {
 		return cellText;
 	}
 
+
+	private static boolean isDateType(Cell cell, int formatIndex) {
+		// yyyy-MM-dd----- 14
+		// yyyy年m月d日---- 31
+		// yyyy年m月------- 57
+		// m月d日 ---------- 58
+		// HH:mm----------- 20
+		// h时mm分 -------- 32
+		if (formatIndex == 14 || formatIndex == 31 || formatIndex == 57 || formatIndex == 58 || formatIndex == 20 || formatIndex == 32) {
+			return true;
+		}
+
+		return org.apache.poi.ss.usermodel.DateUtil.isCellDateFormatted(cell);
+	}
 }

+ 0 - 15
src/main/resources/config.xml

@@ -25,20 +25,5 @@
 	<use_excel>true</use_excel>
 	<random_timeout>false</random_timeout>
 
-	<!--
-	<building id="1101070038">
-		<group meter_from="1000" meter_to="1000" funcid="4" period_second="30" data_type="double" />
-		<group meter_from="1000" meter_to="1000" funcid="5" period_second="30" data_type="double" />
-		<group meter_from="1000" meter_to="1000" funcid="6" period_second="30" data_type="double" />
-		<group meter_from="10001" meter_to="20000" funcid="10106" period_second="1" data_type="boolean" />
-	</building>
-	-->
-	
-	<!--
-	<building id="1101070038">
-		<group meter_from="10001" meter_to="20000" funcid="10101" period_second="1" data_type="double" />
-		<group meter_from="10001" meter_to="20000" funcid="10106" period_second="1" data_type="boolean" />
-	</building>
-	-->
 
 </root>

binární
src/main/resources/report.xlsx