Google スプレッドシート ファイルにアクセスして変更する。一般的な操作は、新しいシートの追加や共同編集者の追加です。
Methods
詳細なドキュメント
addDeveloperMetadata(key)
指定されたキーを持つデベロッパーのメタデータを最上位のスプレッドシートに追加します。
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Adds the key 'NAME' in the developer metadata for the spreadsheet. ss.addDeveloperMetadata('NAME') // Gets the first developer metadata object and logs its key. const developerMetaData = ss.getDeveloperMetadata()[0] console.log(developerMetaData.getKey())
パラメータ
Name | 型 | 説明 |
---|---|---|
key | String | 新しいデベロッパー メタデータのキー。 |
リターン
Spreadsheet
- チェーン用のこのスプレッドシート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addDeveloperMetadata(key, visibility)
指定されたキーと公開設定のデベロッパー メタデータをスプレッドシートに追加します。
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Adds the key 'NAME' in the developer metadata for the spreadsheet and sets the visibility // to the developer project that created the metadata. ss.addDeveloperMetadata('NAME', SpreadsheetApp.DeveloperMetadataVisibility.PROJECT); // Gets the first developer metadata object and logs its key and visibility setting. const developerMetaData = ss.getDeveloperMetadata()[0]; console.log(developerMetaData.getKey()); console.log(`Key: ${developerMetaData.getKey()}, . Visibility: ${developerMetaData.getVisibility()}`);
パラメータ
Name | 型 | 説明 |
---|---|---|
key | String | 新しいデベロッパー メタデータのキー。 |
visibility | DeveloperMetadataVisibility | 新しいデベロッパー メタデータの可視性。 |
リターン
Spreadsheet
- チェーン用のこのスプレッドシート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addDeveloperMetadata(key, value)
指定されたキーと値を含むデベロッパー メタデータをスプレッドシートに追加します。
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Adds the key 'NAME' and sets the value to 'GOOGLE' in the developer metadata for the // spreadsheet. ss.addDeveloperMetadata('NAME', 'GOOGLE'); // Gets the first developer metadata object and logs its key and value. const developerMetaData = ss.getDeveloperMetadata()[0]; console.log(developerMetaData.getKey()); console.log(`Key: ${developerMetaData.getKey()}, Value: ${developerMetaData.getValue()}`);
パラメータ
Name | 型 | 説明 |
---|---|---|
key | String | 新しいデベロッパー メタデータのキー。 |
value | String | 新しいデベロッパー メタデータの値。 |
リターン
Spreadsheet
- チェーン用のこのスプレッドシート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addDeveloperMetadata(key, value, visibility)
指定されたキー、値、公開設定のデベロッパー メタデータをスプレッドシートに追加します。
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Adds the key 'NAME', sets the value to 'GOOGLE', and sets the visibility // to any developer project with document access. ss.addDeveloperMetadata('NAME', 'GOOGLE', SpreadsheetApp.DeveloperMetadataVisibility.DOCUMENT); // Gets the first developer metadata object and logs its key, value, and visibility setting. const developerMetaData = ss.getDeveloperMetadata()[0]; console.log(`Key: ${developerMetaData.getKey()}, Value: ${developerMetaData.getValue()}, Visibility: ${developerMetaData.getVisibility()}`);
パラメータ
Name | 型 | 説明 |
---|---|---|
key | String | 新しいデベロッパー メタデータのキー。 |
value | String | 新しいデベロッパー メタデータの値。 |
visibility | DeveloperMetadataVisibility | 新しいデベロッパー メタデータの可視性。 |
リターン
Spreadsheet
- チェーン用のこのスプレッドシート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addEditor(emailAddress)
指定されたユーザーを Spreadsheet
の編集者のリストに追加します。ユーザーがすでに閲覧者のリストに含まれている場合、このメソッドでは閲覧者のリストでそのユーザーが除外されます。
パラメータ
Name | 型 | 説明 |
---|---|---|
emailAddress | String | 追加するユーザーのメールアドレス。 |
リターン
Spreadsheet
- この Spreadsheet
(チェーン用)。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addEditor(user)
指定されたユーザーを Spreadsheet
の編集者のリストに追加します。ユーザーがすでに閲覧者のリストに含まれている場合、このメソッドでは閲覧者のリストでそのユーザーが除外されます。
パラメータ
Name | 型 | 説明 |
---|---|---|
user | User | 追加するユーザーの表現。 |
リターン
Spreadsheet
- この Spreadsheet
(チェーン用)。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addEditors(emailAddresses)
指定されたユーザー配列を Spreadsheet
の編集者のリストに追加します。いずれかのユーザーがすでに閲覧者のリストに含まれている場合、このメソッドでは閲覧者のリストから除外されます。
パラメータ
Name | 型 | 説明 |
---|---|---|
emailAddresses | String[] | 追加するユーザーのメールアドレスの配列。 |
リターン
Spreadsheet
- この Spreadsheet
(チェーン用)。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addMenu(name, subMenus)
スプレッドシートの UI に新しいメニューを作成します。
各メニュー エントリは、ユーザー定義関数を実行します。通常は、スプレッドシートが読み込まれたときにメニューが自動的に作成されるように、onOpen()
関数から呼び出します。
// The onOpen function is executed automatically every time a Spreadsheet is loaded function onOpen() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var menuEntries = []; // When the user clicks on "addMenuExample" then "Menu Entry 1", the function function1 is // executed. menuEntries.push({name: "Menu Entry 1", functionName: "function1"}); menuEntries.push(null); // line separator menuEntries.push({name: "Menu Entry 2", functionName: "function2"}); ss.addMenu("addMenuExample", menuEntries); }
パラメータ
Name | 型 | 説明 |
---|---|---|
name | String | 作成するメニューの名前。 |
subMenus | Object[] | name パラメータと functionName
パラメータを含む JavaScript マップの配列。付属のライブラリの関数(
Library.libFunction1 など)を使用できます。 |
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addViewer(emailAddress)
指定されたユーザーを Spreadsheet
の閲覧者リストに追加します。ユーザーがすでに編集者のリストに登録されている場合、このメソッドは効力がありません。
パラメータ
Name | 型 | 説明 |
---|---|---|
emailAddress | String | 追加するユーザーのメールアドレス。 |
リターン
Spreadsheet
- この Spreadsheet
(チェーン用)。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addViewer(user)
指定されたユーザーを Spreadsheet
の閲覧者リストに追加します。ユーザーがすでに編集者のリストに登録されている場合、このメソッドは効力がありません。
パラメータ
Name | 型 | 説明 |
---|---|---|
user | User | 追加するユーザーの表現。 |
リターン
Spreadsheet
- この Spreadsheet
(チェーン用)。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
addViewers(emailAddresses)
指定されたユーザー配列を Spreadsheet
の閲覧者リストに追加します。編集者のリストに登録済みのユーザーについては、このメソッドは効力を持ちません。
パラメータ
Name | 型 | 説明 |
---|---|---|
emailAddresses | String[] | 追加するユーザーのメールアドレスの配列。 |
リターン
Spreadsheet
- この Spreadsheet
(チェーン用)。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
appendRow(rowContents)
シート内の現在のデータ領域の一番下に行を追加します。セルの内容が「=
」で始まる場合、セルは数式と解釈されます。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Appends a new row with 3 columns to the bottom of the current // data region in the sheet containing the values in the array. sheet.appendRow(["a man", "a plan", "panama"]);
パラメータ
Name | 型 | 説明 |
---|---|---|
rowContents | Object[] | シートの最後の行の後に挿入する値の配列。 |
リターン
Sheet
- メソッド チェーンに役立つシート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
autoResizeColumn(columnPosition)
指定された列の幅をコンテンツに合わせて設定します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; sheet.getRange('a1').setValue('Whenever it is a damp, drizzly November in my soul...'); // Sets the first column to a width which fits the text sheet.autoResizeColumn(1);
パラメータ
Name | 型 | 説明 |
---|---|---|
columnPosition | Integer | サイズ変更する特定の列の位置。 |
リターン
Sheet
- メソッド チェーンに役立つシート
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
copy(name)
スプレッドシートをコピーして、新しいスプレッドシートを返します。
// This code makes a copy of the current spreadsheet and names it appropriately var ss = SpreadsheetApp.getActiveSpreadsheet(); ss.copy("Copy of " + ss.getName());
パラメータ
Name | 型 | 説明 |
---|---|---|
name | String | コピーの名前。 |
リターン
Spreadsheet
- チェーン用のこのスプレッドシート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
createDeveloperMetadataFinder()
このスプレッドシートの範囲内にあるデベロッパー メタデータを検索するための DeveloperMetadataFinder
を返します。デフォルトでは、スプレッドシート、シート、行、列に関連付けられているすべてのメタデータが考慮されます。
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Adds developer metadata to the spreadsheet. ss.addDeveloperMetadata('NAME', 'CHARLIE'); ss.addDeveloperMetadata('COMPANY', 'EXAMPLE ORGANIZATION'); ss.addDeveloperMetadata('TECHNOLOGY', 'JAVASCRIPT'); // Creates a developer metadata finder. const developerMetadataFinder = ss.createDeveloperMetadataFinder(); // Finds the developer metadata objects with 'COMPANY' as the key. const googleMetadataFromSpreadsheet = developerMetadataFinder.withKey('COMPANY').find(); // Gets the first result of developer metadata that has the key 'COMPANY' and logs its value. console.log(googleMetadataFromSpreadsheet[0].getValue());
リターン
DeveloperMetadataFinder
- このスプレッドシートの範囲内のメタデータを検索するデベロッパーのメタデータ ファインダー。
createTextFinder(findText)
スプレッドシートのテキスト ファインダーを作成します。これを使用して、スプレッドシート内のテキストを検索、置換できます。検索はスプレッドシートの最初のシートから開始されます。
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // Creates a text finder. var textFinder = spreadsheet.createTextFinder('dog'); // Returns the first occurrence of 'dog' in the spreadsheet. var firstOccurrence = textFinder.findNext(); // Replaces the last found occurrence of 'dog' with 'cat' and returns the number // of occurrences replaced. var numOccurrencesReplaced = findOccurrence.replaceWith('cat');
パラメータ
Name | 型 | 説明 |
---|---|---|
findText | String | 検索するテキストです。 |
リターン
TextFinder
- スプレッドシートの TextFinder
。
deleteActiveSheet()
現在アクティブなシートを削除します。
// The code below deletes the currently active sheet and stores the new active sheet in a // variable var newSheet = SpreadsheetApp.getActiveSpreadsheet().deleteActiveSheet();
リターン
Sheet
- 新しいアクティブ シート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
deleteColumn(columnPosition)
指定された列位置の列を削除します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Columns start at "1" - this deletes the first column sheet.deleteColumn(1);
パラメータ
Name | 型 | 説明 |
---|---|---|
columnPosition | Integer | 列の位置。最初の列は 1 から始まります。 |
リターン
Sheet
- メソッド チェーンに役立つシート
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
deleteColumns(columnPosition, howMany)
指定された列位置から始まるいくつかの列を削除します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Columns start at "1" - this deletes the first two columns sheet.deleteColumns(1, 2);
パラメータ
Name | 型 | 説明 |
---|---|---|
columnPosition | Integer | 削除する最初の列の位置。 |
howMany | Integer | 削除する列の数。 |
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
deleteRow(rowPosition)
指定された行位置の行を削除します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Rows start at "1" - this deletes the first row sheet.deleteRow(1);
パラメータ
Name | 型 | 説明 |
---|---|---|
rowPosition | Integer | 行の位置。最初の行は 1 から始まります。 |
リターン
Sheet
- メソッド チェーンに役立つシート
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
deleteRows(rowPosition, howMany)
指定された行位置から始まるいくつかの行を削除します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Rows start at "1" - this deletes the first two rows sheet.deleteRows(1, 2);
パラメータ
Name | 型 | 説明 |
---|---|---|
rowPosition | Integer | 削除する最初の行の位置。 |
howMany | Integer | 削除する行数。 |
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
deleteSheet(sheet)
指定したシートを削除します。
// The code below deletes the specified sheet. var ss = SpreadsheetApp.getActive(); var sheet = ss.getSheetByName('My Sheet'); ss.deleteSheet(sheet);
パラメータ
Name | 型 | 説明 |
---|---|---|
sheet | Sheet | 削除するシート。 |
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
duplicateActiveSheet()
アクティブ シートを複製してアクティブ シートにします。
// The code below makes a duplicate of the active sheet SpreadsheetApp.getActiveSpreadsheet().duplicateActiveSheet();
リターン
Sheet
- 新しいシート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getActiveCell()
このシート内のアクティブなセルを返します。
注: 現在ハイライト表示されているセルを返す getCurrentCell()
を使用することをおすすめします。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Returns the active cell var cell = sheet.getActiveCell();
リターン
Range
- 現在のアクティブ セル
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getActiveRange()
アクティブ シート内の選択した範囲を返します。アクティブ範囲がない場合は null
を返します。複数の範囲を選択した場合、このメソッドは最後に選択された範囲のみを返します。
「アクティブ範囲」という用語はユーザーがアクティブ シートで選択した範囲のことを指しますが、カスタム関数ではアクティブに再計算されているセルを指します。
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var activeRange = sheet.getActiveRange();
リターン
Range
- アクティブ範囲
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
関連情報
getActiveRangeList()
アクティブ シート内のアクティブ範囲のリストを返します。アクティブな範囲がない場合は null
を返します。
範囲が 1 つ選択された場合は、getActiveRange()
呼び出しとして機能します。
var sheet = SpreadsheetApp.getActiveSheet(); // Returns the list of active ranges. var activeRangeList = sheet.getActiveRangeList();
リターン
RangeList
- アクティブ範囲のリスト
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
関連情報
getActiveSheet()
スプレッドシート内のアクティブ シートを取得します。
スプレッドシート内のアクティブ シートは、スプレッドシートの UI に表示されているシートです。
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
リターン
Sheet
- スプレッドシート内のアクティブ シート。
getAs(contentType)
このオブジェクト内のデータを、指定されたコンテンツ タイプに変換された blob として返します。この方法では、ファイル名に適切な拡張子(「myfile.pdf」など)が追加されます。ただし、ファイル名の最後のピリオド(存在する場合)に続く部分は、置き換えられる既存の拡張子であることを前提としています。この結果、「ShoppingList.12.25.2014」は「ShoppingList.12.25.pdf」になります。
コンバージョンの 1 日あたりの割り当てを確認するには、Google サービスの割り当てをご覧ください。新しく作成された Google Workspace ドメインには、一時的に割り当てが厳しくなることがあります。
パラメータ
Name | 型 | 説明 |
---|---|---|
contentType | String | 変換先の MIME タイプ。ほとんどの blob では、有効なオプションは 'application/pdf' のみです。BMP、GIF、JPEG、PNG 形式の画像の場合は、'image/bmp' 、'image/gif' 、'image/jpeg' 、'image/png' のいずれかも有効です。 |
リターン
Blob
- blob としてのデータ。
getBandings()
このスプレッドシートのすべての縞模様を返します。
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Gets an array of the bandings in the spreadsheet. const bandings = ss.getBandings(); // Logs the range of the first banding in the spreadsheet to the console. console.log(bandings[0].getRange().getA1Notation());
リターン
Banding[]
- このスプレッドシートの縞模様。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getBlob()
getColumnWidth(columnPosition)
指定された列の幅(ピクセル単位)を取得します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Columns start at 1 Logger.log(sheet.getColumnWidth(1));
パラメータ
Name | 型 | 説明 |
---|---|---|
columnPosition | Integer | 検証する列の位置。 |
リターン
Integer
- 列幅(ピクセル単位)
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getCurrentCell()
アクティブ シート内の現在のセルを返します。現在のセルがない場合は null
を返します。現在のセルは、Google スプレッドシートの UI でフォーカスされているセルであり、暗い枠線でハイライト表示されています。現在のセルが複数はありません。ユーザーが 1 つ以上のセル範囲を選択すると、選択範囲内のセルの 1 つが現在のセルになります。
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); // Returns the current highlighted cell in the one of the active ranges. var currentCell = sheet.getCurrentCell();
リターン
Range
- 現在のセル
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataRange()
データが存在するディメンションに対応する Range
を返します。
これは、A1 と(Sheet.getLastColumn(), Sheet.getLastRow())で指定された範囲を作成することと機能的に同等です。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This represents ALL the data var range = sheet.getDataRange(); var values = range.getValues(); // This logs the spreadsheet in CSV format with a trailing comma for (var i = 0; i < values.length; i++) { var row = ""; for (var j = 0; j < values[i].length; j++) { if (values[i][j]) { row = row + values[i][j]; } row = row + ","; } Logger.log(row); }
リターン
Range
- スプレッドシート内のすべてのデータを含む範囲
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataSourceFormulas()
すべてのデータソース式を取得します。
// Opens the spreadsheet by its ID. If you created your script from within a Google Sheets // file, use SpreadsheetApp.getActiveSpreadsheet(). // TODO(developer): Replace the ID with your own. const ss = SpreadsheetApp.openById('abc123456'); // Gets Sheet1 by its name. const sheet = ss.getSheetByName('Sheet1'); // Gets an array of the data source formulas on Sheet1. // To get an array of data source formulas for the entire spreadsheet, // replace 'sheet' with 'ss'. const dataSourceFormulas = sheet.getDataSourceFormulas(); // Logs the first data source formula in the array. console.log(dataSourceFormulas[0].getFormula());
リターン
DataSourceFormula[]
- データソース式のリスト。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataSourcePivotTables()
すべてのデータソースのピボット テーブルを取得します。
// Opens the spreadsheet file by its ID. If you created your script from a Google Sheets file, // use SpreadsheetApp.getActiveSpreadsheet(). // TODO(developer): Replace the ID with your own. const ss = SpreadsheetApp.openById('abc123456'); // Gets Sheet1 by its name. const sheet = ss.getSheetByName('Sheet1'); // Gets an array of the data source pivot tables on Sheet1. // To get an array of data source pivot tables for the entire // spreadsheet, replace 'sheet' with 'ss'. const dataSourcePivotTables = sheet.getDataSourcePivotTables(); // Logs the last time that the first pivot table in the array was refreshed. console.log(dataSourcePivotTables[0].getStatus().getLastRefreshedTime());
リターン
DataSourcePivotTable[]
- データソースのピボット テーブルのリスト。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataSourceRefreshSchedules()
このスプレッドシートの更新スケジュールを取得します。
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Activates BigQuery operations for the connected spreadsheet. SpreadsheetApp.enableBigQueryExecution(); // Gets the frequency type of the first referesh schedule in the array. const frequencyType = ss.getDataSourceRefreshSchedules()[0] .getFrequency() .getFrequencyType() .toString(); // Logs the frequency type to the console. console.log(frequencyType);
リターン
DataSourceRefreshSchedule[]
- このスプレッドシートの更新スケジュール。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataSourceSheets()
スプレッドシート内のすべてのデータソース シートを返します。
// Turns data execution on for BigQuery data sources. SpreadsheetApp.enableBigQueryExecution(); // Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Gets the first data source sheet in the spreadsheet. const dataSource = ss.getDataSourceSheets()[0]; // Gets the name of the data source sheet. console.log(dataSource.asSheet().getName());
リターン
DataSourceSheet[]
- すべてのデータソース シートの配列。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataSourceTables()
すべてのデータソース テーブルを取得します。
// Opens the spreadsheet file by its ID. If you created your script from a Google Sheets file, // use SpreadsheetApp.getActiveSpreadsheet(). // TODO(developer): Replace the ID with your own. const ss = SpreadsheetApp.openById('abc123456'); // Gets Sheet1 by its name. const sheet = ss.getSheetByName('Sheet1'); // Gets an array of data source tables on Sheet1. // To get an array of data source tables for the entire spreadsheet, // replace 'sheet' with 'ss'. const dataSourceTables = sheet.getDataSourceTables(); // Logs the last completed data execution time on the first data source table. console.log(dataSourceTables[0].getStatus().getLastExecutionTime());
リターン
DataSourceTable[]
- データソース テーブルのリスト。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataSources()
スプレッドシート内のすべてのデータソースを返します。
// Turns data execution on for BigQuery data sources. SpreadsheetApp.enableBigQueryExecution(); // Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Gets the data sources on the spreadsheet. const dataSources = ss.getDataSources(); // Logs the name of the first column on the first data source. console.log(dataSources[0].getColumns()[0].getName());
リターン
DataSource[]
- すべてのデータソースの配列。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDeveloperMetadata()
最上位のスプレッドシートに関連付けられているデベロッパー メタデータを取得します。
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Adds 'Google' as a key to the spreadsheet metadata. ss.addDeveloperMetadata('Google'); // Gets the spreadsheet's metadata. const ssMetadata = ss.getDeveloperMetadata(); // Gets the first set of the spreadsheet's metadata and logs the key to the console. console.log(ssMetadata[0].getKey());
リターン
DeveloperMetadata[]
- この範囲に関連付けられているデベロッパー メタデータ。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getEditors()
この Spreadsheet
の編集者のリストを取得します。
リターン
User[]
- 編集権限を持つユーザーの配列。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFormUrl()
このスプレッドシートに回答を送信するフォームの URL を返します。このスプレッドシートにフォームが関連付けられていない場合は null
を返します。複数のフォームがこのスプレッドシートに回答を送信した場合、返されるフォームの URL は不確定です。別の方法として、Sheet.getFormUrl()
メソッドでシートフォームごとの URL の関連付けを取得することもできます。
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Gets the form URL from the spreadsheet. const formUrl = ss.getFormUrl(); // Logs the form URL to the console. console.log(formUrl);
リターン
String
- このスプレッドシートに回答を配置するフォームの URL。このスプレッドシートにフォームが関連付けられていない場合は null
。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFrozenColumns()
固定された列の数を返します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; Logger.log("Number of frozen columns: %s", sheet.getFrozenColumns());
リターン
Integer
- 固定列の数
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFrozenRows()
固定された行の数を返します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; Logger.log("Number of frozen rows: %s", sheet.getFrozenRows());
リターン
Integer
- 固定された行の数
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getId()
このスプレッドシートの一意の識別子を取得します。スプレッドシート ID は URL から抽出できます。 たとえば、URL https://docs.google.com/spreadsheets/d/abc1234567/edit#gid=0 のスプレッドシート ID は「abc1234567」です。
// The code below logs the ID for the active spreadsheet. Logger.log(SpreadsheetApp.getActiveSpreadsheet().getId());
リターン
String
- スプレッドシートの一意の ID(またはキー)。
getImages()
シート上のすべてのグリッド上の画像を返します。
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Gets Sheet1 by its name. const sheet = ss.getSheetByName('Sheet1'); // Gets the over-the-grid images from Sheet1. // To get the over-the-grid images from the entire spreadsheet, use ss.getImages() instead. const images = sheet.getImages(); // For each image, logs the anchor cell in A1 notation. for (const image of images) { console.log(image.getAnchorCell().getA1Notation()); }
リターン
OverGridImage[]
- グリッド上の画像の配列。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getIterativeCalculationConvergenceThreshold()
反復計算で使用されるしきい値を返します。逐次計算の結果の差がこの値より小さいと、反復計算は停止します。
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Sets the iterative calculation convergence threshold for the spreadsheet. ss.setIterativeCalculationConvergenceThreshold(2); // Logs the threshold to the console. console.log(ss.getIterativeCalculationConvergenceThreshold());
リターン
Number
- 収束のしきい値。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getLastColumn()
コンテンツを含む最後の列の位置を返します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This logs the value in the very last cell of this sheet var lastRow = sheet.getLastRow(); var lastColumn = sheet.getLastColumn(); var lastCell = sheet.getRange(lastRow, lastColumn); Logger.log(lastCell.getValue());
リターン
Integer
- コンテンツを含むシートの最後の列
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getLastRow()
コンテンツを含む最後の行の位置を返します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This logs the value in the very last cell of this sheet var lastRow = sheet.getLastRow(); var lastColumn = sheet.getLastColumn(); var lastCell = sheet.getRange(lastRow, lastColumn); Logger.log(lastCell.getValue());
リターン
Integer
- コンテンツを含むシートの最後の行
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getMaxIterativeCalculationCycles()
反復計算で使用する反復処理の最大数を返します。
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Sets the max iterative calculation cycles for the spreadsheet. ss.setMaxIterativeCalculationCycles(10); // Logs the max iterative calculation cycles to the console. console.log(ss.getMaxIterativeCalculationCycles());
リターン
Integer
- 計算の反復処理の最大数。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getName()
ドキュメントの名前を取得します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); Logger.log(ss.getName());
リターン
String
- スプレッドシートの名前。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getNamedRanges()
このスプレッドシート内のすべての名前付き範囲を取得します。
// The code below logs the name of the first named range. var namedRanges = SpreadsheetApp.getActiveSpreadsheet().getNamedRanges(); for (var i = 0; i < namedRanges.length; i++) { Logger.log(namedRanges[i].getName()); }
リターン
NamedRange[]
- スプレッドシート内のすべての名前付き範囲の配列。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getNumSheets()
このスプレッドシート内のシート数を返します。
// The code below logs the number of sheets in the active spreadsheet. Logger.log(SpreadsheetApp.getActiveSpreadsheet().getNumSheets());
リターン
Integer
- スプレッドシート内のシート数。
getOwner()
ドキュメントのオーナー、または共有ドライブ内のドキュメントの場合は null
を返します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var owner = ss.getOwner(); Logger.log(owner.getEmail());
リターン
User
- ドキュメントのオーナー、またはドキュメントが共有ドライブ内にある場合は null
。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getPredefinedSpreadsheetThemes()
事前定義されたテーマのリストを返します。
// The code below returns the list of predefined themes. var predefinedThemesList = SpreadsheetApp.getActiveSpreadsheet() .getPredefinedSpreadsheetThemes();
リターン
SpreadsheetTheme[]
- 事前定義されたテーマのリスト。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getProtections(type)
スプレッドシート内のすべての保護されている範囲またはシートを表すオブジェクトの配列を取得します。
// Remove all range protections in the spreadsheet that the user has permission to edit. var ss = SpreadsheetApp.getActive(); var protections = ss.getProtections(SpreadsheetApp.ProtectionType.RANGE); for (var i = 0; i < protections.length; i++) { var protection = protections[i]; if (protection.canEdit()) { protection.remove(); } }
// Remove all sheet protections in the spreadsheet that the user has permission to edit. var ss = SpreadsheetApp.getActive(); var protections = ss.getProtections(SpreadsheetApp.ProtectionType.SHEET); for (var i = 0; i < protections.length; i++) { var protection = protections[i]; if (protection.canEdit()) { protection.remove(); } }
パラメータ
Name | 型 | 説明 |
---|---|---|
type | ProtectionType | 保護地域のタイプ(SpreadsheetApp.ProtectionType.RANGE または SpreadsheetApp.ProtectionType.SHEET )。 |
リターン
Protection[]
- スプレッドシート内のすべての保護されている範囲またはシートを表すオブジェクトの配列。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getRange(a1Notation)
A1 表記または R1C1 表記で指定した範囲を返します。
// Get a range A1:D4 on sheet titled "Invoices" var ss = SpreadsheetApp.getActiveSpreadsheet(); var range = ss.getRange("Invoices!A1:D4"); // Get cell A1 on the first sheet var sheet = ss.getSheets()[0]; var cell = sheet.getRange("A1");
パラメータ
Name | 型 | 説明 |
---|---|---|
a1Notation | String | 返される範囲を A1 表記または R1C1 表記で指定します。 |
リターン
Range
- 指定された位置の範囲
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getRangeByName(name)
名前付き範囲を返します。指定された名前を持つ範囲が見つからない場合は null
を返します。スプレッドシートの複数のシートで同じ範囲名を使用している場合は、引用符を追加せずにシート名を指定します(例: getRangeByName('TaxRates')
または getRangeByName('Sheet Name!TaxRates')
。ただし、getRangeByName('"Sheet
Name"!TaxRates')
は指定できません)。
// Log the number of columns for the range named 'TaxRates' in the active spreadsheet. var range = SpreadsheetApp.getActiveSpreadsheet().getRangeByName('TaxRates'); if (range != null) { Logger.log(range.getNumColumns()); }
パラメータ
Name | 型 | 説明 |
---|---|---|
name | String | 取得する範囲の名前。 |
リターン
Range
- 指定された名前を持つセルの範囲。
getRangeList(a1Notations)
A1 表記または R1C1 表記の空でないリストで指定された同じシート内の範囲を表す RangeList
コレクションを返します。
// Get a list of ranges A1:D4, F1:H4. var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var rangeList = sheet.getRangeList(['A1:D4', 'F1:H4']);
パラメータ
Name | 型 | 説明 |
---|---|---|
a1Notations | String[] | 返される範囲のリストを A1 表記または R1C1 表記で指定します。 |
リターン
RangeList
- 指定されたロケーションの範囲リスト
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getRecalculationInterval()
このスプレッドシートの計算間隔を返します。
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Logs the calculation interval for the spreadsheet to the console. console.log(ss.getRecalculationInterval().toString());
リターン
RecalculationInterval
- このスプレッドシートの計算間隔。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getRowHeight(rowPosition)
指定された行の高さ(ピクセル単位)を取得します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Rows start at 1 Logger.log(sheet.getRowHeight(1));
パラメータ
Name | 型 | 説明 |
---|---|---|
rowPosition | Integer | 検証する行の位置。 |
リターン
Integer
- 行の高さ(ピクセル単位)
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getSelection()
スプレッドシートの現在の Selection
を返します。
var selection = SpreadsheetApp.getActiveSpreadsheet().getSelection(); var currentCell = selection.getCurrentCell();
リターン
Selection
- 現在の選択
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getSheetByName(name)
指定した名前のシートを返します。
同じ名前のシートが複数ある場合は、左端のシートが返されます。指定された名前のシートが存在しない場合は null
を返します。
// The code below logs the index of a sheet named "Expenses" var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Expenses"); if (sheet != null) { Logger.log(sheet.getIndex()); }
パラメータ
Name | 型 | 説明 |
---|---|---|
name | String | 取得するシートの名前。 |
リターン
Sheet
- 指定された名前のシート。
getSheetId()
このオブジェクトによって表されるシートの ID を返します。
スプレッドシートに固有のシートの ID です。この ID は、シートの位置とは無関係にシートの作成時に割り当てられる単調に増加する整数です。これは、Sheet
インスタンスではなく gridId
パラメータを受け取る Range.copyFormatToRange(gridId, column, columnEnd, row, rowEnd)
などのメソッドと組み合わせて使用できます。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; Logger.log(sheet.getSheetId());
リターン
Integer
- スプレッドシートに固有のシートの ID
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getSheetName()
シート名を返します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; Logger.log(sheet.getSheetName());
リターン
String
- シートの名前
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getSheetValues(startRow, startColumn, numRows, numColumns)
指定された座標を起点とする、この範囲の値の長方形グリッドを返します。行または列の位置として値が -1 であれば、シート内にデータを含む最後の行または列を取得することになります。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // The two samples below produce the same output var values = sheet.getSheetValues(1, 1, 3, 3); Logger.log(values); var range = sheet.getRange(1, 1, 3, 3); values = range.getValues(); Logger.log(values);
パラメータ
Name | 型 | 説明 |
---|---|---|
startRow | Integer | 開始行の位置。 |
startColumn | Integer | 開始列の位置。 |
numRows | Integer | 値を返す行数です。 |
numColumns | Integer | 値を返す列の数です。 |
リターン
Object[][]
- 2 次元の値の配列
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getSheets()
このスプレッドシート内のすべてのシートを取得します。
// The code below logs the name of the second sheet var sheets = SpreadsheetApp.getActiveSpreadsheet().getSheets(); if (sheets.length > 1) { Logger.log(sheets[1].getName()); }
リターン
Sheet[]
- スプレッドシート内のすべてのシートの配列。
getSpreadsheetLocale()
スプレッドシートの言語 / 地域を取得します。
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Gets the spreadsheet locale. const ssLocale = ss.getSpreadsheetLocale(); // Logs the locale to the console. console.log(ssLocale);
リターン
String
- スプレッドシートの言語 / 地域。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getSpreadsheetTheme()
スプレッドシートの現在のテーマを返します。テーマが適用されていない場合は null
を返します。
// The code below returns the current theme of the spreadsheet. var currentTheme = SpreadsheetApp.getActiveSpreadsheet().getSpreadsheetTheme();
リターン
SpreadsheetTheme
- 現在適用されているテーマ。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getSpreadsheetTimeZone()
スプレッドシートのタイムゾーンを取得します。
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Sets the time zone of the spreadsheet. ss.setSpreadsheetTimeZone('America/New_York'); // Gets the time zone of the spreadsheet. const ssTimeZone = ss.getSpreadsheetTimeZone(); // Logs the time zone to the console. console.log(ssTimeZone);
リターン
String
- 「long」形式で指定されたタイムゾーン(たとえば、Joda.org でリストされている「America/New_York」)。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getUrl()
指定したスプレッドシートの URL を返します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); Logger.log(ss.getUrl());
リターン
String
- 指定したスプレッドシートの URL。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getViewers()
この Spreadsheet
の閲覧者とコメント投稿者のリストを取得します。
リターン
User[]
- 閲覧またはコメントの権限を持つユーザーの配列。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
hideColumn(column)
指定した範囲内の列を非表示にします。
let ss = SpreadsheetApp.getActiveSpreadsheet(); let sheet = ss.getSheets()[0]; // This hides the first column let range = sheet.getRange("A1"); sheet.hideColumn(range); // This hides the first 3 columns let range = sheet.getRange("A:C"); sheet.hideColumn(range);
パラメータ
Name | 型 | 説明 |
---|---|---|
column | Range | 非表示にする列の範囲です。 |
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
hideRow(row)
指定した範囲内の行を非表示にします。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This hides the first row var range = sheet.getRange("A1"); sheet.hideRow(range);
パラメータ
Name | 型 | 説明 |
---|---|---|
row | Range | 非表示にする行の範囲です。 |
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertColumnAfter(afterPosition)
指定された列位置の後に列を挿入します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This inserts a column after the first column position sheet.insertColumnAfter(1);
パラメータ
Name | 型 | 説明 |
---|---|---|
afterPosition | Integer | 新しい列の追加先となる列です。 |
リターン
Sheet
- メソッド チェーンに役立つシート
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertColumnBefore(beforePosition)
指定された列位置の前に列を挿入します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This inserts a column in the first column position sheet.insertColumnBefore(1);
パラメータ
Name | 型 | 説明 |
---|---|---|
beforePosition | Integer | 新しい列を追加する前の列。 |
リターン
Sheet
- メソッド チェーンに役立つシート
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertColumnsAfter(afterPosition, howMany)
指定された列位置の後に、指定された数の列を挿入します。
let ss = SpreadsheetApp.getActiveSpreadsheet(); let sheet = ss.getSheets()[0]; // Inserts two columns after the first column on the first sheet of the spreadsheet. sheet.insertColumnsAfter(1,2);
パラメータ
Name | 型 | 説明 |
---|---|---|
afterPosition | Integer | 新しい列の追加先となる列です。 |
howMany | Integer | 挿入する列の数。 |
リターン
Sheet
- メソッド チェーンに役立つシート
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertColumnsBefore(beforePosition, howMany)
指定された列位置の前に数列を挿入します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This inserts five columns before the first column sheet.insertColumnsBefore(1, 5);
パラメータ
Name | 型 | 説明 |
---|---|---|
beforePosition | Integer | 新しい列を追加する前の列。 |
howMany | Integer | 挿入する列の数。 |
リターン
Sheet
- メソッド チェーンに役立つシート
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertDataSourceSheet(spec)
スプレッドシートに新しい DataSourceSheet
を挿入し、データ実行を開始します。その結果、新しいシートがアクティブ シートにもなります。
データソース タイプが有効になっていない場合、例外をスローします。特定のデータソース タイプに対してデータ実行を有効にするには、SpreadsheetApp#enable...Execution()
メソッドを使用します。
// Activates BigQuery operations. SpreadsheetApp.enableBigQueryExecution(); // Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Builds a data source specification. // TODO (developer): Update the project ID to your own Google Cloud project ID. const dataSourceSpec = SpreadsheetApp.newDataSourceSpec() .asBigQuery() .setProjectId('project-id-1') .setTableProjectId('bigquery-public-data') .setDatasetId('ncaa_basketball') .setTableId('mbb_historical_teams_games') .build(); // Adds the data source and its data to the spreadsheet. ss.insertDataSourceSheet(dataSourceSpec);
パラメータ
Name | 型 | 説明 |
---|---|---|
spec | DataSourceSpec | 挿入するデータソースの仕様。 |
リターン
DataSourceSheet
- 新しいデータソース シート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertImage(blobSource, column, row)
ドキュメントの指定された行と列に Spreadsheet
を画像として挿入します。画像サイズは blob の内容から取得されます。サポートされている blob の最大サイズは 2 MB です。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; var blob = Utilities.newBlob(binaryData, 'image/png', 'MyImageName'); sheet.insertImage(blob, 1, 1);
パラメータ
Name | 型 | 説明 |
---|---|---|
blobSource | BlobSource | 画像コンテンツ、MIME タイプ、名前(オプション)を含む blob。 |
column | Integer | 列の位置。 |
row | Integer | 行の位置。 |
リターン
OverGridImage
- 挿入される画像。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertImage(blobSource, column, row, offsetX, offsetY)
ピクセル オフセットを使用して、Spreadsheet
をドキュメント内の指定された行と列に画像として挿入します。画像サイズは blob の内容から取得されます。サポートされている blob の最大サイズは 2 MB です。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; var blob = Utilities.newBlob(binaryData, 'image/png', 'MyImageName'); sheet.insertImage(blob, 1, 1, 10, 10);
パラメータ
Name | 型 | 説明 |
---|---|---|
blobSource | BlobSource | 画像コンテンツ、MIME タイプ、名前(オプション)を含む blob。 |
column | Integer | 列の位置。 |
row | Integer | 行の位置。 |
offsetX | Integer | セルの隅からの水平オフセット(ピクセル単位)。 |
offsetY | Integer | セルの隅からの垂直オフセット(ピクセル単位)。 |
リターン
OverGridImage
- 挿入される画像。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertImage(url, column, row)
ドキュメントの指定された行と列に画像を挿入します。
指定された URL は一般公開されている必要があります。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; sheet.insertImage("https://www.google.com/images/srpr/logo3w.png", 1, 1);
パラメータ
Name | 型 | 説明 |
---|---|---|
url | String | 画像の URL です。 |
column | Integer | グリッドの列の位置。 |
row | Integer | グリッドの行の位置。 |
リターン
OverGridImage
- 挿入される画像。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertImage(url, column, row, offsetX, offsetY)
ドキュメント内の指定された行と列に、ピクセル オフセットで画像を挿入します。
指定された URL は一般公開されている必要があります。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; sheet.insertImage("https://www.google.com/images/srpr/logo3w.png", 1, 1, 10, 10);
パラメータ
Name | 型 | 説明 |
---|---|---|
url | String | 画像の URL。 |
column | Integer | 列の位置。 |
row | Integer | 行の位置。 |
offsetX | Integer | セルの隅からの水平オフセット(ピクセル単位)。 |
offsetY | Integer | セルの隅からの垂直オフセット(ピクセル単位)。 |
リターン
OverGridImage
- 挿入された画像。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertRowAfter(afterPosition)
指定された行位置の後に行を挿入します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This inserts a row after the first row position sheet.insertRowAfter(1);
パラメータ
Name | 型 | 説明 |
---|---|---|
afterPosition | Integer | この行の後に新しい行を追加する行。 |
リターン
Sheet
- メソッド チェーンに役立つシート
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertRowBefore(beforePosition)
指定された行位置の前に行を挿入します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This inserts a row before the first row position sheet.insertRowBefore(1);
パラメータ
Name | 型 | 説明 |
---|---|---|
beforePosition | Integer | 新しい行を追加する前の行。 |
リターン
Sheet
- メソッド チェーンに役立つシート
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertRowsAfter(afterPosition, howMany)
指定された行位置の後に数行を挿入します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This inserts five rows after the first row sheet.insertRowsAfter(1, 5);
パラメータ
Name | 型 | 説明 |
---|---|---|
afterPosition | Integer | この行の後に新しい行を追加する行。 |
howMany | Integer | 挿入する行数。 |
リターン
Sheet
- メソッド チェーンに役立つシート
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertRowsBefore(beforePosition, howMany)
指定された行位置の前に数行を挿入します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This inserts five rows before the first row sheet.insertRowsBefore(1, 5);
パラメータ
Name | 型 | 説明 |
---|---|---|
beforePosition | Integer | 新しい行を追加する前の行。 |
howMany | Integer | 挿入する行数。 |
リターン
Sheet
- メソッド チェーンに役立つシート
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertSheet()
insertSheet(sheetIndex)
スプレッドシートの指定されたインデックスに新しいシートを挿入します。新しいシートがアクティブ シートになります。
var ss = SpreadsheetApp.getActiveSpreadsheet(); ss.insertSheet(1);
パラメータ
Name | 型 | 説明 |
---|---|---|
sheetIndex | Integer | 新しく作成されたシートのインデックス。スプレッドシートの最初のシートとしてシートを挿入するには、0 に設定します。 |
リターン
Sheet
- 新しいシート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertSheet(sheetIndex, options)
スプレッドシートの指定されたインデックスに新しいシートを挿入し、オプションの高度な引数を使用します。新しいシートがアクティブ シートになります。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var templateSheet = ss.getSheetByName('Sales'); ss.insertSheet(1, {template: templateSheet});
パラメータ
Name | 型 | 説明 |
---|---|---|
sheetIndex | Integer | 新しく作成されたシートのインデックス。スプレッドシートの最初のシートとしてシートを挿入するには、0 に設定します。 |
options | Object | JavaScript の高度な引数(オプション)。 |
拡張パラメータ
Name | 型 | 説明 |
---|---|---|
template | Sheet | テンプレート シート オブジェクトのすべてのデータが新しいシートにコピーされます。シート テンプレートは、スプレッドシート オブジェクトのシートのいずれかである必要があります。 |
リターン
Sheet
- 新しいシート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertSheet(options)
デフォルトのシート名とオプションの高度な引数を使用して、スプレッドシートに新しいシートを挿入します。新しいシートがアクティブ シートになります。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var templateSheet = ss.getSheetByName('Sales'); ss.insertSheet({template: templateSheet});
パラメータ
Name | 型 | 説明 |
---|---|---|
options | Object | オプションの JavaScript 高度な引数。下記をご覧ください。 |
拡張パラメータ
Name | 型 | 説明 |
---|---|---|
template | Sheet | テンプレート シート オブジェクトのすべてのデータが新しいシートにコピーされます。シート テンプレートは、このスプレッドシート オブジェクトのシートのいずれかである必要があります。 |
リターン
Sheet
- 新しいシート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertSheet(sheetName)
指定した名前で新しいシートをスプレッドシートに挿入します。新しいシートがアクティブ シートになります。
var ss = SpreadsheetApp.getActiveSpreadsheet(); ss.insertSheet('My New Sheet');
パラメータ
Name | 型 | 説明 |
---|---|---|
sheetName | String | 新しいシートの名前。 |
リターン
Sheet
- 新しいシート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertSheet(sheetName, sheetIndex)
指定したインデックスに指定した名前で新しいシートを挿入します。新しいシートがアクティブ シートになります。
var ss = SpreadsheetApp.getActiveSpreadsheet(); ss.insertSheet('My New Sheet', 1);
パラメータ
Name | 型 | 説明 |
---|---|---|
sheetName | String | 新しいシートの名前。 |
sheetIndex | Integer | 新しく作成されたシートのインデックス。スプレッドシートの最初のシートとしてシートを挿入するには、0 に設定します。 |
リターン
Sheet
- 新しいシート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertSheet(sheetName, sheetIndex, options)
指定したインデックスに指定した名前で新しいシートを挿入し、オプションの高度な引数を使用します。新しいシートがアクティブ シートになります。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var templateSheet = ss.getSheetByName('Sales'); ss.insertSheet('My New Sheet', 1, {template: templateSheet});
パラメータ
Name | 型 | 説明 |
---|---|---|
sheetName | String | 新しいシートの名前。 |
sheetIndex | Integer | 新しく挿入されたシートのインデックス。スプレッドシートの最初のシートとしてシートを挿入するには、0 に設定します。 |
options | Object | JavaScript の高度な引数(オプション)。 |
拡張パラメータ
Name | 型 | 説明 |
---|---|---|
template | Sheet | テンプレート シート オブジェクトのすべてのデータが新しいシートにコピーされます。シート テンプレートは、スプレッドシート オブジェクトのシートのいずれかである必要があります。 |
リターン
Sheet
- 新しいシート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertSheet(sheetName, options)
指定された名前で新しいシートをスプレッドシートに挿入し、オプションの高度な引数を使用します。新しいシートがアクティブ シートになります。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var templateSheet = ss.getSheetByName('Sales'); ss.insertSheet('My New Sheet', {template: templateSheet});
パラメータ
Name | 型 | 説明 |
---|---|---|
sheetName | String | 新しいシートの名前。 |
options | Object | JavaScript の高度な引数(オプション)。 |
拡張パラメータ
Name | 型 | 説明 |
---|---|---|
template | Sheet | テンプレート シート オブジェクトのすべてのデータが新しいシートにコピーされます。シート テンプレートは、スプレッドシート オブジェクトのシートのいずれかである必要があります。 |
リターン
Sheet
- 新しいシート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertSheetWithDataSourceTable(spec)
スプレッドシートに新しいシートを挿入し、指定されたデータソース仕様でシート全体にわたる DataSourceTable
を作成して、データ実行を開始します。その結果、新しいシートがアクティブ シートになります。
データソース タイプが有効になっていない場合、例外をスローします。特定のデータソース タイプに対してデータ実行を有効にするには、SpreadsheetApp#enable...Execution()
メソッドを使用します。
// Activates BigQuery operations. SpreadsheetApp.enableBigQueryExecution(); // Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Adds a sheet and sets cell A1 as the parameter cell. const parameterCell = ss.insertSheet('parameterSheet').getRange('A1'); // Sets the value of the parameter cell to 'Duke'. parameterCell.setValue('Duke'); const query = 'select * from `bigquery-public-data`.`ncaa_basketball`.' + '`mbb_historical_tournament_games` WHERE win_school_ncaa = @SCHOOL'; // Adds a data source with a query parameter. // TODO(developer): Update the project ID to your own Google Cloud project ID. const dataSourceSpec = SpreadsheetApp.newDataSourceSpec() .asBigQuery() .setProjectId('project-id-1') .setRawQuery(query) .setParameterFromCell('SCHOOL', 'parameterSheet!A1') .build(); // Adds sheets for the data source and data source table to the spreadsheet. ss.insertSheetWithDataSourceTable(dataSourceSpec);
パラメータ
Name | 型 | 説明 |
---|---|---|
spec | DataSourceSpec | 挿入するデータソースの仕様。 |
リターン
Sheet
- 新しいシート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
isColumnHiddenByUser(columnPosition)
指定された列がユーザーによって非表示かどうかを返します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Columns start at 1 Logger.log(sheet.isColumnHiddenByUser(1));
パラメータ
Name | 型 | 説明 |
---|---|---|
columnPosition | Integer | 検証する列の位置。 |
リターン
Boolean
- 列が非表示の場合は true
、それ以外の場合は false
。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
isIterativeCalculationEnabled()
このスプレッドシートで反復計算が有効になっているかどうかを返します。
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Activates iterative calculation on the spreadsheet. ss.setIterativeCalculationEnabled(true); // Logs whether iterative calculation is activated for the spreadsheet. console.log(ss.isIterativeCalculationEnabled());
リターン
Boolean
- 反復計算が有効になっている場合は true
、そうでない場合は false
。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
isRowHiddenByFilter(rowPosition)
指定された行が(フィルタ表示ではなく)フィルタによって非表示かどうかを返します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Rows start at 1 Logger.log(sheet.isRowHiddenByFilter(1));
パラメータ
Name | 型 | 説明 |
---|---|---|
rowPosition | Integer | 検証する行の位置。 |
リターン
Boolean
- 行が非表示の場合は true
、それ以外の場合は false
。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
isRowHiddenByUser(rowPosition)
指定された行がユーザーによって非表示かどうかを返します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Rows start at 1 Logger.log(sheet.isRowHiddenByUser(1));
パラメータ
Name | 型 | 説明 |
---|---|---|
rowPosition | Integer | 検証する行の位置。 |
リターン
Boolean
- 行が非表示の場合は true
、それ以外の場合は false
。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
moveActiveSheet(pos)
アクティブなシートをシートリスト内の指定された位置に移動します。位置が負の値またはシート数より大きい場合に、例外をスローします。
// This example assumes that there are 2 sheets in the current // active spreadsheet: one named "first" in position 1 and another named "second" // in position 2. var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // Gets the "first" sheet and activates it. var sheet = spreadsheet.getSheetByName("first").activate(); // Logs 'Current index of sheet: 1' console.log("Current index of sheet: %s", sheet.getIndex()); spreadsheet.moveActiveSheet(2); // Logs 'New index of sheet: 2' console.log("New index of sheet: %s", sheet.getIndex());
パラメータ
Name | 型 | 説明 |
---|---|---|
pos | Integer | シートリスト内でアクティブなシートを移動する 1 インデックスの位置。 |
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
moveChartToObjectSheet(chart)
新しい SheetType.OBJECT
シートを作成し、指定されたグラフをそのシートに移動します。グラフがすでに専用のシートにある場合、新しいシートは作成されずに、そのシートが返されます。
var sheet = SpreadsheetApp.getActiveSheet(); var chart = sheet.newChart().setPosition(1, 1, 0, 0).build(); sheet.insertChart(chart); var objectSheet = SpreadsheetApp.getActive().moveChartToObjectSheet(chart);
パラメータ
Name | 型 | 説明 |
---|---|---|
chart | EmbeddedChart | 移動するグラフ。 |
リターン
Sheet
- グラフが配置されているシート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
refreshAllDataSources()
サポートされているすべてのデータソースと、それらにリンクされているデータソース オブジェクトを更新し、無効なデータソース オブジェクトをスキップします。
特定のデータソース タイプに対してデータ実行を有効にするには、SpreadsheetApp#enable...Execution()
メソッドを使用します。
// Activates BigQuery operations. SpreadsheetApp.enableBigQueryExecution(); // Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Gets the first data source sheet on the spreadsheet. const dataSheet = ss.getDataSourceSheets()[0]; // Refreshes all data sources on the spreadsheet. ss.refreshAllDataSources(); // Logs the last refreshed time of the first data source sheet. console.log(`Last refresh time: ${dataSheet.getStatus().getLastRefreshedTime()}`);
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
removeEditor(emailAddress)
Spreadsheet
の編集者のリストから指定されたユーザーを削除します。このメソッドは、一般的なアクセス権を持つユーザーのクラスに所属するユーザーが Spreadsheet
にアクセスすることをブロックしません。たとえば、Spreadsheet
がユーザーのドメイン全体と共有されている場合や、Spreadsheet
がユーザーがアクセスできる共有ドライブ内にある場合です。
ドライブ ファイルの場合、閲覧者リストからもユーザーが削除されます。
パラメータ
Name | 型 | 説明 |
---|---|---|
emailAddress | String | 削除するユーザーのメールアドレス。 |
リターン
Spreadsheet
- この Spreadsheet
(チェーン用)。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
removeEditor(user)
Spreadsheet
の編集者のリストから指定されたユーザーを削除します。このメソッドは、一般的なアクセス権を持つユーザーのクラスに所属するユーザーが Spreadsheet
にアクセスすることをブロックしません。たとえば、Spreadsheet
がユーザーのドメイン全体と共有されている場合や、Spreadsheet
がユーザーがアクセスできる共有ドライブ内にある場合です。
ドライブ ファイルの場合、閲覧者リストからもユーザーが削除されます。
パラメータ
Name | 型 | 説明 |
---|---|---|
user | User | 削除するユーザーの表現。 |
リターン
Spreadsheet
- この Spreadsheet
(チェーン用)。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
removeMenu(name)
addMenu(name, subMenus)
によって追加されたメニューを削除します。name
引数の値は、対応する addMenu(name, subMenus)
の呼び出しと同じ値にする必要があります。
// The onOpen function is executed automatically every time a Spreadsheet is loaded function onOpen() { var ss = SpreadsheetApp.getActiveSpreadsheet(); ss.addMenu("badMenu", [{name: "remove bad menu", functionName: "removeBadMenu"}, {name: "foo", functionName: "foo"}]); } function removeBadMenu() { var ss = SpreadsheetApp.getActiveSpreadsheet(); ss.removeMenu("badMenu"); // name must match the name used when added the menu } function foo(){ // Do nothing }
パラメータ
Name | 型 | 説明 |
---|---|---|
name | String | 削除するメニューの名前。 |
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
removeNamedRange(name)
指定した名前の名前付き範囲を削除します。指定した名前の範囲がスプレッドシートにない場合は、例外をスローします。
// The code below creates a new named range "foo", and then remove it. var ss = SpreadsheetApp.getActiveSpreadsheet(); ss.setNamedRange("foo", ss.getActiveRange()); ss.removeNamedRange("foo");
パラメータ
Name | 型 | 説明 |
---|---|---|
name | String | 範囲名。 |
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
removeViewer(emailAddress)
Spreadsheet
の閲覧者とコメント投稿者のリストから、指定されたユーザーを削除します。ユーザーが閲覧者やコメント投稿者ではなく編集者の場合、このメソッドは効力を持ちません。また、このメソッドによって、ユーザーが一般的なアクセス権を持つユーザーのクラスに属している場合(たとえば、Spreadsheet
がユーザーのドメイン全体と共有されている場合や、Spreadsheet
がユーザーがアクセスできる共有ドライブ内にある場合)は、Spreadsheet
へのアクセスがブロックされません。
ドライブ ファイルの場合、編集者のリストからもユーザーが削除されます。
パラメータ
Name | 型 | 説明 |
---|---|---|
emailAddress | String | 削除するユーザーのメールアドレス。 |
リターン
Spreadsheet
- チェーン用のこの Spreadsheet
。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
removeViewer(user)
Spreadsheet
の閲覧者とコメント投稿者のリストから、指定されたユーザーを削除します。ユーザーが閲覧者ではなく編集者の場合、このメソッドは効力がありません。また、Spreadsheet
がユーザーのドメイン全体と共有されている場合や、Spreadsheet
がユーザーがアクセスできる共有ドライブ内にある場合など、一般的なアクセス権を持つユーザーのクラスに所属しているユーザーも、Spreadsheet
にアクセスすることはブロックされません。
ドライブ ファイルの場合、編集者のリストからもユーザーが削除されます。
パラメータ
Name | 型 | 説明 |
---|---|---|
user | User | 削除するユーザーの表現。 |
リターン
Spreadsheet
- チェーン用のこの Spreadsheet
。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
rename(newName)
ドキュメント名を変更します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); ss.rename("This is the new name");
パラメータ
Name | 型 | 説明 |
---|---|---|
newName | String | ドキュメントの新しい名前。 |
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
renameActiveSheet(newName)
現在のアクティブ シートの名前を、指定された新しい名前に変更します。
// The code below renames the active sheet to "Hello world" SpreadsheetApp.getActiveSpreadsheet().renameActiveSheet("Hello world");
パラメータ
Name | 型 | 説明 |
---|---|---|
newName | String | 現在のアクティブ シートの新しい名前。 |
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
resetSpreadsheetTheme()
適用したテーマを削除し、スプレッドシートのデフォルトのテーマを設定します。
// The code below applies default theme on the spreadsheet. SpreadsheetApp.getActiveSpreadsheet().resetSpreadsheetTheme();
リターン
SpreadsheetTheme
- デフォルトのテーマ。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setActiveRange(range)
指定した範囲をアクティブ シートの active range
として設定します。範囲内の左上のセルを current cell
として設定します。
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var range = sheet.getRange('A1:D4'); sheet.setActiveRange(range); var selection = sheet.getSelection(); // Current cell: A1 var currentCell = selection.getCurrentCell(); // Active Range: A1:D4 var activeRange = selection.getActiveRange();
パラメータ
Name | 型 | 説明 |
---|---|---|
range | Range | アクティブ範囲として設定する範囲。 |
リターン
Range
- 新しいアクティブ範囲
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setActiveRangeList(rangeList)
指定した範囲リストをアクティブ シートの active ranges
として設定します。リストの最後の範囲が active range
として設定されます。
var sheet = SpreadsheetApp.getActiveSheet(); var rangeList = sheet.getRangeList(['D4', 'B2:C4']); sheet.setActiveRangeList(rangeList); var selection = sheet.getSelection(); // Current cell: B2 var currentCell = selection.getCurrentCell(); // Active range: B2:C4 var activeRange = selection.getActiveRange(); // Active range list: [D4, B2:C4] var activeRangeList = selection.getActiveRangeList();
パラメータ
Name | 型 | 説明 |
---|---|---|
rangeList | RangeList | 選択する範囲のリスト。 |
リターン
RangeList
- 新しく選択された範囲のリスト
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setActiveSelection(range)
このシートのアクティブな選択領域を設定します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; var range = sheet.getRange("A1:D4"); sheet.setActiveSelection(range);
パラメータ
Name | 型 | 説明 |
---|---|---|
range | Range | アクティブな選択として設定する範囲。 |
リターン
Range
- 新しいアクティブ範囲
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setActiveSelection(a1Notation)
アクティブな選択を A1 表記または R1C1 表記で指定します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; sheet.setActiveSelection("A1:D4");
パラメータ
Name | 型 | 説明 |
---|---|---|
a1Notation | String | アクティブに設定する範囲。A1 表記または R1C1 表記で指定します。 |
リターン
Range
- 新しいアクティブ範囲
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setActiveSheet(sheet)
指定したシートをスプレッドシート内のアクティブ シートに設定します。Google スプレッドシートの UI には、別のスプレッドシートに属している場合を除き、選択されたシートが表示されます。
// The code below makes the first sheet active in the active spreadsheet. var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); spreadsheet.setActiveSheet(spreadsheet.getSheets()[0]);
パラメータ
Name | 型 | 説明 |
---|---|---|
sheet | Sheet | アクティブ シートとして設定するシート。 |
リターン
Sheet
- アクティブ シート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setActiveSheet(sheet, restoreSelection)
指定されたシートをスプレッドシート内のアクティブ シートとして設定し、そのシート内の直近の選択を復元するオプションを提供します。Google スプレッドシートの UI には、別のスプレッドシートに属している場合を除き、選択されたシートが表示されます。
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); var firstSheet = spreadsheet.getSheets()[0]; var secondSheet = spreadsheet.getSheets()[1]; // Set the first sheet as the active sheet and select the range D4:F4. spreadsheet.setActiveSheet(firstSheet).getRange('D4:F4').activate(); // Switch to the second sheet to do some work. spreadsheet.setActiveSheet(secondSheet); // Switch back to first sheet, and restore its selection. spreadsheet.setActiveSheet(firstSheet, true); // The selection of first sheet is restored, and it logs D4:F4 var range = spreadsheet.getActiveSheet().getSelection().getActiveRange(); Logger.log(range.getA1Notation());
パラメータ
Name | 型 | 説明 |
---|---|---|
sheet | Sheet | 新しいアクティブ シート。 |
restoreSelection | Boolean | true の場合、新しいシートがアクティブになると、新しいアクティブ シートの最新の選択が再び選択されます。false の場合、現在の選択を変更せずに新しいシートがアクティブになります。 |
リターン
Sheet
- 新しいアクティブ シート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setColumnWidth(columnPosition, width)
指定された列の幅をピクセル単位で設定します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Sets the first column to a width of 200 pixels sheet.setColumnWidth(1, 200);
パラメータ
Name | 型 | 説明 |
---|---|---|
columnPosition | Integer | 設定する列の位置を指定します。 |
width | Integer | 設定する幅(ピクセル単位)。 |
リターン
Sheet
- メソッド チェーンに役立つシート
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setCurrentCell(cell)
指定したセルを current cell
として設定します。
指定したセルがすでに選択されている範囲に存在する場合は、その範囲がアクティブ範囲になり、セルは現在のセルとなります。
指定したセルが選択した範囲に存在しない場合は、既存の選択内容が削除され、そのセルが現在のセルおよびアクティブ範囲になります。
注: 指定する Range
は 1 つのセルで構成する必要があります。そうでない場合、例外がスローされます。
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var cell = sheet.getRange('B5'); sheet.setCurrentCell(cell); var selection = sheet.getSelection(); // Current cell: B5 var currentCell = selection.getCurrentCell();
パラメータ
Name | 型 | 説明 |
---|---|---|
cell | Range | 現在のセルとして設定するセルです。 |
リターン
Range
- 新しく設定された現在のセル
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFrozenColumns(columns)
指定された数の列を固定します。ゼロの場合、どの列も固定されません。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Freezes the first column sheet.setFrozenColumns(1);
パラメータ
Name | 型 | 説明 |
---|---|---|
columns | Integer | 固定する列の数です。 |
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFrozenRows(rows)
指定された行数を固定します。ゼロの場合、どの行も固定されません。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Freezes the first row sheet.setFrozenRows(1);
パラメータ
Name | 型 | 説明 |
---|---|---|
rows | Integer | 固定する行数。 |
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setIterativeCalculationConvergenceThreshold(minThreshold)
反復計算の最小しきい値を設定します。逐次計算の結果の差がこの値より小さいと、反復計算は停止します。この値は負でない必要があり、デフォルトは 0.05 です。
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Sets the iterative calculation convergence threshold for the spreadsheet. ss.setIterativeCalculationConvergenceThreshold(2); // Logs the threshold to the console. console.log(ss.getIterativeCalculationConvergenceThreshold());
パラメータ
Name | 型 | 説明 |
---|---|---|
minThreshold | Number | 最小収束しきい値(負でない値)。 |
リターン
Spreadsheet
- チェーン用のこのスプレッドシート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setIterativeCalculationEnabled(isEnabled)
このスプレッドシートで反復計算を有効にするかどうかを設定します。計算を有効にした時点で、最大計算サイクル数と収束しきい値が設定されていない場合は、それぞれデフォルトで 50 と 0.05 に設定されます。いずれかが以前に設定されている場合は、以前の値が保持されます。
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Activates iterative calculation on the spreadsheet. ss.setIterativeCalculationEnabled(true); // Logs whether iterative calculation is activated for the spreadsheet. console.log(ss.isIterativeCalculationEnabled());
パラメータ
Name | 型 | 説明 |
---|---|---|
isEnabled | Boolean | 反復計算を有効にする場合は true 、そうでない場合は false 。 |
リターン
Spreadsheet
- チェーン用のこのスプレッドシート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setMaxIterativeCalculationCycles(maxIterations)
反復計算で実行する計算の最大反復回数を設定します。この値は 1 ~ 10,000(両端を含む)の範囲で指定する必要があります。デフォルトは 50 です。
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Sets the max iterative calculation cycles for the spreadsheet. ss.setMaxIterativeCalculationCycles(10); // Logs the max iterative calculation cycles to the console. console.log(ss.getMaxIterativeCalculationCycles());
パラメータ
Name | 型 | 説明 |
---|---|---|
maxIterations | Integer | 計算反復処理の最大数(1 ~ 10,000)。 |
リターン
Spreadsheet
- チェーン用のこのスプレッドシート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setNamedRange(name, range)
範囲に名前を付けます。
// The code below creates a new named range "TaxRates" in the active spreadsheet var ss = SpreadsheetApp.getActiveSpreadsheet(); ss.setNamedRange("TaxRates", SpreadsheetApp.getActiveRange());
パラメータ
Name | 型 | 説明 |
---|---|---|
name | String | 範囲に付ける名前。 |
range | Range | 範囲の指定。 |
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setRecalculationInterval(recalculationInterval)
このスプレッドシートを再計算する頻度を設定します。
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets file, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Sets the calculation interval for the spreadsheet to 'ON_CHANGE'. const interval = ss.setRecalculationInterval(SpreadsheetApp.RecalculationInterval.ON_CHANGE); // Logs the calculation interval to the console. console.log(interval);
パラメータ
Name | 型 | 説明 |
---|---|---|
recalculationInterval | RecalculationInterval | 新しい再計算間隔。 |
リターン
Spreadsheet
- チェーン用のこのスプレッドシート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setRowHeight(rowPosition, height)
指定された行の行の高さをピクセル単位で設定します。デフォルトでは、セルのコンテンツに合わせて行が拡大されます。行の高さを強制的に指定するには、Sheet.setRowHeightsForced(startRow, numRows, height)
を使用します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Sets the first row to a height of 200 pixels sheet.setRowHeight(1, 200);
パラメータ
Name | 型 | 説明 |
---|---|---|
rowPosition | Integer | 変更する行の位置。 |
height | Integer | 設定する高さ(ピクセル単位)です。 |
リターン
Sheet
- メソッド チェーンに役立つシート。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setSpreadsheetLocale(locale)
スプレッドシートの言語 / 地域を設定します。
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Sets the spreadsheet locale. ss.setSpreadsheetLocale('fr'); // Gets the spreadsheet locale. const ssLocale = ss.getSpreadsheetLocale(); // Logs the locale to the console. console.log(ssLocale);
パラメータ
Name | 型 | 説明 |
---|---|---|
locale | String | 使用する言語 / 地域コード(「en」、「fr」、「en_US」など)。 |
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setSpreadsheetTheme(theme)
スプレッドシートのテーマを設定します。
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); // The code below sets the second predefined theme as the current theme of the spreadsheet. var predefinedThemesList = spreadsheet.getPredefinedSpreadsheetThemes(); spreadsheet.setSpreadsheetTheme(predefinedThemesList[1]);
パラメータ
Name | 型 | 説明 |
---|---|---|
theme | SpreadsheetTheme | 適用するテーマ。 |
リターン
SpreadsheetTheme
- 新しい現在のテーマ。
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setSpreadsheetTimeZone(timezone)
スプレッドシートのタイムゾーンを設定します。
// Opens the spreadsheet file by its URL. If you created your script from within a // Google Sheets spreadsheet, you can use SpreadsheetApp.getActiveSpreadsheet() instead. // TODO(developer): Replace the URL with your own. const ss = SpreadsheetApp.openByUrl('https://docs.google.com/spreadsheets/d/abc123456/edit'); // Sets the time zone of the spreadsheet. ss.setSpreadsheetTimeZone('America/New_York'); // Gets the time zone of the spreadsheet. const ssTimeZone = ss.getSpreadsheetTimeZone(); // Logs the time zone to the console. console.log(ssTimeZone);
パラメータ
Name | 型 | 説明 |
---|---|---|
timezone | String | 「long」形式で指定されるタイムゾーン(Joda.org でリストされている「America/New_York」など)。 |
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
show(userInterface)
ユーザーのブラウザのビューポートの中央のダイアログに、カスタム ユーザー インターフェース コンポーネントを表示します。サーバーサイド スクリプトの実行は一時停止されていません。サーバー側と通信するために、ユーザー インターフェース コンポーネントはサーバー側のスクリプトに対して非同期コールバックを行う必要があります。
サーバーサイド スクリプトが以前に閉じていないダイアログを表示していた場合、既存のダイアログは、新しくリクエストされたダイアログのユーザー インターフェースに置き換えられます。
次のコード スニペットは、指定したタイトル、高さ、幅で、シンプルな HtmlService
アプリをダイアログに表示します。
var htmlApp = HtmlService .createHtmlOutput('<p>A change of speed, a change of style...</p>') .setTitle('My HtmlService Application') .setWidth(250) .setHeight(300); SpreadsheetApp.getActiveSpreadsheet().show(htmlApp); // The script resumes execution immediately after showing the dialog.
パラメータ
Name | 型 | 説明 |
---|---|---|
userInterface | Object | HtmlOutput 。 |
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/script.container.ui
sort(columnPosition)
列を基準にシートを昇順で並べ替えます。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Sorts the sheet by the first column, ascending sheet.sort(1);
パラメータ
Name | 型 | 説明 |
---|---|---|
columnPosition | Integer | 並べ替える列です。 |
リターン
Sheet
- メソッド チェーンに役立つシート
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
sort(columnPosition, ascending)
シートを列で並べ替えます。昇順または降順を指定するパラメータを受け取ります。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // Sorts the sheet by the first column, descending sheet.sort(1, false);
パラメータ
Name | 型 | 説明 |
---|---|---|
columnPosition | Integer | 並べ替える列です。 |
ascending | Boolean | 昇順の並べ替えの場合は true 、降順の場合は false を指定します。 |
リターン
Sheet
- メソッド チェーンに役立つシート
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
toast(msg)
スプレッドシートの右下に、指定したメッセージを含むポップアップ ウィンドウを表示します。
// Show a popup with the message "Task started". SpreadsheetApp.getActiveSpreadsheet().toast('Task started');
パラメータ
Name | 型 | 説明 |
---|---|---|
msg | String | トーストに表示されるメッセージ。 |
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
toast(msg, title)
指定したメッセージとタイトルを含むポップアップ ウィンドウをスプレッドシートの右下に表示します。
// Show a popup with the title "Status" and the message "Task started". SpreadsheetApp.getActiveSpreadsheet().toast('Task started', 'Status');
パラメータ
Name | 型 | 説明 |
---|---|---|
msg | String | トーストに表示されるメッセージ。 |
title | String | トーストのタイトル(省略可)。 |
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
toast(msg, title, timeoutSeconds)
指定したタイトルとメッセージを含むポップアップ ウィンドウをスプレッドシートの右下に特定の時間だけ表示する。
// Show a 3-second popup with the title "Status" and the message "Task started". SpreadsheetApp.getActiveSpreadsheet().toast('Task started', 'Status', 3);
パラメータ
Name | 型 | 説明 |
---|---|---|
msg | String | トーストに表示されるメッセージ。 |
title | String | トーストのタイトル(省略可)。 |
timeoutSeconds | Number | タイムアウト(秒単位)。null の場合、トーストはデフォルトで 5 秒に設定されます。負の場合、トーストは終了するまで表示されます。 |
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
unhideColumn(column)
指定した範囲内の列を再表示します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This unhides the first column if it was previously hidden var range = sheet.getRange("A1"); sheet.unhideColumn(range);
パラメータ
Name | 型 | 説明 |
---|---|---|
column | Range | 再表示する範囲(非表示の場合)。 |
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
unhideRow(row)
指定された範囲内の行を再表示します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[0]; // This unhides the first row if it was previously hidden var range = sheet.getRange("A1"); sheet.unhideRow(range);
パラメータ
Name | 型 | 説明 |
---|---|---|
row | Range | 再表示する範囲(非表示の場合)。 |
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
updateMenu(name, subMenus)
addMenu(name, subMenus)
によって追加されたメニューを更新します。addMenu(name, subMenus)
とまったく同じように動作します。
var ss = SpreadsheetApp.getActiveSpreadsheet(); var menuEntries = []; menuEntries.push({name: "Lone Menu Entry", functionName: "function1"}); ss.updateMenu("addMenuExample", menuEntries);
パラメータ
Name | 型 | 説明 |
---|---|---|
name | String | 更新するメニューの名前。 |
subMenus | Object[] | name パラメータと functionName
パラメータを含む JavaScript マップの配列。付属のライブラリの関数(
Library.libFunction1 など)を使用できます。 |
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
waitForAllDataExecutionsCompletion(timeoutInSeconds)
スプレッドシートの現在の実行がすべて完了するまで待機し、指定された秒数後にタイムアウトします。タイムアウト時に実行が完了しない場合は例外をスローしますが、データ実行はキャンセルされません。
パラメータ
Name | 型 | 説明 |
---|---|---|
timeoutInSeconds | Integer | データ実行の待機時間(秒単位)。最大値は 300 秒です。 |
承認
この方法を使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets