0% found this document useful (0 votes)
47 views

Excel Read

To read or write data from an XLS file in Python, the XLRD and XLWT modules must be installed. These can be downloaded and installed via the command line. To read a file, the XLRD module is imported and used to open the workbook. Individual sheets can then be accessed and cells can be read by creating cell objects. Writing data involves importing XLWT, creating a workbook and worksheet, and using write methods to enter values into cells before saving.

Uploaded by

nitintyagi1984
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Excel Read

To read or write data from an XLS file in Python, the XLRD and XLWT modules must be installed. These can be downloaded and installed via the command line. To read a file, the XLRD module is imported and used to open the workbook. Individual sheets can then be accessed and cells can be read by creating cell objects. Writing data involves importing XLWT, creating a workbook and worksheet, and using write methods to enter values into cells before saving.

Uploaded by

nitintyagi1984
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

EXCEL READ/WRITE

1. To Read/ Write data from XLS file, we need XLRD, XLWT python module (work on any plateform)
2. Download package from http://www.python-excel.org/
3. Unzip downloaded jar file, pick folder "xlrd" & xlwt and place is either in your current directory
or "Lib" folder inside python installation
OR Install python module by following way
a) Unzip downloaded python module
b) Open command prompt and move to location where setup.py file is place(inside unzip folder)
c) Write command on console python setup.py install



READ XLS FILE

1. Import xlrd python module
import xlrd

2. Create workbook object
wk= xlrd.open_workbook("G:\Data.xls")

Here with workbook object we can find number of sheets, sheet name etc
print wk.nsheets
print wk.sheet_names()


3. Now create a sheet object on which you want to perform task
print sh.nrows


4. To work on cell or to read data from cell, create a cell objet


import xlrd
wk= xlrd.open_workbook("G:\Data.xls")
print wk.nsheets
print wk.sheet_names()

sh= wk.sheet_by_index(0);
print sh.nrows
c1 = sh.cell(1,1)
print c1.value

WRITE DATA TO EXCEL FILE

1. Import xlwt python module
import xlwt


import xlwt
wk= xlwt.Workbook()
ws = wk.add_sheet("Sheet1")
ws.write(1,1,"HELLO")
wk.save("G:\N1.xls")

You might also like