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,12 +3,7 @@ package com.bsth.util; | ||
| 3 | import java.io.File; | 3 | import java.io.File; |
| 4 | import java.io.FileInputStream; | 4 | import java.io.FileInputStream; |
| 5 | import java.io.FileOutputStream; | 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 | import java.util.regex.Matcher; | 7 | import java.util.regex.Matcher; |
| 13 | import java.util.regex.Pattern; | 8 | import java.util.regex.Pattern; |
| 14 | 9 | ||
| @@ -36,6 +31,8 @@ public class ReportUtils { | @@ -36,6 +31,8 @@ public class ReportUtils { | ||
| 36 | 31 | ||
| 37 | private final Pattern pattern = Pattern.compile("^\\d+(\\.\\d*)?$"); | 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,6 +512,7 @@ public class ReportUtils { | ||
| 515 | // 保有存单元格的内容 | 512 | // 保有存单元格的内容 |
| 516 | String cellValue = key = key.replace("\\n", ""); | 513 | String cellValue = key = key.replace("\\n", ""); |
| 517 | String tmpKey; | 514 | String tmpKey; |
| 515 | + String fieldName = null; | ||
| 518 | // 判断单元格内容是否是公式 | 516 | // 判断单元格内容是否是公式 |
| 519 | if(cell.getCellType() == HSSFCell.CELL_TYPE_FORMULA){ | 517 | if(cell.getCellType() == HSSFCell.CELL_TYPE_FORMULA){ |
| 520 | Pattern p=Pattern.compile("(\\d+)"); // | 518 | Pattern p=Pattern.compile("(\\d+)"); // |
| @@ -538,7 +536,7 @@ public class ReportUtils { | @@ -538,7 +536,7 @@ public class ReportUtils { | ||
| 538 | String className = tmpKey.substring(0, tmpKey.indexOf(".")); | 536 | String className = tmpKey.substring(0, tmpKey.indexOf(".")); |
| 539 | // 取得类的全限定名 | 537 | // 取得类的全限定名 |
| 540 | String classWholeName = packaegName + className; | 538 | String classWholeName = packaegName + className; |
| 541 | - String fieldName = tmpKey.substring(tmpKey.indexOf(".") + 1); | 539 | + fieldName = tmpKey.substring(tmpKey.indexOf(".") + 1); |
| 542 | // 如果obj是数组,循环判断哪个对象是对应的 | 540 | // 如果obj是数组,循环判断哪个对象是对应的 |
| 543 | if (obj instanceof Object[]) { | 541 | if (obj instanceof Object[]) { |
| 544 | Object[] objs = (Object[]) obj; | 542 | Object[] objs = (Object[]) obj; |
| @@ -563,7 +561,7 @@ public class ReportUtils { | @@ -563,7 +561,7 @@ public class ReportUtils { | ||
| 563 | } | 561 | } |
| 564 | cell.setCellValue(cellValue); | 562 | cell.setCellValue(cellValue); |
| 565 | Matcher matcher = pattern.matcher(cellValue); | 563 | Matcher matcher = pattern.matcher(cellValue); |
| 566 | - if (matcher.matches()) { | 564 | + if (matcher.matches()&&!Arrays.asList(NaN).contains(fieldName)) { |
| 567 | if (cellValue.indexOf(".") > -1) { | 565 | if (cellValue.indexOf(".") > -1) { |
| 568 | cell.setCellValue(Double.parseDouble(cellValue)); | 566 | cell.setCellValue(Double.parseDouble(cellValue)); |
| 569 | } else { | 567 | } else { |