Thursday, 9 May 2013

Reading Excel file using ruby

 This is an example to read excel file in ruby (this can be used for reading excel workbook as well) using RubyXL gem

Step 1) Create an excel workbook like below

 Step 2) Create a ruby file including gems
require 'rubygems'
require 'rubyXL'

Copy path to excel file and replace it in place of work book
    workbook = RubyXL::Parser.parse("/Users/username/Downloads/simple_spreadsheet.xlsm")

This first sheet of excel workbook can be read into hash table using below command
    hash_arr=workbook[0].get_table(["Login", "email", "password"])

Multiple tables can be present in same file and they will read based on the format given in the above command (this helps in organizing many data tables in single sheet of excel file)

 Step 3: If needed it can be used in cucumber file as below

Source code :

require 'rubygems'
require 'rubyXL'
workbook = RubyXL::Parser.parse("simple_spreadsheet.xlsm")
hash_arr=workbook[0].get_table(["Login", "email", "password"])
puts all_tables

For more details refer to - project

Output looks like below


  1. Best place to learn Appium Android IOS Automation Testing Training in Chennai
    Go for Appium training in chennai for real time mobile automation testing training with real time project support.
    UI Automation Tools with real time scenarios You can contact 8122241286 for Best APPIUM and selenium Training in Chennai

  2. Hi Sir i am gettig following error : in `': undefined method `get_table' for # (NoMethodError)
    from -e:1:in `load'
    from -e:1:in `'

  3. please try that