Friday, June 3, 2011

Web Application Testing in Ruby: Web Application Testing in Ruby: Ruby scripting with Excel

Web Application Testing in Ruby: Web Application Testing in Ruby: Ruby scripting with Excel

reading data from spreadsheet

worksheet.Range('a12')['Value'] #get value of single cell
data = worksheet.Range('a1:c12')['Value'] #read into 2D array

Web Application Testing in Ruby: Ruby scripting with Excel

Web Application Testing in Ruby: Ruby scripting with Excel

Opening spreadsheets, accessing workbooks and worksheets
excel = WIN32OLE::new('excel.Application')
workbook = excel.Workbooks.Open('c:\examples\spreadsheet.xls')
worksheet = workbook.Worksheets(1) #get hold of the first worksheet
worksheet.Select #bring it to the front -need sometimes to run macros,
# not for working with a worksheet from ruby
excel['Visible'] = true #make visible, set to false to make invisible
# again. Don't need it to be visible for script to work