This script, based upon the script template provided on the table editing page, uses both the unique and inherited properties of a cell, to style an existing table, so that a specific cell or cells are highlighted as an intersection.
It provides examples of these techniques:
Deriving the parent rows and columns of a selection range (27-28)
The application of styling properties to ranges (31-50)
Here’s the script:
Highlight Intersection
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
15
-- set the default colors for intersection
16
set theintersectionbackgroundColorto {65535, 65535, 65535} -- white
17
set theintersectiontextColorto {0, 0, 0} -- black
18
19
-- set the default colors for parent columns/rows
20
set thebackgroundColorto {52428, 26214, 65535}
21
set thetextColorto {65535, 65535, 65535}
22
23
tellselectedTable
24
set theselectionRangeto theselection range
25
26
-- get the parent columns and rows of the selection
27
settheseColumnsto thecolumnsofselection range
28
settheseRowsto therowsofselection range
29
30
-- format the parent columns
31
repeat withifrom 1 to thecountoftheseColumns
32
setthisColumntoitemioftheseColumns
33
set thebackground colorofthisColumntobackgroundColor
34
set thetext colorofthisColumntotextColor
35
set thefont nameofthisColumnto "Helvetica"
36
set thefont sizeofthisColumnto 15
37
end repeat
38
39
-- format the parent rows
40
repeat withifrom 1 to the count oftheseRows
41
setthisRowtoitemioftheseRows
42
set thebackground colorofthisRowtobackgroundColor
43
set thetext colorofthisRowtotextColor
44
set thefont nameofthisRowto "Helvetica"
45
set thefont sizeofthisRowto 15
46
end repeat
47
48
-- format the intersection
49
set thebackground colorofselectionRangetointersectionbackgroundColor
50
set thetext colorofselectionRangetointersectiontextColor
51
end tell
52
end tell
53
on errorerrorMessagenumbererrorNumber
54
iferrorNumberis 1000 then
55
setalertStringto "MISSING RESOURCE"
56
seterrorMessageto ¬
57
"Please create or open a document before running this script."
58
else iferrorNumberis 1001 then
59
setalertStringto "SELECTION ERROR"
60
seterrorMessageto ¬
61
"Please select a table before running this script."
To use the script, simply select one or more contiguous cells, and run the script. The parent rows and columns of the selected cells will be colorized.
TIP: use the Table to Image script to save the table as an image file to share the highlighted table with others.
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.