Skip to content

Sheet comparison does not handle additional rows/columns in second file #14

@Colette-Jin

Description

@Colette-Jin

Hi,

If the second file has more rows or columns than the first one, the tool does not report those differences. Because the for-loops are based on sheet1's dimensions:

private void processAllRows() throws Exception {
for (int rowIndex = 0; rowIndex <= sheet1.getLastRowNum(); rowIndex++) {
XSSFRow row1 = sheet1.getRow(rowIndex);
XSSFRow row2 = sheet2.getRow(rowIndex);

		if (row1 == null || row2 == null) {
			if (!(row1 == null && row2 == null)) {
				crt.setDiffFlag(true);
				processNullRow(sheet1, rowIndex, row2);
			}
			continue;
		}

		processAllColumns(row1, row2);
	}
}

To solve this problem, since it's not complex, you can add two more variables int max_row and max_column, and use the max between both sheets.

int max_row = sheet11.getLastCellNum();
if (sheet12.getLastCellNum()>max_row) {
max_row = sheet12.getLastCellNum();
}
private void processAllRows() throws Exception {
for (int rowIndex = 0; rowIndex <= max_row); rowIndex++) {
XSSFRow row1 = sheet1.getRow(rowIndex);
XSSFRow row2 = sheet2.getRow(rowIndex);

		if (row1 == null || row2 == null) {
			if (!(row1 == null && row2 == null)) {
				crt.setDiffFlag(true);
				processNullRow(sheet1, rowIndex, row2);
			}
			continue;
		}
		processAllColumns(row1, row2);
	}
}

Similar issue happens in function: processAllColumns(XSSFRow row1, XSSFRow row2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions