Fetch an excel sheet name in ruby

hi,
I got this error.in `method_missing’: Open (WIN32OLERuntimeError)
OLE error code:800A03EC in Microsoft Office Excel

For the below coding:

require ‘win32ole’
require ‘rubygems’

xl = WIN32OLE.new(‘Excel.Application’)
wb = xl.Workbooks.Open(“C:\Documents and
Settings\mpf18.MPFD18\Desktop\Achievement-with Target(JNJ-Wise)”)
ws = wb.Worksheets(1)
puts ws.Name
wb.Close
xl.Quit

Deepa R. wrote:

hi,
I got this error.in `method_missing’: Open (WIN32OLERuntimeError)
OLE error code:800A03EC in Microsoft Office Excel

Escape (double-up) your backslashes in double quotes, or place your
filepath in single quotes.

Change this:

wb = xl.Workbooks.Open(“C:\Documents and
Settings\mpf18.MPFD18\Desktop\Achievement-with Target(JNJ-Wise)”)

To this:

wb = xl.Workbooks.Open(“C:\Documents and
Settings\mpf18.MPFD18\Desktop\Achievement-with Target(JNJ-Wise)”)

Or this:

wb = xl.Workbooks.Open(‘C:\Documents and
Settings\mpf18.MPFD18\Desktop\Achievement-with Target(JNJ-Wise)’)

David

hi,
It works only in windows what i have to do for working in both linux
and window environment

require ‘win32ole’
require ‘rubygems’
excel = WIN32OLE.new(“excel.application”)
excel.visible =false
workbook = excel.workbooks.open(“E:\Book1.xls”)
tt=workbook.Worksheets.count
puts “Number of Worksheets”
puts tt.to_i
puts “Randomly Generate”
ff=rand(tt)
if ff.to_i==0
ff=1
else
ff=ff
end
puts ff.to_i
worksheet=workbook.worksheets(ff)
puts “Worksheet Name”
puts worksheet.Name
workbook.Close
excel.Quit

Hi,
Thanks those who help me

        Here is the coding.which i got the excel sheet name.but i 

have a doubt how to use minimum and maximum value to generate random
number in ruby.

require ‘win32ole’
require ‘rubygems’
excel = WIN32OLE.new(“excel.application”)
excel.visible =false
workbook = excel.workbooks.open(“E:\Book1.xls”)
tt=workbook.Worksheets.count
puts “Number of Worksheets”
puts tt.to_i
puts “Randomly Generate”
ff=rand(tt)
if ff.to_i==0
ff=1
else
ff=ff
end
puts ff.to_i
worksheet=workbook.worksheets(ff)
puts “Worksheet Name”
puts worksheet.Name
workbook.Close
excel.Quit