Skip to content

Commit db84304

Browse files
Refined diff remarks
1 parent de1c412 commit db84304

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

apps/excel-diff-checker.jar

-1.5 KB
Binary file not shown.

apps/launch.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
"%java8home%/bin/java" -jar excel-diff-checker.jar -b old* -t new* %* > edc.log
1+
"%java8home%/bin/java" -jar excel-diff-checker.jar -b old.* -t new.* %* > edc.log
22
pause

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

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

5757
private void processAllColumns(XSSFRow row1, XSSFRow row2) throws Exception {
58-
StringBuilder sb = new StringBuilder();
58+
StringBuilder rowRemarks = new StringBuilder();
5959
boolean isRow1Blank = true, isRow2Blank = true;
6060

6161
for (int columnIndex = 0; columnIndex <= row1.getLastCellNum(); columnIndex++) {
@@ -67,55 +67,55 @@ private void processAllColumns(XSSFRow row1, XSSFRow row2) throws Exception {
6767
isRow2Blank = false;
6868
crt.setDiffFlag(true);
6969
Utility.processDiffForColumn(cell1 == null ? row1.createCell(columnIndex) : cell1, remarksOnly,
70-
Utility.getCellValue(cell2), sb);
70+
Utility.getCellValue(cell2), rowRemarks);
7171
}
7272
} else if (Utility.hasNoContent(cell2)) {
7373
if (Utility.hasContent(cell1)) {
7474
isRow1Blank = false;
7575
crt.setDiffFlag(true);
76-
Utility.processDiffForColumn(cell1, remarksOnly, cell2 == null? null : Utility.getCellValue(cell2), sb);
76+
Utility.processDiffForColumn(cell1, remarksOnly, cell2 == null? null : Utility.getCellValue(cell2), rowRemarks);
7777
}
7878
} else {
7979
isRow1Blank = isRow2Blank = false;
8080

8181
if (!Utility.getCellValue(cell1).equals(Utility.getCellValue(cell2))) {
8282
crt.setDiffFlag(true);
83-
Utility.processDiffForColumn(cell1, remarksOnly, Utility.getCellValue(cell2), sb);
83+
Utility.processDiffForColumn(cell1, remarksOnly, Utility.getCellValue(cell2), rowRemarks);
8484
}
8585
}
8686
}
8787

8888
if(!isRow1Blank && isRow2Blank)
89-
crt.getDiffContainer().append(String.format("Removed Row[%s] in sheet[%s]\n",
89+
crt.getDiffContainer().append(String.format("\nRemoved Row[%s] of Sheet[%s]",
9090
(row1.getRowNum() + 1), sheet1.getSheetName()));
9191
else if(isRow1Blank && !isRow2Blank)
92-
crt.getDiffContainer().append(String.format("Added Row[%s] in sheet[%s]\n",
92+
crt.getDiffContainer().append(String.format("\nAdded Row[%s] in Sheet[%s]",
9393
(row1.getRowNum() + 1), sheet1.getSheetName()));
9494
else
95-
crt.getDiffContainer().append(sb);
95+
crt.getDiffContainer().append(rowRemarks);
9696
}
9797

9898
public void processNullRow(XSSFSheet sheet1, int rowIndex, XSSFRow row2) throws Exception {
9999
XSSFRow row1 = sheet1.getRow(rowIndex);
100-
StringBuilder sb = new StringBuilder();
100+
StringBuilder rowRemarks = new StringBuilder();
101101

102102
if (row1 == null) {
103103
if (row2.getPhysicalNumberOfCells() != 0) {
104104
row1 = sheet1.createRow(rowIndex);
105105
crt.setDiffFlag(true);
106106
for (int columnIndex = 0; columnIndex <= row2.getLastCellNum(); columnIndex++) {
107107
Utility.processDiffForColumn(row1.createCell(0), remarksOnly,
108-
Utility.getCellValue(row2.getCell(columnIndex)), sb);
108+
Utility.getCellValue(row2.getCell(columnIndex)), rowRemarks);
109109
}
110-
crt.getDiffContainer().append(String.format("Added Row[%s] in sheet[%s]\n",
110+
crt.getDiffContainer().append(String.format("\nAdded Row[%s] in Sheet[%s]",
111111
(row1.getRowNum() + 1), sheet1.getSheetName()));
112112
}
113113
} else {
114114
if (row1.getPhysicalNumberOfCells() != 0) {
115115
crt.setDiffFlag(true);
116116
XSSFCell cell1 = row1.getCell(0);
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",
117+
Utility.processDiffForColumn(cell1 == null ? row1.createCell(0) : cell1, remarksOnly, "Null row", rowRemarks);
118+
crt.getDiffContainer().append(String.format("\nRemoved Row[%s] of Sheet[%s]",
119119
(row1.getRowNum() + 1), sheet1.getSheetName()));
120120
}
121121
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ public static void processDiffForColumn(XSSFCell cell1, boolean remarksOnly, Str
3333

3434
Sheet sheet = cell1.getSheet();
3535

36-
sb.append(String.format("Diff at cell[%s] of sheet[%s]\n", cell1.getReference(), sheet.getSheetName()));
37-
3836
if(remarksOnly) {
39-
sb.append(String.format("Expected: [%s], Found: [%s]\n", getCellValue(cell1), note));
37+
sb.append(String.format("\nDiff at Cell[%s] of Sheet[%s]", cell1.getReference(), sheet.getSheetName()));
38+
sb.append(String.format("\nExpected: [%s], Found: [%s]", getCellValue(cell1), note));
4039
return;
40+
} else {
41+
sb.append(sb.length() > 0 ? " " : String.format("\nDiff at Row[%s] of Sheet[%s]: ", (cell1.getRowIndex() + 1), sheet.getSheetName()));
42+
sb.append(cell1.getReference());
4143
}
4244

4345
synchronized(sheet.getWorkbook()) {
@@ -84,7 +86,7 @@ public static String getCellValue(XSSFCell cell) throws Exception {
8486
break;
8587
case _NONE: content += null;
8688
break;
87-
default: throw new Exception(String.format("Unexpected Cell[%s] Type[%s] of sheet[%s]", cell.getReference(),
89+
default: throw new Exception(String.format("Unexpected Cell[%s] Type[%s] of Sheet[%s]", cell.getReference(),
8890
cell.getCellType(), cell.getSheet().getSheetName()));
8991
}
9092
return content;

0 commit comments

Comments
 (0)