0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Numbers.app で VBA のように、行番号・列番号でセルを走査したい

Last updated at Posted at 2022-05-07

 Excel VBA の Cells(2, 3).Value = "foobar..." のように、行番号、列番号を指定して、Numbers.app 上のセルを走査したい場合のスニペットです。

 実行してみると、すこぶる遅い...。

AppleScript の場合

tell application "Numbers"
    tell front document
        tell active sheet
            set theTable to first table
            repeat with r from 1 to 5
                repeat with c from 1 to 3
                    set theCell to item c of cells of item r of rows of theTable
                    set value of theCell to "hello"
                end repeat
            end repeat
        end tell
    end tell
end tell

JavaScript(JXA) の場合

 うーん。もうちょっとキレイに書けないでしょうか...。

var Numbers = Application("Numbers");
var Document = Numbers.documents[0];
var WorkSheet = Document.sheets[0];
var Table = WorkSheet.tables[0];

function Cells(r, c)
{
	return Table.rows[r - 1].cells[c - 1];
}

for (let r = 1; r <= 5; r++)
{
	for (let c = 1; c <= 3; c++)
	{
		Cells(r, c).value = "hello";
	}
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?