Commit 6db05b0940aadcc027f03b99f52dcb8a512c8c6d

Authored by gaoming
1 parent 0d53168f
Exists in master

优化excel读日期

@@ -59,7 +59,7 @@ uploadArchives { @@ -59,7 +59,7 @@ uploadArchives {
59 authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) 59 authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD)
60 } 60 }
61 pom.project { 61 pom.project {
62 - version '1.1.105' 62 + version '1.1.106'
63 artifactId ARTIFACT_Id 63 artifactId ARTIFACT_Id
64 groupId GROUP_ID 64 groupId GROUP_ID
65 packaging TYPE 65 packaging TYPE
src/main/java/com/taover/util/UtilExcel.java
@@ -10,11 +10,13 @@ import java.util.HashMap; @@ -10,11 +10,13 @@ import java.util.HashMap;
10 import java.util.List; 10 import java.util.List;
11 import java.util.Map; 11 import java.util.Map;
12 12
  13 +import org.apache.poi.hssf.usermodel.HSSFDateUtil;
13 import org.apache.poi.hssf.usermodel.HSSFWorkbook; 14 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
14 import org.apache.poi.openxml4j.util.ZipSecureFile; 15 import org.apache.poi.openxml4j.util.ZipSecureFile;
15 import org.apache.poi.ss.usermodel.Cell; 16 import org.apache.poi.ss.usermodel.Cell;
16 import org.apache.poi.ss.usermodel.CellStyle; 17 import org.apache.poi.ss.usermodel.CellStyle;
17 import org.apache.poi.ss.usermodel.CellType; 18 import org.apache.poi.ss.usermodel.CellType;
  19 +import org.apache.poi.ss.usermodel.DateUtil;
18 import org.apache.poi.ss.usermodel.FillPatternType; 20 import org.apache.poi.ss.usermodel.FillPatternType;
19 import org.apache.poi.ss.usermodel.Row; 21 import org.apache.poi.ss.usermodel.Row;
20 import org.apache.poi.ss.usermodel.Sheet; 22 import org.apache.poi.ss.usermodel.Sheet;
@@ -449,10 +451,7 @@ public class UtilExcel { @@ -449,10 +451,7 @@ public class UtilExcel {
449 */ 451 */
450 System.out.println(cell.getCellStyle().getDataFormat()); 452 System.out.println(cell.getCellStyle().getDataFormat());
451 short format = cell.getCellStyle().getDataFormat(); 453 short format = cell.getCellStyle().getDataFormat();
452 - if (format==28 || format==22||format==31 || format == 58 || format==14 || format==57 || format==32 || format==20 || format==176 ) {  
453 -  
454 - // 如果是date类型则 ,获取该cell的date值  
455 - //return new SimpleDateFormat("yyyy-MM-dd").format(DateUtil.getJavaDate(cell.getNumericCellValue())); 454 + if (DateUtil.isCellDateFormatted(cell)) {
456 SimpleDateFormat sdf = null; 455 SimpleDateFormat sdf = null;
457 if(format == 14 || format == 31 || format == 57 || format == 58 ){ 456 if(format == 14 || format == 31 || format == 57 || format == 58 ){
458 //日期 457 //日期
@@ -513,7 +512,7 @@ public class UtilExcel { @@ -513,7 +512,7 @@ public class UtilExcel {
513 System.out.println(df.format(3.3300)); 512 System.out.println(df.format(3.3300));
514 513
515 514
516 - String filepath = "C:\\Users\\EDZ\\Desktop\\ttt.xls"; 515 + String filepath = "C:\\Users\\EDZ\\Desktop\\date - 副本.xlsx";
517 List<List<Object>> data = null; 516 List<List<Object>> data = null;
518 517
519 try { 518 try {