My_Play_Lists ~BlackCatWhiteTail’s blog~

Talk About My Favorite Songs

applescript+numbers > 練習問題_1


  • A列の単価×B列の数量を計算して、C列の書く.
  • 繰り返し(repeat)を用いる.
  • 最終行の取得の取得は過去記事(最終行の取得(2))で作成した最終行取得スクリプトオブジェクトを使う.


  • script Test's f("A")  "Test"というスクリプトの"f(x)"というハンドラに変数"A"をいれて実行.

  • script Test's Y  スクリプトオブジェクト属性の"Y"を取り出す.


# preparation

tell application "Numbers"
  set tgtDoc to make new document
     tell tgtDoc
        set tgtSheet to front sheet
        tell tgtSheet
            delete every table
            set tgtTable to make new table with properties {row count:11, column count:3, header row count:0, header column count:0}
            tell tgtTable
                set tmpArr_1 to {"120", "100", "150", "90", "80", "120", "180", "80", "160", "130"}
                set tmpArr_2 to {"3", "2", "6", "2", "6", "8", "3", "5", "2", "5"}
                set tmpArr_3 to {"単価", "数量", "金額"}

                repeat with i from 1 to 3
                    set value of cell i of row 1 to (item i of tmpArr_3 as string)
                end repeat

                repeat with i from 2 to 11
                    set value of cell i of column 1 to (item (i - 1) of tmpArr_1 as string)
                    set value of cell i of column 2 to (item (i - 1) of tmpArr_2 as string)
                end repeat

(Here insert code: see article below)

            end tell
        end tell
    end tell
end tell

# Hear insert script object to get end row of a column

--This script object is to get endRow of a column

script endUp
    property endRow_ : "" as number
    on f(x)
        tell application "Numbers"'s front document
            tell front sheet's front table
                set lastRow to count of every cell of column x
                set i to 0
                repeat while i < lastRow
                    if value of cell (lastRow - i) of column x ≠ missing value then
                        exit repeat
                        set i to i + 1
                    end if
                end repeat
                set endRow to (lastRow - i)
                set selection range to cell (lastRow - i) in column x
                set endRow_ to endRow
            end tell
        end tell
    end f
end script


  • (Here insert code) に以下のコードを書く.
endUp's f("A")
set theEndRow to endUp's endRow_
repeat with i from 2 to theEndRow
    set value of cell i of column 3 to (((value of cell i of column 1) as number) * ((value of cell i of column 1) as number))
end repeat


参考 Reference 総合練習問題1|VBA入門

Translated To English

Martiply "values of cells of colum A" and "values of cells of column B", and set these results to cells of column C.






TOP 1 To 5

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