list to excel python 1

list to excel python

import xlsxwriter

new_list = [['first', 'second'], ['third', 'four'], [1, 2, 3, 4, 5, 6]]

with xlsxwriter.Workbook('test.xlsx') as workbook:  #generate file test.xlsx
    worksheet = workbook.add_worksheet()

    for row_num, data in enumerate(new_list):
        worksheet.write_row(row_num, 0, data)

Here is what the above code is Doing:
1. Create a new workbook object.
2. Add a new worksheet to the workbook.
3. Iterate over the list of lists.
4. Write each list to the worksheet as a row.

Similar Posts