Commit 89401b411fd27b07dcfe19ae3f8b7a0e5000943a
Exists in
master
fix a bug
Showing
2 changed files
with
21 additions
and
19 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.76' | 62 | + version '1.1.82' |
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
@@ -2,6 +2,7 @@ package com.taover.util; | @@ -2,6 +2,7 @@ package com.taover.util; | ||
2 | 2 | ||
3 | import java.io.File; | 3 | import java.io.File; |
4 | import java.io.FileOutputStream; | 4 | import java.io.FileOutputStream; |
5 | +import java.math.BigDecimal; | ||
5 | import java.text.DecimalFormat; | 6 | import java.text.DecimalFormat; |
6 | import java.text.SimpleDateFormat; | 7 | import java.text.SimpleDateFormat; |
7 | import java.util.ArrayList; | 8 | import java.util.ArrayList; |
@@ -10,6 +11,7 @@ import java.util.HashMap; | @@ -10,6 +11,7 @@ import java.util.HashMap; | ||
10 | import java.util.List; | 11 | import java.util.List; |
11 | import java.util.Map; | 12 | import java.util.Map; |
12 | 13 | ||
14 | +import org.apache.poi.hssf.usermodel.HSSFDataFormatter; | ||
13 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; | 15 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
14 | import org.apache.poi.openxml4j.util.ZipSecureFile; | 16 | import org.apache.poi.openxml4j.util.ZipSecureFile; |
15 | import org.apache.poi.ss.usermodel.Cell; | 17 | import org.apache.poi.ss.usermodel.Cell; |
@@ -387,10 +389,6 @@ public class UtilExcel { | @@ -387,10 +389,6 @@ public class UtilExcel { | ||
387 | } | 389 | } |
388 | Workbook wb = UtilExcel.getWorkbook(filepath, true); | 390 | Workbook wb = UtilExcel.getWorkbook(filepath, true); |
389 | Sheet sheet = wb.getSheetAt(sheetIndex); | 391 | Sheet sheet = wb.getSheetAt(sheetIndex); |
390 | - int end = sheet.getLastRowNum(); | ||
391 | - if(end > UtilExcel.maxExcelRowNum){ | ||
392 | - //throw new Exception("目前系统只支持读取10000行以内记录,您当前Excel行数过大"); | ||
393 | - } | ||
394 | return readExcelBySheet(sheet, UtilExcel.maxExcelRowNum, false); | 392 | return readExcelBySheet(sheet, UtilExcel.maxExcelRowNum, false); |
395 | } | 393 | } |
396 | 394 | ||
@@ -400,11 +398,7 @@ public class UtilExcel { | @@ -400,11 +398,7 @@ public class UtilExcel { | ||
400 | 398 | ||
401 | private static List<List<Object>> readExcelBySheetIndex(Workbook wb, int sheetIndex, boolean hasRowLimit) throws Exception{ | 399 | private static List<List<Object>> readExcelBySheetIndex(Workbook wb, int sheetIndex, boolean hasRowLimit) throws Exception{ |
402 | Sheet sheet = wb.getSheetAt(sheetIndex); | 400 | Sheet sheet = wb.getSheetAt(sheetIndex); |
403 | - int end = sheet.getLastRowNum(); | ||
404 | if(hasRowLimit){ | 401 | if(hasRowLimit){ |
405 | - if(end > UtilExcel.maxExcelRowNum) { | ||
406 | - throw new Exception("目前系统只支持读取10000行以内记录,您当前Excel行数过大"); | ||
407 | - } | ||
408 | return readExcelBySheet(sheet, UtilExcel.maxExcelRowNum, false); | 402 | return readExcelBySheet(sheet, UtilExcel.maxExcelRowNum, false); |
409 | }else { | 403 | }else { |
410 | return readExcelBySheet(sheet, Integer.MAX_VALUE, false); | 404 | return readExcelBySheet(sheet, Integer.MAX_VALUE, false); |
@@ -459,13 +453,25 @@ public class UtilExcel { | @@ -459,13 +453,25 @@ public class UtilExcel { | ||
459 | if(currCellType.compareTo(CellType.STRING) == 0){ | 453 | if(currCellType.compareTo(CellType.STRING) == 0){ |
460 | return UtilString.trimCodePage(cell.getRichStringCellValue().getString()); | 454 | return UtilString.trimCodePage(cell.getRichStringCellValue().getString()); |
461 | }else if(currCellType.compareTo(CellType.NUMERIC) == 0){ | 455 | }else if(currCellType.compareTo(CellType.NUMERIC) == 0){ |
462 | - if (cell.getCellStyle().getDataFormat()==28||cell.getCellStyle().getDataFormat()==31 || cell.getCellStyle().getDataFormat() == 58) { | 456 | + |
457 | + /** | ||
458 | + * yyyy-MM-dd----- 14 | ||
459 | + yyyy年m月d日--- 31 | ||
460 | + yyyy年m月------- 57 | ||
461 | + m月d日 ---------- 58 | ||
462 | + HH:mm----------- 20 | ||
463 | + h时mm分 ------- 32 | ||
464 | + */ | ||
465 | + System.out.println(cell.getCellStyle().getDataFormat()); | ||
466 | + if (cell.getCellStyle().getDataFormat()==28||cell.getCellStyle().getDataFormat()==31 | ||
467 | + || cell.getCellStyle().getDataFormat() == 58 || cell.getCellStyle().getDataFormat()==14 | ||
468 | + || cell.getCellStyle().getDataFormat()==57 || cell.getCellStyle().getDataFormat()==32 || cell.getCellStyle().getDataFormat()==20) { | ||
463 | // 如果是date类型则 ,获取该cell的date值 | 469 | // 如果是date类型则 ,获取该cell的date值 |
464 | return new SimpleDateFormat("yyyy-MM-dd").format(DateUtil.getJavaDate(cell.getNumericCellValue())); | 470 | return new SimpleDateFormat("yyyy-MM-dd").format(DateUtil.getJavaDate(cell.getNumericCellValue())); |
465 | - } else { | ||
466 | - // 纯数字gaoming 新增兼容浮点型,转成字符串读取,不然小数点被省略了 | ||
467 | - cell.setCellType(CellType.STRING); | ||
468 | - return UtilString.trimCodePage(cell.getRichStringCellValue().getString()); | 471 | + } else { |
472 | + //gaoming 这个是poi自带获取value通用,如果再有问题就用这个试试!!! | ||
473 | + HSSFDataFormatter dataFormatter = new HSSFDataFormatter(); | ||
474 | + return dataFormatter.formatCellValue(cell); | ||
469 | } | 475 | } |
470 | }else if(currCellType.compareTo(CellType.BOOLEAN) == 0){ | 476 | }else if(currCellType.compareTo(CellType.BOOLEAN) == 0){ |
471 | return cell.getBooleanCellValue(); | 477 | return cell.getBooleanCellValue(); |
@@ -497,16 +503,12 @@ public class UtilExcel { | @@ -497,16 +503,12 @@ public class UtilExcel { | ||
497 | } | 503 | } |
498 | Workbook wb = UtilExcel.getWorkbook(filepath, true); | 504 | Workbook wb = UtilExcel.getWorkbook(filepath, true); |
499 | Sheet sheet = wb.getSheetAt(sheetIndex); | 505 | Sheet sheet = wb.getSheetAt(sheetIndex); |
500 | - int end = sheet.getLastRowNum(); | ||
501 | - if(end > UtilExcel.maxExcelRowNum){ | ||
502 | - throw new Exception("目前系统只支持读取10000行以内记录,您当前Excel行数过大"); | ||
503 | - } | ||
504 | return readExcelBySheet(sheet, UtilExcel.maxExcelRowNum, true); | 506 | return readExcelBySheet(sheet, UtilExcel.maxExcelRowNum, true); |
505 | } | 507 | } |
506 | 508 | ||
507 | public static void main(String args[]){ | 509 | public static void main(String args[]){ |
508 | //String filepath = "C:\\Users\\root\\Desktop\\千丁-6.27.xlsx"; | 510 | //String filepath = "C:\\Users\\root\\Desktop\\千丁-6.27.xlsx"; |
509 | - String filepath = "C:\\Users\\gaoming\\Desktop\\mmm.xlsx"; | 511 | + String filepath = "C:\\Users\\EDZ\\Desktop\\aaa.xlsx"; |
510 | List<List<Object>> data = null; | 512 | List<List<Object>> data = null; |
511 | 513 | ||
512 | try { | 514 | try { |