Commit 8e63098a9503b0b6eabbf2344f3072f92fd85df1
1 parent
de2c4e80
对不需要做数字处理的字段 以可变参数形式传入 不需要时不用传
Showing
2 changed files
with
13 additions
and
11 deletions
src/main/java/com/bsth/controller/forms/ExportController.java
| ... | ... | @@ -272,7 +272,7 @@ public class ExportController { |
| 272 | 272 | listI.add(resList.iterator()); |
| 273 | 273 | String path = this.getClass().getResource("/").getPath() + "static/pages/forms/"; |
| 274 | 274 | ee.excelReplace(listI, new Object[] { map }, path + "mould/singledata.xls", |
| 275 | - path + "export/路单数据" + sdfSimple.format(sdfMonth.parse(map.get("startDate").toString())) + ".xls"); | |
| 275 | + path + "export/路单数据" + sdfSimple.format(sdfMonth.parse(map.get("startDate").toString())) + ".xls",new String[]{"jsy","sgh"}); | |
| 276 | 276 | } catch (Exception e) { |
| 277 | 277 | e.printStackTrace(); |
| 278 | 278 | } | ... | ... |
src/main/java/com/bsth/util/ReportUtils.java
| ... | ... | @@ -31,7 +31,6 @@ public class ReportUtils { |
| 31 | 31 | |
| 32 | 32 | private final Pattern pattern = Pattern.compile("^\\d+(\\.\\d*)?$"); |
| 33 | 33 | |
| 34 | - private final String[] NaN={"jsy","sgh"}; | |
| 35 | 34 | |
| 36 | 35 | /** |
| 37 | 36 | * /** |
| ... | ... | @@ -48,7 +47,7 @@ public class ReportUtils { |
| 48 | 47 | * 生成路径 |
| 49 | 48 | */ |
| 50 | 49 | public void excelReplace(List<Iterator<?>> list, Object[] tArray, |
| 51 | - String sourcePath, String targetPath) { | |
| 50 | + String sourcePath, String targetPath,String...NaN) { | |
| 52 | 51 | try { |
| 53 | 52 | // 把源文件放入流中 |
| 54 | 53 | POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream( |
| ... | ... | @@ -98,13 +97,13 @@ public class ReportUtils { |
| 98 | 97 | Iterator<?> iterator = list.get(listIndex); |
| 99 | 98 | // 根据模板创建行并填弃数据,返回增加的行数 |
| 100 | 99 | int rowCount = iteratorFillCellValue(wb, sheet, |
| 101 | - cell, iterator, i, rowNum, key); | |
| 100 | + cell, iterator, i, rowNum, key,NaN); | |
| 102 | 101 | rowNum += rowCount; |
| 103 | 102 | i += rowCount; |
| 104 | 103 | break; |
| 105 | 104 | } else { |
| 106 | 105 | // 直接填充数据的列,从对象数组中取得值,这里的数组不传值 |
| 107 | - getValueAndSetCellValue(cell, key, tArray, new String[]{""}); | |
| 106 | + getValueAndSetCellValue(cell, key, tArray, new String[]{""},NaN); | |
| 108 | 107 | } |
| 109 | 108 | } |
| 110 | 109 | |
| ... | ... | @@ -128,9 +127,10 @@ public class ReportUtils { |
| 128 | 127 | * @param tArray |
| 129 | 128 | * @param sourcePath 模板路径 |
| 130 | 129 | * @param targetPath 生成路径 |
| 130 | + * @param NaN 非数字参数(String[] 传入的key不做数字处理) | |
| 131 | 131 | */ |
| 132 | 132 | public void excelMoreSheetReplace(List<List<Iterator<?>>> sheetList, Object[] tArray, |
| 133 | - String sourcePath, String targetPath) { | |
| 133 | + String sourcePath, String targetPath,String...NaN) { | |
| 134 | 134 | try { |
| 135 | 135 | // 把源文件放入流中 |
| 136 | 136 | POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream( |
| ... | ... | @@ -188,7 +188,7 @@ public class ReportUtils { |
| 188 | 188 | break; |
| 189 | 189 | } else { |
| 190 | 190 | // 直接填充数据的列,从对象数组中取得值,这里的数组不传值 |
| 191 | - getValueAndSetCellValue(cell, key, tArray, new String[]{""}); | |
| 191 | + getValueAndSetCellValue(cell, key, tArray, new String[]{""},NaN); | |
| 192 | 192 | } |
| 193 | 193 | } |
| 194 | 194 | |
| ... | ... | @@ -431,11 +431,12 @@ public class ReportUtils { |
| 431 | 431 | * 表格总行数 |
| 432 | 432 | * @param key |
| 433 | 433 | * 表格内容 |
| 434 | + * @param NaN 非数字参数(String[] 传入的key不做数字处理) | |
| 434 | 435 | * @return |
| 435 | 436 | */ |
| 436 | 437 | private int iteratorFillCellValue(HSSFWorkbook wb, HSSFSheet sheet, |
| 437 | 438 | HSSFCell cell, Iterator<?> iterator, int index, int rowNum, |
| 438 | - String key) { | |
| 439 | + String key,String...NaN) { | |
| 439 | 440 | int rowCount = 0; |
| 440 | 441 | Object obj = null; |
| 441 | 442 | int p = 0; |
| ... | ... | @@ -486,7 +487,7 @@ public class ReportUtils { |
| 486 | 487 | if (key.trim().indexOf(" ") != -1) { |
| 487 | 488 | key = key.split(" ")[1]; |
| 488 | 489 | } |
| 489 | - getValueAndSetCellValue(cell, key, obj,new String[]{listIndex+""}); | |
| 490 | + getValueAndSetCellValue(cell, key, obj,new String[]{listIndex+""},NaN); | |
| 490 | 491 | } |
| 491 | 492 | // list的数量 |
| 492 | 493 | listIndex ++; |
| ... | ... | @@ -504,10 +505,11 @@ public class ReportUtils { |
| 504 | 505 | * @param key 列内容 |
| 505 | 506 | * @param obj 数据源对象 |
| 506 | 507 | * @param args 其他参数 数组 |
| 508 | + * @param NaN 非数字参数(String[] 传入的key不做数字处理) | |
| 507 | 509 | * 数组内容: |
| 508 | 510 | * 0位:在list中的第几条数据 |
| 509 | 511 | */ |
| 510 | - private void getValueAndSetCellValue(HSSFCell cell, String key, Object obj, String[] args) { | |
| 512 | + private void getValueAndSetCellValue(HSSFCell cell, String key, Object obj, String[] args,String...NaN) { | |
| 511 | 513 | try { |
| 512 | 514 | // 保有存单元格的内容 |
| 513 | 515 | String cellValue = key = key.replace("\\n", ""); |
| ... | ... | @@ -561,7 +563,7 @@ public class ReportUtils { |
| 561 | 563 | } |
| 562 | 564 | cell.setCellValue(cellValue); |
| 563 | 565 | Matcher matcher = pattern.matcher(cellValue); |
| 564 | - if (matcher.matches()&&!Arrays.asList(NaN).contains(fieldName)) { | |
| 566 | + if (matcher.matches() && !Arrays.asList(NaN).contains(fieldName)) { | |
| 565 | 567 | if (cellValue.indexOf(".") > -1) { |
| 566 | 568 | cell.setCellValue(Double.parseDouble(cellValue)); |
| 567 | 569 | } else { | ... | ... |