简体   繁体   English

使用“xlsxwriter”写入 Excel 时没有 output

[英]Nothing output while using 'xlsxwriter' to write in Excel

I use the following code to write data to an excel file, but got nothing in the excel file.我使用以下代码将数据写入 excel 文件,但在 excel 文件中一无所获。 How can I get my desired output:我怎样才能得到我想要的 output:

Code:代码:

import xlsxwriter
workbook = xlsxwriter.Workbook('print_def.xlsx')
worksheet = workbook.add_worksheet()
tree = 'YES'
while i < 4:
    worksheet.write(i, 0,  tree) #nothing is written to the excel file
    i+=1
workbook.close() 

My desired output:我想要的 output:

1  YES
2  YES
3  YES
4  YES

Question : How can I update the code for my desired output?:如何更新我想要的 output 的代码? Thanks in advance!提前致谢!

As pointed by @Lucvv, I forgot to put i=0 in the code, it then works after adding i=0 .正如@Lucvv 所指出的,我忘记将i=0放入代码中,然后在添加i=0后即可工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM