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

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

Li Chen wrote:

worksheet.Range(“A5:L5”).Value= f_2D_array[4]
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 P.
[email protected]

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

dvn

— Gustav P. [email protected] 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