Python Excel Example

Do you like this?

This article shows you how to handle excel files using Python


If you are using Windows, you can use PyWin32 which is a wrapper around Excel COM library. You can check out Python Inserting Images Into Word Documents for examples on how to use the library. If you are using Macbook or Linux, you can use Python Excel. In this tutorial, I'll be talking about the second option which is Python Excel. Python Excel comprises of 2 libraries. xlrd is for reading Excel files and xlwt is for writing data to Excel files. Following are examples on how to use them.

tar -zxvf xlrd-0.9.3.tar.gz
cd xlrd-0.9.3
python install

from xlrd import open_workbook
wb = open_workbook('/path/to/file')
for s in wb.sheets():

Open an existing excel file to edit

from xlrd import open_workbook
from xlutils.copy import copy
from xlwt import easyxf

excel_file= "\path\to\excel\file.xls"

rb = open_workbook(excel_file)
book = copy(rb)
sheet = book.get_sheet(0)
row= 0
for v in ['a','b','c']:
	row +=1

comments powered by Disqus