Using Excel Files in Vizard

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

  • Download the win32.exe installers from the xlrd and xlwt sites.
  • Run the installer. If you have multiple Python installations on your computer, make sure you select the Vizard Python installation:
    • Vizard 2.x uses Python 2.3
    • Vizard 3.x uses Python 2.4
    • Vizard 4.x uses Python 2.7
    • Vizard 5.x uses Python 2.7

NOTE for Vizard 4 users: The Package Manager, in the Tools menu, can be used to easily install these libraries. Use the search tab to locate the libraries and click install.

Example

Write to an Excel 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 Excel 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