import openpyxl
from openpyxl.styles import PatternFill
from openpyxl import workbook
wrong_fill_pattern = PatternFill(patternType='solid', fgColor='FF0000')
right_fill_pattern = PatternFill(patternType='solid', fgColor='008000')
starting = (input("Bill Starting Row `A1` : "))
ending = (input("Bill Ending Row `A20` : "))
wb = openpyxl.load_workbook('test.xlsx')
s = wb["Sheet1"]
billtocheck = input("Enter Bills : ")
billist = [float(item) for item in billtocheck.split(' ')]
for j in s[f'{starting}':f'{ending}']:
for cel in j:
for billtocheck in billist:
if cel.value == billtocheck:
print(cel.coordinate, cel.value)
rightcoordinate = cel.coordinate
s[f'{rightcoordinate}'].fill = right_fill_pattern
print('+')
wb.save("TEST2.xlsx")
break
if cel.value != billtocheck:
wrongcoordinate = cel.coordinate
s[f'{wrongcoordinate}'].fill = wrong_fill_pattern
print("-")
print('-------------')
wb.save("TEST2.xlsx")
This code is kind of bill validation program. In this code user enters column and row starting point and ending point and in that range of column and row i wanted to find the bills and if value exist it just fills the bacground green if not red, it is working fine but i got another problem which is sometimes a bill exist multiple times and i want them to validate by their bill number in different row. The file example i am working on as you can see in this excel file bills located in E column and bill number located at H column so as i say i just want to check if E column contains same value multiple times i just want those multiple values to put user in a confirmation section to get an input which is going to be first where bill numbers located column and row range such as H1 to H20 and get multiple inputs which is going to be bill numbers ( if there are 3 times 64,04 and 2 times 52,02 the program going to ask user to enter input 5 times which is going to be bill numbers). So last thing is if bill number not matching with bill it is going to paint the bill red if it matches paint it green.
=IDEA= To confirm duplicated bills and seperate them each other, when user enters bill numbers it can check the cell coordinates and try to match it with rows of duplicated values and if both is in same row it is match and confirmed.