Commit e109fb98a6f2474c2155bcdd00ce079a088c6d3b
1 parent
4a162f66
部分字段不做数字处理
Showing
1 changed file
with
6 additions
and
8 deletions
src/main/java/com/bsth/util/ReportUtils.java
| ... | ... | @@ -3,12 +3,7 @@ package com.bsth.util; |
| 3 | 3 | import java.io.File; |
| 4 | 4 | import java.io.FileInputStream; |
| 5 | 5 | import java.io.FileOutputStream; |
| 6 | -import java.util.ArrayList; | |
| 7 | -import java.util.HashMap; | |
| 8 | -import java.util.Iterator; | |
| 9 | -import java.util.List; | |
| 10 | -import java.util.Map; | |
| 11 | -import java.util.TreeMap; | |
| 6 | +import java.util.*; | |
| 12 | 7 | import java.util.regex.Matcher; |
| 13 | 8 | import java.util.regex.Pattern; |
| 14 | 9 | |
| ... | ... | @@ -36,6 +31,8 @@ public class ReportUtils { |
| 36 | 31 | |
| 37 | 32 | private final Pattern pattern = Pattern.compile("^\\d+(\\.\\d*)?$"); |
| 38 | 33 | |
| 34 | + private final String[] NaN={"jsy","sgh"}; | |
| 35 | + | |
| 39 | 36 | /** |
| 40 | 37 | * /** |
| 41 | 38 | * |
| ... | ... | @@ -515,6 +512,7 @@ public class ReportUtils { |
| 515 | 512 | // 保有存单元格的内容 |
| 516 | 513 | String cellValue = key = key.replace("\\n", ""); |
| 517 | 514 | String tmpKey; |
| 515 | + String fieldName = null; | |
| 518 | 516 | // 判断单元格内容是否是公式 |
| 519 | 517 | if(cell.getCellType() == HSSFCell.CELL_TYPE_FORMULA){ |
| 520 | 518 | Pattern p=Pattern.compile("(\\d+)"); // |
| ... | ... | @@ -538,7 +536,7 @@ public class ReportUtils { |
| 538 | 536 | String className = tmpKey.substring(0, tmpKey.indexOf(".")); |
| 539 | 537 | // 取得类的全限定名 |
| 540 | 538 | String classWholeName = packaegName + className; |
| 541 | - String fieldName = tmpKey.substring(tmpKey.indexOf(".") + 1); | |
| 539 | + fieldName = tmpKey.substring(tmpKey.indexOf(".") + 1); | |
| 542 | 540 | // 如果obj是数组,循环判断哪个对象是对应的 |
| 543 | 541 | if (obj instanceof Object[]) { |
| 544 | 542 | Object[] objs = (Object[]) obj; |
| ... | ... | @@ -563,7 +561,7 @@ public class ReportUtils { |
| 563 | 561 | } |
| 564 | 562 | cell.setCellValue(cellValue); |
| 565 | 563 | Matcher matcher = pattern.matcher(cellValue); |
| 566 | - if (matcher.matches()) { | |
| 564 | + if (matcher.matches()&&!Arrays.asList(NaN).contains(fieldName)) { | |
| 567 | 565 | if (cellValue.indexOf(".") > -1) { |
| 568 | 566 | cell.setCellValue(Double.parseDouble(cellValue)); |
| 569 | 567 | } else { | ... | ... |