Python XlsxWriter - 写入多张纸 [英] Python XlsxWriter - Write to many sheets

查看:65
本文介绍了Python XlsxWriter - 写入多张纸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这会写入第一张纸,但所有其他纸都是空白的.

This writes to the first sheet but all other sheets are blank.

for date in dates:
    sheet = wb.add_worksheet(date)
    sheet.write(row, 0, 'example')

对于每个日期,我想创建一个名称等于日期的工作表,然后写入每个工作表.这些工作表是使用正确的名称创建的,但除了第一张工作表之外,没有任何内容.

For each date I want to creat a sheet with the name equal to the date and then write to each sheet. The sheets are created with the correct names but there is nothing in them except for the first sheet.

推荐答案

我认为您的变量 wb 是工作簿并且之前已初始化.在说明中

I supposed that your variable wb is the workbook and is initialized before. In the instruction

sheet.write(row, 0, 'example')

我不知道如何增强 row.所以我创建了一个小脚本:

I don't know how row is enhanced. So i created a little script:

import xlsxwriter
list_name = ["first sheet", "second sheet", "third sheet"]

workbook = xlsxwriter.Workbook(<Your full path>)
for sheet_name in list_name:
    worksheet = workbook.add_worksheet(sheet_name)
    worksheet.write('A1', sheet_name)

workbook.close()

问候

这篇关于Python XlsxWriter - 写入多张纸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆