Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > How to get value of constants in Excel using WIN32OLE

Reply
Thread Tools

How to get value of constants in Excel using WIN32OLE

 
 
Li Chen
Guest
Posts: n/a
 
      12-01-2006
Hi all,

I have a script to store all Excel constants in an array. ButI can't
return the value for each constant. By using "inspect" method I think
all the constants in the array are turn into a string. The only chance I
can get the value of a constant is that I run the script to print out
all the constants and then add a line outside the array

puts Excel_Const::XlYDMFormat => return a value of 8

which is so inefficient!

I also notice that the line below will return a string

puts "Excel_Const::XlYDMFormat" => return a string as
Excel_Const::XlYDMFormat

I want to print out the values for all the constants at once. I wonder
if any expert out there can give me a hand.

Thank you in advnace,

Li

######
equire 'win32ole'
require 'enumerator'

module Excel_Const
end

excel=WIN32OLE.new('Excel.Application')
WIN32OLE.const_load(excel, Excel_Const)

array=Array.new
Excel_Const.constants.each{|c| array<<c}

count=0
array.sort!.each_slice(5) do |slice|
slice.each do |con|
v="Excel_Const::"+"#{con}"
puts v.inspect
count+=1
end
end

puts "The value is\t", Excel_Const::XlYDMFormat

puts "The total constants are ", count

##output
>ruby consts.rb

"Excel_Const::CONSTANTS"
"Excel_Const::Xl24HourClock"
"Excel_Const::Xl3DArea"
"Excel_Const::Xl3DAreaStacked"
...
"Excel_Const::XlYDMFormat"
...

The value is
8
The total constants are
1387

>Exit code: 0


--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Jan Svitok
Guest
Posts: n/a
 
      12-01-2006
On 12/1/06, Li Chen <> wrote:
> Hi all,
>
> I have a script to store all Excel constants in an array. ButI can't
> return the value for each constant. By using "inspect" method I think
> all the constants in the array are turn into a string. The only chance I
> can get the value of a constant is that I run the script to print out
> all the constants and then add a line outside the array
>
> puts Excel_Const::XlYDMFormat => return a value of 8
>
> which is so inefficient!
>
> I also notice that the line below will return a string
>
> puts "Excel_Const::XlYDMFormat" => return a string as
> Excel_Const::XlYDMFormat
>
> I want to print out the values for all the constants at once. I wonder
> if any expert out there can give me a hand.
>
> Thank you in advnace,
>
> Li
>
> ######
> equire 'win32ole'
> require 'enumerator'
>
> module Excel_Const
> end
>
> excel=WIN32OLE.new('Excel.Application')
> WIN32OLE.const_load(excel, Excel_Const)
>
> array=Array.new
> Excel_Const.constants.each{|c| array<<c}
>
> count=0
> array.sort!.each_slice(5) do |slice|
> slice.each do |con|
> v="Excel_Const::"+"#{con}"
> puts v.inspect
> count+=1
> end
> end
>
> puts "The value is\t", Excel_Const::XlYDMFormat
>
> puts "The total constants are ", count
>
> ##output
> >ruby consts.rb

> "Excel_Const::CONSTANTS"
> "Excel_Const::Xl24HourClock"
> "Excel_Const::Xl3DArea"
> "Excel_Const::Xl3DAreaStacked"
> ...
> "Excel_Const::XlYDMFormat"
> ...
>
> The value is
> 8
> The total constants are
> 1387
>
> >Exit code: 0


See programming ruby, especially the chapter on reflection. THe
interesting methods are: Module#constants, Module#const_get

 
Reply With Quote
 
 
 
 
Li Chen
Guest
Posts: n/a
 
      12-01-2006
Jan Svitok wrote:
> On 12/1/06, Li Chen <> wrote:
>> which is so inefficient!
>>
>> WIN32OLE.const_load(excel, Excel_Const)
>> end
>> "Excel_Const::Xl3DArea"
>> >Exit code: 0

> See programming ruby, especially the chapter on reflection. THe
> interesting methods are: Module#constants, Module#const_get




Thanks Jan. I haven't touch this chapter yet but I will take a look at
them. BTW could you browse my last post about "VBA to Ruby code again"?
I change every constants into the required format and Ruby still
complains the script.


Li

--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Win32OLE.const_load -- where to find missing constants David Lewis Ruby 0 05-01-2011 12:53 AM
WIN32OLE - failed to create WIN32OLE zxem Ruby 1 12-19-2007 07:01 PM
How to populate a 2D array data into Excel using WIN32OLE Li Chen Ruby 3 01-21-2007 10:51 PM
WIN32OLE#[] and WIN32OLE#[]= method in Ruby 1.9 (or later) Masaki Suketa Ruby 4 03-27-2006 11:17 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57