Advertisement
AppajiC

Format Excel

Oct 6th, 2022
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. import os
  2. import openpyxl
  3. import concurrent.futures
  4.  
  5. DIR = "15% SEEPAGE"
  6. files = os.listdir(DIR)
  7.  
  8.  
  9. def format_excel_file(path):
  10.     wb = openpyxl.load_workbook(path)
  11.  
  12.     # Deleting Sheet 1
  13.     del wb["Sheet1"]
  14.     ws = wb["Sheet2"]
  15.  
  16.     # Deleting first two rows
  17.     ws.delete_rows(1, 2)
  18.  
  19.     # Renaming Columns
  20.     ws.cell(row=1, column=1).value = "T"
  21.     ws.cell(row=1, column=2).value = "U"
  22.     ws.cell(row=1, column=3).value = "V"
  23.     ws.cell(row=1, column=4).value = "W"
  24.  
  25.     # Renaming Sheet2 to Sheet1
  26.     ws.title = "Sheet1"
  27.  
  28.     wb.save(path)
  29.     print(f"Updated file: {path}")
  30.  
  31.  
  32. for file in files:
  33.     path = os.path.join(DIR, file)
  34.     format_excel_file(path)
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement