Commit 4ce30feac1fb81c746c9cd3776a4c076b742ce61

Authored by unknown
1 parent 44d8aa83
Exists in master

fix a bug about excel read

build.gradle
... ... @@ -59,7 +59,7 @@ uploadArchives {
59 59 authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD)
60 60 }
61 61 pom.project {
62   - version '1.1.92'
  62 + version '1.1.96'
63 63 artifactId ARTIFACT_Id
64 64 groupId GROUP_ID
65 65 packaging TYPE
... ...
src/main/java/com/taover/util/UtilExcel.java
... ... @@ -2,7 +2,6 @@ package com.taover.util;
2 2  
3 3 import java.io.File;
4 4 import java.io.FileOutputStream;
5   -import java.math.BigDecimal;
6 5 import java.text.DecimalFormat;
7 6 import java.text.SimpleDateFormat;
8 7 import java.util.ArrayList;
... ... @@ -11,13 +10,11 @@ import java.util.HashMap;
11 10 import java.util.List;
12 11 import java.util.Map;
13 12  
14   -import org.apache.poi.hssf.usermodel.HSSFDataFormatter;
15 13 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
16 14 import org.apache.poi.openxml4j.util.ZipSecureFile;
17 15 import org.apache.poi.ss.usermodel.Cell;
18 16 import org.apache.poi.ss.usermodel.CellStyle;
19 17 import org.apache.poi.ss.usermodel.CellType;
20   -import org.apache.poi.ss.usermodel.DateUtil;
21 18 import org.apache.poi.ss.usermodel.FillPatternType;
22 19 import org.apache.poi.ss.usermodel.Row;
23 20 import org.apache.poi.ss.usermodel.Sheet;
... ... @@ -416,7 +413,7 @@ public class UtilExcel {
416 413 if(end > rowLimit){
417 414 end = rowLimit;
418 415 }
419   - DecimalFormat df = new DecimalFormat("0");
  416 + DecimalFormat df = new DecimalFormat("0.#");
420 417 for(int i=start; i<end+1; ++i){
421 418 Row row = sheet.getRow(i);
422 419 if(row == null){
... ... @@ -485,9 +482,7 @@ public class UtilExcel {
485 482 Date date = org.apache.poi.ss.usermodel.DateUtil.getJavaDate(value);
486 483 return sdf.format(date);
487 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 488 }else if(currCellType.compareTo(CellType.BOOLEAN) == 0){
... ...
src/test/java/TempExcel.java
... ... @@ -15,13 +15,13 @@ public class TempExcel {
15 15 public static void checkExcelError() {
16 16 List<List<Object>> data = null;
17 17 try {
18   - data = UtilExcel.readExcelAllSheet("C:\\Users\\Administrator\\Desktop\\异常Excel\\大文件测试2.xlsx");
  18 + data = UtilExcel.readExcelAllSheet("C:\\Users\\Administrator\\Desktop\\1234.xls");
19 19 } catch (Exception e) {
20 20 e.printStackTrace();
21 21 }
22   - System.out.println("end");
  22 + System.out.println("end"+data.get(1).get(10));
23 23 //dealExcel();
24   - readExcel();
  24 + //readExcel();
25 25 }
26 26  
27 27 private static void readExcel() {
... ...