Vizard 8 » Tutorials & Examples » Python Programming » Addons » xlrd and xlwt
8.1

xlrd and xlwt

With the xlrd and xlwt Python Addon libraries you can easily read and write directly to Excel files (.xls) from Vizard. For complete documentation and examples on using these libraries go to http://www.python-excel.org/.

Installation

From the Tools menu, open the Package Manager. Use the Search tab to locate the libraries and click Install.

Example

Write to an .xls file:

import xlwt

#Create a workbook object
workbook = xlwt.Workbook()

#Add a sheet
sheet = workbook.add_sheet('sheet 1')

#Write values to the sheet by cell number
for x in range(1,11):
    for y in range(1,11):
        sheet.write(x-1,y-1,x*y)

#Save the workbook to the xls format
workbook.save('ExperimentData.xls')

Read from an .xls file:

import xlrd
workbook = xlrd.open_workbook('ExperimentData.xls')

#Get the first sheet in the workbook by index
sheet1 = workbook.sheet_by_index(0)

#Get each row in the sheet as a list and print the list
for rowNumber in range(sheet1.nrows):
    row = sheet1.row_values(rowNumber)
    print(row)