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/

Accessing Excel in Ruby

Accessing Excel in Ruby

CODE:

require ‘win32ole’
excel = WIN32OLE.new(‘excel.application’)
excel.visible = true
work=excel.workbooks.open(“C:\\Documents and Settings\\raveendran\\Desktop\\output.xls”)
excel.range(“A1”).value = “name”
excel.range(“B1”).value = “address”
excel.range(“C1”).value = “city ”
excel.range(“D1”).value = “state ”
excel.range(“E1”).value = “zip”
work.save

OUPUT:

Excel