Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #!/usr/env python
  2.  
  3. from os import listdir
  4.  
  5. from openpyxl import Workbook
  6. from openpyxl import load_workbook
  7.  
  8. # Setup custom lambdas - Assigning lambdas to variables is considered bad practice, use functions
  9. month_num = lambda file_name: int(file_name[-10:-8])
  10. date_from_file = lambda file_name: file_name[-15:-5]
  11.  
  12. # Build file list
  13. data_folder = 'N:\****\Trade Email\\'
  14. file_names = [name for name in listdir(data_folder) if name.endswith('.xlsm') and int(name[-10:-8])>=3]
  15.  
  16. # Create our output workbook
  17. wb_output = Workbook()
  18.  
  19. # Add 'SOTER' sheet in each file to our workbook
  20. for idx,file_name in enumerate(file_names):
  21. print 'Processing File ' + str(idx + 1) + ' of ' + str(len(file_names)) # PEP 8 for whitespace
  22.  
  23. ws_output = wb_output.create_sheet(date_from_file(file_name))
  24.  
  25. wb_input = load_workbook(data_folder + file_name, read_only=True) # PEP 8 Whitespace
  26. ws_input = wb_input['SOTER']
  27.  
  28. for row in ws_input.rows:
  29. for cell in row:
  30. ws_output[cell.coordinate].value = cell.value
  31.  
  32. wb_output.save('H:\Dump.xlsx')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement