Refactor report merging logic in ReportService for improved clarity and consistency

- Replaced the existing mergeIfNeeded method with a more descriptive mergeTitleRegion method to enhance readability.
- Updated report generation logic to use the new merging method for both title and subtitle rows in Excel reports.
- Ensured consistent merging behavior across different report sections by standardizing the merging approach.
This commit is contained in:
DongHeon Jang 2026-04-17 12:47:04 +09:00
parent 8224cd02f5
commit b5e88d562e
1 changed files with 7 additions and 8 deletions

View File

@ -169,11 +169,11 @@ public class ReportService {
Row titleRow = sheet.createRow(0); Row titleRow = sheet.createRow(0);
titleRow.setHeightInPoints(28); titleRow.setHeightInPoints(28);
createCell(titleRow, 0, "한화 연결 집계 요약", styles.get("title")); createCell(titleRow, 0, "한화 연결 집계 요약", styles.get("title"));
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3)); mergeTitleRegion(sheet, 0, 4);
Row subtitleRow = sheet.createRow(1); Row subtitleRow = sheet.createRow(1);
createCell(subtitleRow, 0, "회계기간 " + fiscalPeriod + " | 생성시각 " + generatedAt(), styles.get("subtitle")); createCell(subtitleRow, 0, "회계기간 " + fiscalPeriod + " | 생성시각 " + generatedAt(), styles.get("subtitle"));
sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 3)); mergeTitleRegion(sheet, 1, 4);
Row sectionRow = sheet.createRow(3); Row sectionRow = sheet.createRow(3);
createCell(sectionRow, 0, "주요 지표", styles.get("section")); createCell(sectionRow, 0, "주요 지표", styles.get("section"));
@ -210,11 +210,11 @@ public class ReportService {
Row titleRow = sheet.createRow(0); Row titleRow = sheet.createRow(0);
titleRow.setHeightInPoints(24); titleRow.setHeightInPoints(24);
createCell(titleRow, 0, sheetName, styles.get("title")); createCell(titleRow, 0, sheetName, styles.get("title"));
mergeIfNeeded(sheet, 0, columnCount); mergeTitleRegion(sheet, 0, columnCount);
Row subtitleRow = sheet.createRow(1); Row subtitleRow = sheet.createRow(1);
createCell(subtitleRow, 0, "회계기간 " + fiscalPeriod + " | 건수 " + rows.size(), styles.get("subtitle")); createCell(subtitleRow, 0, "회계기간 " + fiscalPeriod + " | 건수 " + rows.size(), styles.get("subtitle"));
mergeIfNeeded(sheet, 1, columnCount); mergeTitleRegion(sheet, 1, columnCount);
if (rows.isEmpty()) { if (rows.isEmpty()) {
Row emptyRow = sheet.createRow(3); Row emptyRow = sheet.createRow(3);
@ -356,10 +356,9 @@ public class ReportService {
cell.setCellStyle(style); cell.setCellStyle(style);
} }
private void mergeIfNeeded(Sheet sheet, int rowIndex, int columnCount) { private void mergeTitleRegion(Sheet sheet, int rowIndex, int columnCount) {
if (columnCount > 1) { int lastColumn = Math.max(1, columnCount - 1);
sheet.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 0, columnCount - 1)); sheet.addMergedRegion(new CellRangeAddress(rowIndex, rowIndex, 0, lastColumn));
}
} }
private CellStyle styleForKey(Map<String, CellStyle> styles, String key) { private CellStyle styleForKey(Map<String, CellStyle> styles, String key) {