0

I am unable to Rename every Worksheet in an Excel File. Yes, I am aware I can do so by individual sheet

import openpyxl

eventDate = ('data_entries/BOS-10.28.20.xlsx')

wb = openpyxl.load_workbook(eventDate)
print(wb.sheetnames)

['TC-Sheet-1', 'TC-Sheet-2', 'TC-Sheet-3', 'TC-Sheet-4', ... etc]

for sheet in wb.worksheets:
    wb = sheet[9:]  # to remove the ("'TC-Sheet-" characters)
    wb.sheetnames = sheet.title

However, I cannot complete this loop, I am not comprehending the openpyxl documentation, obviously.

An Almost Similar Question

This is useful for only one sheet, not an entire workbook

Thank You for Any Input or Insight !

1 Answers1

0

Try the following:

for sheet in wb.sheetnames:
    new_name = sheet[9:] # to remove the ("'TC-Sheet-" characters)
    wb[sheet].title = new_name
Jon S
  • 165
  • 6