Python | write on excel file using xlsxwriter module

Configurare noua (How To)

Situatie

XlsxWriter is a Python module for writing files in the XLSX file format. It can be used to write text, numbers, and formulas to multiple worksheets. Also, it supports features such as formatting, images, charts, page setup, auto filters, conditional formatting and many others.

Solutie

Pasi de urmat

Use this command to install xlsxwriter module:

pip install xlsxwriter

Note: Throughout XlsxWriter, rows and columns are zero indexed. The first cell in a worksheet, A1 is (0, 0), B1 is (0, 1), A2 is (1, 0), B2 is (1, 1) ..similarly for all.

Using the row-column notation(indexing value) for writing data in the specific cells.

# import xlsxwriter module
import xlsxwriter
workbook = xlsxwriter.Workbook(‘Example2.xlsx’)
worksheet = workbook.add_worksheet()
# Start from the first cell.
# Rows and columns are zero indexed.
row = 0
column = 0
content = [“ankit”, “rahul”, “priya”, “harshita”,
“sumit”, “neeraj”, “shivam”]
# iterating through content list
for item in content :
# write operation perform
worksheet.write(row, column, item)
# incrementing the value of row by one
# with each iteratons.
row += 1
workbook.close()
Output:
Lightbox

Tip solutie

Permanent

Voteaza

(6 din 10 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?