Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rownum = appendSheet.range('A' + str(appendSheet.cells.last_cell.row)).end('up').row #checks for last row with data
- def findValues(self):
- """ find values """
- try:
- dictionary = {}
- app = xw.App(visible=False)
- appendWorkbook = xw.Book(r'{0}{1}'.format(Directory[0],GSS_Excel[0]))
- appendSheet = appendWorkbook.sheets['Sheet1']
- app1 = xw.App(visible=False)
- masterWorkbook = xw.Book(r'{0}{1}'.format(Directory[1],GSS_Excel[1]))
- masterSheet = masterWorkbook.sheets['Inventory Master']
- while True:
- print("Started Loop")
- rownum = appendSheet.range('A' + str(appendSheet.cells.last_cell.row)).end('up').row #checks for last row with data
- for row in range(2,rownum + 1):
- dictionary[row] = str(appendSheet.range('A'+str(row)).value) #creates dictionary of keys and values for each row
- for key, value in dictionary.items():
- if masterWorkbook.sheets[masterSheet].api.UsedRange.Find(value) != None: #Look for duplicates in master workbook
- print("found item, preparing to clear..")
- #appendSheet.range('{0}:{0}'.format(key)).clear()
- appendSheet.range('{0}:{0}'.format(key)).api.Delete(xw.constants.DeleteShiftDirection.xlShiftUp) #this does not work correctly, it skips lines
- print("row:{0} cleared".format(key))
- appendWorkbook.save(r'{0}{1}'.format(Directory[0],GSS_Excel[0]))
- app.kill()
- app1.kill()
- break
- except:
- print(traceback.format_exc())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement