Adding columns to a table is accomplished using the add column after and add column before commands, which take as a direct parameter, a range of the table.
add column afterv : Add a column to the table after a specified range of cells.
add column afterrange
add column beforev : Add a column to the table before a specified range of cells.
add column beforerange
The script example below, adds a summation column to the end of the currently selected table:
(⬆ see above ) Table before adding SUM column. (⬇ see below ) Table after adding SUM column to end.
Here’s the script:
Add Summation Column to Selected Table
01
tellapplication "Numbers"
02
activate
03
try
04
if not (existsdocument 1) then errornumber 1000
05
telldocument 1
06
try
07
tellactive sheet
08
set theselectedTableto ¬
09
(the firsttablewhoseclassofselection rangeisrange)
10
end tell
11
on error
12
errornumber 1001
13
end try
14
tellselectedTable
15
-- currently, use of headers and footers cannot be determined by a script.
16
-- make the following assumptions:
17
set usesHeaders to true-- assume 1 row and 1 column
18
set usesFooters to false-- assume 1 row
19
-- add a new column
20
add column afterlastcolumn
21
set thesummationColumnto the lastcolumn
22
-- set the formula of each cell of the summation column
23
tellsummationColumn
24
ifusesHeadersistruethen
25
setstartIndexto 2
26
else
27
setstartIndexto 1
28
end if
29
repeat withifromstartIndexto thecountofcells
30
-- get the row of the cell
31
setthisRowto therowofcelli
32
-- determine range coordinates
33
set therangeStartto thenameofcellstartIndexofthisRow
Mention of third-party websites and products is for informational purposes only and constitutes neither an endorsement nor a recommendation. MACOSXAUTOMATION.COM assumes no responsibility with regard to the selection, performance or use of information or products found at third-party websites. MACOSXAUTOMATION.COM provides this only as a convenience to our users. MACOSXAUTOMATION.COM has not tested the information found on these sites and makes no representations regarding its accuracy or reliability. There are risks inherent in the use of any information or products found on the Internet, and MACOSXAUTOMATION.COM assumes no responsibility in this regard. Please understand that a third-party site is independent from MACOSXAUTOMATION.COM and that MACOSXAUTOMATION.COM has no control over the content on that website. Please contact the vendor for additional information.