Commit 6db05b0940aadcc027f03b99f52dcb8a512c8c6d

Authored by gaoming
1 parent 0d53168f
Exists in master

优化excel读日期

build.gradle
... ... @@ -59,7 +59,7 @@ uploadArchives {
59 59 authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD)
60 60 }
61 61 pom.project {
62   - version '1.1.105'
  62 + version '1.1.106'
63 63 artifactId ARTIFACT_Id
64 64 groupId GROUP_ID
65 65 packaging TYPE
... ...
src/main/java/com/taover/util/UtilExcel.java
... ... @@ -10,11 +10,13 @@ import java.util.HashMap;
10 10 import java.util.List;
11 11 import java.util.Map;
12 12  
  13 +import org.apache.poi.hssf.usermodel.HSSFDateUtil;
13 14 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
14 15 import org.apache.poi.openxml4j.util.ZipSecureFile;
15 16 import org.apache.poi.ss.usermodel.Cell;
16 17 import org.apache.poi.ss.usermodel.CellStyle;
17 18 import org.apache.poi.ss.usermodel.CellType;
  19 +import org.apache.poi.ss.usermodel.DateUtil;
18 20 import org.apache.poi.ss.usermodel.FillPatternType;
19 21 import org.apache.poi.ss.usermodel.Row;
20 22 import org.apache.poi.ss.usermodel.Sheet;
... ... @@ -449,10 +451,7 @@ public class UtilExcel {
449 451 */
450 452 System.out.println(cell.getCellStyle().getDataFormat());
451 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 455 SimpleDateFormat sdf = null;
457 456 if(format == 14 || format == 31 || format == 57 || format == 58 ){
458 457 //日期
... ... @@ -513,7 +512,7 @@ public class UtilExcel {
513 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 516 List<List<Object>> data = null;
518 517  
519 518 try {
... ...