Commit 005d3462658c53724076bb3c864258ee63cfa6be
Exists in
master
Merge branch 'master' of gitlab.taover.com:taov-erp/com-taover-util
Showing
2 changed files
with
38 additions
and
10 deletions
Show diff stats
build.gradle
src/main/java/com/taover/util/UtilExcel.java
| ... | ... | @@ -461,18 +461,35 @@ public class UtilExcel { |
| 461 | 461 | m月d日 ---------- 58 |
| 462 | 462 | HH:mm----------- 20 |
| 463 | 463 | h时mm分 ------- 32 |
| 464 | + yyyy-MM-dd HH:hh:ss 22 | |
| 464 | 465 | */ |
| 465 | 466 | System.out.println(cell.getCellStyle().getDataFormat()); |
| 466 | - if (cell.getCellStyle().getDataFormat()==28||cell.getCellStyle().getDataFormat()==31 | |
| 467 | + short format = cell.getCellStyle().getDataFormat(); | |
| 468 | + if (cell.getCellStyle().getDataFormat()==28 || cell.getCellStyle().getDataFormat()==22||cell.getCellStyle().getDataFormat()==31 | |
| 467 | 469 | || cell.getCellStyle().getDataFormat() == 58 || cell.getCellStyle().getDataFormat()==14 |
| 468 | 470 | || cell.getCellStyle().getDataFormat()==57 || cell.getCellStyle().getDataFormat()==32 || cell.getCellStyle().getDataFormat()==20) { |
| 469 | - // 如果是date类型则 ,获取该cell的date值 | |
| 470 | - return new SimpleDateFormat("yyyy-MM-dd").format(DateUtil.getJavaDate(cell.getNumericCellValue())); | |
| 471 | + | |
| 472 | + // 如果是date类型则 ,获取该cell的date值 | |
| 473 | + //return new SimpleDateFormat("yyyy-MM-dd").format(DateUtil.getJavaDate(cell.getNumericCellValue())); | |
| 474 | + SimpleDateFormat sdf = null; | |
| 475 | + if(format == 14 || format == 31 || format == 57 || format == 58){ | |
| 476 | + //日期 | |
| 477 | + sdf = new SimpleDateFormat("yyyy-MM-dd"); | |
| 478 | + }else if (format == 20 || format == 32) { | |
| 479 | + //时间 | |
| 480 | + sdf = new SimpleDateFormat("HH:mm"); | |
| 481 | + }else { | |
| 482 | + sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
| 483 | + } | |
| 484 | + double value = cell.getNumericCellValue(); | |
| 485 | + Date date = org.apache.poi.ss.usermodel.DateUtil.getJavaDate(value); | |
| 486 | + return sdf.format(date); | |
| 471 | 487 | } else { |
| 472 | - //gaoming 这个是poi自带获取value通用,如果再有问题就用这个试试!!! | |
| 488 | + //gaoming 这个是poi自带获取value通用,如果再有问题就用这个试试!!!此处用于获取纯数字和小数类型 | |
| 473 | 489 | HSSFDataFormatter dataFormatter = new HSSFDataFormatter(); |
| 474 | - return dataFormatter.formatCellValue(cell); | |
| 490 | + return dataFormatter.formatCellValue(cell); | |
| 475 | 491 | } |
| 492 | + | |
| 476 | 493 | }else if(currCellType.compareTo(CellType.BOOLEAN) == 0){ |
| 477 | 494 | return cell.getBooleanCellValue(); |
| 478 | 495 | }else if(currCellType.compareTo(CellType.FORMULA) == 0){ |
| ... | ... | @@ -508,16 +525,27 @@ public class UtilExcel { |
| 508 | 525 | |
| 509 | 526 | public static void main(String args[]){ |
| 510 | 527 | //String filepath = "C:\\Users\\root\\Desktop\\千丁-6.27.xlsx"; |
| 511 | - String filepath = "C:\\Users\\EDZ\\Desktop\\aaa.xlsx"; | |
| 528 | + String filepath = "C:\\Users\\gaoming\\Desktop\\测试返单数量.xlsx"; | |
| 529 | + //String filepath = "C:\\Users\\EDZ\\Desktop\\aaa.xlsx"; | |
| 512 | 530 | List<List<Object>> data = null; |
| 513 | 531 | |
| 514 | 532 | try { |
| 533 | + long start = System.currentTimeMillis(); | |
| 534 | + System.out.println(start); | |
| 515 | 535 | Map<String, List<List<Object>>> map = UtilExcel.readExcelAllSheetMap(filepath); |
| 516 | - System.out.println(map); | |
| 536 | + long end = System.currentTimeMillis(); | |
| 537 | + System.out.println(end); | |
| 538 | + System.out.println((end-start)/1000); | |
| 539 | + | |
| 540 | + | |
| 541 | + //System.out.println(map); | |
| 517 | 542 | data = map.get("0"); |
| 518 | 543 | System.out.println(data); |
| 519 | - System.out.println(data.size()); | |
| 520 | - System.out.println(UtilExcel.readExcelAllSheetMap(filepath)); | |
| 544 | + for (int i = 0; i < data.size(); i++) { | |
| 545 | + System.out.println(data.get(i).get(1)); | |
| 546 | + } | |
| 547 | +// System.out.println(data.size()); | |
| 548 | +// System.out.println(UtilExcel.readExcelAllSheetMap(filepath)); | |
| 521 | 549 | } catch (Exception e) { |
| 522 | 550 | // TODO Auto-generated catch block |
| 523 | 551 | e.printStackTrace(); | ... | ... |