Roo is a gem that lets you access contents of ,
1> Excel Spreadsheets(.xls), 2> Open office spread sheets(.ods), 3>Excel’s new format .xlsx and 4>Google spreadsheets.
Consider the following spreadsheet:
The above spreadsheet can be accessed using the following code:
1 |
require 'rubygems' |
#Require the roo library in the script
1 |
require 'roo' |
# To parse an excel worksheet, create an instance of Excel workbook
1 |
xl= Excel.new("simple_spreadsheet.xls") |
#To define the worksheet in the workbook
1 2 3 4 5 6 7 |
xl.default_sheet = xl.sheets.first upto(xl.last_row) do |line| emp_id = xl.cell(line,'A') first_name = xl.cell(line,'B') last_name = xl.cell(line,'C') start_date = xl.cell(line,'D') dept = <code>xl.cell(line,'E') |
1 2 3 4 |
if start_date puts "#{start_date}t#{last_name}t#{emp_id}t#{dept}" end end |
To know more about Roo, check out the following sites:
http://rubyonwindows.blogspot.com/2008/01/parsing-spreadsheets-with-roo-gem.html
http://roo.rubyforge.org/rdoc/index.html
http://watirmelon.com/2009/01/05/watir-and-roo/