Commit 45a966adb2052fc0f9cf88cc79e0268c7a880ac7
Exists in
master
Merge branch 'master' of gitlab.taover.com:taov-erp/com-taover-util
Showing
2 changed files
with
21 additions
and
4 deletions
Show diff stats
build.gradle
@@ -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.29' | 62 | + version '1.1.32' |
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
@@ -4,6 +4,7 @@ import java.io.File; | @@ -4,6 +4,7 @@ import java.io.File; | ||
4 | import java.io.FileInputStream; | 4 | import java.io.FileInputStream; |
5 | import java.io.FileOutputStream; | 5 | import java.io.FileOutputStream; |
6 | import java.text.DecimalFormat; | 6 | import java.text.DecimalFormat; |
7 | +import java.text.SimpleDateFormat; | ||
7 | import java.util.ArrayList; | 8 | import java.util.ArrayList; |
8 | import java.util.Date; | 9 | import java.util.Date; |
9 | import java.util.HashMap; | 10 | import java.util.HashMap; |
@@ -14,6 +15,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook; | @@ -14,6 +15,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook; | ||
14 | import org.apache.poi.ss.usermodel.Cell; | 15 | import org.apache.poi.ss.usermodel.Cell; |
15 | import org.apache.poi.ss.usermodel.CellStyle; | 16 | import org.apache.poi.ss.usermodel.CellStyle; |
16 | import org.apache.poi.ss.usermodel.CellType; | 17 | import org.apache.poi.ss.usermodel.CellType; |
18 | +import org.apache.poi.ss.usermodel.DateUtil; | ||
17 | import org.apache.poi.ss.usermodel.Row; | 19 | import org.apache.poi.ss.usermodel.Row; |
18 | import org.apache.poi.ss.usermodel.Sheet; | 20 | import org.apache.poi.ss.usermodel.Sheet; |
19 | import org.apache.poi.ss.usermodel.Workbook; | 21 | import org.apache.poi.ss.usermodel.Workbook; |
@@ -379,7 +381,15 @@ public class UtilExcel { | @@ -379,7 +381,15 @@ public class UtilExcel { | ||
379 | if(currCellType.compareTo(CellType.STRING) == 0){ | 381 | if(currCellType.compareTo(CellType.STRING) == 0){ |
380 | return UtilString.trimCodePage(cell.getRichStringCellValue().getString()); | 382 | return UtilString.trimCodePage(cell.getRichStringCellValue().getString()); |
381 | }else if(currCellType.compareTo(CellType.NUMERIC) == 0){ | 383 | }else if(currCellType.compareTo(CellType.NUMERIC) == 0){ |
382 | - return df.format(cell.getNumericCellValue()); | 384 | + |
385 | + //if (DateUtil.isCellDateFormatted(cell)) { | ||
386 | + if (cell.getCellStyle().getDataFormat()==28||cell.getCellStyle().getDataFormat()==31 || cell.getCellStyle().getDataFormat() == 58) { | ||
387 | + // 如果是date类型则 ,获取该cell的date值 | ||
388 | + return new SimpleDateFormat("yyyy-MM-dd").format(DateUtil.getJavaDate(cell.getNumericCellValue())); | ||
389 | + } else { // 纯数字 | ||
390 | + // return String.valueOf(cell.getNumericCellValue()); | ||
391 | + return df.format(cell.getNumericCellValue()); | ||
392 | + } | ||
383 | }else if(currCellType.compareTo(CellType.BOOLEAN) == 0){ | 393 | }else if(currCellType.compareTo(CellType.BOOLEAN) == 0){ |
384 | return cell.getBooleanCellValue(); | 394 | return cell.getBooleanCellValue(); |
385 | }else if(currCellType.compareTo(CellType.FORMULA) == 0){ | 395 | }else if(currCellType.compareTo(CellType.FORMULA) == 0){ |
@@ -440,7 +450,14 @@ public class UtilExcel { | @@ -440,7 +450,14 @@ public class UtilExcel { | ||
440 | if(currCellType.compareTo(CellType.STRING) == 0){ | 450 | if(currCellType.compareTo(CellType.STRING) == 0){ |
441 | dataRow.add(UtilString.trimCodePage(cell.getRichStringCellValue().getString())); | 451 | dataRow.add(UtilString.trimCodePage(cell.getRichStringCellValue().getString())); |
442 | }else if(currCellType.compareTo(CellType.NUMERIC) == 0){ | 452 | }else if(currCellType.compareTo(CellType.NUMERIC) == 0){ |
443 | - dataRow.add(df.format(cell.getNumericCellValue())); | 453 | + //if (DateUtil.isCellDateFormatted(cell)) { |
454 | + if (cell.getCellStyle().getDataFormat()==28||cell.getCellStyle().getDataFormat()==31 || cell.getCellStyle().getDataFormat() == 58) { | ||
455 | + // 如果是date类型则 ,获取该cell的date值 | ||
456 | + dataRow.add( new SimpleDateFormat("yyyy-MM-dd").format(DateUtil.getJavaDate(cell.getNumericCellValue()))); | ||
457 | + } else { // 纯数字 | ||
458 | + // return String.valueOf(cell.getNumericCellValue()); | ||
459 | + dataRow.add( df.format(cell.getNumericCellValue())); | ||
460 | + } | ||
444 | 461 | ||
445 | }else if(currCellType.compareTo(CellType.BOOLEAN) == 0){ | 462 | }else if(currCellType.compareTo(CellType.BOOLEAN) == 0){ |
446 | dataRow.add(cell.getBooleanCellValue()); | 463 | dataRow.add(cell.getBooleanCellValue()); |
@@ -509,7 +526,7 @@ public class UtilExcel { | @@ -509,7 +526,7 @@ public class UtilExcel { | ||
509 | 526 | ||
510 | public static void main(String args[]){ | 527 | public static void main(String args[]){ |
511 | //String filepath = "C:\\Users\\root\\Desktop\\千丁-6.27.xlsx"; | 528 | //String filepath = "C:\\Users\\root\\Desktop\\千丁-6.27.xlsx"; |
512 | - String filepath = "C:\\Users\\EDZ\\Desktop\\榴莲1 (5).xlsx"; | 529 | + String filepath = "C:\\Users\\EDZ\\Desktop\\qwer.xlsx"; |
513 | List<List<Object>> data = null; | 530 | List<List<Object>> data = null; |
514 | try { | 531 | try { |
515 | data = UtilExcel.readExcel(filepath); | 532 | data = UtilExcel.readExcel(filepath); |