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()
问候