|
|
@@ -78,6 +78,8 @@ public class LivestockOwnershipHouseholdExcelExporter
|
|
78
|
78
|
updateTitleYearMonth(sheet, statYear, statMonth);
|
|
79
|
79
|
updateFiller(sheet, fillerName);
|
|
80
|
80
|
int dataStartRow = headerRowIndex + 2;
|
|
|
81
|
+ CellStyle[] dataRowStyles = captureDataRowStyles(sheet, dataStartRow);
|
|
|
82
|
+ Float dataRowHeight = captureRowHeight(sheet, dataStartRow);
|
|
81
|
83
|
clearTemplateDataRegion(sheet, dataStartRow);
|
|
82
|
84
|
Totals totals = new Totals();
|
|
83
|
85
|
int rowIndex = dataStartRow;
|
|
|
@@ -95,6 +97,7 @@ public class LivestockOwnershipHouseholdExcelExporter
|
|
95
|
97
|
setIntegerCell(row, LivestockOwnershipHouseholdExcelParser.COL_SEQ, seq++);
|
|
96
|
98
|
setStringCell(row, LivestockOwnershipHouseholdExcelParser.COL_TOWN, report.getTownName());
|
|
97
|
99
|
fillDataRow(row, report);
|
|
|
100
|
+ applyDataRowStyles(row, dataRowStyles, dataRowHeight);
|
|
98
|
101
|
totals.add(report);
|
|
99
|
102
|
rowIndex++;
|
|
100
|
103
|
}
|
|
|
@@ -102,8 +105,9 @@ public class LivestockOwnershipHouseholdExcelExporter
|
|
102
|
105
|
Row totalRow = getOrCreateRow(sheet, rowIndex);
|
|
103
|
106
|
clearDataCells(totalRow);
|
|
104
|
107
|
setStringCell(totalRow, LivestockOwnershipHouseholdExcelParser.COL_SEQ, "合计");
|
|
105
|
|
- mergeTotalLabelCells(sheet, rowIndex);
|
|
106
|
108
|
totals.writeToRow(totalRow);
|
|
|
109
|
+ applyDataRowStyles(totalRow, dataRowStyles, dataRowHeight);
|
|
|
110
|
+ mergeTotalLabelCells(sheet, rowIndex);
|
|
107
|
111
|
removeRowsAfter(sheet, rowIndex);
|
|
108
|
112
|
workbook.write(out);
|
|
109
|
113
|
return out.toByteArray();
|
|
|
@@ -186,7 +190,8 @@ public class LivestockOwnershipHouseholdExcelExporter
|
|
186
|
190
|
continue;
|
|
187
|
191
|
}
|
|
188
|
192
|
String text = formatter.formatCellValue(cell);
|
|
189
|
|
- if (StringUtils.isEmpty(text) || !text.contains("年"))
|
|
|
193
|
+ // 跳过填表人/填表时间行,避免把「XXXX年X月」先改成统计年导致填表日期无法落到当月
|
|
|
194
|
+ if (StringUtils.isEmpty(text) || !text.contains("年") || isFillerMetaText(text))
|
|
190
|
195
|
{
|
|
191
|
196
|
continue;
|
|
192
|
197
|
}
|
|
|
@@ -210,6 +215,9 @@ public class LivestockOwnershipHouseholdExcelExporter
|
|
210
|
215
|
}
|
|
211
|
216
|
}
|
|
212
|
217
|
|
|
|
218
|
+ /**
|
|
|
219
|
+ * 将填表人、填表时间/日期写为当前登录用户与<strong>系统当月</strong>(非导出统计年月)。
|
|
|
220
|
+ */
|
|
213
|
221
|
static void updateFiller(Sheet sheet, String fillerName)
|
|
214
|
222
|
{
|
|
215
|
223
|
java.time.LocalDate today = java.time.LocalDate.now();
|
|
|
@@ -236,7 +244,7 @@ public class LivestockOwnershipHouseholdExcelExporter
|
|
236
|
244
|
continue;
|
|
237
|
245
|
}
|
|
238
|
246
|
String text = formatter.formatCellValue(cell);
|
|
239
|
|
- if (StringUtils.isEmpty(text) || (!text.contains("填表人") && !text.contains("填表时间")))
|
|
|
247
|
+ if (StringUtils.isEmpty(text) || !isFillerMetaText(text))
|
|
240
|
248
|
{
|
|
241
|
249
|
continue;
|
|
242
|
250
|
}
|
|
|
@@ -245,9 +253,12 @@ public class LivestockOwnershipHouseholdExcelExporter
|
|
245
|
253
|
{
|
|
246
|
254
|
updated = updated.replace("登录用户名称", fillerName);
|
|
247
|
255
|
}
|
|
248
|
|
- updated = updated.replaceAll("填表时间:\\s*XXXX年X月", "填表时间:" + fillTime);
|
|
249
|
|
- updated = updated.replaceAll("填表时间:\\s*\\d{4}年\\d{1,2}月", "填表时间:" + fillTime);
|
|
250
|
|
- if (updated.contains("XXXX年") && updated.contains("填表时间"))
|
|
|
256
|
+ // 兼容「填表时间」「填表日期」及占位 XXXX年X月 / 已被误替换的 yyyy年X月
|
|
|
257
|
+ updated = updated.replaceAll("(填表时间|填表日期):\\s*XXXX年X月", "$1:" + fillTime);
|
|
|
258
|
+ updated = updated.replaceAll("(填表时间|填表日期):\\s*\\d{4}年X月", "$1:" + fillTime);
|
|
|
259
|
+ updated = updated.replaceAll("(填表时间|填表日期):\\s*\\d{4}年\\d{1,2}月", "$1:" + fillTime);
|
|
|
260
|
+ if (updated.contains("XXXX年")
|
|
|
261
|
+ && (updated.contains("填表时间") || updated.contains("填表日期")))
|
|
251
|
262
|
{
|
|
252
|
263
|
updated = updated.replaceFirst("XXXX年X?月?", fillTime);
|
|
253
|
264
|
}
|
|
|
@@ -256,6 +267,66 @@ public class LivestockOwnershipHouseholdExcelExporter
|
|
256
|
267
|
}
|
|
257
|
268
|
}
|
|
258
|
269
|
|
|
|
270
|
+ private static boolean isFillerMetaText(String text)
|
|
|
271
|
+ {
|
|
|
272
|
+ return text.contains("填表人") || text.contains("填表时间") || text.contains("填表日期");
|
|
|
273
|
+ }
|
|
|
274
|
+
|
|
|
275
|
+ private static CellStyle[] captureDataRowStyles(Sheet sheet, int styleSourceRow)
|
|
|
276
|
+ {
|
|
|
277
|
+ CellStyle[] styles = new CellStyle[LivestockOwnershipHouseholdExcelParser.COL_LAST + 1];
|
|
|
278
|
+ Row src = sheet.getRow(styleSourceRow);
|
|
|
279
|
+ if (src == null)
|
|
|
280
|
+ {
|
|
|
281
|
+ return styles;
|
|
|
282
|
+ }
|
|
|
283
|
+ for (int col = 0; col < styles.length; col++)
|
|
|
284
|
+ {
|
|
|
285
|
+ Cell cell = src.getCell(col);
|
|
|
286
|
+ if (cell != null)
|
|
|
287
|
+ {
|
|
|
288
|
+ styles[col] = cell.getCellStyle();
|
|
|
289
|
+ }
|
|
|
290
|
+ }
|
|
|
291
|
+ return styles;
|
|
|
292
|
+ }
|
|
|
293
|
+
|
|
|
294
|
+ private static Float captureRowHeight(Sheet sheet, int styleSourceRow)
|
|
|
295
|
+ {
|
|
|
296
|
+ Row src = sheet.getRow(styleSourceRow);
|
|
|
297
|
+ if (src == null)
|
|
|
298
|
+ {
|
|
|
299
|
+ return null;
|
|
|
300
|
+ }
|
|
|
301
|
+ return src.getHeightInPoints();
|
|
|
302
|
+ }
|
|
|
303
|
+
|
|
|
304
|
+ private static void applyDataRowStyles(Row row, CellStyle[] styles, Float rowHeight)
|
|
|
305
|
+ {
|
|
|
306
|
+ if (row == null || styles == null)
|
|
|
307
|
+ {
|
|
|
308
|
+ return;
|
|
|
309
|
+ }
|
|
|
310
|
+ if (rowHeight != null && rowHeight > 0)
|
|
|
311
|
+ {
|
|
|
312
|
+ row.setHeightInPoints(rowHeight);
|
|
|
313
|
+ }
|
|
|
314
|
+ for (int col = 0; col < styles.length; col++)
|
|
|
315
|
+ {
|
|
|
316
|
+ CellStyle style = styles[col];
|
|
|
317
|
+ if (style == null)
|
|
|
318
|
+ {
|
|
|
319
|
+ continue;
|
|
|
320
|
+ }
|
|
|
321
|
+ Cell cell = row.getCell(col);
|
|
|
322
|
+ if (cell == null)
|
|
|
323
|
+ {
|
|
|
324
|
+ cell = row.createCell(col);
|
|
|
325
|
+ }
|
|
|
326
|
+ cell.setCellStyle(style);
|
|
|
327
|
+ }
|
|
|
328
|
+ }
|
|
|
329
|
+
|
|
259
|
330
|
private static void mergeTotalLabelCells(Sheet sheet, int rowIndex)
|
|
260
|
331
|
{
|
|
261
|
332
|
int firstCol = LivestockOwnershipHouseholdExcelParser.COL_SEQ;
|