Guest User

Untitled

a guest
Jul 31st, 2017
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.79 KB | None | 0 0
  1.  
  2. ##############################################################################
  3. # imports required for the script to work
  4. import openpyxl
  5. from openpyxl.styles import NamedStyle, Font, Border, Side, PatternFill
  6. import sys
  7. import time
  8. import os
  9. import glob
  10. ###############################################################################
  11.  
  12. os.chdir(".")       # bound path to the current directory
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19. wb = openpyxl.load_workbook("test.xlsx")
  20. userSheet = wb.get_sheet_by_name("user")
  21. bankSheet = wb.get_sheet_by_name("bank")
  22.  
  23. C = userSheet["C"]
  24. B = userSheet["B"]
  25. IDS = []
  26. LEAVES= []
  27. for e in C:
  28.     LEAVES.append(e.value)
  29. print("\n")
  30. for e in B:
  31.     IDS.append(e.value)
  32.  
  33.  
  34. IDS_LEAVES = dict(zip(IDS, LEAVES))  # create a dict() with keys = IDS and values = LEAVES
  35.  
  36. IDS_LEAVES.pop("ID")  # get rid of the first key-pair since it contains "headings" of the sheets
  37. print(IDS_LEAVES)       # make sure we got the correct key-pairs in our dict()
  38.  
  39. bankID = bankSheet["B"]     # gives tuples of everything in column B of our bank sheet
  40. list_bankID = list(bankID) # convert  to list so we can pop the first element which contains header
  41. list_bankID.pop(0)  #pop header
  42.  
  43. bankLV = bankSheet["C"]         #get tuples of everything in column C
  44. list_bankLV = list(bankLV)  # convert to list so we can pop header aka first element
  45. list_bankLV.pop(0)          # pop the header
  46.  
  47. for i in range(1,len(bankLV)):   #for every item in the leaves column of sheet bank
  48.     if bankID[i].value in IDS_LEAVES.keys():   #check if the item exist in the keys of our dict()
  49.             try:
  50.                 bankLV[i].value = IDS_LEAVES[bankID[i].value]   # populate with the correct key
  51.             except:
  52.                 None
  53.  
  54. wb.save("ready.xlsx")             # all ready
  55. print("Exiting...")
Add Comment
Please, Sign In to add comment