Python 循环使用 Openpyxl 创建工作表
Python Loop to Create Sheets Using Openpyxl
我正在尝试创建一个循环,以根据列表中的名称将工作表添加到 excel 文件。由于某种原因,它不起作用。非常感谢您的帮助。
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])
运行 的结果完全没有。文件没有任何变化,代码运行良好“进程已完成,退出代码为 0”。
感谢任何帮助。
快速浏览文档表明您需要调用 template.save(filename)
才能实际保存到磁盘。
我正在尝试创建一个循环,以根据列表中的名称将工作表添加到 excel 文件。由于某种原因,它不起作用。非常感谢您的帮助。
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])
运行 的结果完全没有。文件没有任何变化,代码运行良好“进程已完成,退出代码为 0”。
感谢任何帮助。
快速浏览文档表明您需要调用 template.save(filename)
才能实际保存到磁盘。