excel · Spreadsheet

Spreadsheet – rubygem

We can handle spreadsheets easily with the help of SPREADSHEET ruby gem.

Installation:

> gem install spreadsheet

Basic Code:

require ‘rubygems’
require ‘spreadsheet’

book = Spreadsheet::Workbook.new
sheet1 = book.create_worksheet  :name => (‘Names’)
sheet1[0,0] = ‘Raveendran’
sheet1[0,1] = ‘Age : 24’

sheet1[1,0] = ‘Jazzezravi’
sheet1[1,1] = ‘Age : 25’

sheet1[2,0] = ‘Jazzez’
sheet1[2,1] = ‘Age: 26’

book.write(‘F:\ravi\sample.xls’)

For more details —  http://spreadsheet.rubyforge.org/

Advertisements

4 thoughts on “Spreadsheet – rubygem

  1. Hi Raveendran,
    Your site is very helpful. I am new to Selenium scripting in Ruby. I created a script and would like some of the text checks to write to an output file but whenever I run the script I get error that outfile is an undefined local variable. Can you please help me? Here’s the main body of my code –
    # Main body of the test starts here-
    def test_new_user_login
    @outfile = File.new(“NewuserLogin.txt”, “w”)
    @err1 = “Error 404”
    @err2 = “Status 404”
    @textcheck1 = “Sign In”
    #@signinpage = “Sign In”
    @selenium.open “/”
    @selenium.click “link=Sign In”
    @selenium.wait_for_page_to_load “30000”
    #assert_equal signinpage, @selenium.get_title
    outfile.write(“\r\n”)
    String loginPageTitle = @selenium.get_title

    if loginPageTitle == “Sign In”
    outfile.write(“\r\n Successfully opened Sign In page”)
    else
    outfile.write(“\r\n Failed to open Sign In page”)
    end
    begin
    assert @selenium.is_text_present(textcheck1)
    rescue Test::Unit::AssertionFailedError
    @verification_erros<< $!
    end
    if(@selenium.is_text_present(textcheck1))
    outfile.write("\r\n Successfully opened Sign In Page.")
    else
    outfile.write("\r\n Incorrect page")
    end

    @selenium.type "login", "user_001"
    @selenium.type "password", "test111"
    @selenium.click "signin"
    @selenium.wait_for_page_to_load "30000"
    sleep 0.01
    begin
    assert @selenium.is_text_present("Status")
    rescue Test::Unit::AssertionFailedError
    @verification_erros<< $!
    end
    @selenium.click "link=Sign Out"
    @selenium.wait_for_page_to_load "30000"
    @selenium.click "signOut"
    @selenium.wait_for_page_to_load "30000"
    end

    Your help will be appreiciated. Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s