Hello
There is a huge difference.
In the four first ones, it's Applescript which asks the application to return values calling it one cell at a time.
The 5th one ask the app to return a range of values so,sending the order and delivering the values is made only once versus 5 times
And the time vary from 8 to 40.
My old correspondant (I don't know if he would be OK if I named him 'old friend') HIROTO is proposing a climb one more step grabbing the cells from several rows and columns in a single call.
He can't test because he don't own the app.
But I may do that for some one which helped me very often.
--
tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1
set maybe to value of cells 3 thru 20 of columns 2 thru 6
end tell
--
returns:
{{date "lundi 1 février 2010 1:00:00", date "lundi 1 mars 2010 1:00:00", date "jeudi 1 avril 2010 2:00:00", date "samedi 1 mai 2010 2:00:00", date "mardi 1 juin 2010 2:00:00", date "jeudi 1 juillet 2010 2:00:00", date "dimanche 1 août 2010 2:00:00", date "mercredi 1 septembre 2010 2:00:00", date "vendredi 1 octobre 2010 2:00:00", date "lundi 1 novembre 2010 1:00:00", date "mercredi 1 décembre 2010 1:00:00", date "samedi 1 janvier 2011 1:00:00", date "mardi 1 février 2011 1:00:00", date "mardi 1 mars 2011 1:00:00", date "vendredi 1 avril 2011 2:00:00", date "dimanche 1 mai 2011 2:00:00", date "mercredi 1 juin 2011 2:00:00", date "vendredi 1 juillet 2011 2:00:00"}, {"history3", "history4", "history5", "history6", "history7", "history8", "history9", "history10", "history11", "history12", "history13", "history14", "history15", "history16", "history17", "history18", "history19", "history20"}, {"category3", "category4", "category5", "category6", "category7", "category8", "category9", "category10", "category11", "category12", "category13", "category14", "category15", "category16", "category17", "category18", "category19", "category20"}, {"subcategory3", "subcategory4", "subcategory5", "subcategory6", "subcategory7", "subcategory8", "subcategory9", "subcategory10", "subcategory11", "subcategory12", "subcategory13", "subcategory14", "subcategory15", "subcategory16", "subcategory17", "subcategory18", "subcategory19", "subcategory20"}, {42.0, 56.0, 23.0, 14.0, 30.0, 20.0, 73.0, 57.0, 13.0, 34.0, 31.0, 74.0, 32.0, 59.0, 98.0, 31.0, 91.0, 32.0}}
This structure isn't easy to use
but with this code :
--
tell application "Numbers" to tell document 1 to tell sheet 1 to tell table 1
set maybe to value of cells 2 thru 6 of rows 3 thru 20
end tell
--
we get :
{{date "lundi 1 février 2010 1:00:00", "history3", "category3", "subcategory3", 42.0}, {date "lundi 1 mars 2010 1:00:00", "history4", "category4", "subcategory4", 56.0}, {date "jeudi 1 avril 2010 2:00:00", "history5", "category5", "subcategory5", 23.0}, {date "samedi 1 mai 2010 2:00:00", "history6", "category6", "subcategory6", 14.0}, {date "mardi 1 juin 2010 2:00:00", "history7", "category7", "subcategory7", 30.0}, {date "jeudi 1 juillet 2010 2:00:00", "history8", "category8", "subcategory8", 20.0}, {date "dimanche 1 août 2010 2:00:00", "history9", "category9", "subcategory9", 73.0}, {date "mercredi 1 septembre 2010 2:00:00", "history10", "category10", "subcategory10", 57.0}, {date "vendredi 1 octobre 2010 2:00:00", "history11", "category11", "subcategory11", 13.0}, {date "lundi 1 novembre 2010 1:00:00", "history12", "category12", "subcategory12", 34.0}, {date "mercredi 1 décembre 2010 1:00:00", "history13", "category13", "subcategory13", 31.0}, {date "samedi 1 janvier 2011 1:00:00", "history14", "category14", "subcategory14", 74.0}, {date "mardi 1 février 2011 1:00:00", "history15", "category15", "subcategory15", 32.0}, {date "mardi 1 mars 2011 1:00:00", "history16", "category16", "subcategory16", 59.0}, {date "vendredi 1 avril 2011 2:00:00", "history17", "category17", "subcategory17", 98.0}, {date "dimanche 1 mai 2011 2:00:00", "history18", "category18", "subcategory18", 31.0}, {date "mercredi 1 juin 2011 2:00:00", "history19", "category19", "subcategory19", 91.0}, {date "vendredi 1 juillet 2011 2:00:00", "history20", "category20", "subcategory20", 32.0}}
And the full set of datas is grabbed in less than a second
--
(* version 6 *)
property |old list| : {}
on run
set startingTime to current date
repeat 10 times
set my |old list| to {}
tell application "Numbers" to tell document "American Express 3.numbers" to tell sheet "Folha 9" to tell table "Transações"
set my |old list| to value of cells 2 thru 6 of rows 2 thru 45
end tell
end repeat
display dialog "required : " & (current date) - startingTime & " secondes"
my |old list|
end run
--
is designed to return the same set of datas than my 'old' examples.
With the editor in report events mode (efficient brake), the full set is returned 10 times in one second.
I don't know what the OP really want to achieve.
If he want to swap columns contents, the correct scripte would be
--
(* version 7 *)
property |old list| : {}
on run
set startingTime to current date
repeat 10 times
set my |old list| to {}
tell application "Numbers" to tell document "American Express 3.numbers" to tell sheet "Folha 9" to tell table "Transações"
set my |old list| to value of cells 2 thru 45 of columns 2 thru 6
end tell
end repeat
display dialog "required : " & (current date) - startingTime & " secondes"
my |old list|
end run
--
Both return a list of lists.
The version 6 return a list of short lists of values belonging to a row
and
version 7 return a list of long lists of values belonging to a column.
Most of the time, when I discover HIROTO's name in a thread in which I posted, he wrote upon this kind of tip. It seems that he was born in a library dedicated to Applescript. AppleScript behave as its second language. He know subtelties of this one and he is always OK to share its knowledge.
I'm a fool, I tried using
set my |old list| to value of cells 2
to 45 of columns 2
to 6
and when it was rejected by the Editor, I didn't thought to try with
thru
Thank you Hiroto.
Back to the performances.
The first scripts where asking for values 10
445 times with an execution time of 40 seconds
the fifth one was asking for values 10*44 times with an execution time of 8 seconds (40/5)
the new ones are asking only 10 times with an execution time of 1 second. As the time function embedded in Applescript count only the seconds we may admit that the duration was divided by 44.
Wih give a final factor of 1 to 220.
Isn't it astounding ?
Thank you again HIROTO.
When was our first exchange ? I would say six years ago but I'm not sure.
Yvan KOENIG (VALLAURIS, France) jeudi 24 juin 2010 22:58:23