Commit 4ce30feac1fb81c746c9cd3776a4c076b742ce61
1 parent
44d8aa83
Exists in
master
fix a bug about excel read
Showing
3 changed files
with
6 additions
and
11 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.92' | 62 | + version '1.1.96' |
| 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,7 +2,6 @@ package com.taover.util; | @@ -2,7 +2,6 @@ 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; | ||
| 6 | import java.text.DecimalFormat; | 5 | import java.text.DecimalFormat; |
| 7 | import java.text.SimpleDateFormat; | 6 | import java.text.SimpleDateFormat; |
| 8 | import java.util.ArrayList; | 7 | import java.util.ArrayList; |
| @@ -11,13 +10,11 @@ import java.util.HashMap; | @@ -11,13 +10,11 @@ import java.util.HashMap; | ||
| 11 | import java.util.List; | 10 | import java.util.List; |
| 12 | import java.util.Map; | 11 | import java.util.Map; |
| 13 | 12 | ||
| 14 | -import org.apache.poi.hssf.usermodel.HSSFDataFormatter; | ||
| 15 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; | 13 | import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
| 16 | import org.apache.poi.openxml4j.util.ZipSecureFile; | 14 | import org.apache.poi.openxml4j.util.ZipSecureFile; |
| 17 | import org.apache.poi.ss.usermodel.Cell; | 15 | import org.apache.poi.ss.usermodel.Cell; |
| 18 | import org.apache.poi.ss.usermodel.CellStyle; | 16 | import org.apache.poi.ss.usermodel.CellStyle; |
| 19 | import org.apache.poi.ss.usermodel.CellType; | 17 | import org.apache.poi.ss.usermodel.CellType; |
| 20 | -import org.apache.poi.ss.usermodel.DateUtil; | ||
| 21 | import org.apache.poi.ss.usermodel.FillPatternType; | 18 | import org.apache.poi.ss.usermodel.FillPatternType; |
| 22 | import org.apache.poi.ss.usermodel.Row; | 19 | import org.apache.poi.ss.usermodel.Row; |
| 23 | import org.apache.poi.ss.usermodel.Sheet; | 20 | import org.apache.poi.ss.usermodel.Sheet; |
| @@ -416,7 +413,7 @@ public class UtilExcel { | @@ -416,7 +413,7 @@ public class UtilExcel { | ||
| 416 | if(end > rowLimit){ | 413 | if(end > rowLimit){ |
| 417 | end = rowLimit; | 414 | end = rowLimit; |
| 418 | } | 415 | } |
| 419 | - DecimalFormat df = new DecimalFormat("0"); | 416 | + DecimalFormat df = new DecimalFormat("0.#"); |
| 420 | for(int i=start; i<end+1; ++i){ | 417 | for(int i=start; i<end+1; ++i){ |
| 421 | Row row = sheet.getRow(i); | 418 | Row row = sheet.getRow(i); |
| 422 | if(row == null){ | 419 | if(row == null){ |
| @@ -485,9 +482,7 @@ public class UtilExcel { | @@ -485,9 +482,7 @@ public class UtilExcel { | ||
| 485 | Date date = org.apache.poi.ss.usermodel.DateUtil.getJavaDate(value); | 482 | Date date = org.apache.poi.ss.usermodel.DateUtil.getJavaDate(value); |
| 486 | return sdf.format(date); | 483 | return sdf.format(date); |
| 487 | } else { | 484 | } else { |
| 488 | - //gaoming 这个是poi自带获取value通用,如果再有问题就用这个试试!!!此处用于获取纯数字和小数类型 | ||
| 489 | - HSSFDataFormatter dataFormatter = new HSSFDataFormatter(); | ||
| 490 | - return dataFormatter.formatCellValue(cell); | 485 | + return df.format(cell.getNumericCellValue()); |
| 491 | } | 486 | } |
| 492 | 487 | ||
| 493 | }else if(currCellType.compareTo(CellType.BOOLEAN) == 0){ | 488 | }else if(currCellType.compareTo(CellType.BOOLEAN) == 0){ |
src/test/java/TempExcel.java
| @@ -15,13 +15,13 @@ public class TempExcel { | @@ -15,13 +15,13 @@ public class TempExcel { | ||
| 15 | public static void checkExcelError() { | 15 | public static void checkExcelError() { |
| 16 | List<List<Object>> data = null; | 16 | List<List<Object>> data = null; |
| 17 | try { | 17 | try { |
| 18 | - data = UtilExcel.readExcelAllSheet("C:\\Users\\Administrator\\Desktop\\异常Excel\\大文件测试2.xlsx"); | 18 | + data = UtilExcel.readExcelAllSheet("C:\\Users\\Administrator\\Desktop\\1234.xls"); |
| 19 | } catch (Exception e) { | 19 | } catch (Exception e) { |
| 20 | e.printStackTrace(); | 20 | e.printStackTrace(); |
| 21 | } | 21 | } |
| 22 | - System.out.println("end"); | 22 | + System.out.println("end"+data.get(1).get(10)); |
| 23 | //dealExcel(); | 23 | //dealExcel(); |
| 24 | - readExcel(); | 24 | + //readExcel(); |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | private static void readExcel() { | 27 | private static void readExcel() { |