My_Play_Lists ~BlackCatWhiteTail’s blog~

Talk About My Favorite Songs

applescript+numbers > 範囲の指定

準備

  • 扱いやすい大きさのtableとcellを準備しておく.
  • アスタリスク(*)にコードを入れていく.
  • 検証のためにselection range を用いる.

An example of how to use "selection range"

...
set selection range to range "A4:C6"
...



make table as you like, and set cell size (width and height) as you like

tell application "Numbers"
    activate
    make new document
    tell document 1
        tell sheet 1
            delete every table
            make table with properties {row count:9, column count:9 , header row count:0, header column count:0}
            tell table 1
                set width of every column to 36
                set height of every row to 24
                
                -- * HERE INSERT CODE (see articles below)
                
            end tell
        end tell
    end tell
end tell

定義

  • 範囲を表現するのに "name" と "address (or index)"を用いる方法がある.
  • applescriptの用語説明と参考記事から以下のようにする.
  • 2行目を表現する場合
  • nameを用いる場合,ダブルクオートで挟む.
  • 従って,ダブルクオートで挟まれない数字はindexとして解釈される.
row 2 -- row address (or index)
row "2" -- row name
  • 2列目を表現する場合
column 2 -- column address (or index)
column "B" -- column name
  • セルA3を表現する場合
cell 3 -- cell address (or index)
cell "A3" -- cell name

(1) cellの指定

cell nameを用いた方法

Focus on a cell with cell name method

 set selection range to cell "A2"

cell address (or index) [1]を用いた方法

  • cell indexは行方向へ順に1,2・・・とつけられていく.

Focus on a cell with cell index method

set selection range to cell 2

"range" を用いた方法

  • rangeを用いても指定できる.
  • ただし,わかりやすくするため,単一cellを指定する場合はrangeではなくcellで指定することをお勧めする.

These two codes work correctly, but are not recomended.

 set selection range to range "A2"
 set selection range to range "A2:A2"

It doesn't work.

value of range "A2"


ある行の何番目のセル,という指定(cell index in row nameの形)

set selection range to cell 2 in row "2"

ある行の何番目のセル,という指定(cell index in row indexの形)

set selection range to cell 2 in row 2

ある列の何番目のセル,という指定(cell index in column nameの形)

set selection range to cell 2 in column "C"

ある列の何番目のセル,という指定(cell index in column indexの形)

  • column "A" は column 1,column "B" は column 2に相当.
set selection range to cell 2 in column 3

(2) 行の指定

set selection range to  row "2"

or

set selection range to  row 2

or

set selection range to range "6"


(3) 列の指定

set selection range to column "H"

or

set selection range to column 8

or

set selection range to range "H"


(4)連続する複数行の指定

注意:

  • "row"を用いた方法ではうまくいかない.
  • "range"を用いる.
  • indexを用いた方法は使えず,nameを用いた方法のみ使える.

Using "range", not "row"

set selection range to range "3:8"


CAUTION: It doesn't work, which is a method using "row"

set selection range to row "2:4" --It doesn't work !


(5)連続する複数列の指定

Using "range", not column

set selection range to range "A:D"

CAUTION: It doesn't work, which is a method using "column"

set selection range to column "B:C" --It doesn't work !


(6) 長方形の範囲の指定

  • table内の一箇所なら指定できる.
  • エクセルのように離れた場所は指定できない(と思う).
set selection range to range "B2:E6"


(7) "The opposing corners technieque"[2]

  • 直訳すると「対角テクニック」.
  • もう少しわかりやすく言うと,「対角指定テクニック」.
  • 指定する範囲の長方形の左上と右下のセルを指定するテクニック.純正テクニックかどうかは不明.
  • 上のコード: cell index in column name を用いた場合.
  • 下のコード: cell index in column name を用いた場合.

Here is "the opposing corners technieque"

set selection range to range ((name of the first cell of column "C") & ":" & (name of the last cell of column "E"))

or

set selection range to range ((name of the first cell of column 3) & ":" & (name of the last cell of column 5))
  • 同じことを cell index in row name, または cell index in row indexでもできる.
set selection range to range ((name of the first cell of row "3") & ":" & (name of the last cell of row "5"))

or

set selection range to range ((name of the first cell of row 3) & ":" & (name of the last cell of row 5))


(8) 特別な名前

  • cell range: 全体を選択
set the selection range to the cell range
  • first: ある列,またはある行の一番indexが小さいセル.
  • last: ある列,またはある行の一番indexが大きいセル.
set selection range to first cell in row 5
set selection range to last cell in row 5
set selection range to first cell in column 3
set selection range to last cell in column 3
  • count of cells: tableの総セル数.
count of cells
-- 戻り値は総セル数の100



注意点
  • "cell index"

 applescriptの"用語説明"で"Numbers"の用語を調べても"cell index"という用語は見当たらない(と思う).参考記事の筆者独自の名付けかもしれない.用語説明に"column address","row address" はある.文脈的に "address" は "index"と同じものを指す.indexという用語は利用価値が高いので以後も用いる.

  • "the opposing corners technieque"

 これも筆者独自の名付けかもしれない.英語のままのほうが分かりやすい.

  • Exelにおけるcells(1,1)といった書き方はNumbersにはない.

 ExelではRange("A1")とcells(1,1)とは同じものを指す.
 Numbersではcells(1,1)に相当する書き方はない.
 また,NumbersではExelとちがってカッコ()は不要.

[1] AppleScript and Numbers/ Ranges: https://iworkautomation.com/numbers/range.html

[2] AppleScript and Numbers/ Defining and Selecting Ranges :https://iworkautomation.com/numbers/range-select.html

 このウェブサイトについて

 練習用のサイトです.

 自分の好きな曲について感想を述べます.

 また,世に役に立つかもと考えたことも書きます.

 

TOP 1 To 5

Title Artist Album
ロックバンド 中村中 私を抱いて下さい
犬の生活 SEX MACHINEGUNS SEX MACHINEGUNS
Megalovania Toby Fox UNDERTALE Soundtrack
Bokura No Fly Away Base Ball Bear Bokura No Fly Away - single
人魚の檻 陰陽座 迦陵頻伽(Ka Ryo Bin Ga