Write Data to MS Excel (XLSX) File using Python

XlsxWriter module

  1. Install XlsxWriter module from the command line:
pip install XlsxWriter
  1. Write data to MS Excel (XLSX) file:
import xlsxwriter

data = [
    ['John', 25],
    ['Mary', 30],
    ['Robert', 42],
]

workbook = xlsxwriter.Workbook('test.xlsx')
worksheet = workbook.add_worksheet()

row = 0
for item in data:
    worksheet.write(row, 0, item[0])
    worksheet.write(row, 1, item[1])
    row += 1

workbook.close()

Leave a Comment

Cancel reply

Your email address will not be published.