Excel scripting

F

Fredrik Jagenheim

Hi,

Why isn't this working as expected?

require 'win32ole'

data1 =3D []
100.times { data1 << rand(100) }

excel =3D WIN32OLE::new('excel.Application')
workbook =3D excel.Workbooks.Add
worksheet =3D workbook.Worksheets(1)
worksheet.Select # bring it to front

worksheet.Range('a1:c1')['Value'] =3D ['Test', '25', 'result']
worksheet.Range('a2:a4')['Value'] =3D ['Test', '25', 'result']

excel['Visible'] =3D true



This results in:
Test 25 result
Test
Test
Test

while I expected:
Test 25 result
Test
25
result

Any ideas?

//F
 
P

Pit Capitain

Fredrik said:
...
worksheet.Range('a1:c1')['Value'] = ['Test', '25', 'result']
worksheet.Range('a2:a4')['Value'] = ['Test', '25', 'result']

This results in:
Test 25 result
Test
Test
Test

Hi Fredrik,

just a guess, but maybe you need to feed values for more than one row as
an array of arrays: [['Test'], ['25'], ['result']]

If this doesn't work, you could try to fill the values one cell at a
time and look at the format of the data when reading the values:

worksheet.Range('a2:a2')['Value'] = ['Test']
worksheet.Range('a3:a3')['Value'] = ['25']
worksheet.Range('a4:a4')['Value'] = ['result']
p worksheet.Range('a2:a4')['Value']

HTH

Regards,
Pit
 
F

Fredrik Jagenheim

=20
just a guess, but maybe you need to feed values for more than one row as
an array of arrays: [['Test'], ['25'], ['result']]

This did it, thanks.

//F
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top