How to Read a Excel file

Hello,

I am trying to read a excel file using ruby but i am not able to read
the file. below is the code i have used


require ‘rubygems’
require ‘selenium-webdriver’
require ‘parseexcel’

workbook =
Spreadsheet::ParseExcel.parse(“c:\Ruby193\scripts\testing.xls”)
worksheet = workbook.worksheet (1)
j = 1
worksheet.each { |row|

i=0
if row != nil
row.each { |cell|
if cell != nil
contents = cell.to_s(‘latin1’)
puts “Row: #{j} cell: #{i} > #{contents}”
end
i = i+1
}
end
}

Please any one can help me in this… Provide me the right code

this is how i usually resolve this (by using the spreadsheet gem)

      book = Spreadsheet.open(File.dirname(__FILE__) + 

‘/xyz/data.xls’)
sheet1 = book.worksheet(‘strange name’) # can use an index or
worksheet name
array = []
sheet1.each do |row|
break if row[0].nil? # if first cell empty
array << {:value1 => row[0].to_datetime, :value2 =>
row[1].to_f}
end

hope this helps

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs