Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python3
- ##############################################################################
- # imports required for the script to work
- import openpyxl
- from openpyxl.styles import NamedStyle, Font, Border, Side, PatternFill
- import sys
- import time
- import os
- import glob
- ###############################################################################
- os.chdir(".") # bound path to the current directory
- #satisfy openpyxl requirements for highlighting cells
- tf = NamedStyle(name="tf")
- tf.font = Font(bold=False, size=18)
- bd = Side(style='thick', color="000000")
- tf.border = Border(left=bd, top=bd, right=bd, bottom=bd)
- tf.fill = PatternFill(fill_type='lightUp',
- start_color='fff000',
- end_color='6efdfd')
- print("\n")
- print("files avilable in this folder:")
- print("\n")
- #enum files in current directory
- files = os.listdir()
- i = 1
- for f in glob.glob("*.xlsx"):
- print("(" + str(i) + "). " + str(f))
- i+= 1
- print("\n")
- print("enter the name of your excel file without extension:")
- wb_name = input()
- print("\n")
- print("opening your book...")
- time.sleep(1)
- try:
- workBook = openpyxl.load_workbook(wb_name + str(".xlsx"))
- except IOError:
- print("could not find the book. exiting...")
- sys.exit()
- print("I found the following sheets in your book:")
- print("\n")
- j = 1;
- for sheets in workBook.sheetnames:
- print("(" + str(j) + "). " + str(sheets))
- j += 1
- print("\n")
- print("enter the sheet name with bank data:")
- b_sheet = input()
- print("\n")
- try:
- bankSheet = workBook.get_sheet_by_name(b_sheet)
- except KeyError:
- print("no such sheet in your file: " + wb_name + " xlsx.")
- print("exitting....")
- sys.exit()
- print("SUCESS: bank data found at sheet: " + b_sheet)
- print("\n")
- print("enter the sheet name with your data:")
- u_sheet = input()
- try:
- userSheet = workBook.get_sheet_by_name(u_sheet)
- print("\n")
- print("SUCESS: user data found at sheet: " + u_sheet)
- print("\n")
- except KeyError:
- print("no such sheet found in your file: " + wb_name + " xlsx.")
- sys.exit()
- #loop through all records in Column B of the excel file and convert them
- #into an array. return that array
- def get_stuff(sheetName):
- stuff = []
- for row in range(2, sheetName.max_row + 1):
- cellObj = sheetName["B" + str(row)]
- eachChq = cellObj.value
- stuff.append(eachChq)
- return stuff
- bank_IDS = get_stuff(bankSheet)
- print("processing your data....")
- time.sleep(2)
- print("finding matches...")
- time.sleep(2)
- count = 0 #keep track of matches found
- for row in range(2, userSheet.max_row + 1):
- IDSObject = userSheet["B" + str(row)]
- leavesObj = userSheet["C" + str(row)]
- if IDSObject.value in bank_IDS:
- bankSheet["B" + str(row)].style = tf
- bankSheet["C" + str(row)].value = leavesObj.value
- count += 1
- print(str(count) + " matches found")
- print("\n")
- print("hold on...")
- time.sleep(1)
- print("highlighting in process...")
- time.sleep(2)
- print("SUCCESS:" + str(count) + " matches highlighted")
- time.sleep(1)
- print("creating new file in your folder....")
- time.sleep(1)
- workBook.save("ready.xlsx") # create new file with all the matched instance highlighted automatically
- print("ready.xlsx created")
- time.sleep(2)
- print("Exiting...")
Add Comment
Please, Sign In to add comment