Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Excel scripting

0 views
Skip to first unread message

Fredrik Jagenheim

unread,
Jun 17, 2005, 3:45:52 AM6/17/05
to
Hi,

Why isn't this working as expected?

require 'win32ole'

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

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

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

excel['Visible'] = true

This results in:
Test 25 result
Test
Test
Test

while I expected:
Test 25 result
Test
25
result

Any ideas?

//F


Pit Capitain

unread,
Jun 17, 2005, 4:57:10 AM6/17/05
to
Fredrik Jagenheim schrieb:
> ...

> 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


Fredrik Jagenheim

unread,
Jun 17, 2005, 5:26:02 AM6/17/05
to
On 6/17/05, Pit Capitain <p...@capitain.de> wrote:
>
> 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


0 new messages