From 711787ac5f0ebb54fa487fad36323050f6a2bec5 Mon Sep 17 00:00:00 2001 From: gaoming Date: Mon, 13 Apr 2020 11:51:51 +0800 Subject: [PATCH] 优化excel读取时间 --- build.gradle | 2 +- src/main/java/com/taover/util/UtilExcel.java | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index ce53ce8..29a8d04 100644 --- a/build.gradle +++ b/build.gradle @@ -59,7 +59,7 @@ uploadArchives { authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) } pom.project { - version '1.1.79' + version '1.1.80' artifactId ARTIFACT_Id groupId GROUP_ID packaging TYPE diff --git a/src/main/java/com/taover/util/UtilExcel.java b/src/main/java/com/taover/util/UtilExcel.java index ac4dd24..15f96cd 100644 --- a/src/main/java/com/taover/util/UtilExcel.java +++ b/src/main/java/com/taover/util/UtilExcel.java @@ -446,7 +446,19 @@ public class UtilExcel { if(currCellType.compareTo(CellType.STRING) == 0){ return UtilString.trimCodePage(cell.getRichStringCellValue().getString()); }else if(currCellType.compareTo(CellType.NUMERIC) == 0){ - if (cell.getCellStyle().getDataFormat()==28||cell.getCellStyle().getDataFormat()==31 || cell.getCellStyle().getDataFormat() == 58) { + + /** + * yyyy-MM-dd----- 14 + yyyy年m月d日--- 31 + yyyy年m月------- 57 + m月d日 ---------- 58 + HH:mm----------- 20 + h时mm分 ------- 32 + */ + System.out.println(cell.getCellStyle().getDataFormat()); + if (cell.getCellStyle().getDataFormat()==28||cell.getCellStyle().getDataFormat()==31 + || cell.getCellStyle().getDataFormat() == 58 || cell.getCellStyle().getDataFormat()==14 + || cell.getCellStyle().getDataFormat()==57 || cell.getCellStyle().getDataFormat()==32 || cell.getCellStyle().getDataFormat()==20) { // 如果是date类型则 ,获取该cell的date值 return new SimpleDateFormat("yyyy-MM-dd").format(DateUtil.getJavaDate(cell.getNumericCellValue())); } else { @@ -489,7 +501,7 @@ public class UtilExcel { public static void main(String args[]){ //String filepath = "C:\\Users\\root\\Desktop\\千丁-6.27.xlsx"; - String filepath = "C:\\Users\\gaoming\\Desktop\\mmm.xlsx"; + String filepath = "C:\\Users\\EDZ\\Desktop\\mmm.xlsx"; List> data = null; try { -- libgit2 0.21.2