Skip to content

Commit

Permalink
小调整。
Browse files Browse the repository at this point in the history
  • Loading branch information
wangliang181230 committed Jul 15, 2024
1 parent 4742d2d commit 22fb54f
Showing 1 changed file with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -353,33 +353,32 @@ public static void mergeSameCells(Sheet sheet, ExcelMapping mapping) {
}
}

int mergeStartRow = -1;
int mergeEndRow = -1;

int startRow = mapping.isNeedHeadRow() ? 2 : 1;
for (int i = startRow; i < sheet.getPhysicalNumberOfRows(); i++) {
int mergeStartRowNum = -1;
int mergeEndRowNum = -1;
int startRowNum = mapping.isNeedHeadRow() ? 2 : 1;
for (int i = startRowNum; i < sheet.getPhysicalNumberOfRows(); i++) {
if (isSameCells(sheet.getRow(i - 1), sheet.getRow(i), mergeCellNums)) {
if (mergeStartRow == -1) {
mergeStartRow = i - 1;
mergeEndRow = i;
if (mergeStartRowNum == -1) {
mergeStartRowNum = i - 1;
mergeEndRowNum = i;
} else {
mergeEndRow++;
mergeEndRowNum++;
}
continue;
}

if (mergeStartRow >= 0) {
if (mergeStartRowNum >= 0) {
for (int mergeCellNum : mergeCellNums) {
sheet.addMergedRegion(new CellRangeAddress(mergeStartRow, mergeEndRow, mergeCellNum, mergeCellNum));
sheet.addMergedRegion(new CellRangeAddress(mergeStartRowNum, mergeEndRowNum, mergeCellNum, mergeCellNum));
}
mergeStartRow = -1;
mergeEndRow = -1;
mergeStartRowNum = -1;
mergeEndRowNum = -1;
}
}

if (mergeStartRow >= 0) {
if (mergeStartRowNum >= 0) {
for (int mergeCellNum : mergeCellNums) {
sheet.addMergedRegion(new CellRangeAddress(mergeStartRow, mergeEndRow, mergeCellNum, mergeCellNum));
sheet.addMergedRegion(new CellRangeAddress(mergeStartRowNum, mergeEndRowNum, mergeCellNum, mergeCellNum));
}
}
}
Expand Down

0 comments on commit 22fb54f

Please sign in to comment.