Forum: Ruby unable to open Excel file

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.
Ec39f5fd7d54f7b3464ab3964313b237?d=identicon&s=25 Riya Rai (riya)
on 2008-12-29 09:47
i am using below code for opening Excel application.
But it not opening  Excel file.

Code:-
require 'win32ole'

excel = WIN32OLE.new("excel.application")
excel.visible = true
workbook = excel.workbooks.open("c:\\temp.xls")
worksheet=workbook.worksheets(1)


i just want to open a excel file and write text in it.kindly help me.

Thanks in Advance
Bfa670ef2303deb7dec5a8027367b30b?d=identicon&s=25 David Mullet (mully)
on 2008-12-29 14:33
Riya Rai wrote:
>
> i am using below code for opening Excel application.
> But it not opening  Excel file.
>
> Code:-
> require 'win32ole'
>
> excel = WIN32OLE.new("excel.application")
> excel.visible = true
> workbook = excel.workbooks.open("c:\\temp.xls")
> worksheet=workbook.worksheets(1)
>
>
> i just want to open a excel file and write text in it.kindly help me.
>
> Thanks in Advance

You'll need to provide more details.

What happens when you run this code?
Does the Excel window appear?
Do you receive an error?

Do you have Excel installed on that PC?
Does the workbook already exist?  Or are you looking to create a new
workbook?

These links may help:

http://rubyonwindows.blogspot.com/2007/03/automati...

http://rubyonwindows.blogspot.com/search/label/excel

David
Ec39f5fd7d54f7b3464ab3964313b237?d=identicon&s=25 Riya Rai (riya)
on 2008-12-30 07:32
Hi David,

What happens when you run this code?
>> only Console opens(command prompt)

Does the Excel window appear?
>>No

Do you receive an error?
>>No message appears

Do you have Excel installed on that PC?
>> Ms Excel is installed

Does the workbook already exist?  Or are you looking to create a new
workbook?
>>already exists

Problem - unable to open Excel with this code.
Want to open (visible) and want to write text and then save.


Thanks
Riya


David Mullet wrote:
> Riya Rai wrote:
>>
>> i am using below code for opening Excel application.
>> But it not opening  Excel file.
>>
>> Code:-
>> require 'win32ole'
>>
>> excel = WIN32OLE.new("excel.application")
>> excel.visible = true
>> workbook = excel.workbooks.open("c:\\temp.xls")
>> worksheet=workbook.worksheets(1)
>>
>>
>> i just want to open a excel file and write text in it.kindly help me.
>>
>> Thanks in Advance
>
> You'll need to provide more details.
>
> What happens when you run this code?
> Does the Excel window appear?
> Do you receive an error?
>
> Do you have Excel installed on that PC?
> Does the workbook already exist?  Or are you looking to create a new
> workbook?
>
> These links may help:
>
> http://rubyonwindows.blogspot.com/2007/03/automati...
>
> http://rubyonwindows.blogspot.com/search/label/excel
>
> David
34a7615f38496a5dafbb3e6b721c435e?d=identicon&s=25 Mohit Sindhwani (Guest)
on 2008-12-30 08:30
(Received via mailing list)
Riya,

Not sure if this is the problem but your code is:

excel = WIN32OLE.new("excel.application")

On David's site, the line is:

excel = WIN32OLE::new('excel.Application')

Notice the capital A in Application; however, in irb on my PC, it works
irrespective of the case.  So, that's probably not the problem.  What
version of Excel is installed on the PC on which you are running the
code?  Do you get any other errors at all?

Could you try going line by line in irb to see if it dies anywhere?

Cheers,
Mohit.
12/30/2008 | 3:24 PM.
Ec39f5fd7d54f7b3464ab3964313b237?d=identicon&s=25 Riya Rai (riya)
on 2008-12-30 11:02
Thanks every one

Now the below code is working

'To open Excel file
require 'win32ole'

xl = WIN32OLE.new('Excel.Application')

xl.Visible = 1

wb = xl.Workbooks.Open('c:\file.xls')


Thanks again to all

Riya

Mohit Sindhwani wrote:
> Riya,
>
> Not sure if this is the problem but your code is:
>
> excel = WIN32OLE.new("excel.application")
>
> On David's site, the line is:
>
> excel = WIN32OLE::new('excel.Application')
>
> Notice the capital A in Application; however, in irb on my PC, it works
> irrespective of the case.  So, that's probably not the problem.  What
> version of Excel is installed on the PC on which you are running the
> code?  Do you get any other errors at all?
>
> Could you try going line by line in irb to see if it dies anywhere?
>
> Cheers,
> Mohit.
> 12/30/2008 | 3:24 PM.
34a7615f38496a5dafbb3e6b721c435e?d=identicon&s=25 Mohit Sindhwani (Guest)
on 2008-12-30 16:11
(Received via mailing list)
Riya Rai wrote:
>
> wb = xl.Workbooks.Open('c:\file.xls')
>
What was the problem though?

Cheers,
Mohit.
12/30/2008 | 11:10 PM.
This topic is locked and can not be replied to.