[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

How to populate a 2D array data into Excel using WIN32OLE

Li Chen

12/4/2006 10:36:00 AM

Hi all,

I process a raw data file into a 2D array. The only way I can think of
to populate it into Excel is to use the following lines, which is
obviously not a good way:

worksheet.Range("A1:L1").Value= f_2D_array[0]
worksheet.Range("A2:L2").Value= f_2D_array[1]
worksheet.Range("A3:L3").Value= f_2D_array[2]
worksheet.Range("A4:L4").Value= f_2D_array[3]
worksheet.Range("A5:L5").Value= f_2D_array[4]
worksheet.Range("A6:L6").Value= f_2D_array[5]
worksheet.Range("A7:L7").Value= f_2D_array[6]
worksheet.Range("A8:L8").Value= f_2D_array[7]
...

I want to find another way such that I just mention the starting cell
and can dump my 2D data automatically. I read some documents about
WIN32OLE and Excel scripting. But they only mention how to set the value
for one cell or use the above Range method to set a collection of data.

Any input will be appreciated.

Thanks,

Li

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

3 Answers

Gustav - Railist

12/4/2006 11:01:00 AM

0

Li Chen wrote:
> Hi all,
>
> I process a raw data file into a 2D array. The only way I can think of
> to populate it into Excel is to use the following lines, which is
> obviously not a good way:
>
> worksheet.Range("A1:L1").Value= f_2D_array[0]
> worksheet.Range("A2:L2").Value= f_2D_array[1]
> worksheet.Range("A3:L3").Value= f_2D_array[2]
> worksheet.Range("A4:L4").Value= f_2D_array[3]
> worksheet.Range("A5:L5").Value= f_2D_array[4]
> worksheet.Range("A6:L6").Value= f_2D_array[5]
> worksheet.Range("A7:L7").Value= f_2D_array[6]
> worksheet.Range("A8:L8").Value= f_2D_array[7]
> ...
>
> I want to find another way such that I just mention the starting cell
> and can dump my 2D data automatically. I read some documents about
> WIN32OLE and Excel scripting. But they only mention how to set the value
> for one cell or use the above Range method to set a collection of data.
>
> Any input will be appreciated.
>
> Thanks,
>
> Li
>
>
Hey

I haven't tried it, but does this work? :

worksheet.Range("A1:L#{f_2D_array.length}").Value = f_2D_array

Just a wild guess, but it seems a plausible.

Hope it helps,
Gustav Paul
gustav@rails.co.za

Li Chen

12/4/2006 2:00:00 PM

0


--- Gustav Paul <gustav@rails.co.za> wrote:
> Hey
>
> I haven't tried it, but does this work? :
>
> worksheet.Range("A1:L#{f_2D_array.length}").Value =
> f_2D_array
>
> Just a wild guess, but it seems a plausible.


Yes it works. Thank you very much, Paul.

Li



____________________________________________________________________________________
Any questions? Get answers on any topic at www.Answers.yahoo.com. Try it now.

dkmd_nielsen

1/21/2007 10:51:00 PM

0

Any examples for doing just the opposite? Taking the Excel range and
putting the data into an array?

dvn

chen li wrote:
> --- Gustav Paul <gustav@rails.co.za> wrote:
> > Hey
> >
> > I haven't tried it, but does this work? :
> >
> > worksheet.Range("A1:L#{f_2D_array.length}").Value =
> > f_2D_array
> >
> > Just a wild guess, but it seems a plausible.
>
>
> Yes it works. Thank you very much, Paul.
>
> Li
>
>
>
> ____________________________________________________________________________________
> Any questions? Get answers on any topic at www.Answers.yahoo.com. Try it now.