Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. rownum = appendSheet.range('A' + str(appendSheet.cells.last_cell.row)).end('up').row #checks for last row with data
  2.  
  3. def findValues(self):
  4. """ find values """
  5. try:
  6. dictionary = {}
  7. app = xw.App(visible=False)
  8. appendWorkbook = xw.Book(r'{0}{1}'.format(Directory[0],GSS_Excel[0]))
  9. appendSheet = appendWorkbook.sheets['Sheet1']
  10. app1 = xw.App(visible=False)
  11. masterWorkbook = xw.Book(r'{0}{1}'.format(Directory[1],GSS_Excel[1]))
  12. masterSheet = masterWorkbook.sheets['Inventory Master']
  13. while True:
  14. print("Started Loop")
  15. rownum = appendSheet.range('A' + str(appendSheet.cells.last_cell.row)).end('up').row #checks for last row with data
  16. for row in range(2,rownum + 1):
  17. dictionary[row] = str(appendSheet.range('A'+str(row)).value) #creates dictionary of keys and values for each row
  18. for key, value in dictionary.items():
  19. if masterWorkbook.sheets[masterSheet].api.UsedRange.Find(value) != None: #Look for duplicates in master workbook
  20. print("found item, preparing to clear..")
  21. #appendSheet.range('{0}:{0}'.format(key)).clear()
  22. appendSheet.range('{0}:{0}'.format(key)).api.Delete(xw.constants.DeleteShiftDirection.xlShiftUp) #this does not work correctly, it skips lines
  23. print("row:{0} cleared".format(key))
  24. appendWorkbook.save(r'{0}{1}'.format(Directory[0],GSS_Excel[0]))
  25. app.kill()
  26. app1.kill()
  27. break
  28. except:
  29. print(traceback.format_exc())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement