|
|
@@ -125,6 +125,8 @@ public class YakHerdInventoryExcelExporter
|
|
125
|
125
|
updateTitleYearMonth(sheet, statYear, statMonth);
|
|
126
|
126
|
updateFiller(sheet, fillerName);
|
|
127
|
127
|
int dataStartRow = headerRowIndex + 3;
|
|
|
128
|
+ CellStyle[] dataRowStyles = captureDataRowStyles(sheet, dataStartRow);
|
|
|
129
|
+ Float dataRowHeight = captureRowHeight(sheet, dataStartRow);
|
|
128
|
130
|
clearTemplateDataRegion(sheet, dataStartRow);
|
|
129
|
131
|
Totals totals = new Totals();
|
|
130
|
132
|
int rowIndex = dataStartRow;
|
|
|
@@ -142,6 +144,7 @@ public class YakHerdInventoryExcelExporter
|
|
142
|
144
|
setIntegerCell(row, COL_SEQ, seq++);
|
|
143
|
145
|
setStringCell(row, YakHerdInventoryExcelParser.COL_TOWN, inv.getTownName());
|
|
144
|
146
|
fillDataRow(row, inv);
|
|
|
147
|
+ applyDataRowStyles(row, dataRowStyles, dataRowHeight);
|
|
145
|
148
|
if (inv.getVillageDeptId() != null || inv.getYakTotal() != null || inv.getBullTotal() != null
|
|
146
|
149
|
|| inv.getCowTotal() != null || inv.getGrandTotal() != null)
|
|
147
|
150
|
{
|
|
|
@@ -153,8 +156,9 @@ public class YakHerdInventoryExcelExporter
|
|
153
|
156
|
Row totalRow = getOrCreateRow(sheet, rowIndex);
|
|
154
|
157
|
clearDataCells(totalRow);
|
|
155
|
158
|
setStringCell(totalRow, COL_SEQ, "合计");
|
|
156
|
|
- mergeTotalLabelCells(sheet, rowIndex);
|
|
157
|
159
|
totals.writeToRow(totalRow);
|
|
|
160
|
+ applyDataRowStyles(totalRow, dataRowStyles, dataRowHeight);
|
|
|
161
|
+ mergeTotalLabelCells(sheet, rowIndex);
|
|
158
|
162
|
removeRowsAfter(sheet, rowIndex);
|
|
159
|
163
|
workbook.write(out);
|
|
160
|
164
|
return out.toByteArray();
|
|
|
@@ -273,7 +277,8 @@ public class YakHerdInventoryExcelExporter
|
|
273
|
277
|
continue;
|
|
274
|
278
|
}
|
|
275
|
279
|
String text = formatter.formatCellValue(cell);
|
|
276
|
|
- if (StringUtils.isEmpty(text) || !text.contains("年") || text.contains("填表时间"))
|
|
|
280
|
+ // 跳过填表人/填表时间行,避免把占位年月改成统计年导致填表时间无法落到当月
|
|
|
281
|
+ if (StringUtils.isEmpty(text) || !text.contains("年") || isFillerMetaText(text))
|
|
277
|
282
|
{
|
|
278
|
283
|
continue;
|
|
279
|
284
|
}
|
|
|
@@ -292,11 +297,20 @@ public class YakHerdInventoryExcelExporter
|
|
292
|
297
|
{
|
|
293
|
298
|
updated = monthMatcher.replaceFirst("(" + statMonth + "月)");
|
|
294
|
299
|
}
|
|
|
300
|
+ else if (updated.contains("(X月)") || updated.contains("(X月)"))
|
|
|
301
|
+ {
|
|
|
302
|
+ updated = updated.replace("(X月)", "(" + statMonth + "月)").replace("(X月)", "(" + statMonth + "月)");
|
|
|
303
|
+ }
|
|
295
|
304
|
cell.setCellValue(updated);
|
|
296
|
305
|
}
|
|
297
|
306
|
}
|
|
298
|
307
|
}
|
|
299
|
308
|
|
|
|
309
|
+ private static boolean isFillerMetaText(String text)
|
|
|
310
|
+ {
|
|
|
311
|
+ return text.contains("填表人") || text.contains("填表时间");
|
|
|
312
|
+ }
|
|
|
313
|
+
|
|
300
|
314
|
/**
|
|
301
|
315
|
* 填写「填表人」与「填表时间」;填表时间固定为导出当日的当前年月。
|
|
302
|
316
|
*/
|
|
|
@@ -413,6 +427,61 @@ public class YakHerdInventoryExcelExporter
|
|
413
|
427
|
return row;
|
|
414
|
428
|
}
|
|
415
|
429
|
|
|
|
430
|
+ private static CellStyle[] captureDataRowStyles(Sheet sheet, int styleSourceRow)
|
|
|
431
|
+ {
|
|
|
432
|
+ CellStyle[] styles = new CellStyle[YakHerdInventoryExcelParser.COL_LAST + 1];
|
|
|
433
|
+ Row src = sheet.getRow(styleSourceRow);
|
|
|
434
|
+ if (src == null)
|
|
|
435
|
+ {
|
|
|
436
|
+ return styles;
|
|
|
437
|
+ }
|
|
|
438
|
+ for (int col = 0; col < styles.length; col++)
|
|
|
439
|
+ {
|
|
|
440
|
+ Cell cell = src.getCell(col);
|
|
|
441
|
+ if (cell != null)
|
|
|
442
|
+ {
|
|
|
443
|
+ styles[col] = cell.getCellStyle();
|
|
|
444
|
+ }
|
|
|
445
|
+ }
|
|
|
446
|
+ return styles;
|
|
|
447
|
+ }
|
|
|
448
|
+
|
|
|
449
|
+ private static Float captureRowHeight(Sheet sheet, int styleSourceRow)
|
|
|
450
|
+ {
|
|
|
451
|
+ Row src = sheet.getRow(styleSourceRow);
|
|
|
452
|
+ if (src == null)
|
|
|
453
|
+ {
|
|
|
454
|
+ return null;
|
|
|
455
|
+ }
|
|
|
456
|
+ return src.getHeightInPoints();
|
|
|
457
|
+ }
|
|
|
458
|
+
|
|
|
459
|
+ private static void applyDataRowStyles(Row row, CellStyle[] styles, Float rowHeight)
|
|
|
460
|
+ {
|
|
|
461
|
+ if (row == null || styles == null)
|
|
|
462
|
+ {
|
|
|
463
|
+ return;
|
|
|
464
|
+ }
|
|
|
465
|
+ if (rowHeight != null && rowHeight > 0)
|
|
|
466
|
+ {
|
|
|
467
|
+ row.setHeightInPoints(rowHeight);
|
|
|
468
|
+ }
|
|
|
469
|
+ for (int col = 0; col < styles.length; col++)
|
|
|
470
|
+ {
|
|
|
471
|
+ CellStyle style = styles[col];
|
|
|
472
|
+ if (style == null)
|
|
|
473
|
+ {
|
|
|
474
|
+ continue;
|
|
|
475
|
+ }
|
|
|
476
|
+ Cell cell = row.getCell(col);
|
|
|
477
|
+ if (cell == null)
|
|
|
478
|
+ {
|
|
|
479
|
+ cell = row.createCell(col);
|
|
|
480
|
+ }
|
|
|
481
|
+ cell.setCellStyle(style);
|
|
|
482
|
+ }
|
|
|
483
|
+ }
|
|
|
484
|
+
|
|
416
|
485
|
private static void fillDataRow(Row row, BizYakHerdInventory inv)
|
|
417
|
486
|
{
|
|
418
|
487
|
YakHerdInventoryValidation.recalculateDerived(inv);
|