'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. How can I get my desired 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:

1  YES
2  YES
3  YES
4  YES

Question: How can I update the code for my desired output? Thanks in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source