可以使用openpyxl库来实现这个需求。以下是一个示例代码:

from openpyxl import Workbook

# 创建工作簿
wb = Workbook()

# 获取默认的工作表
sheet = wb.active

# 将工作表重命名为"酒店评分"
sheet.title = "酒店评分"

# 表头
attributes = ['总评','员工素质','设施服务', '清洁程度', '舒适度', '性价比', '位置']

# 写入表头
for col_num, attribute in enumerate(attributes, 1):
    sheet.cell(row=1, column=col_num, value=attribute)

# 保存工作簿
wb.save("酒店评分.xlsx")

运行以上代码后,会生成一个名为"酒店评分.xlsx"的文件,其中包含一个名为"酒店评分"的工作表,并且写入了表头。

openpyxl新建excel把sheet命名为酒店评分并且写入表头attributes=总评员工素质设施服务 清洁程度 舒适度 性价比 位置保存怎么写python代码

原文地址: https://www.cveoy.top/t/topic/hFGP 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录