Commit 8e63098a9503b0b6eabbf2344f3072f92fd85df1

Authored by yiming
1 parent de2c4e80

对不需要做数字处理的字段 以可变参数形式传入 不需要时不用传

src/main/java/com/bsth/controller/forms/ExportController.java
@@ -272,7 +272,7 @@ public class ExportController { @@ -272,7 +272,7 @@ public class ExportController {
272 listI.add(resList.iterator()); 272 listI.add(resList.iterator());
273 String path = this.getClass().getResource("/").getPath() + "static/pages/forms/"; 273 String path = this.getClass().getResource("/").getPath() + "static/pages/forms/";
274 ee.excelReplace(listI, new Object[] { map }, path + "mould/singledata.xls", 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 } catch (Exception e) { 276 } catch (Exception e) {
277 e.printStackTrace(); 277 e.printStackTrace();
278 } 278 }
src/main/java/com/bsth/util/ReportUtils.java
@@ -31,7 +31,6 @@ public class ReportUtils { @@ -31,7 +31,6 @@ public class ReportUtils {
31 31
32 private final Pattern pattern = Pattern.compile("^\\d+(\\.\\d*)?$"); 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,7 +47,7 @@ public class ReportUtils {
48 * 生成路径 47 * 生成路径
49 */ 48 */
50 public void excelReplace(List<Iterator<?>> list, Object[] tArray, 49 public void excelReplace(List<Iterator<?>> list, Object[] tArray,
51 - String sourcePath, String targetPath) { 50 + String sourcePath, String targetPath,String...NaN) {
52 try { 51 try {
53 // 把源文件放入流中 52 // 把源文件放入流中
54 POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream( 53 POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(
@@ -98,13 +97,13 @@ public class ReportUtils { @@ -98,13 +97,13 @@ public class ReportUtils {
98 Iterator<?> iterator = list.get(listIndex); 97 Iterator<?> iterator = list.get(listIndex);
99 // 根据模板创建行并填弃数据,返回增加的行数 98 // 根据模板创建行并填弃数据,返回增加的行数
100 int rowCount = iteratorFillCellValue(wb, sheet, 99 int rowCount = iteratorFillCellValue(wb, sheet,
101 - cell, iterator, i, rowNum, key); 100 + cell, iterator, i, rowNum, key,NaN);
102 rowNum += rowCount; 101 rowNum += rowCount;
103 i += rowCount; 102 i += rowCount;
104 break; 103 break;
105 } else { 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,9 +127,10 @@ public class ReportUtils {
128 * @param tArray 127 * @param tArray
129 * @param sourcePath 模板路径 128 * @param sourcePath 模板路径
130 * @param targetPath 生成路径 129 * @param targetPath 生成路径
  130 + * @param NaN 非数字参数(String[] 传入的key不做数字处理)
131 */ 131 */
132 public void excelMoreSheetReplace(List<List<Iterator<?>>> sheetList, Object[] tArray, 132 public void excelMoreSheetReplace(List<List<Iterator<?>>> sheetList, Object[] tArray,
133 - String sourcePath, String targetPath) { 133 + String sourcePath, String targetPath,String...NaN) {
134 try { 134 try {
135 // 把源文件放入流中 135 // 把源文件放入流中
136 POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream( 136 POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(
@@ -188,7 +188,7 @@ public class ReportUtils { @@ -188,7 +188,7 @@ public class ReportUtils {
188 break; 188 break;
189 } else { 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,11 +431,12 @@ public class ReportUtils {
431 * 表格总行数 431 * 表格总行数
432 * @param key 432 * @param key
433 * 表格内容 433 * 表格内容
  434 + * @param NaN 非数字参数(String[] 传入的key不做数字处理)
434 * @return 435 * @return
435 */ 436 */
436 private int iteratorFillCellValue(HSSFWorkbook wb, HSSFSheet sheet, 437 private int iteratorFillCellValue(HSSFWorkbook wb, HSSFSheet sheet,
437 HSSFCell cell, Iterator<?> iterator, int index, int rowNum, 438 HSSFCell cell, Iterator<?> iterator, int index, int rowNum,
438 - String key) { 439 + String key,String...NaN) {
439 int rowCount = 0; 440 int rowCount = 0;
440 Object obj = null; 441 Object obj = null;
441 int p = 0; 442 int p = 0;
@@ -486,7 +487,7 @@ public class ReportUtils { @@ -486,7 +487,7 @@ public class ReportUtils {
486 if (key.trim().indexOf(" ") != -1) { 487 if (key.trim().indexOf(" ") != -1) {
487 key = key.split(" ")[1]; 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 // list的数量 492 // list的数量
492 listIndex ++; 493 listIndex ++;
@@ -504,10 +505,11 @@ public class ReportUtils { @@ -504,10 +505,11 @@ public class ReportUtils {
504 * @param key 列内容 505 * @param key 列内容
505 * @param obj 数据源对象 506 * @param obj 数据源对象
506 * @param args 其他参数 数组 507 * @param args 其他参数 数组
  508 + * @param NaN 非数字参数(String[] 传入的key不做数字处理)
507 * 数组内容: 509 * 数组内容:
508 * 0位:在list中的第几条数据 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 try { 513 try {
512 // 保有存单元格的内容 514 // 保有存单元格的内容
513 String cellValue = key = key.replace("\\n", ""); 515 String cellValue = key = key.replace("\\n", "");
@@ -561,7 +563,7 @@ public class ReportUtils { @@ -561,7 +563,7 @@ public class ReportUtils {
561 } 563 }
562 cell.setCellValue(cellValue); 564 cell.setCellValue(cellValue);
563 Matcher matcher = pattern.matcher(cellValue); 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 if (cellValue.indexOf(".") > -1) { 567 if (cellValue.indexOf(".") > -1) {
566 cell.setCellValue(Double.parseDouble(cellValue)); 568 cell.setCellValue(Double.parseDouble(cellValue));
567 } else { 569 } else {