Fetch an excel sheet name in ruby

D

Deepa Rajendran

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
 
D

David Mullet

Deepa said:
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
 
D

Deepa Rajendran

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top