Skip to content

Commit eb63463

Browse files
committed
add case feature
1 parent 2fcd4c4 commit eb63463

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

gui.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
[sg.HorizontalSeparator()],
5050
[sg.T("")],
5151
[
52-
[sg.Button(" Start ", key="--START--")]
52+
sg.Button(" Start ", key="--START--"),
53+
sg.CBox(" Ignore case ", key="--case--")
5354
],
5455
]
5556
font = "Arial, 12"
@@ -73,8 +74,9 @@
7374
ws2 = values.get("--ws2--", None)
7475
cols1 = values.get("--cols1--", None)
7576
cols2 = values.get("--cols2--", None)
77+
case = values.get("--case--", None)
7678
try:
77-
main.main(wb1, wb2, ws1, ws2, cols1, cols2)
79+
main.main(wb1, wb2, ws1, ws2, cols1, cols2, case)
7880
except Exception as e:
7981
print("Something went wrong:", str(e))
8082
window.close()

main.py

+19-10
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,35 @@
44
from openpyxl import load_workbook
55
from openpyxl.cell import Cell
66

7-
def compare_cells(c1: Cell, c2: Cell):
7+
case = False
8+
9+
def compare_cells(c1: Cell, c2: Cell, case: bool):
810
#TODO: ignore whitespace and add case-insensitive comparison
9-
if c1.value != c2.value:
10-
print(f"[w1'{c1.coordinate}' != w2'{c2.coordinate}'] {c1.value} != {c2.value}")
11+
if case:
12+
if c1.value.lower() != c2.value.lower():
13+
print(f"[w1'{c1.coordinate}' != w2'{c2.coordinate}'] {c1.value} != {c2.value}")
14+
print("WOWOWO")
15+
16+
else:
17+
if c1.value != c2.value:
18+
print(f"[w1'{c1.coordinate}' != w2'{c2.coordinate}'] {c1.value} != {c2.value}")
1119

12-
def compare_columns(ws1: Worksheet, ws2: Worksheet, col1: str, col2: str):
20+
def compare_columns(ws1: Worksheet, ws2: Worksheet, col1: str, col2: str, case: bool):
1321
for cell_1, cell_2 in zip(ws1[col1], ws2[col2]):
14-
compare_cells(cell_1, cell_2)
22+
compare_cells(cell_1, cell_2, case)
1523
if len(ws1[col1]) > len(ws2[col2]):
1624
print(f"[ws1'{col1}' has more rows than ws2'{col2}', skipping extra rows]\n")
1725
if len(ws1[col1]) < len(ws2[col2]):
1826
print(f"[ws2'{col2}' has more rows than ws1'{col1}', skipping extra rows]\n")
1927

20-
def compare_entire_worksheets(ws1: Worksheet, ws2: Worksheet):
28+
def compare_entire_worksheets(ws1: Worksheet, ws2: Worksheet, case: bool):
2129
ws1_rows, ws2_rows = ws1.max_row, ws2.max_row
2230
ws1_cols, ws2_cols = ws1.max_column, ws2.max_column
2331
rows = min(ws1_rows, ws2_rows)
2432
cols = min(ws1_cols, ws2_cols)
2533
for i in range(1, rows+1):
2634
for j in range(1, cols+1):
27-
compare_cells(ws1.cell(i, j), ws2.cell(i, j))
35+
compare_cells(ws1.cell(i, j), ws2.cell(i, j), case)
2836
if ws1_rows > ws2_rows:
2937
print(f"[ws1'{ws1.title}' has more rows than ws2'{ws2.title}', skipping extra rows]")
3038
if ws1_rows < ws2_rows:
@@ -41,6 +49,7 @@ def compare_workbooks(
4149
s2: str = None,
4250
cols1: str = None,
4351
cols2: str = None,
52+
case: bool = False,
4453
):
4554
ws1: Worksheet = w1[s1] if s1 else w1.active
4655
ws2: Worksheet = w2[s2] if s2 else w2.active
@@ -51,11 +60,11 @@ def compare_workbooks(
5160
return
5261
else:
5362
for c1, c2 in zip([x.strip() for x in cols1.split(",")], [x.strip() for x in cols2.split(",")]):
54-
compare_columns(ws1, ws2, c1, c2)
63+
compare_columns(ws1, ws2, c1, c2, case)
5564

56-
def main(w1, w2, s1=None, s2=None, cols1=None, cols2=None):
65+
def main(w1, w2, s1=None, s2=None, cols1=None, cols2=None, case=False):
5766
ws1: Workbook = load_workbook(w1)
5867
ws2: Workbook = load_workbook(w2)
5968
print("Starting comparison...\n")
60-
compare_workbooks(ws1, ws2, s1=s1, s2=s2, cols1=cols1, cols2=cols2)
69+
compare_workbooks(ws1, ws2, s1=s1, s2=s2, cols1=cols1, cols2=cols2, case=case)
6170
print("\nComparison finished!")

0 commit comments

Comments
 (0)