Skip to content

Commit

Permalink
bugfix: 合并单元格功能,第一行数据被忽略了的问题修复。
Browse files Browse the repository at this point in the history
  • Loading branch information
wangliang181230 committed Jul 15, 2024
1 parent 18d5833 commit 4742d2d
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public static void mergeSameCells(Sheet sheet, ExcelMapping mapping) {
int mergeStartRow = -1;
int mergeEndRow = -1;

int startRow = mapping.isNeedHeadRow() ? 3 : 2;
int startRow = mapping.isNeedHeadRow() ? 2 : 1;
for (int i = startRow; i < sheet.getPhysicalNumberOfRows(); i++) {
if (isSameCells(sheet.getRow(i - 1), sheet.getRow(i), mergeCellNums)) {
if (mergeStartRow == -1) {
Expand Down Expand Up @@ -397,6 +397,14 @@ private static int[] getMergeCellNums(ExcelMapping mapping, String[] mergeFieldN
return mergeCellNums;
}

/**
* 判断两行对应的多列是否完全相同
*
* @param row1 行1
* @param row2 行2
* @param cellNums 列号数组
* @return 是否相同
*/
private static boolean isSameCells(Row row1, Row row2, int[] cellNums) {
for (int cellNum : cellNums) {
Cell row1Cell = row1.getCell(cellNum);
Expand Down

0 comments on commit 4742d2d

Please sign in to comment.