Forum: Ruby Fetch an excel sheet name in ruby

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
D2f4861bb915581c2aca4fc9f2c8015d?d=identicon&s=25 Deepa Rajendran (deeparaj)
on 2009-02-24 13:00
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
Bfa670ef2303deb7dec5a8027367b30b?d=identicon&s=25 David Mullet (mully)
on 2009-02-24 14:24
Deepa Rajendran 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

http://rubyonwindows.blogspot.com/
http://rubyonwindows.blogspot.com/search/label/excel
D2f4861bb915581c2aca4fc9f2c8015d?d=identicon&s=25 Deepa Rajendran (deeparaj)
on 2009-02-25 09:01
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
D2f4861bb915581c2aca4fc9f2c8015d?d=identicon&s=25 Deepa Rajendran (deeparaj)
on 2009-02-25 10:44
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
This topic is locked and can not be replied to.