セルの結合はあまり使用する機会がない。たまたま最近使用することがあったので書いておく。
「用語説明」(shift + command + o もしくは メニューバー > ファイル > 用語説明を開く)で Numbers.appの用語説明を調べると以下のようにある。
merge v : Merge a specified range of cells. merge range unmerge v : Unmerge all merged cells in a specified range. unmerge range
上記にて、結合する範囲は "range" を用いる。たとえば、セルA1とセルB1を結合したいときは以下。
~~省略
merge range "A1:B1"
~~省略
繰り返し処理でやるときは以下。
~~ repeat with i from 1 to rowCount merge range ("A" & i & ":" & "B" & i) end repeat ~~
注意点
(その1)
ヘッダーのセル同士の結合はできるが、ヘッダーのセルとヘッダーでないセルの結合はできない。
なので、以下のコードでは、header column count =0
と header row count = 0
でヘッダーを解除した。
(その2)
unmerge
の挙動に注意が必要。
A1とB1を結合すると、A1とB1の値を連結した文字列がA1の値となる。
それをunmerge
すると上記の連結した文字列かA1に収まり、B1は空となる。
tell application "Numbers" activate -- mak new document if there is no document if (count of document) as boolean then else set tgtDoc to make new document end if tell tgtDoc tell sheet 1 tell table 1 -- unset header column and header row set header column count to 0 set header row count to 0 -- get last row set rowCount to count of row of column "A" -- preparatian values repeat with i from 1 to rowCount set (value of cell i in column "A") to (name of cell i in column "A") set (value of cell i in column "B") to (name of cell i in column "B") end repeat -- *** merge cells in column A and column B *** repeat with i from 1 to rowCount merge range ("A" & i & ":" & "B" & i) end repeat repeat with i from 1 to rowCount unmerge range "A" & i end repeat end tell end tell end tell end tell