1
1

More than 1 year has passed since last update.

Google Apps Script: シートの最終行にレコードを追加する方法

Posted at

Google Apps Scriptでスプレッドシートの最終行にデータを追加する方法を説明します。

最終行にデータを挿入する関数

function addRecord(sheet, rowValues) {
  const lastRow = sheet.getLastRow();
  const range = sheet.getRange(lastRow + 1, 1, 1, rowValues.length);
  range.setValues([rowValues]);
}

SheetのAPIには最終行にデータを追加するメソッドがないので、上のような関数を作っておく必要があります。

使い方

最終行のA列〜C列にそれぞれのセルに1、2、3を追加する例です。

const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
addRecord(sheet, ["1", "2", "3"]);

rowValuesの型はstring[]です。

1
1
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
1
1