(1) As far as I know we can’t do that. The only ways to fill cells are :
(a) use set value.
(b) GUIScripting pasting datas
(c) Create a table thru read a text file but it will create a new document.
(2) The word header doesn’t exists in the Numbers’s AppleScript dictionary so, GUI Scripting is required.
To do that, I use these three handlers :
--=====
(*
which = 10 --> set count of HEADer ROWs
my setNbXers(1, "Feuille 2", "Tableau 1", 10, 1) (* to set 1 HEADer ROW *)
which = 11 --> set count of HEADer COLUMNs
my setNbXers("my doc.numbers", "Sheet 5", "Table aux", 11, 4) (* to set 4 HEADer COLUMNs *)
which = 14 --> set count of FOOTer ROWs
my setNbXers("ASCII.numbers", "Sheet of paper", "TableTop", 14, 3) (* to set 3 FOOTer ROWs *)
*)
on setNbXers(docName, sheetName, tableName, whichItem, nbXers)
my selectTable(docName, sheetName, tableName)
set {theApp, mt, mi, ms} to {"Numbers", 6, whichItem, nbXers + 1}
tell application theApp to activate
tell application "System Events" to tell process theApp to tell menu bar 1 to ¬
tell menu bar item mt to tell menu 1 to tell menu item mi to tell menu 1
set maybe to get value of attribute "AXMenuitemMarkChar" of menu items
--> {missing value, missing value, missing value, "✓", missing value, missing value}
set existants to 0
repeat with i from 1 to count of maybe
if item i of maybe is not missing value then
set existants to i
exit repeat
end if
end repeat
if ms > existants then click menu item ms
end tell -- menu bar item.
end setNbXers
--=====
(*
Thanks to Nigel Garvey
*)
on selectTable(theDoc, theSheet, theTable)
local maybe, targetSheetRow, rowIndex, r
try
tell application "Numbers"
activate
set theDoc to name of document theDoc (* useful if the passed value is a number. Checks also that we passed the name of an open doc *)
end tell -- Numbers
on error
if my parleAnglais() then
error "The spreadsheet "" & theDoc & "" is not open !"
else
error "Le tableur « " & theDoc & " » n'est pas ouvert ! "
end if -- my parleAnglais
end try
try
tell application "Numbers" to tell document theDoc
set theSheet to name of sheet theSheet (* useful if the passed value is a number and check the availability of theSheet if it's a string *)
end tell -- Numbers
on error
if my parleAnglais() then
error "The sheet "" & theSheet & "" is unavailable in the spreadsheet "" & theDoc & "" !"
else
error "La feuille « " & theSheet & " » n'existe pas dans le tableur « " & theDoc & " » ! "
end if -- my parleAnglais
end try
try
tell application "Numbers" to tell document theDoc to tell sheet theSheet
set theTable to name of table theTable (* useful if the passed value is a number and check the availability of theSheet if it's a string *)
end tell -- Numbers
on error
if my parleAnglais() then
error "The table "" & theTable & "" is unavailable in the sheet "" & theSheet & "" of the spreadsheet "" & d & "" !"
else
error "La table « " & theTable & " » n'existe pas dans la feuille « " & theSheet & " » du tableur « " & d & " » ! "
end if -- my parleAnglais
end try
set maybe to 5 > (system attribute "sys2")
tell application "System Events" to tell application process "Numbers"
tell outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window theDoc
if maybe then (* macOS X 10.4.x
'(value of attributes contains 0)': '(value of attribute "AXDisclosureLevel" is 0)' sometimes works in Tiger, sometimes not.
The only possible instances of 0 amongst the attributes are the disclosure level of a sheet row and the index of the first row, which represents a sheet anyway.
Another possibility is '(value of attribute -1 is 0)', which makes me uneasy. *)
set targetSheetRow to first row where ((value of attributes contains 0) and (value of first static text is theSheet))
else (* macOS X 10.5.x or higher *)
set targetSheetRow to first row where ((value of attribute "AXDisclosureLevel" is 0) and ((groups is {}) and (value of first static text is theSheet)) or (value of first group's first static text is theSheet))
end if -- maybe
tell targetSheetRow to set {value of attribute "AXSelected", value of attribute "AXDisclosing"} to {true, true}
-- Get the sheet row's 0-based index + 2 for the following row's 1-based index.
set r to (value of attribute "AXIndex" of targetSheetRow) + 2
repeat until (value of first static text of row r is theTable)
set r to r + 1
end repeat
set value of attribute "AXSelected" of row r to true
end tell -- outline 1 .
end tell -- System Events
end selectTable
--=====
on parleAnglais()
local z
try
tell application "Numbers" to set z to localized string "Cancel"
on error
set z to "Cancel"
end try
return (z is not "Annuler")
end parleAnglais
--=====
Yvan KOENIG (VALLAURIS, France) mercredi 21 décembre 2011 10:57:37