Skip to content

Commit 2f41c32

Browse files
Added consolidation of added/removed rows
1 parent 06deb36 commit 2f41c32

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

apps/excel-diff-checker.jar

424 Bytes
Binary file not shown.

src/main/java/edu/abhi/poi/excel/SheetProcessorTask.java

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,45 +55,68 @@ private void processAllRows() throws Exception {
5555
}
5656

5757
private void processAllColumns(XSSFRow row1, XSSFRow row2) throws Exception {
58+
StringBuilder sb = new StringBuilder();
59+
boolean isRow1Blank = true, isRow2Blank = true;
60+
5861
for (int columnIndex = 0; columnIndex <= row1.getLastCellNum(); columnIndex++) {
5962
XSSFCell cell1 = (XSSFCell) row1.getCell(columnIndex);
6063
XSSFCell cell2 = (XSSFCell) row2.getCell(columnIndex);
6164

6265
if (Utility.hasNoContent(cell1)) {
6366
if (Utility.hasContent(cell2)) {
67+
isRow2Blank = false;
6468
crt.setDiffFlag(true);
6569
Utility.processDiffForColumn(cell1 == null ? row1.createCell(columnIndex) : cell1, remarksOnly,
66-
Utility.getCellValue(cell2), crt.getDiffContainer());
70+
Utility.getCellValue(cell2), sb);
6771
}
6872
} else if (Utility.hasNoContent(cell2)) {
6973
if (Utility.hasContent(cell1)) {
74+
isRow1Blank = false;
7075
crt.setDiffFlag(true);
71-
Utility.processDiffForColumn(cell1, remarksOnly, cell2 == null? null : Utility.getCellValue(cell2), crt.getDiffContainer());
76+
Utility.processDiffForColumn(cell1, remarksOnly, cell2 == null? null : Utility.getCellValue(cell2), sb);
77+
}
78+
} else {
79+
isRow1Blank = isRow2Blank = false;
80+
81+
if (!Utility.getCellValue(cell1).equals(Utility.getCellValue(cell2))) {
82+
crt.setDiffFlag(true);
83+
Utility.processDiffForColumn(cell1, remarksOnly, Utility.getCellValue(cell2), sb);
7284
}
73-
} else if (!Utility.getCellValue(cell1).equals(Utility.getCellValue(cell2))) {
74-
crt.setDiffFlag(true);
75-
Utility.processDiffForColumn(cell1, remarksOnly, Utility.getCellValue(cell2), crt.getDiffContainer());
7685
}
7786
}
87+
88+
if(!isRow1Blank && isRow2Blank)
89+
crt.getDiffContainer().append(String.format("Removed Row[%s] in sheet[%s]\n",
90+
(row1.getRowNum() + 1), sheet1.getSheetName()));
91+
else if(isRow1Blank && !isRow2Blank)
92+
crt.getDiffContainer().append(String.format("Added Row[%s] in sheet[%s]\n",
93+
(row1.getRowNum() + 1), sheet1.getSheetName()));
94+
else
95+
crt.getDiffContainer().append(sb);
7896
}
7997

8098
public void processNullRow(XSSFSheet sheet1, int rowIndex, XSSFRow row2) throws Exception {
8199
XSSFRow row1 = sheet1.getRow(rowIndex);
82-
100+
StringBuilder sb = new StringBuilder();
101+
83102
if (row1 == null) {
84103
if (row2.getPhysicalNumberOfCells() != 0) {
85104
row1 = sheet1.createRow(rowIndex);
86105
crt.setDiffFlag(true);
87106
for (int columnIndex = 0; columnIndex <= row2.getLastCellNum(); columnIndex++) {
88107
Utility.processDiffForColumn(row1.createCell(0), remarksOnly,
89-
Utility.getCellValue(row2.getCell(columnIndex)), crt.getDiffContainer());
108+
Utility.getCellValue(row2.getCell(columnIndex)), sb);
90109
}
110+
crt.getDiffContainer().append(String.format("Added Row[%s] in sheet[%s]\n",
111+
(row1.getRowNum() + 1), sheet1.getSheetName()));
91112
}
92113
} else {
93114
if (row1.getPhysicalNumberOfCells() != 0) {
94115
crt.setDiffFlag(true);
95116
XSSFCell cell1 = row1.getCell(0);
96-
Utility.processDiffForColumn(cell1 == null ? row1.createCell(0) : cell1, remarksOnly, "Null row", crt.getDiffContainer());
117+
Utility.processDiffForColumn(cell1 == null ? row1.createCell(0) : cell1, remarksOnly, "Null row", sb);
118+
crt.getDiffContainer().append(String.format("Removed Row[%s] in sheet[%s]\n",
119+
(row1.getRowNum() + 1), sheet1.getSheetName()));
97120
}
98121
}
99122
}

0 commit comments

Comments
 (0)