Commit 60ed22eeed01325a26a56c4e9dc848006410ac7f

Authored by gaoming
1 parent 299ab778
Exists in master

获取自定义日期格式

@@ -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.30'
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;
@@ -15,6 +16,7 @@ import org.apache.poi.hssf.util.HSSFColor; @@ -15,6 +16,7 @@ import org.apache.poi.hssf.util.HSSFColor;
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.Row; 20 import org.apache.poi.ss.usermodel.Row;
19 import org.apache.poi.ss.usermodel.Sheet; 21 import org.apache.poi.ss.usermodel.Sheet;
20 import org.apache.poi.ss.usermodel.Workbook; 22 import org.apache.poi.ss.usermodel.Workbook;
@@ -331,7 +333,15 @@ public class UtilExcel { @@ -331,7 +333,15 @@ public class UtilExcel {
331 if(currCellType.compareTo(CellType.STRING) == 0){ 333 if(currCellType.compareTo(CellType.STRING) == 0){
332 return UtilString.trimCodePage(cell.getRichStringCellValue().getString()); 334 return UtilString.trimCodePage(cell.getRichStringCellValue().getString());
333 }else if(currCellType.compareTo(CellType.NUMERIC) == 0){ 335 }else if(currCellType.compareTo(CellType.NUMERIC) == 0){
334 - return df.format(cell.getNumericCellValue()); 336 +
  337 + //if (DateUtil.isCellDateFormatted(cell)) {
  338 + if (cell.getCellStyle().getDataFormat()==28||cell.getCellStyle().getDataFormat()==31 || cell.getCellStyle().getDataFormat() == 58) {
  339 + // 如果是date类型则 ,获取该cell的date值
  340 + return new SimpleDateFormat("yyyy-MM-dd").format(DateUtil.getJavaDate(cell.getNumericCellValue()));
  341 + } else { // 纯数字
  342 + // return String.valueOf(cell.getNumericCellValue());
  343 + return df.format(cell.getNumericCellValue());
  344 + }
335 }else if(currCellType.compareTo(CellType.BOOLEAN) == 0){ 345 }else if(currCellType.compareTo(CellType.BOOLEAN) == 0){
336 return cell.getBooleanCellValue(); 346 return cell.getBooleanCellValue();
337 }else if(currCellType.compareTo(CellType.FORMULA) == 0){ 347 }else if(currCellType.compareTo(CellType.FORMULA) == 0){
@@ -413,7 +423,7 @@ public class UtilExcel { @@ -413,7 +423,7 @@ public class UtilExcel {
413 423
414 public static void main(String args[]){ 424 public static void main(String args[]){
415 //String filepath = "C:\\Users\\root\\Desktop\\千丁-6.27.xlsx"; 425 //String filepath = "C:\\Users\\root\\Desktop\\千丁-6.27.xlsx";
416 - String filepath = "C:\\Users\\EDZ\\Desktop\\榴莲1 (5).xlsx"; 426 + String filepath = "C:\\Users\\EDZ\\Desktop\\qwer.xlsx";
417 List<List<Object>> data = null; 427 List<List<Object>> data = null;
418 try { 428 try {
419 data = UtilExcel.readExcel(filepath); 429 data = UtilExcel.readExcel(filepath);