Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript, working with arrays

Is there a way to write a list to a range? I tried the following:

+tell application "Numbers"+
+ get value of every cell of range "B2:C4" of table 1 of sheet 1 of document 1+
+ --> {1.0, 4.0, 2.0, 5.0, 3.0, 6.0}+
+ set value of every cell of range "E2:E3" of table 1 of sheet 1 of document 1 to {1.0, 2.0}+
+ --> error number -10000+
Result:
+error "Numbers got an error: AppleEvent handler failed." number -10000+

So the first weird thing is the result of the first command: I was expecting a list of lists (as in, say, Excel) instead of a flattened single list.
The second problem is that I have found no way to make the second command work. Is it really necessary to write to cells one by one?

Also, does anyone know what Apple's plans for Applescript support in Numbers are? It would be nice to also be able to script charting...

Thanks
Christian

MacMini Server, Mac OS X (10.6.2)

Posted on Sep 2, 2010 1:32 AM

Reply
Question marked as Best reply

Posted on Sep 2, 2010 2:13 AM

zCRP wrote:
Is there a way to write a list to a range? I tried the following:

+tell application "Numbers"+
+ get value of every cell of range "B2:C4" of table 1 of sheet 1 of document 1+
+ --> {1.0, 4.0, 2.0, 5.0, 3.0, 6.0}+


The best syntax is :

get value of cells 2 thru 4 of columns 2 thru 3
--> {{71.0, 84.0, 74.0}, {22.0, 52.0, 60.0}}

+ set value of every cell of range "E2:E3" of table 1 of sheet 1 of document 1 to {1.0, 2.0}+
+ --> error number -10000+
Result:
+error "Numbers got an error: AppleEvent handler failed." number -10000+


As far as I know, there is no way to set the values of a range. We must set values of cells.
--

tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1

set les_valeurs to value of cells 2 thru 4 of columns 2 thru 3

set rDest to 8
set cDest to 7
set nb_lignes to count of les_valeurs
set nb_colonnes to count of item 1 of les_valeurs

repeat with r from 1 to nb_lignes
repeat with c from 1 to nb_colonnes
set value of cell (rDest - 1 + r) of column (cDest - 1 + c) to item c of (item r of les_valeurs)
end repeat
end repeat
end tell
--


So the first weird thing is the result of the first command: I was expecting a list of lists (as in, say, Excel) instead of a flattened single list.


You asked the values of cells of a Range so you logically got a single list.
I ask the values of cells of different rows, I get a list of lists.

The second problem is that I have found no way to make the second command work. Is it really necessary to write to cells one by one?


Yes, it is !

Also, does anyone know what Apple's plans for Applescript support in Numbers are? It would be nice to also be able to script charting...


*_If some of us are aware of Apple projects, they are under Non Disclosure Agreement and so will not respond. So please don't bother them with this kind of question !_*

Yvan KOENIG (VALLAURIS, France) 2 septembre 2010 11:13:03
1 reply
Question marked as Best reply

Sep 2, 2010 2:13 AM in response to zCRP

zCRP wrote:
Is there a way to write a list to a range? I tried the following:

+tell application "Numbers"+
+ get value of every cell of range "B2:C4" of table 1 of sheet 1 of document 1+
+ --> {1.0, 4.0, 2.0, 5.0, 3.0, 6.0}+


The best syntax is :

get value of cells 2 thru 4 of columns 2 thru 3
--> {{71.0, 84.0, 74.0}, {22.0, 52.0, 60.0}}

+ set value of every cell of range "E2:E3" of table 1 of sheet 1 of document 1 to {1.0, 2.0}+
+ --> error number -10000+
Result:
+error "Numbers got an error: AppleEvent handler failed." number -10000+


As far as I know, there is no way to set the values of a range. We must set values of cells.
--

tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1

set les_valeurs to value of cells 2 thru 4 of columns 2 thru 3

set rDest to 8
set cDest to 7
set nb_lignes to count of les_valeurs
set nb_colonnes to count of item 1 of les_valeurs

repeat with r from 1 to nb_lignes
repeat with c from 1 to nb_colonnes
set value of cell (rDest - 1 + r) of column (cDest - 1 + c) to item c of (item r of les_valeurs)
end repeat
end repeat
end tell
--


So the first weird thing is the result of the first command: I was expecting a list of lists (as in, say, Excel) instead of a flattened single list.


You asked the values of cells of a Range so you logically got a single list.
I ask the values of cells of different rows, I get a list of lists.

The second problem is that I have found no way to make the second command work. Is it really necessary to write to cells one by one?


Yes, it is !

Also, does anyone know what Apple's plans for Applescript support in Numbers are? It would be nice to also be able to script charting...


*_If some of us are aware of Apple projects, they are under Non Disclosure Agreement and so will not respond. So please don't bother them with this kind of question !_*

Yvan KOENIG (VALLAURIS, France) 2 septembre 2010 11:13:03

Applescript, working with arrays

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.