Commit 5349d0134e7f4d191ad693147fc1ea0a89726507

Authored by gaoming
1 parent cb385326
Exists in master

.

Showing 1 changed file with 46 additions and 43 deletions   Show diff stats
src/main/java/com/taover/util/UtilExcel.java
@@ -462,8 +462,9 @@ public class UtilExcel { @@ -462,8 +462,9 @@ public class UtilExcel {
462 // 如果是date类型则 ,获取该cell的date值 462 // 如果是date类型则 ,获取该cell的date值
463 return new SimpleDateFormat("yyyy-MM-dd").format(DateUtil.getJavaDate(cell.getNumericCellValue())); 463 return new SimpleDateFormat("yyyy-MM-dd").format(DateUtil.getJavaDate(cell.getNumericCellValue()));
464 } else { 464 } else {
465 - // 纯数字  
466 - return df.format(cell.getNumericCellValue()); 465 + // 纯数字gaoming 新增兼容浮点型,转成字符串读取,不然小数点被省略了
  466 + cell.setCellType(CellType.STRING);
  467 + return UtilString.trimCodePage(cell.getRichStringCellValue().getString());
467 } 468 }
468 }else if(currCellType.compareTo(CellType.BOOLEAN) == 0){ 469 }else if(currCellType.compareTo(CellType.BOOLEAN) == 0){
469 return cell.getBooleanCellValue(); 470 return cell.getBooleanCellValue();
@@ -504,19 +505,21 @@ public class UtilExcel { @@ -504,19 +505,21 @@ public class UtilExcel {
504 505
505 public static void main(String args[]){ 506 public static void main(String args[]){
506 //String filepath = "C:\\Users\\root\\Desktop\\千丁-6.27.xlsx"; 507 //String filepath = "C:\\Users\\root\\Desktop\\千丁-6.27.xlsx";
507 -// String filepath = "C:\\Users\\gaoming\\Desktop\\qwer.xls";  
508 -// List<List<Object>> data = null;  
509 -//  
510 -// try {  
511 -// data = UtilExcel.readExcelAllSheetMap(filepath).get("0");  
512 -// System.out.println(data);  
513 -// System.out.println(data.size());  
514 -// System.out.println(UtilExcel.readExcelAllSheetMap(filepath));  
515 -// } catch (Exception e) {  
516 -// // TODO Auto-generated catch block  
517 -// e.printStackTrace();  
518 -// }  
519 -// List<Short> styleList = new ArrayList<Short>(); 508 + String filepath = "C:\\Users\\gaoming\\Desktop\\mmm.xlsx";
  509 + List<List<Object>> data = null;
  510 +
  511 + try {
  512 + Map<String, List<List<Object>>> map = UtilExcel.readExcelAllSheetMap(filepath);
  513 + System.out.println(map);
  514 + data = map.get("0");
  515 + System.out.println(data);
  516 + System.out.println(data.size());
  517 + System.out.println(UtilExcel.readExcelAllSheetMap(filepath));
  518 + } catch (Exception e) {
  519 + // TODO Auto-generated catch block
  520 + e.printStackTrace();
  521 + }
  522 + List<Short> styleList = new ArrayList<Short>();
520 // for(int i=0; i<data.size(); ++i){ 523 // for(int i=0; i<data.size(); ++i){
521 // if(i == 1)styleList.add(Short.valueOf(HSSFColor.RED.index)); 524 // if(i == 1)styleList.add(Short.valueOf(HSSFColor.RED.index));
522 // else styleList.add(null); 525 // else styleList.add(null);
@@ -525,33 +528,33 @@ public class UtilExcel { @@ -525,33 +528,33 @@ public class UtilExcel {
525 // } 528 // }
526 // System.out.println(""); 529 // System.out.println("");
527 // } 530 // }
528 - try {  
529 - List<String> headerList = new ArrayList<String>();  
530 - headerList.add("shhe1");  
531 - headerList.add("shhe2");  
532 - List<List<List<Object>>> dataList = new ArrayList<List<List<Object>>>();  
533 - List<List<Object>> list1 = new ArrayList<List<Object>>();  
534 - List<Object> list11 = new ArrayList<Object>();  
535 - list11.add("hahaha");  
536 - list11.add("hahaha");  
537 - list11.add("hahaha");  
538 - list1.add(list11);  
539 -  
540 - List<List<Object>> list2 = new ArrayList<List<Object>>();  
541 - List<Object> list22 = new ArrayList<Object>();  
542 - list22.add("hahaha2");  
543 - list22.add("hahaha2");  
544 - list22.add("hahaha2");  
545 - list2.add(list22);  
546 - list2.add(list22);  
547 -  
548 - dataList.add(list1);  
549 - dataList.add(list2);  
550 -  
551 - UtilExcel.saveExcelContailSheet(headerList, dataList, "C:\\Users\\gaoming\\Desktop\\qwer.xls");  
552 - } catch (Exception e) {  
553 - // TODO Auto-generated catch block  
554 - e.printStackTrace();  
555 - } 531 +// try {
  532 +// List<String> headerList = new ArrayList<String>();
  533 +// headerList.add("shhe1");
  534 +// headerList.add("shhe2");
  535 +// List<List<List<Object>>> dataList = new ArrayList<List<List<Object>>>();
  536 +// List<List<Object>> list1 = new ArrayList<List<Object>>();
  537 +// List<Object> list11 = new ArrayList<Object>();
  538 +// list11.add("hahaha");
  539 +// list11.add("hahaha");
  540 +// list11.add("hahaha");
  541 +// list1.add(list11);
  542 +//
  543 +// List<List<Object>> list2 = new ArrayList<List<Object>>();
  544 +// List<Object> list22 = new ArrayList<Object>();
  545 +// list22.add("hahaha2");
  546 +// list22.add("hahaha2");
  547 +// list22.add("hahaha2");
  548 +// list2.add(list22);
  549 +// list2.add(list22);
  550 +//
  551 +// dataList.add(list1);
  552 +// dataList.add(list2);
  553 +//
  554 +// UtilExcel.saveExcelContailSheet(headerList, dataList, "C:\\Users\\gaoming\\Desktop\\qwer.xls");
  555 +// } catch (Exception e) {
  556 +// // TODO Auto-generated catch block
  557 +// e.printStackTrace();
  558 +// }
556 } 559 }
557 } 560 }