I am trying to create a loop to add sheets to an excel file based on names in a list. For some reason it is not working. Would appreciate some help.
import openpyxl
worksheets = ['Balance Sheet Entries',
'Production Costs',
'Model - Realised',
'Orders',
'Manufacturing Comparison',
'Unit Economics']
# File where new sheets should be created
template = openpyxl.load_workbook('New File.xlsx')
#Loop through worksheets and create one new sheet using each name in the list.
for i in range(len(worksheets)):
template.create_sheet(worksheets[i]) #or template.create_sheet(title=worksheets[i])
The outcome of running this is exactly nothing. Nothing happens to the file and the code runs fine "Process finished with exit code 0".
Any help appreciated.
for worksheet in worksheets.