[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Scrounging for WIN32OLE <--> MS-Excel Examples

dhtapp

11/10/2003 4:53:00 AM

Hi,

I've suddenly developed an interest in populating an Excel worksheet from
within a little simulation I'm running.

I've Googled for docs & examples on using the WIN32OLE class, and been able
to cobble together some basic functionality with the help of what I've found
(plus Dave & Andy's book), but I haven't been able to branch out much.

I've also tried recording a couple of basic Excel macros and examining the
output. Unfortunately, the number of hours I've spent in VB can be counted
on a dog's left paw, and I'm not having much luck translating the syntax
into stuff that WIN32OLE recognizes.

And, I've perused Microsoft's tech site. For instance, they list multiple
ways that Excel ranges can be accessed, including a simple 2d index (i, j),
which would be perfect. But so far, I can only get the standard
"A1:A5"-style notation to work.

Does anyone know of some docs or guidelines posted somewhere that I may have
missed?

Thanks,

- dan

PS I know there's a specialized Excel library to write worksheets directly,
but that appears to be semi-broken under 1.8, and I'm not nearly experienced
enough to know how to patch it yet.



4 Answers

Bernhard Leicher

11/11/2003 4:48:00 PM

0

In <vQErb.11593$7B2.11385@fed1read04> dhtapp wrote:

> I've suddenly developed an interest in populating an Excel worksheet
> from within a little simulation I'm running.

> Does anyone know of some docs or guidelines posted somewhere that I
> may have missed?
>

Hi,

there's a page on the Rubygarden Wiki: http://www.rubygarden...
ScriptingExcel
(maybe I'll find the time to add to the page what I learned so far)

A great resource for general and programming Excel knowhow is Chip
Pearson's site, for addressing cells in a range, take a look at http://
www.cpearson.com/excel/cells.htm

Some examples of addressing cells by index:

# supposed that "sheet" contains a reference to an Excel worksheet
sheet.range("a1").item(2,1).value=5 # 5 goes to B1

# or get cell A1 first
range = sheet.range("a1")
# and use that from now on
range.item(3,1).value=6

# this should also be possible
sheet.cells(4,1).value=7


Parameters are in the order: rowindex, columnindex.

In VBA you can omit item and value, as they are somehow default
properties:
VBA: range("a1")(3,1)=5
Ruby: range("a1").item(3,1).value=5

Regards, Bernhard

daz

11/12/2003 6:21:00 AM

0


"Bernhard Leicher" <bernhard.leicher@t-online.de> wrote:
>
> # this should also be possible
> sheet.cells(4,1).value=7
>

Not my question, Bernhard, but thanks for the reply.

I spent some time looking at the problem (thinking that
it should be fairly simple) and got nowhere.


Now ...
# Multiplication Table without alphanumeric cell references:

require 'win32ole'
excel = WIN32OLE.new("Excel.application")
excel.visible = true
excel.Workbooks.Add()

for row in (1..12)
for col in (1..12)
excel.cells(row, col).value = row * col
end
end


OK, it was easy - with the right help :)


daz



PepsiFreak@teranews.com

11/21/2010 4:17:00 PM

0


"Jack Johnson" <jdjj2@msn.com> wrote in message
news:20226-4CE8AF83-530@baytvnwsxa002.msntv.msn.com...
>I agree, the rich probably aren't gonna invest any more in OUR country,
> with, or without, tax breaks......than they do already. The die has
> been cast. And, that die is OUTSOURCING. Those who run the largest
> corporations have taken full advantage of a global economy, (which is
> only going to increase), and they will continue to send our middle class
> jobs out of here, to places like China, because they can.


The proplem is that the old fairy tale "The trickle down theory" (as you've
mentioned) doesn't work; it never did.
The main reason is the reality that the game, for the rich and corporations
of all sizes, is to take in as much money as possible - and spend as little
as absolutely necessary.
All tax breaks (for the rich) mean is that they take in more money. The is
no guarantee (not even a promise) that they will use that money in a way
that benefits the economy or the average person.

(When you give to the lower classes, they by food, transportation, housing
and other things that have a more direct impact on the economy.
That makes it the difference between putting money where it helps most - or
putting it into a wishing well, believing it will coome back with interest.)

>
>
> Our government, (and governments around the world), have made too many
> 'Free Trade' agreements, that take from the developed world, and give to
> the third world. The so-called "developing" world. In fact, it IS
> income redistribution, at t's worst, (despite conservatives pretending
> it's not). They do so, all in the name of PROFITS. They can pay
> poverty wages, (wages that would NEVER be acceptable here), be it union,
> or NON union labor......because a person can NOT live on the poverty
> wages of the third world, here, in America. In China, the current
> minimum wage is $176.00 per MONTH. (And, that's with a recent RAISE).
> And, that's based on China's average work week, which exceeds our own 40
> hours. So, with those kinds of wages, for most general
> labor........NO American worker can compete. And, (again), union or
> NON union. So, the anti-unionists can't use unions as the excuse for
> outsourcing any longer.

No to mention the fact that with lower restrictions on imports - and even
corporate tax breaks TO move - the "fair trade" is a lie - because it is
outrageously unfair to us (US).

The trickle down theory,
The even more insane "supply side economics",
and many "fair trade agreements" are nothing more than frauds, cons and
masks to get more ane more money to the upper classes (at the expense of
orking classes all over the world).


>
>
> As long as our corporations, and the rich who run them, are allowed to
> simply relocate entire offices, and factories, to places like China,
> BECAUSE of the cheap labor. With NO benefits, and FEW, (if any) real
> regulations......then, they will take the tax cuts, and RUN.....all the
> way to China. And, we'll end up losing BILLIONS in revenue, as a
> result. And, NO, they have no plans on taking that money, and
> investing here. That has been PROVED, (like the article pointed out),
> by their behavior of NOT investing here, during the Bush years, after
> gaining HUGE tax breaks. The super rich, however, will continue to
> make more threats about sending even more jobs overseas.........and brow
> beat middle class American workers, with their spin, until they get
> their way.

Threats?
Browbeating and blackmail is more like it.
Unfortunately they are making the threats to people with the same economic
delusions that, without special favoratism and government financing to
businesses, the economy and the whole lifestyle will fail.

Yes, there will be depressions, but the bottom of the ecomomic pyramid is a
base of working class people and customers - NOT Exxon, Ford, Chrysler - and
certainly not Boing.

>
>
> Small businesses now create more than three quarters of all jobs. And,
> many of those jobs DO depend on large corporations keeping those large
> offices, and factories HERE........because many of those are service
> industry businesses, who service those same large offices, and
> factories. There's the rub. If we don't give the demanded tax
> breaks to these super rich, (and their large corporations), then they'll
> continue on outsourcing, (or make threats to do so)........and that WILL
> effect how many small businesses, who supply them, or service them HERE,
> will be able to hire more workers themselves. So, there is a trickle
> down effect. And, that's why, in the end, I DO support extending these
> tax breaks to EVERYONE......including the wealthiest among us.
> Because, like it (or not) they DO control our economy, and our destiny.
> Without them, even many small businesses will not be able to do
> business. They feed off each other. And, such is the reality of a
> global economy.

The threat, before, was "if you make business too hard (with taxes and
regulations), we'll shut down.
and the RIGHT answer, instead of giving into them, was -"Go ahead! This is
America - someone else will move into that slot"!

Personally, I would buy a more reliable (even if more expensive) product
made here in America - than totally waste my money on crap from China.




PepsiFreak@teranews.com

11/21/2010 4:18:00 PM

0


"ray" <xxxrayted@aol.com> wrote in message
news:icb2oi020oa@news4.newsguy.com...
> In article <20226-4CE8AF83-530@baytvnwsxa002.msntv.msn.com>,
> jdjj2@msn.com (Jack Johnson) wrote:
>
>> I agree, the rich probably aren't gonna invest any more in OUR country,
>> with, or without, tax breaks......than they do already. The die has
>> been cast. And, that die is OUTSOURCING. Those who run the largest
>> corporations have taken full advantage of a global economy, (which is
>> only going to increase), and they will continue to send our middle class
>> jobs out of here, to places like China, because they can.
>>
>>
>> Our government, (and governments around the world), have made too many
>> 'Free Trade' agreements, that take from the developed world, and give to
>> the third world. The so-called "developing" world. In fact, it IS
>> income redistribution, at t's worst, (despite conservatives pretending
>> it's not). They do so, all in the name of PROFITS. They can pay
>> poverty wages, (wages that would NEVER be acceptable here), be it union,
>> or NON union labor......because a person can NOT live on the poverty
>> wages of the third world, here, in America. In China, the current
>> minimum wage is $176.00 per MONTH. (And, that's with a recent RAISE).
>> And, that's based on China's average work week, which exceeds our own 40
>> hours. So, with those kinds of wages, for most general
>> labor........NO American worker can compete. And, (again), union or
>> NON union. So, the anti-unionists can't use unions as the excuse for
>> outsourcing any longer.
>>
>>
>> As long as our corporations, and the rich who run them, are allowed to
>> simply relocate entire offices, and factories, to places like China,
>> BECAUSE of the cheap labor. With NO benefits, and FEW, (if any) real
>> regulations......then, they will take the tax cuts, and RUN.....all the
>> way to China. And, we'll end up losing BILLIONS in revenue, as a
>> result. And, NO, they have no plans on taking that money, and
>> investing here. That has been PROVED, (like the article pointed out),
>> by their behavior of NOT investing here, during the Bush years, after
>> gaining HUGE tax breaks. The super rich, however, will continue to
>> make more threats about sending even more jobs overseas.........and brow
>> beat middle class American workers, with their spin, until they get
>> their way.
>>
>>
>> Small businesses now create more than three quarters of all jobs. And,
>> many of those jobs DO depend on large corporations keeping those large
>> offices, and factories HERE........because many of those are service
>> industry businesses, who service those same large offices, and
>> factories. There's the rub. If we don't give the demanded tax
>> breaks to these super rich, (and their large corporations), then they'll
>> continue on outsourcing, (or make threats to do so)........and that WILL
>> effect how many small businesses, who supply them, or service them HERE,
>> will be able to hire more workers themselves. So, there is a trickle
>> down effect. And, that's why, in the end, I DO support extending these
>> tax breaks to EVERYONE......including the wealthiest among us.
>> Because, like it (or not) they DO control our economy, and our destiny.
>> Without them, even many small businesses will not be able to do
>> business. They feed off each other. And, such is the reality of a
>> global economy.
>
> I agree and disagree with you here Jack. I agree with you that raising
> taxes on anybody during these trying times is a grave mistake. But I
> disagree with you about unions.

It is not "raising taxes" when you quit giving favored status tax breaks.
Of course you'll blame the unions ......... that's all you ever do.