Python read excel file and Write to Excel in Python

By: On:

In this Python tutorial, we will discuss how to read Excel file (Python read excel file) and how to write to an excel file in python with examples.

Read Excel File in Python

To read an excel file in Python, we will use xlrd module to retrieve information from a spreadsheet. The command need to be installed is xlrd module. xlrd module is used to extract data from a spreadsheet.

import xlrd
location = "C:\\Users\\   \\Documents\\demo.xlsx"
wb = xlrd.open_workbook(location)
sheet = wb.sheet_by_index(0)
print(sheet.cell_value(0, 0))

After writing the above code (Read Excel File in Python), Ones you will print then the output will appear as a “ Name ”. Here, row 0 and column 0 data is extracted from the spreadsheet.


You can refer to the below screenshot Read Excel file in Python

Read Excel File in Python

write to excel python

To write to an excel file in Python, we can use xlsx module and we can perform multiple operations on the spreadsheet, also we can modify the data on python.

The command need to be installed is xlsxwriter module.

import xlsxwriter
outWorkbook = xlsxwriter.Workbook("out.xlsx")
outSheet = outWorkbook.add_worksheet()
Name = ["John"]
Salary = [12000]
outSheet.write("A1", "Names")
outSheet.write("B1", "sal")
outSheet.write(1, 0, Name[0])
outSheet.write(1, 1, Salary[0])
outWorkbook.close()

After writing the above code (Write Excel File in Python), Ones you will print then the output will appear as a “ Names John sal 12000 ”. Here, we can write the data on the spreadsheet by using the xlsxwriter module.


You can refer to the below screenshot Write Excel file in Python.

Write Excel File in Python
write to excel python

This is how we can write to existing excel file in Python.


You may like the following Python tutorials:

In this Python tutorial, we learned how to read an excel file in Python and how to write to an existing file in Python.

Leave a Comment