Merging A Range - AppleScript And Numbers - IWork And Automation

 | OS X | Automation | AppleScript | iWork
AppleScript and Numbers: Doing crunches just got easier! Merging a Range

The range class can be the target of the merge and unmerge commands.

merge v : Merge a specified range of cells.

merge range

unmerge v : Unmerge all merged the cells in a specified range.

unmerge range

The merging of cells is often done for organizational or esthetic reasons, as a way to separate or highlight data in a table. In the example table shown below, alternating rows have been merged to provide a buffer between the rows that will contain the data.

merged-row-table

NOTE: You can merge cells wholly within a table header region or the body. You cannot merge cells that span those regions. e.g. If you set the number of header columns to 5 then merge range "A1:E1" will work but merge range "A1:F1" will not, because F1 is in the body and the others are in the header.

The following example script will create such a table on the current spread of the frontmost document:

Create Table with Alternating Merged Rows
Open in AppleScript Editor
01property rowCount : 10
02property columnCount : 10
03property useRowHeaders : true
04property useColumnHeaders : true
05
06tell application "Numbers"
07activate
08if not (exists document 1) then make new document
09tell document 1
10tell active sheet
11set thisTable to ¬
12make new table with properties ¬
13{row count:rowCount, column count:columnCount}
14tell thisTable
15set height of every row to 40
16set width of every column to 60
17if useRowHeaders is true then
18set startRowCellIndex to 2
19else
20set startRowCellIndex to 1
21end if
22if useColumnHeaders is true then
23set startColumnCellIndex to 3
24else
25set startColumnCellIndex to 2
26end if
27repeat with i from startColumnCellIndex to rowCount by 2
28-- define the cell range to merge
29set rangeStart to name of cell startRowCellIndex of row i
30set rangeEnd to name of cell -1 of row i
31set the rowRange to rangeStart & ":" & rangeEnd
32-- merge the specified range
33merge range rowRange
34tell cell 2 of row i -- format the merged area
35set background color to {59121, 59119, 59120}
36set text color to {46137, 46137, 46137}
37set alignment to center
38set vertical alignment to center
39set font size to 18.0
40set value to "▼"
41end tell
42end repeat
43set the selection range to cell range
44end tell
45end tell
46end tell
47end tell

TOP | CONTINUE

NUMBERS SCRIPTING

  • Overview
  • Automation Utilities
  • Template
  • Document
  • Sheet
  • Table
  • Range
  • Selecting a Range
  • Merging a Range
  • Clearing a Range
  • Cell
  • Column
  • Row
  • Image
  • Media Items
  • Text Item
  • Exporting to Keynote
  • SQLite & Numbers
  • Examples

DISCLAIMER

THIS WEBSITE IS NOT HOSTED BY APPLE INC.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.

Tag » How To Merge Cells In Numbers