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

L

Li Chen

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
 
G

Gustav Paul

Li said:
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
(e-mail address removed)
 
C

chen li

--- Gustav Paul said:
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.
 
D

donn

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

dvn
 

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

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top