スプレッドシートの範囲にアクセスして変更する。範囲は、シート内の 1 つのセル、またはシート内の隣接するセルのグループにすることができます。
メソッド
メソッド | 戻り値の型 | 概要 |
---|---|---|
activate() | Range | 指定した範囲を active range として設定し、範囲内の左上のセルを current cell として設定します。 |
activate | Range | 指定したセルを current cell に設定します。 |
add | Range | 指定されたキーを持つデベロッパー メタデータを範囲に追加します。 |
add | Range | 指定したキーと公開設定を持つデベロッパー メタデータを範囲に追加します。 |
add | Range | 指定されたキーと値を持つデベロッパー メタデータを範囲に追加します。 |
add | Range | 指定されたキー、値、公開設定を持つデベロッパー メタデータを範囲に追加します。 |
apply | Banding | 範囲にデフォルトの列のバンドリング テーマを適用します。 |
apply | Banding | 指定した列のバンドリング テーマを範囲に適用します。 |
apply | Banding | 指定された列のバンドリング テーマを、指定されたヘッダーとフッターの設定で範囲に適用します。 |
apply | Banding | 範囲にデフォルトの行バンド テーマを適用します。 |
apply | Banding | 指定した行バンドのテーマを範囲に適用します。 |
apply | Banding | 指定された行バンドのテーマを、指定されたヘッダーとフッターの設定で範囲に適用します。 |
auto | void | この範囲内のデータに基づいて、destination にデータを入力します。 |
auto | void | 隣接するセルに基づいて新しいデータで入力する範囲を計算し、この範囲に含まれるデータに基づいてその範囲に新しい値を自動的に入力します。 |
break | Range | 範囲内の複数列セルを個々のセルに分割し直します。 |
can | Boolean | ユーザーが範囲内のすべてのセルを編集する権限を持っているかどうかを判断します。 |
check() | Range | 範囲内のチェックボックスの状態を [オン] に変更します。 |
clear() | Range | コンテンツと形式の範囲を消去します。 |
clear(options) | Range | 指定された詳細オプションで指定されている内容、形式、データ検証ルール、コメントの範囲を消去します。 |
clear | Range | 範囲の内容を消去し、書式はそのまま残します。 |
clear | Range | 範囲のデータ入力規則を消去します。 |
clear | Range | この範囲の書式をクリアします。 |
clear | Range | 指定したセルのノートを消去します。 |
collapse | Range | 範囲内に完全に含まれるすべてのグループを閉じます。 |
copy | void | 範囲の書式を指定の場所にコピーします。 |
copy | void | 範囲の書式を指定の場所にコピーします。 |
copy | void | セル範囲のデータを別のセル範囲にコピーします。 |
copy | void | セル範囲のデータを別のセル範囲にコピーします。 |
copy | void | セル範囲のデータを別のセル範囲にコピーします。 |
copy | void | 範囲の内容を指定された場所にコピーします。 |
copy | void | 範囲の内容を指定された場所にコピーします。 |
create | Data | データソースから空のデータソース ピボット テーブルを作成し、この範囲の最初のセルをアンカーにします。 |
create | Data | この範囲の最初のセルをアンカーとして、データソースから空のデータソース テーブルを作成します。 |
create | Developer | この範囲内のデベロッパー メタデータを検索するための DeveloperMetadataFinderApi を返します。 |
create | Filter | フィルタを作成して、シート上の指定した範囲に適用します。 |
create | Pivot | この範囲の最初のセルに固定された指定された source から空のピボット テーブルを作成します。 |
create | Text | 範囲のテキスト検索ツールを作成します。このツールを使用すると、範囲内のテキストを検索して置換できます。 |
delete | void | このセル範囲を削除します。 |
expand | Range | この範囲と範囲またはコントロール トグルが交差する、閉じられたグループを開きます。 |
getA1Notation() | String | A1 表記で範囲の文字列の説明を返します。 |
get | String | 範囲内の左上のセルの背景色を返します(例: '#ffffff' )。 |
get | Color | 範囲内の左上のセルの背景色を返します。 |
get | Color[][] | 範囲内のセルの背景色を返します。 |
get | String[][] | 範囲内のセルの背景色を返します(例: '#ffffff' )。 |
get | Banding[] | この範囲内の任意のセルに適用されているすべてのバンドを返します。 |
get | Range | 範囲内の指定したセルを返します。 |
get | Integer | この範囲の開始列位置を返します。 |
get | Range | 4 つの基本方向の Direction で拡張された範囲のコピーを返します。これにより、データを含む隣接するすべてのセルがカバーされます。 |
get | Range | 指定されたディメンションが Dimension.ROWS の場合は範囲拡張された Direction.UP と Direction.DOWN のコピーを返します。ディメンションが Dimension.COLUMNS の場合は Direction.NEXT と Direction.PREVIOUS を返します。 |
get | Data | 範囲内の最初のセルの Data を返します。セルにデータソースの式が含まれていない場合は null を返します。 |
get | Data | 範囲内のセルの Data を返します。 |
get | Data | 範囲と交差するすべてのデータソースのピボット テーブルを取得します。 |
get | Data | 範囲と交差するすべてのデータソース テーブルを取得します。 |
get | String | この範囲内のデータの URL を返します。この URL は、グラフやクエリの作成に使用できます。 |
get | Data | このオブジェクト内のデータは DataTable として返されます。 |
get | Data | この範囲内のデータを DataTable として返します。 |
get | Data | 範囲内の左上のセルのデータ入力規則を返します。 |
get | Data | 範囲内のすべてのセルのデータ入力規則を返します。 |
get | Developer | この範囲に関連付けられているデベロッパーのメタデータを取得します。 |
get | String | 範囲内の左上のセルの表示値を返します。 |
get | String[][] | この範囲の値の長方形グリッドを返します。 |
get | Filter | この範囲が属するシートのフィルタを返します。シートにフィルタがない場合、null を返します。 |
get | Color | 範囲の左上にあるセルのフォント色を返します。 |
get | Color[][] | 範囲内のセルのフォント色を返します。 |
get | String[][] | 範囲内のセルのフォント ファミリーを返します。 |
get | String | 範囲の左上にあるセルのフォント ファミリーを返します。 |
get | String | 範囲の左上隅にあるセルの線のスタイルを取得します('underline' 、'line-through' 、'none' )。 |
get | String[][] | 範囲内のセルの線のスタイルを取得します('underline' 、'line-through' 、'none' )。 |
get | Integer | 範囲の左上にあるセルのフォントサイズをポイント単位で返します。 |
get | Integer[][] | 範囲内のセルのフォントサイズを返します。 |
get | String | 範囲の左上にあるセルのフォント スタイル('italic' または 'normal' )を返します。 |
get | String[][] | 範囲内のセルのフォント スタイルを返します。 |
get | String | 範囲の左上にあるセルのフォント太さ(標準/太字)を返します。 |
get | String[][] | 範囲内のセルのフォント重みを返します。 |
get | String | 範囲の左上のセルの式(A1 表記)を返します。セルが空であるか式が含まれていない場合は、空の文字列を返します。 |
get | String | 指定されたセルの数式(R1C1 表記)を返します。数式がない場合、null を返します。 |
get | String[][] | 範囲内のセルの数式(A1 表記)を返します。 |
get | String[][] | 範囲内のセルの数式(R1C1 表記)を返します。 |
get | Integer | 範囲の親シートのグリッド ID を返します。 |
get | Integer | 範囲の高さを返します。 |
get | String | 範囲の左上にあるセルのテキストの水平方向の配置(左/中央/右)を返します。 |
get | String[][] | 範囲内のセルの水平方向の配置を返します。 |
get | Integer | 終了列の位置を返します。 |
get | Integer | 終了行の位置を返します。 |
get | Range[] | 現在の範囲内に完全に含まれているか、現在の範囲内に 1 つ以上のセルを含む結合セルを表す Range オブジェクトの配列を返します。 |
get | Range | 範囲の最初の列と行のセルから、指定された方向の次のセルを返します。このセルは、データを含む連続したセルの範囲の端にあるセルか、その方向のスプレッドシートの端にあるセルです。 |
get | String | 指定された範囲に関連付けられているメモを返します。 |
get | String[][] | 範囲内のセルに関連付けられているメモを返します。 |
get | Integer | この範囲内の列数を返します。 |
get | Integer | この範囲内の行数を返します。 |
get | String | 指定した範囲の左上のセルの数値または日付の書式を取得します。 |
get | String[][] | 範囲内のセルの数値または日付の形式を返します。 |
get | Rich | 範囲の左上のセルのリッチテキスト値を返します。セル値がテキストでない場合、null を返します。 |
get | Rich | 範囲内のセルの HTML 形式のテキスト値を返します。 |
get | Integer | この範囲の行番号を返します。 |
get | Integer | この範囲の行番号を返します。 |
get | Sheet | この範囲が属するシートを返します。 |
get | Text | 範囲の左上セルの文章方向を返します。 |
get | Text | 範囲内のセルのテキストの向きを返します。 |
get | Text | 範囲の左上のセルのテキストの回転設定を返します。 |
get | Text | 範囲内のセルのテキストの回転設定を返します。 |
get | Text | 範囲の左上にあるセルのテキスト スタイルを返します。 |
get | Text | 範囲内のセルのテキスト スタイルを返します。 |
get | Object | 範囲内の左上のセルの値を返します。 |
get | Object[][] | この範囲の値の長方形グリッドを返します。 |
get | String | 範囲の左上にあるセルの垂直方向の配置(上/中央/下)を返します。 |
get | String[][] | 範囲内のセルの垂直方向の配置を返します。 |
get | Integer | 範囲の幅を列単位で返します。 |
get | Boolean | セル内のテキストが折り返されるかどうかを返します。 |
get | Wrap | 範囲内のセルのテキストの折り返し戦略を返します。 |
get | Wrap | 範囲の左上セルのテキストの折り返し方法を返します。 |
get | Boolean[][] | セル内のテキストが折り返されるかどうかを返します。 |
insert | Range | この範囲に空白セルを挿入します。 |
insert | Range | 範囲内の各セルにチェックボックスを挿入します。チェックボックスがオンの場合は true 、オフの場合は false で構成されます。 |
insert | Range | 範囲内の各セルにチェックボックスを挿入します。チェックボックスがオンの場合はカスタム値で、オフの場合は空の文字列で構成されます。 |
insert | Range | 範囲内の各セルにチェックボックスを挿入します。チェックボックスは、オンとオフの状態のカスタム値で構成されます。 |
is | Boolean | 範囲が完全に空白の場合、true を返します。 |
is | Boolean | 範囲内のすべてのセルのチェックボックスの状態が「オン」かどうかを返します。 |
is | Boolean | 範囲の終了が特定の列にバインドされているかどうかを判断します。 |
is | Boolean | 範囲の終了が特定の行にバインドされているかどうかを決定します。 |
is | Boolean | 現在の範囲内のセルが結合セルと重複している場合は、true を返します。 |
is | Boolean | 範囲の開始が特定の列にバインドされているかどうかを判断します。 |
is | Boolean | 範囲の開始が特定の行にバインドされているかどうかを決定します。 |
merge() | Range | 範囲内のセルを 1 つのブロックに結合します。 |
merge | Range | 範囲内のセルを範囲の列全体にわたって結合します。 |
merge | Range | 範囲内のセルを結合します。 |
move | void | この範囲から対象範囲に(形式と値の両方を)カットして貼り付けます。 |
offset(rowOffset, columnOffset) | Range | この範囲から指定された行数と列数(負の値も指定可能)だけオフセットした新しい範囲を返します。 |
offset(rowOffset, columnOffset, numRows) | Range | 現在の範囲を基準とする新しい範囲を返します。この範囲の左上は、指定された行と列で現在の範囲からオフセットされ、セルの高さも指定されます。 |
offset(rowOffset, columnOffset, numRows, numColumns) | Range | 現在の範囲を基準とする新しい範囲を返します。この範囲の左上は、指定された行と列で現在の範囲からオフセットされ、指定されたセルの高さと幅になります。 |
protect() | Protection | 権限を持つユーザーを除き、範囲の編集を保護できるオブジェクトを作成します。 |
randomize() | Range | 指定した範囲内の行の順序をランダムにします。 |
remove | Range | 範囲内のすべてのチェックボックスを削除します。 |
remove | Range | この範囲内の、前の行の値と重複する値を含む行を削除します。 |
remove | Range | 指定した列に、前の行の値と重複する値が含まれている行を、この範囲内で削除します。 |
set | Range | 範囲内のすべてのセルの背景色を CSS 表記('#ffffff' や 'white' など)で設定します。 |
set | Range | 範囲内のすべてのセルの背景色を設定します。 |
set | Range | 背景色の長方形のグリッドを設定します(この範囲のサイズと一致している必要があります)。 |
set | Range | RGB 値(0 ~ 255 の整数)を使用して、背景を指定された色に設定します。 |
set | Range | 背景色の長方形のグリッドを設定します(この範囲のサイズと一致している必要があります)。 |
set | Range | 境界プロパティを設定します。 |
set | Range | 色やスタイルを指定して、枠線プロパティを設定します。 |
set | Range | 範囲内のすべてのセルに 1 つのデータ検証ルールを設定します。 |
set | Range | 範囲内のすべてのセルにデータ入力規則を設定します。 |
set | Range | CSS 記法('#ffffff' や 'white' など)でフォントの色を設定します。 |
set | Range | 指定した範囲のフォントの色を設定します。 |
set | Range | フォントの色の長方形のグリッドを設定します(この範囲のディメンションと一致している必要があります)。 |
set | Range | フォントの色の長方形のグリッドを設定します(この範囲のディメンションと一致している必要があります)。 |
set | Range | フォント ファミリーの長方形のグリッドを設定します(この範囲のサイズと一致している必要があります)。 |
set | Range | フォント ファミリー(「Arial」や「Helvetica」など)を設定します。 |
set | Range | 指定した範囲のフォント線のスタイルを設定します('underline' 、'line-through' 、'none' )。 |
set | Range | 線スタイルの長方形のグリッドを設定します(この範囲のディメンションと一致している必要があります)。 |
set | Range | フォントサイズを設定します。サイズは、使用するポイントサイズです。 |
set | Range | フォントサイズの長方形のグリッドを設定します(この範囲のディメンションと一致している必要があります)。 |
set | Range | 指定した範囲のフォント スタイルを設定します('italic' または 'normal' )。 |
set | Range | フォント スタイルの長方形のグリッドを設定します(この範囲のディメンションと一致している必要があります)。 |
set | Range | 指定した範囲のフォントウェイトを設定します(通常/太字)。 |
set | Range | フォントウェイトの長方形のグリッドを設定します(この範囲のサイズと一致している必要があります)。 |
set | Range | この範囲の数式を更新します。 |
set | Range | この範囲の数式を更新します。 |
set | Range | 数式の長方形のグリッドを設定します(この範囲のサイズと一致している必要があります)。 |
set | Range | 数式の長方形のグリッドを設定します(この範囲のサイズと一致している必要があります)。 |
set | Range | 指定した範囲の水平方向(左から右)の配置を設定します(左揃え/中央揃え/右揃え)。 |
set | Range | 水平方向に配置された長方形のグリッドを設定します。 |
set | Range | メモを指定された値に設定します。 |
set | Range | メモの長方形のグリッドを設定します(この範囲のサイズと一致している必要があります)。 |
set | Range | 数値または日付の形式を指定された書式文字列に設定します。 |
set | Range | 数値または日付形式の長方形のグリッドを設定します(この範囲のディメンションと一致する必要があります)。 |
set | Range | 範囲内のセルにリッチテキスト値を設定します。 |
set | Range | リッチテキスト値の長方形のグリッドを設定します。 |
set | Range | 範囲にハイパーリンクを表示するかどうかを設定します。 |
set | Range | 範囲内のセルの文章方向を設定します。 |
set | Range | 文章方向の長方形のグリッドを設定します。 |
set | Range | 範囲内のセルのテキストの回転設定を設定します。 |
set | Range | 範囲内のセルのテキストの回転設定を設定します。 |
set | Range | テキストの回転の長方形グリッドを設定します。 |
set | Range | 範囲内のセルのテキスト スタイルを設定します。 |
set | Range | テキスト スタイルの長方形のグリッドを設定します。 |
set | Range | 範囲の値を設定します。 |
set | Range | 値の長方形のグリッドを設定します(この範囲のディメンションと一致している必要があります)。 |
set | Range | 指定した範囲の垂直(上から下)の配置を設定します(上部/中央/下部)。 |
set | Range | 垂直方向に配置された長方形のグリッドを設定します(この範囲のサイズと一致している必要があります)。 |
set | Range | 範囲内のセルのテキストを積み重ねるかどうかを設定します。 |
set | Range | 指定した範囲のセル折り返しを設定します。 |
set | Range | 折り返し戦略の長方形のグリッドを設定します。 |
set | Range | 範囲内のセルのテキストの折り返し方法を設定します。 |
set | Range | 折り返しポリシーの長方形のグリッドを設定します(この範囲のサイズと一致している必要があります)。 |
shift | Range | 範囲の列グループの階層を指定された量だけ変更します。 |
shift | Range | 範囲の行のグループ化の階層を指定された量だけ変更します。 |
sort(sortSpecObj) | Range | 指定された範囲内のセルを、指定された列と順序で並べ替えます。 |
split | void | 自動検出された区切り文字に基づいて、テキスト列を複数の列に分割します。 |
split | void | 指定した文字列をカスタム区切り文字として使用して、テキストの列を複数の列に分割します。 |
split | void | 指定された区切り文字に基づいて、テキストの列を複数の列に分割します。 |
trim | Range | この範囲内のすべてのセルの空白文字(スペース、タブ、改行など)を削除します。 |
uncheck() | Range | 範囲内のチェックボックスの状態を [オフ] に変更します。 |
サポート終了のメソッド
メソッド | 戻り値の型 | 概要 |
---|---|---|
| String | 範囲の左上にあるセルのフォント色を CSS 表記('#ffffff' や 'white' など)で返します。 |
| String[][] | 範囲内のセルのフォント色を CSS 表記('#ffffff' や 'white' など)で返します。 |
詳細なドキュメント
activate()
指定した範囲を active range
として設定し、範囲内の左上のセルを current cell
として設定します。
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getRange('A1:D10');
range.activate();
const selection = sheet.getSelection();
// Current cell: A1
const currentCell = selection.getCurrentCell();
// Active Range: A1:D10
const activeRange = selection.getActiveRange();
戻る
Range
- チェーン用のこの範囲。
activateAsCurrentCell()
指定したセルを current cell
として設定します。
指定したセルが既存の範囲内にある場合、その範囲がアクティブな範囲になり、そのセルが現在のセルになります。
指定したセルが既存の範囲にない場合、既存の選択範囲は削除され、そのセルが現在のセルとアクティブな範囲になります。
注: 指定する Range
は 1 つのセルで構成する必要があります。指定しない場合、例外がスローされます。
// Gets the first sheet of the spreadsheet.
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
// Gets the cell B5 and sets it as the active cell.
const range = sheet.getRange('B5');
const currentCell = range.activateAsCurrentCell();
// Logs the activated cell.
console.log(currentCell.getA1Notation());
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
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',
);
// Gets Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');
// Gets row 2 on the sheet.
const range = sheet.getRange('2:2');
// Adds the key 'NAME' to the developer metadata for row 2.
range.addDeveloperMetadata('NAME');
// Gets the metadata and logs it to the console.
const developerMetaData = range.getDeveloperMetadata()[0];
console.log(developerMetaData.getKey());
パラメータ
名前 | 型 | 説明 |
---|---|---|
key | String | 新しいデベロッパー メタデータのキー。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 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',
);
// Gets Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');
// Gets row 2 on Sheet1.
const range = sheet.getRange('2:2');
// Adds the key 'NAME' and sets the developer metadata visibility to 'DOCUMENT'
// for row 2 on Sheet1.
range.addDeveloperMetadata(
'NAME',
SpreadsheetApp.DeveloperMetadataVisibility.DOCUMENT,
);
// Gets the updated metadata info and logs it to the console.
const developerMetaData = range.getDeveloperMetadata()[0];
console.log(developerMetaData.getKey());
console.log(developerMetaData.getVisibility().toString());
パラメータ
名前 | 型 | 説明 |
---|---|---|
key | String | 新しいデベロッパー メタデータのキー。 |
visibility | Developer | 新しいデベロッパー メタデータの公開設定。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 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',
);
// Gets Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');
// Gets row 2 of Sheet1.
const range = sheet.getRange('2:2');
// Adds the key 'NAME' and sets the value to 'GOOGLE' for the metadata of row 2.
range.addDeveloperMetadata('NAME', 'GOOGLE');
// Gets the metadata and logs it to the console.
const developerMetaData = range.getDeveloperMetadata()[0];
console.log(developerMetaData.getKey());
console.log(developerMetaData.getValue());
パラメータ
名前 | 型 | 説明 |
---|---|---|
key | String | 新しいデベロッパー メタデータのキー。 |
value | String | 新しいデベロッパー メタデータの値。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 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',
);
// Gets Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');
// Gets row 2 on the sheet.
const range = sheet.getRange('2:2');
// Adds the key 'NAME', sets the value to 'GOOGLE', and sets the visibility
// to PROJECT for row 2 on the sheet.
range.addDeveloperMetadata(
'NAME',
'GOOGLE',
SpreadsheetApp.DeveloperMetadataVisibility.PROJECT,
);
// Gets the updated metadata info and logs it to the console.
const developerMetaData = range.getDeveloperMetadata()[0];
console.log(developerMetaData.getKey());
console.log(developerMetaData.getValue());
console.log(developerMetaData.getVisibility().toString());
パラメータ
名前 | 型 | 説明 |
---|---|---|
key | String | 新しいデベロッパー メタデータのキー。 |
value | String | 新しいデベロッパー メタデータの値。 |
visibility | Developer | 新しいデベロッパー メタデータの公開設定。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
applyColumnBanding()
範囲にデフォルトの列のバンドリング テーマを適用します。デフォルトでは、バンドにはヘッダーがあり、フッターの色はありません。
// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');
// Gets row 2 on the sheet.
const range = sheet.getRange('2:2');
// Applies column banding to row 2.
const colBanding = range.applyColumnBanding();
// Gets the first banding on the sheet and logs the color of the header column.
console.log(
sheet.getBandings()[0]
.getHeaderColumnColorObject()
.asRgbColor()
.asHexString(),
);
// Gets the first banding on the sheet and logs the color of the second column.
console.log(
sheet.getBandings()[0]
.getSecondColumnColorObject()
.asRgbColor()
.asHexString(),
);
戻る
Banding
- 新しいバンド。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
applyColumnBanding(bandingTheme)
指定した列のバンドリング テーマを範囲に適用します。デフォルトでは、バンドにはヘッダーがあり、フッターの色はありません。
// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');
// Gets row 2 on the sheet.
const range = sheet.getRange('2:2');
// Applies the INDIGO color banding theme to the columns in row 2.
const colBanding = range.applyColumnBanding(SpreadsheetApp.BandingTheme.INDIGO);
// Gets the first banding on the sheet and logs the color of the second column.
console.log(
sheet.getBandings()[0]
.getSecondColumnColorObject()
.asRgbColor()
.asHexString(),
);
パラメータ
名前 | 型 | 説明 |
---|---|---|
banding | Banding | 範囲内の列に適用するカラーテーマ。 |
戻る
Banding
- 新しいバンド。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
applyColumnBanding(bandingTheme, showHeader, showFooter)
指定された列のバンドリング テーマを、指定されたヘッダーとフッターの設定で範囲に適用します。
// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');
// Gets rows 12-22 on the sheet.
const range = sheet.getRange('12:22');
// Applies the BLUE color banding theme to rows 12-22.
// Sets the header visibility to false and the footer visibility to true.
const colBanding = range.applyColumnBanding(
SpreadsheetApp.BandingTheme.BLUE,
false,
true,
);
// Gets the banding color and logs it to the console.
console.log(
sheet.getBandings()[0]
.getSecondColumnColorObject()
.asRgbColor()
.asHexString(),
);
// Gets the header color object and logs it to the console. Returns null because
// the header visibility is set to false.
console.log(sheet.getBandings()[0].getHeaderColumnColorObject());
// Gets the footer color and logs it to the console.
console.log(
sheet.getBandings()[0]
.getFooterColumnColorObject()
.asRgbColor()
.asHexString(),
);
パラメータ
名前 | 型 | 説明 |
---|---|---|
banding | Banding | 範囲内の列に適用するカラーテーマ。 |
show | Boolean | true の場合、バンドル テーマのヘッダー色が最初の列に適用されます。 |
show | Boolean | true の場合、バンドル テーマのフッターの色が最後の列に適用されます。 |
戻る
Banding
- 新しいバンド。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
applyRowBanding()
範囲にデフォルトの行バンド テーマを適用します。デフォルトでは、バンドにはヘッダーがあり、フッターの色はありません。
// Opens the spreadsheet 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 rows 1-30 on Sheet1.
const range = sheet.getRange('1:30');
// Applies row banding to rows 1-30.
range.applyRowBanding();
// Gets the hex color of the second banded row.
const secondRowColor =
range.getBandings()[0].getSecondRowColorObject().asRgbColor().asHexString();
// Logs the hex color to console.
console.log(secondRowColor);
戻る
Banding
- バンド。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
applyRowBanding(bandingTheme)
指定した行バンドのテーマを範囲に適用します。デフォルトでは、バンドにはヘッダーがあり、フッターの色はありません。
// Opens the spreadsheet 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 rows 1-30 on Sheet1.
const range = sheet.getRange('1:30');
// Applies the INDIGO row banding theme to rows 1-30.
range.applyRowBanding(SpreadsheetApp.BandingTheme.INDIGO);
// Gets the hex color of the second banded row.
const secondRowColor =
range.getBandings()[0].getSecondRowColorObject().asRgbColor().asHexString();
// Logs the hex color to console.
console.log(secondRowColor);
パラメータ
名前 | 型 | 説明 |
---|---|---|
banding | Banding | 範囲内の行に適用するカラーテーマ。 |
戻る
Banding
- 新しいバンド。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
applyRowBanding(bandingTheme, showHeader, showFooter)
指定された行バンドのテーマを、指定されたヘッダーとフッターの設定で範囲に適用します。
// Opens the spreadsheet 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 rows 1-30 on Sheet1.
const range = sheet.getRange('1:30');
// Applies the INDIGO row banding to rows 1-30 and
// specifies to hide the header and show the footer.
range.applyRowBanding(SpreadsheetApp.BandingTheme.INDIGO, false, true);
パラメータ
名前 | 型 | 説明 |
---|---|---|
banding | Banding | 範囲内の行に適用するカラーテーマ。 |
show | Boolean | true の場合、バンディング テーマのヘッダー色が最初の行に適用されます。 |
show | Boolean | true の場合、最後の行にバンドル テーマのフッターの色が適用されます。 |
戻る
Banding
- 新しいバンド。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
autoFill(destination, series)
この範囲内のデータに基づいて destination
にデータを入力します。新しい値は、指定された series
タイプによっても決まります。宛先範囲にはこの範囲が含まれ、一方向にのみ拡張する必要があります。たとえば、次のコードは、A1:A4
の現在の値に基づいて、A1:A20
に連続する増加する数値を入力します。
const sheet = SpreadsheetApp.getActiveSheet();
// Has values [1, 2, 3, 4].
const sourceRange = sheet.getRange('A1:A4');
// The range to fill with values.
const destination = sheet.getRange('A1:A20');
// Inserts new values in A5:A20, continuing the pattern expressed in A1:A4
sourceRange.autoFill(destination, SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);
パラメータ
名前 | 型 | 説明 |
---|---|---|
destination | Range | 値で自動入力する範囲。転送先の範囲には、この範囲を含め、一方向(上、下、左、右)にのみ拡張する必要があります。 |
series | Auto | 新しい値の計算に使用する自動入力シリーズのタイプ。このシリーズの効果は、ソースデータの種類と量によって異なります。 |
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
autoFillToNeighbor(series)
隣接するセルに基づいて新しいデータで入力する範囲を計算し、この範囲に含まれるデータに基づいてその範囲に新しい値を自動的に入力します。これらの新しい値も、指定された series
タイプによって決まります。
計算された宛先範囲では、周囲のデータを考慮して、新しい値を挿入する場所が決まります。自動入力される列のすぐ左または右にデータがある場合、新しい値は隣接するデータまでしか拡張されません。
たとえば、A1:A20
に連続する増加する数値が入力され、このメソッドが連続する日付を含む範囲 B1:B4
で呼び出されると、新しい値は B5:B20
にのみ挿入されます。これにより、これらの新しい値は、A 列の値を含むセルに「貼り付け」られます。
const sheet = SpreadsheetApp.getActiveSheet();
// A1:A20 has values [1, 2, 3, ... 20].
// B1:B4 has values [1/1/2017, 1/2/2017, ...]
const sourceRange = sheet.getRange('B1:B4');
// Results in B5:B20 having values [1/5/2017, ... 1/20/2017]
sourceRange.autoFillToNeighbor(SpreadsheetApp.AutoFillSeries.DEFAULT_SERIES);
パラメータ
名前 | 型 | 説明 |
---|---|---|
series | Auto | 新しい値の計算に使用する自動入力シリーズのタイプ。このシリーズの効果は、ソースデータの種類と量によって異なります。 |
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
breakApart()
範囲内の複数列セルを個々のセルに分割します。
範囲でこの関数を呼び出すことは、範囲を選択して [書式] > [セルを結合] > [結合を解除] をクリックすることと同じです。
// Opens the spreadsheet 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 range A1:C6 on Sheet1.
const range = sheet.getRange('A1:C6');
// Unmerges the range A1:C6 into individual cells.
range.breakApart();
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
canEdit()
ユーザーが範囲内のすべてのセルを編集する権限を持っているかどうかを判断します。スプレッドシートのオーナーは、保護された範囲とシートをいつでも編集できます。
// Opens the spreadsheet 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 range A1:C6 on Sheet1.
const range = sheet.getRange('A1:C6');
// Logs whether the user has permission to edit every cell in the range.
console.log(range.canEdit());
戻る
Boolean
- 範囲内のすべてのセルを編集する権限がユーザーにある場合は true
、それ以外の場合は false
。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
check()
範囲内のチェックボックスの状態を [オン] に変更します。現在、オンまたはオフの値が設定されていない範囲内のセルは無視されます。
// Changes the state of cells which currently contain either the checked or
// unchecked value configured in the range A1:B10 to 'checked'.
const range = SpreadsheetApp.getActive().getRange('A1:B10');
range.check();
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
clear()
コンテンツと形式の範囲を消去します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('A1:D10');
range.clear();
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
clear(options)
指定された詳細オプションで指定されている内容、形式、データ検証ルール、コメントの範囲を消去します。デフォルトでは、すべてのデータが消去されます。
// The code below clears range C2:G7 in the active sheet, but preserves the
// format, data validation rules, and comments.
SpreadsheetApp.getActiveSheet().getRange(2, 3, 6, 5).clear({
contentsOnly: true
});
パラメータ
名前 | 型 | 説明 |
---|---|---|
options | Object | 以下に示す詳細なパラメータを指定する JavaScript オブジェクト。 |
拡張パラメータ
名前 | 型 | 説明 |
---|---|---|
comments | Boolean | コメントのみを消去するかどうか。 |
contents | Boolean | コンテンツのみを消去するかどうか。 |
format | Boolean | 書式のみを消去するかどうか。書式を消去すると、データの入力規則も消去されます。 |
validations | Boolean | データの入力規則のみを消去するかどうか。 |
skip | Boolean | フィルタされた行を消去しないかどうか。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
clearContent()
範囲の内容を消去し、書式はそのまま残します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('A1:D10');
range.clearContent();
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
clearDataValidations()
範囲のデータ入力規則を消去します。
// Clear the data validation rules for cells A1:B5.
const range = SpreadsheetApp.getActive().getRange('A1:B5');
range.clearDataValidations();
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
clearFormat()
この範囲の書式をクリアします。
これにより、範囲内のセルのテキスト書式は消去されますが、数値書式ルールはリセットされません。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('A1:D10');
range.clearFormat();
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
clearNote()
指定したセルのノートを消去します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('A1:D10');
range.clearNote();
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
collapseGroups()
範囲内に完全に含まれるすべてのグループを閉じます。範囲内に完全に含まれるグループがない場合、範囲内に部分的に含まれる最も深く展開されたグループが閉じられます。
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getActiveRange();
// All row and column groups within the range are collapsed.
range.collapseGroups();
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
copyFormatToRange(gridId, column, columnEnd, row, rowEnd)
範囲の書式を指定の場所にコピーします。宛先がソース範囲よりも大きい場合や小さい場合は、それに応じてソースが繰り返されるか切り捨てられます。この方法では、書式のみがコピーされます。
gridId パラメータの詳細については、get
をご覧ください。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const source = ss.getSheets()[0];
const range = source.getRange('B2:D4');
// This copies the formatting in B2:D4 in the source sheet to
// D4:F6 in the sheet with gridId 1555299895. Note that you can get the gridId
// of a sheet by calling sheet.getSheetId() or range.getGridId().
range.copyFormatToRange(1555299895, 4, 6, 4, 6);
パラメータ
名前 | 型 | 説明 |
---|---|---|
grid | Integer | スプレッドシート内のシートの一意の ID(位置に関係なく)。 |
column | Integer | 対象範囲の最初の列。 |
column | Integer | 対象範囲の最終列。 |
row | Integer | 対象範囲の開始行。 |
row | Integer | 対象範囲の最終行。 |
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
関連情報
copyFormatToRange(sheet, column, columnEnd, row, rowEnd)
範囲の書式を指定の場所にコピーします。宛先がソース範囲よりも大きい場合や小さい場合は、それに応じてソースが繰り返されるか切り捨てられます。この方法では、書式のみがコピーされます。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const source = ss.getSheets()[0];
const destination = ss.getSheets()[1];
const range = source.getRange('B2:D4');
// This copies the formatting in B2:D4 in the source sheet to
// D4:F6 in the second sheet
range.copyFormatToRange(destination, 4, 6, 4, 6);
パラメータ
名前 | 型 | 説明 |
---|---|---|
sheet | Sheet | 対象シート。 |
column | Integer | 対象範囲の最初の列。 |
column | Integer | 対象範囲の最終列。 |
row | Integer | 対象範囲の開始行。 |
row | Integer | 対象範囲の最終行。 |
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
copyTo(destination)
セル範囲のデータを別のセル範囲にコピーします。値と書式設定の両方がコピーされます。
// The code below copies the first 5 columns over to the 6th column.
const sheet = SpreadsheetApp.getActiveSheet();
const rangeToCopy = sheet.getRange(1, 1, sheet.getMaxRows(), 5);
rangeToCopy.copyTo(sheet.getRange(1, 6));
パラメータ
名前 | 型 | 説明 |
---|---|---|
destination | Range | コピー先の範囲。左上のセルの位置のみが関連します。 |
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
copyTo(destination, copyPasteType, transposed)
セル範囲のデータを別のセル範囲にコピーします。
// The code below copies only the values of the first 5 columns over to the 6th
// column.
const sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange('A:E').copyTo(
sheet.getRange('F1'),
SpreadsheetApp.CopyPasteType.PASTE_VALUES,
false,
);
パラメータ
名前 | 型 | 説明 |
---|---|---|
destination | Range | コピー先の範囲。左上のセルの位置のみが関連します。 |
copy | Copy | 範囲の内容を宛先に貼り付ける方法を指定する型。 |
transposed | Boolean | 範囲を転置した状態で貼り付けるかどうか。 |
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
copyTo(destination, options)
セル範囲のデータを別のセル範囲にコピーします。デフォルトでは、値とフォーマットの両方がコピーされますが、これは高度な引数を使用してオーバーライドできます。
// The code below copies only the values of the first 5 columns over to the 6th
// column.
const sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange('A:E').copyTo(sheet.getRange('F1'), {contentsOnly: true});
パラメータ
名前 | 型 | 説明 |
---|---|---|
destination | Range | コピー先の範囲。左上のセルの位置のみが関連します。 |
options | Object | 以下に示す詳細なパラメータを指定する JavaScript オブジェクト。 |
拡張パラメータ
名前 | 型 | 説明 |
---|---|---|
format | Boolean | 形式のみをコピーすることを指定します。 |
contents | Boolean | コンテンツのみをコピーすることを指定します。 |
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
copyValuesToRange(gridId, column, columnEnd, row, rowEnd)
範囲の内容を指定された場所にコピーします。宛先がソース範囲よりも大きい場合や小さい場合は、それに応じてソースが繰り返されるか切り捨てられます。
gridId パラメータの詳細については、get
をご覧ください。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const source = ss.getSheets()[0];
const range = source.getRange('B2:D4');
// This copies the data in B2:D4 in the source sheet to
// D4:F6 in the sheet with gridId 0
range.copyValuesToRange(0, 4, 6, 4, 6);
パラメータ
名前 | 型 | 説明 |
---|---|---|
grid | Integer | スプレッドシート内のシートの一意の ID(位置に関係なく)。 |
column | Integer | 対象範囲の最初の列。 |
column | Integer | 対象範囲の最終列。 |
row | Integer | 対象範囲の開始行。 |
row | Integer | 対象範囲の最終行。 |
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
関連情報
copyValuesToRange(sheet, column, columnEnd, row, rowEnd)
範囲の内容を指定された場所にコピーします。宛先がソース範囲よりも大きい場合や小さい場合は、それに応じてソースが繰り返されるか切り捨てられます。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const source = ss.getSheets()[0];
const destination = ss.getSheets()[1];
const range = source.getRange('B2:D4');
// This copies the data in B2:D4 in the source sheet to
// D4:F6 in the second sheet
range.copyValuesToRange(destination, 4, 6, 4, 6);
パラメータ
名前 | 型 | 説明 |
---|---|---|
sheet | Sheet | 対象シート。 |
column | Integer | 対象範囲の最初の列。 |
column | Integer | 対象範囲の最終列。 |
row | Integer | 対象範囲の開始行。 |
row | Integer | 対象範囲の最終行。 |
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
createDataSourcePivotTable(dataSource)
データソースから空のデータソース ピボット テーブルを作成し、この範囲の最初のセルをアンカーにします。
この例では、新しいデータソースのピボット テーブルを作成して構成する方法を示します。
const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
const anchorCell = spreadsheet.getSheets()[0].getRange('A1');
const dataSource = spreadsheet.getDataSources()[0];
const pivotTable = anchorCell.createDataSourcePivotTable(dataSource);
pivotTable.addRowGroup('dataColumnA');
pivotTable.addColumnGroup('dataColumnB');
pivotTable.addPivotValue(
'dataColumnC',
SpreadsheetApp.PivotTableSummarizeFunction.SUM,
);
pivotTable.addFilter(
'dataColumnA',
SpreadsheetApp.newFilterCriteria().whenTextStartsWith('A').build(),
);
パラメータ
名前 | 型 | 説明 |
---|---|---|
data | Data | ピボット テーブルを作成するデータソース。 |
戻る
Data
- 新しく作成されたデータソース ピボット テーブル。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
createDataSourceTable(dataSource)
この範囲の最初のセルをアンカーとして、データソースから空のデータソース テーブルを作成します。
この例では、新しいデータソース テーブルを作成して構成する方法を示します。
const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
const anchorCell = spreadsheet.getSheets()[0].getRange('A1');
const dataSource = spreadsheet.getDataSources()[0];
const dataSourceTable =
anchorCell.createDataSourceTable(dataSource)
.addColumns('dataColumnA', 'dataColumnB', 'dataColumnC')
.addSortSpec('dataColumnA', true) // ascending=true
.addSortSpec('dataColumnB', false); // ascending=false
パラメータ
名前 | 型 | 説明 |
---|---|---|
data | Data | ピボット テーブルを作成するデータソース。 |
戻る
Data
- 新しく作成されたデータソース テーブル。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
createDeveloperMetadataFinder()
この範囲内のデベロッパー メタデータを検索するための DeveloperMetadataFinderApi を返します。メタデータが範囲のスコープ内にあるのは、その範囲内に完全に含まれている場合のみです。たとえば、行「3:3」に関連付けられているメタデータは、範囲「A1:D5」のスコープ内ではありませんが、範囲「1:5」のスコープ内にあります。
// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');
// Gets the range A1:C6.
const range = sheet.getRange('A1:C6');
// Creates a developer metadata finder to search for metadata in the scope of
// this range.
const developerMetaDataFinder = range.createDeveloperMetadataFinder();
// Logs information about the developer metadata finder to the console.
const developerMetaData = developerMetaDataFinder.find()[0];
console.log(developerMetaData.getKey());
console.log(developerMetaData.getValue());
console.log(developerMetaData.getVisibility().toString());
戻る
Developer
- この範囲内のメタデータを検索するデベロッパー メタデータ検索ツール。
createFilter()
フィルタを作成して、シート上の指定した範囲に適用します。1 つのシートに複数のフィルタを作成することはできません。作成したフィルタにアクセスして変更するには、get
または Sheet.getFilter()
を使用します。
const ss = SpreadsheetApp.getActiveSheet();
const range = ss.getRange('A1:C20');
// Creates a new filter and applies it to the range A1:C20 on the active sheet.
function createFilter() {
range.createFilter();
}
// Gets the filter and applies criteria that only shows cells that aren't empty.
function getFilterAddCriteria() {
const filter = range.getFilter();
const criteria =
SpreadsheetApp.newFilterCriteria().whenCellNotEmpty().build();
filter.setColumnFilterCriteria(2, criteria);
}
Grid
シートのフィルタを作成するために使用します。グリッドシートは、データベースに接続されていないシートです。他のタイプのフィルタを作成するには、以下をご覧ください。
Pivot
を使用してピボット テーブルのフィルタを作成します。Table.addFilter(sourceDataColumn, filterCriteria) Data
を使用して、データベースに接続されているシートのフィルタを作成します。Source Sheet.addFilter(columnName, filterCriteria) Data
を使用して、データベースに接続されたピボット テーブルのフィルタを作成します。Source Pivot Table.addFilter(columnName, filterCriteria)
戻る
Filter
- 新しいフィルタ。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
createPivotTable(sourceData)
この範囲の最初のセルに固定された指定された source
から空のピボット テーブルを作成します。
// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');
// Gets cell A1 as a range in order to place the pivot table.
const range = sheet.getRange('A1');
// Gets the range of the source data for the pivot table.
const dataRange = sheet.getRange('E12:G20');
// Creates an empty pivot table from the specified source data.
const pivotTable = range.createPivotTable(dataRange);
// Logs the values from the pivot table's source data to the console.
console.log(pivotTable.getSourceDataRange().getValues());
パラメータ
名前 | 型 | 説明 |
---|---|---|
source | Range | ピボット テーブルを作成するデータ。 |
戻る
Pivot
- 新しく作成された Pivot
。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
createTextFinder(findText)
範囲のテキスト検索ツールを作成します。このツールを使用すると、範囲内のテキストを検索して置換できます。
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getActiveRange();
// Creates a text finder for the range.
const textFinder = range.createTextFinder('dog');
// Returns the first occurrence of 'dog'.
const firstOccurrence = textFinder.findNext();
// Replaces the last found occurrence of 'dog' with 'cat' and returns the number
// of occurrences replaced.
const numOccurrencesReplaced = textFinder.replaceWith('cat');
パラメータ
名前 | 型 | 説明 |
---|---|---|
find | String | 検索するテキスト。 |
戻る
Text
- 範囲の Text
deleteCells(shiftDimension)
このセル範囲を削除します。指定されたディメンションに沿って、シート内の既存のデータが削除された範囲に移動します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('A1:D10');
range.deleteCells(SpreadsheetApp.Dimension.COLUMNS);
パラメータ
名前 | 型 | 説明 |
---|---|---|
shift | Dimension | 既存のデータをシフトするディメンション。 |
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
expandGroups()
この範囲と範囲またはコントロール トグルが交差する、閉じられたグループを開きます。コントロール トグルの位置は、設定に応じてグループの直前または直後に表示されるコントロール トグルのインデックスです。同じ場所に複数のグループがある場合は、最も浅いグループが展開されます。
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getActiveRange();
// All row and column groups within the range are expanded.
range.expandGroups();
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getA1Notation()
A1 表記で範囲の文字列の説明を返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange(1, 1, 2, 5);
// Logs "A1:E2"
Logger.log(range.getA1Notation());
戻る
String
- A1 表記の範囲の文字列の説明。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getBackground()
範囲内の左上のセルの背景色を返します(例: '#ffffff'
)。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const cell = sheet.getRange('B5');
Logger.log(cell.getBackground());
戻る
String
- 背景のカラーコード。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getBackgroundObject()
範囲内の左上のセルの背景色を返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const cell = sheet.getRange('B5');
Logger.log(cell.getBackgroundObject().asRgbColor().asHexString());
戻る
Color
- 範囲内の左上のセルの背景色。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getBackgroundObjects()
範囲内のセルの背景色を返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B5:C6');
const bgColors = range.getBackgroundObjects();
for (const i in bgColors) {
for (const j in bgColors[i]) {
Logger.log(bgColors[i][j].asRgbColor().asHexString());
}
}
戻る
Color[][]
- 背景色の 2 次元配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getBackgrounds()
範囲内のセルの背景色を返します(例: '#ffffff'
)。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B5:C6');
const bgColors = range.getBackgrounds();
for (const i in bgColors) {
for (const j in bgColors[i]) {
Logger.log(bgColors[i][j]);
}
}
戻る
String[][]
- 背景のカラーコードの 2 次元配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getBandings()
この範囲内の任意のセルに適用されているすべてのバンドを返します。
// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');
// Sets a range.
const range = sheet.getRange('A1:K50');
// Gets the banding info for the range.
const bandings = range.getBandings();
// Logs the second row color for each banding to the console.
for (const banding of bandings) {
console.log(banding.getSecondRowColor());
}
戻る
Banding[]
- この範囲内の任意のセルに適用されているすべてのバンド。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getCell(row, column)
範囲内の指定したセルを返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
// The row and column here are relative to the range
// getCell(1,1) in this code returns the cell at B2
const cell = range.getCell(1, 1);
Logger.log(cell.getValue());
パラメータ
名前 | 型 | 説明 |
---|---|---|
row | Integer | 範囲を基準とするセルの行。 |
column | Integer | 範囲を基準としたセルの列。 |
戻る
Range
- 指定された座標の単一セルを含む範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getColumn()
この範囲の開始列位置を返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
// Logs "2.0"
Logger.log(range.getColumn());
戻る
Integer
- スプレッドシート内の範囲の開始列位置。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataRegion()
4 つの基本方向の Direction
で拡張された範囲のコピーを返します。これにより、データを含む隣接するすべてのセルが対象になります。範囲が対角線に沿ったセルを除く空白セルで囲まれている場合、範囲自体が返されます。これは、範囲を選択してエディタに Ctrl+A
と入力するのと同じです。
// Assume the active spreadsheet is blank.
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
sheet.getRange('C2').setValue(100);
sheet.getRange('B3').setValue(100);
sheet.getRange('D3').setValue(100);
sheet.getRange('C4').setValue(100);
// Logs "B2:D4"
Logger.log(sheet.getRange('C3').getDataRegion().getA1Notation());
戻る
Range
- 範囲のデータ領域またはスプレッドシート全体の範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataRegion(dimension)
指定されたディメンションが Dimension.ROWS
の場合は範囲拡張された Direction.UP
と Direction.DOWN
のコピーを返します。ディメンションが Dimension.COLUMNS
の場合は Direction.NEXT
と Direction.PREVIOUS
を返します。範囲の拡張は、テーブルのように編成された範囲の横にあるデータを検出することで行われます。拡張範囲は、指定したディメンションに沿って、テーブルの境界を含む、データを含む隣接するすべてのセルに適用されます。元の範囲が指定されたディメンションに沿って空白セルで囲まれている場合、範囲自体が返されます。この方法は、範囲を選択して、エディタで列の場合は
Ctrl+Space
、行の場合は Shift+Space
を入力する場合と同様です。
// Assume the active spreadsheet is blank.
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
sheet.getRange('C2').setValue(100);
sheet.getRange('B3').setValue(100);
sheet.getRange('D3').setValue(100);
sheet.getRange('C4').setValue(100);
// Logs "C2:C4"
Logger.log(
sheet.getRange('C3')
.getDataRegion(SpreadsheetApp.Dimension.ROWS)
.getA1Notation(),
);
// Logs "B3:D3"
Logger.log(
sheet.getRange('C3')
.getDataRegion(SpreadsheetApp.Dimension.COLUMNS)
.getA1Notation(),
);
パラメータ
名前 | 型 | 説明 |
---|---|---|
dimension | Dimension | 範囲を拡張するディメンション。 |
戻る
Range
- 範囲のデータ領域、または元の範囲にまたがる各列または各行をカバーする範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataSourceFormula()
範囲内の最初のセルの Data
を返します。セルにデータソースの式が含まれていない場合は null
を返します。
// 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 the range A1 on Sheet1.
const range = sheet.getRange('A1');
// Gets the data source formula from cell A1.
const dataSourceFormula = range.getDataSourceFormula();
// Gets the formula.
const formula = dataSourceFormula.getFormula();
// Logs the formula.
console.log(formula);
戻る
Data
- セルの Data
。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataSourceFormulas()
範囲内のセルの Data
を返します。
// 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 the range A1:B5 on Sheet1.
const range = sheet.getRange('A1:B5');
// Gets an array of the data source formulas in the range A1:B5.
const dataSourceFormulas = range.getDataSourceFormulas();
// Logs the first formula in the array.
console.log(dataSourceFormulas[0].getFormula());
戻る
Data
- Data
の配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 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 the range A1:G50 on Sheet1.
const range = sheet.getRange('A1:G50');
// Gets an array of the data source pivot tables in the range A1:G50.
const dataSourcePivotTables = range.getDataSourcePivotTables();
// Logs the last time that the first pivot table in the array was refreshed.
console.log(dataSourcePivotTables[0].getStatus().getLastRefreshedTime());
戻る
Data
- データソース ピボット テーブルのリスト。
承認
このメソッドを使用するスクリプトには、次のスコープの 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 the range A1:G50 on Sheet1.
const range = sheet.getRange('A1:G50');
// Gets the first data source table in the range A1:G50.
const dataSourceTable = range.getDataSourceTables()[0];
// Logs the time of the last completed data execution on the data source table.
console.log(dataSourceTable.getStatus().getLastExecutionTime());
戻る
Data
- データソース テーブルのリスト。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataSourceUrl()
この範囲内のデータの URL を返します。この URL は、グラフやクエリの作成に使用できます。
function doGet() {
const ss = SpreadsheetApp.openById(
'1khO6hBWTNNyvyyxvob7aoZTI9ZvlqqASNeq0e29Tw2c',
);
const sheet = ss.getSheetByName('ContinentData');
const range = sheet.getRange('A1:B8');
const template = HtmlService.createTemplateFromFile('piechart');
template.dataSourceUrl = range.getDataSourceUrl();
return template.evaluate();
}
<!DOCTYPE html>
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
// Load the Visualization API and the corechart package.
google.charts.load('current', {'packages': ['corechart']});
// Set a callback to run when the Google Visualization API is loaded.
google.charts.setOnLoadCallback(queryData);
function queryData() {
var query = new google.visualization.Query('<?= dataSourceUrl ?>');
query.send(drawChart);
}
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart(response) {
if (response.isError()) {
alert('Error: ' + response.getMessage() + ' ' + response.getDetailedMessage());
return;
}
var data = response.getDataTable();
// Set chart options.
var options = {
title: 'Population by Continent',
width: 400,
height: 300
};
// Instantiate and draw the chart, passing in some options.
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
</head>
<body>
<!-- Div that holds the pie chart. -->
<div id="chart_div"></div>
</body>
</html>
戻る
String
- グラフなどの他の API に渡すことができるデータソースとして、この範囲の URL。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataTable()
このオブジェクト内のデータは DataTable として返されます。
// 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 the range A1:B7 on Sheet1.
const range = sheet.getRange('A1:B7');
// Gets the range A1:B7 as a data table. The values in each column must be of
// the same type.
const datatable = range.getDataTable();
// Uses the Charts service to build a bar chart from the data table.
// This doesn't build an embedded chart. To do that, use
// sheet.newChart().addRange() instead.
const chart = Charts.newBarChart()
.setDataTable(datatable)
.setOption('title', 'Your Chart Title Here')
.build();
戻る
Data
- データテーブル形式のデータ。
getDataTable(firstRowIsHeader)
この範囲内のデータを DataTable として返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('A1:B7');
// Calling this method with "true" sets the first line to be the title of the
// axes
const datatable = range.getDataTable(true);
// Note that this doesn't build an EmbeddedChart, so you can't just use
// Sheet#insertChart(). To do that, use sheet.newChart().addRange() instead.
const chart = Charts.newBarChart()
.setDataTable(datatable)
.setOption('title', 'Your Title Here')
.build();
パラメータ
名前 | 型 | 説明 |
---|---|---|
first | Boolean | 最初の行をヘッダーとして扱うかどうか。 |
戻る
Data
- データテーブル形式のデータ。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataValidation()
範囲内の左上のセルのデータ入力規則を返します。セルにデータ入力規則が設定されていない場合、このメソッドは null
を返します。
// Log information about the data validation rule for cell A1.
const cell = SpreadsheetApp.getActive().getRange('A1');
const rule = cell.getDataValidation();
if (rule != null) {
const criteria = rule.getCriteriaType();
const args = rule.getCriteriaValues();
Logger.log('The data validation rule is %s %s', criteria, args);
} else {
Logger.log('The cell does not have a data validation rule.');
}
戻る
Data
- 範囲内の左上のセルのデータの入力規則。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDataValidations()
範囲内のすべてのセルのデータ入力規則を返します。特定のセルにデータ検証が設定されていない場合、このメソッドは、そのセルの配列内の位置に null
を返します。
// Change existing data validation rules that require a date in 2013 to require
// a date in 2014.
const oldDates = [new Date('1/1/2013'), new Date('12/31/2013')];
const newDates = [new Date('1/1/2014'), new Date('12/31/2014')];
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange(1, 1, sheet.getMaxRows(), sheet.getMaxColumns());
const rules = range.getDataValidations();
for (let i = 0; i < rules.length; i++) {
for (let j = 0; j < rules[i].length; j++) {
const rule = rules[i][j];
if (rule != null) {
const criteria = rule.getCriteriaType();
const args = rule.getCriteriaValues();
if (criteria === SpreadsheetApp.DataValidationCriteria.DATE_BETWEEN &&
args[0].getTime() === oldDates[0].getTime() &&
args[1].getTime() === oldDates[1].getTime()) {
// Create a builder from the existing rule, then change the dates.
rules[i][j] = rule.copy().withCriteria(criteria, newDates).build();
}
}
}
}
range.setDataValidations(rules);
戻る
Data
- 範囲内のセルに関連付けられたデータの入力規則の 2 次元配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 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 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');
// Gets row 2 on Sheet1.
const range = sheet.getRange('2:2');
// Adds metadata to row 2.
range.addDeveloperMetadata('NAME', 'GOOGLE');
// Logs the metadata to console.
for (const metadata of range.getDeveloperMetadata()) {
console.log(`${metadata.getKey()}: ${metadata.getValue()}`);
}
戻る
Developer
- この範囲に関連付けられているデベロッパーのメタデータ。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDisplayValue()
範囲内の左上のセルの表示値を返します。値は String
です。表示される値には、日時と通貨の書式設定(スプレッドシートの言語 / 地域設定によって自動的に適用される書式を含む)が考慮されます。空のセルからは空の文字列が返されます。
// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');
// Gets cell A30 and sets its value to 'Test code.'
const cell = sheet.getRange('A30');
cell.setValue('Test code');
// Gets the value and logs it to the console.
console.log(cell.getDisplayValue());
戻る
String
- このセルに表示される値。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getDisplayValues()
この範囲の値の長方形グリッドを返します。
表示される値の 2 次元配列を返します。インデックスは行、列の順に付けられます。値は String
オブジェクトです。表示される値には、日付、時刻、通貨の形式(スプレッドシートの言語 / 地域の設定によって自動的に適用される形式を含む)が考慮されます。空のセルは、配列内の空の文字列で表されます。範囲インデックスは 1, 1
から始まりますが、JavaScript 配列のインデックスは [0][0]
から始まることに注意してください。
// The code below gets the displayed values for the range C2:G8
// in the active spreadsheet. Note that this is a JavaScript array.
const values =
SpreadsheetApp.getActiveSheet().getRange(2, 3, 6, 4).getDisplayValues();
Logger.log(values[0][0]);
戻る
String[][]
- 値の 2 次元配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFilter()
この範囲が属するシートのフィルタを返します。シートにフィルタがない場合、null
を返します。
const ss = SpreadsheetApp.getActiveSheet();
const range = ss.getRange('A1:C20');
// Gets the existing filter on the sheet that the given range belongs to.
const filter = range.getFilter();
戻る
Filter
- フィルタ。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFontColorObject()
範囲の左上にあるセルのフォント色を返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
Logger.log(range.getFontColorObject().asRgbColor().asHexString());
戻る
Color
- 範囲内の左上のセルのフォント色。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFontColorObjects()
範囲内のセルのフォント色を返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
const results = range.getFontColorObjects();
for (const i in results) {
for (const j in results[i]) {
Logger.log(results[i][j].asRgbColor().asHexString());
}
}
戻る
Color[][]
- 範囲内のセルに関連付けられたフォント色の 2 次元配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFontFamilies()
範囲内のセルのフォント ファミリーを返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
const results = range.getFontFamilies();
for (const i in results) {
for (const j in results[i]) {
Logger.log(results[i][j]);
}
}
戻る
String[][]
- 範囲内のセルに関連付けられたフォント ファミリーの 2 次元配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFontFamily()
範囲の左上にあるセルのフォント ファミリーを返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
Logger.log(range.getFontFamily());
戻る
String
- セルのフォント ファミリー。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFontLine()
範囲の左上隅にあるセルの線のスタイルを取得します('underline'
、'line-through'
、'none'
)。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
Logger.log(range.getFontLine());
戻る
String
- フォント行。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFontLines()
範囲内のセルの線のスタイルを取得します('underline'
、'line-through'
、'none'
)。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
const results = range.getFontLines();
for (const i in results) {
for (const j in results[i]) {
Logger.log(results[i][j]);
}
}
戻る
String[][]
- 範囲内のセルに関連付けられたフォントラインを含む 2 次元配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFontSize()
範囲の左上にあるセルのフォントサイズをポイント単位で返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
Logger.log(range.getFontSize());
戻る
Integer
- フォントサイズ(ポイント単位)。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFontSizes()
範囲内のセルのフォントサイズを返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
const results = range.getFontSizes();
for (const i in results) {
for (const j in results[i]) {
Logger.log(results[i][j]);
}
}
戻る
Integer[][]
- 範囲内のセルに関連付けられたテキストのフォントサイズの 2 次元配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFontStyle()
範囲の左上にあるセルのフォント スタイル('italic'
または 'normal'
)を返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
Logger.log(range.getFontStyle());
戻る
String
- セル内のテキストのフォント スタイル。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFontStyles()
範囲内のセルのフォント スタイルを返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
const results = range.getFontStyles();
for (const i in results) {
for (const j in results[i]) {
Logger.log(results[i][j]);
}
}
戻る
String[][]
- 範囲内のセルに関連付けられたテキストのフォントスタイルの 2 次元配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFontWeight()
範囲の左上にあるセルのフォント太さ(標準/太字)を返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
Logger.log(range.getFontWeight());
戻る
String
- セル内のテキストのフォント ウェイト。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFontWeights()
範囲内のセルのフォント重みを返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
const results = range.getFontWeights();
for (const i in results) {
for (const j in results[i]) {
Logger.log(results[i][j]);
}
}
戻る
String[][]
- 範囲内のセルに関連付けられたテキストのフォント ウェイトの 2 次元配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFormula()
範囲の左上のセルの式(A1 表記)を返します。セルが空であるか式が含まれていない場合は、空の文字列を返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
// This assumes you have a function in B5 that sums up
// B2:B4
const range = sheet.getRange('B5');
// Logs the calculated value and the formula
Logger.log(
'Calculated value: %s Formula: %s',
range.getValue(),
range.getFormula(),
);
戻る
String
- セルの式。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFormulaR1C1()
指定されたセルの数式(R1C1 表記)を返します。数式がない場合、null
を返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B5');
const formula = range.getFormulaR1C1();
Logger.log(formula);
戻る
String
- R1C1 表記の数式。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFormulas()
範囲内のセルの数式(A1 表記)を返します。2 次元配列内のエントリは、数式のないセルの場合は空の文字列です。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B5:C6');
const formulas = range.getFormulas();
for (const i in formulas) {
for (const j in formulas[i]) {
Logger.log(formulas[i][j]);
}
}
戻る
String[][]
- 文字列形式の式の 2 次元配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFormulasR1C1()
範囲内のセルの数式(R1C1 表記)を返します。2 次元配列内のエントリは、数式のないセルの場合は null
です。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B5:C6');
const formulas = range.getFormulasR1C1();
for (const i in formulas) {
for (const j in formulas[i]) {
Logger.log(formulas[i][j]);
}
}
戻る
String[][]
- R1C1 表記の数式の 2 次元配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getGridId()
範囲の親シートのグリッド ID を返します。ID はランダムな正の整数値です。
// Log the grid ID of the first sheet (by tab position) in the spreadsheet.
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
Logger.log(range.getGridId());
戻る
Integer
- 親シートのグリッド ID。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getHeight()
範囲の高さを返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
// logs 3.0
Logger.log(range.getHeight());
戻る
Integer
- 範囲の高さ。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getHorizontalAlignment()
範囲の左上にあるセルのテキストの水平方向の配置(左/中央/右)を返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
Logger.log(range.getHorizontalAlignment());
戻る
String
- セル内のテキストの水平方向の配置。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getHorizontalAlignments()
範囲内のセルの水平方向の配置を返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
const results = range.getHorizontalAlignments();
for (const i in results) {
for (const j in results[i]) {
Logger.log(results[i][j]);
}
}
戻る
String[][]
- 範囲内のセルに関連付けられたテキストの水平方向の配置の 2 次元配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getLastColumn()
終了列の位置を返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
// Logs "4.0"
Logger.log(range.getLastColumn());
戻る
Integer
- スプレッドシート内の範囲の終了列の位置。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getLastRow()
終了行の位置を返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
// Logs "4.0"
Logger.log(range.getLastRow());
戻る
Integer
- スプレッドシート内の範囲の終了行の位置。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getMergedRanges()
現在の範囲内に完全に含まれているか、現在の範囲内に 1 つ以上のセルを含む結合セルを表す Range
オブジェクトの配列を返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('A1:B3');
const mergedRanges = range.getMergedRanges();
for (let i = 0; i < mergedRanges.length; i++) {
Logger.log(mergedRanges[i].getA1Notation());
Logger.log(mergedRanges[i].getDisplayValue());
}
戻る
getNextDataCell(direction)
範囲の最初の列と行のセルから、指定された方向の次のセルを返します。このセルは、データを含む連続したセルの範囲の端にあるセルか、その方向のスプレッドシートの端にあるセルです。これは、エディタで
Ctrl+[arrow key]
と入力するのと同じです。
// Assume the active spreadsheet is blank.
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('C3:E5');
// Logs "C1"
Logger.log(range.getNextDataCell(SpreadsheetApp.Direction.UP).getA1Notation());
パラメータ
名前 | 型 | 説明 |
---|---|---|
direction | Direction | 次のデータ領域の端のセルを見つける方向。 |
戻る
Range
- データ領域の端のセルまたはスプレッドシートの端のセル。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getNote()
指定された範囲に関連付けられているメモを返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
Logger.log(range.getNote());
戻る
String
- 指定されたセルに関連付けられているメモ。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getNotes()
範囲内のセルに関連付けられているメモを返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
const results = range.getNotes();
for (const i in results) {
for (const j in results[i]) {
Logger.log(results[i][j]);
}
}
戻る
String[][]
- 範囲内のセルに関連付けられたメモの 2 次元配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getNumColumns()
この範囲内の列数を返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D5');
Logger.log(range.getNumColumns());
戻る
Integer
- この範囲内の列数。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getNumRows()
この範囲内の行数を返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D5');
Logger.log(range.getNumRows());
戻る
Integer
- この範囲内の行数。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getNumberFormat()
指定した範囲の左上のセルの数値または日付の書式を取得します。返される形式パターンについては、Sheets API のドキュメントをご覧ください。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const cell = sheet.getRange('C4');
Logger.log(cell.getNumberFormat());
戻る
String
- 範囲の左上のセルの数値形式。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getNumberFormats()
範囲内のセルの数値または日付の形式を返します。返される形式パターンについては、Sheets API のドキュメントをご覧ください。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B5:C6');
const formats = range.getNumberFormats();
for (const i in formats) {
for (const j in formats[i]) {
Logger.log(formats[i][j]);
}
}
戻る
String[][]
- 数値形式の 2 次元配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getRichTextValue()
範囲の左上のセルのリッチテキスト値を返します。セル値がテキストでない場合、null
を返します。
// Gets the Rich Text value of cell D4.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('D4:F6');
const richText = range.getRichTextValue();
console.log(richText.getText());
戻る
Rich
- 範囲内の左上のセルのリッチテキスト値。セル値がテキストでない場合、null
です。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getRichTextValues()
範囲内のセルの HTML 形式のテキスト値を返します。
// Gets the Rich Text values for all cells in range B5:C6
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B5:C6');
const values = range.getRichTextValues();
for (let i = 0; i < values.length; i++) {
for (let j = 0; j < values[i].length; j++) {
console.log(values[i][j].getText());
}
}
戻る
Rich
- リッチテキスト値の 2 次元配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getRow()
この範囲の行番号を返します。get
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2');
Logger.log(range.getRow());
戻る
Integer
- 範囲の行番号。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getRowIndex()
この範囲の行番号を返します。get
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2');
Logger.log(range.getRowIndex());
戻る
Integer
- 範囲の行番号。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
関連情報
getSheet()
この範囲が属するシートを返します。
// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');
// Gets the range A1:D10 on Sheet1.
const range = sheet.getRange('A1:D10');
// Gets the sheet that the range belongs to.
const rangeSheet = range.getSheet();
// Gets the sheet name and logs it to the console.
console.log(rangeSheet.getName());
戻る
Sheet
- この範囲が属するシート。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getTextDirection()
範囲の左上セルの文章方向を返します。セルのテキストの向きが自動検出で決定された場合は、null
を返します。
// Get the text direction of cell B1.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B1:D4');
Logger.log(range.getTextDirection());
戻る
Text
- 範囲内の左上セルのテキストの向き。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getTextDirections()
範囲内のセルのテキストの向きを返します。2 次元配列内のエントリは、自動検出を使用するセルの場合は null
です。
// Get the text directions for all cells in range B5:C6
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B5:C6');
const directions = range.getTextDirections();
for (let i = 0; i < directions.length; i++) {
for (let j = 0; j < directions[i].length; j++) {
Logger.log(directions[i][j]);
}
}
戻る
Text
- テキスト ルートの 2 次元配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getTextRotation()
範囲の左上のセルのテキストの回転設定を返します。
// Log the text rotation settings for a cell.
const sheet = SpreadsheetApp.getActiveSheet();
const cell = sheet.getRange('A1');
Logger.log(cell.getTextRotation());
戻る
Text
- テキストの回転設定。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getTextRotations()
範囲内のセルのテキストの回転設定を返します。
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B2:D4');
const results = range.getTextRotations();
for (const i in results) {
for (const j in results[i]) {
const rotation = results[i][j];
Logger.log('Cell [%s, %s] has text rotation: %v', i, j, rotation);
}
}
戻る
Text
- 範囲内のセルに関連付けられたテキストの回転の 2 次元配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getTextStyle()
範囲の左上セルのテキスト スタイルを返します。
// Get the text style of cell D4.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('D4:F6');
const style = range.getTextStyle();
Logger.log(style);
戻る
Text
- 範囲内の左上のセルのテキスト スタイル。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getTextStyles()
範囲内のセルのテキスト スタイルを返します。
// Get the text styles for all cells in range B5:C6
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B5:C6');
const styles = range.getTextStyles();
for (let i = 0; i < styles.length; i++) {
for (let j = 0; j < styles[i].length; j++) {
Logger.log(styles[i][j]);
}
}
戻る
Text
- テキスト スタイルの 2 次元配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getValue()
範囲内の左上のセルの値を返します。値は、セルの値に応じて Number
、Boolean
、Date
、String
のいずれかになります。空のセルは空の文字列を返します。
// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');
// Gets the range A1:D10 on Sheet1.
const range = sheet.getRange('A1:D10');
// Gets the value of the top-left cell in the range and logs it to the console.
console.log(range.getValue());
戻る
Object
- このセルの値。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getValues()
この範囲の値の長方形グリッドを返します。
値の 2 次元配列を返します。インデックスは行、列の順に付けられます。値は、セルの値に応じて、Number
、Boolean
、Date
、String
のいずれかになります。空のセルは、配列内の空の文字列で表されます。範囲インデックスは 1, 1
から始まりますが、JavaScript 配列のインデックスは [0][0]
から始まることに注意してください。
// The code below gets the values for the range C2:G8
// in the active spreadsheet. Note that this is a JavaScript array.
const values = SpreadsheetApp.getActiveSheet().getRange(2, 3, 6, 4).getValues();
Logger.log(values[0][0]);
Date
値は有効なパラメータではありません。範囲に Date
値を含むセルが含まれている場合、getValues()
はウェブアプリにデータを返せません。代わりに、シートから取得したすべての値を、Number
、Boolean
、String
などのサポートされている JavaScript プリミティブに変換します。戻る
Object[][]
- 値の 2 次元配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getVerticalAlignment()
範囲の左上にあるセルの垂直方向の配置(上/中央/下)を返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
Logger.log(range.getVerticalAlignment());
戻る
String
- セル内のテキストの垂直方向の配置。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getVerticalAlignments()
範囲内のセルの垂直方向の配置を返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
const results = range.getVerticalAlignments();
for (const i in results) {
for (const j in results[i]) {
Logger.log(results[i][j]);
}
}
戻る
String[][]
- 範囲内のセルに関連付けられたテキストの垂直方向の配置の 2 次元配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getWidth()
範囲の幅を列単位で返します。
// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');
// Gets the range A1:D10 on Sheet1.
const range = sheet.getRange('A1:D10');
// Gets the width of the range in number of columns and logs it to the console.
console.log(range.getWidth());
戻る
Integer
- 範囲内の列数。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getWrap()
セル内のテキストが折り返されるかどうかを返します。より詳細なラップ戦略を取得するには、get
を使用します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
Logger.log(range.getWrap());
戻る
Boolean
- このセル内のテキストを折り返すかどうか。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getWrapStrategies()
範囲内のセルのテキスト折り返し戦略を返します。
// Get the text wrapping strategies for all cells in range B5:C6
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B5:C6');
const strategies = range.getWrapStrategies();
for (let i = 0; i < strategies.length; i++) {
for (let j = 0; j < strategies[i].length; j++) {
Logger.log(strategies[i][j]);
}
}
戻る
Wrap
- テキスト折り返し戦略の 2 次元配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getWrapStrategy()
範囲の左上セルのテキストの折り返し方法を返します。
// Get the text wrapping strategy of cell B1.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B1:D4');
Logger.log(range.getWrapStrategy());
戻る
Wrap
- 範囲の左上セルのテキストの折り返し方法。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getWraps()
セル内のテキストが折り返されるかどうかを返します。より詳細なラップ戦略を取得するには、get
を使用します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
const results = range.getVerticalAlignments();
for (const i in results) {
for (const j in results[i]) {
const isWrapped = results[i][j];
if (isWrapped) {
Logger.log('Cell [%s, %s] has wrapped text', i, j);
}
}
}
戻る
Boolean[][]
- 範囲内のセルに関連付けられたテキストの垂直方向の配置の 2 次元配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertCells(shiftDimension)
この範囲に空白セルを挿入します。新しいセルには、この範囲を占有していたセルの書式設定が保持されます。指定されたディメンションに沿って、シート内の既存のデータが挿入された範囲からずれます。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('A1:D10');
range.insertCells(SpreadsheetApp.Dimension.COLUMNS);
パラメータ
名前 | 型 | 説明 |
---|---|---|
shift | Dimension | 既存のデータをシフトするディメンション。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertCheckboxes()
範囲内の各セルにチェックボックスを挿入します。チェックボックスがオンの場合は true
、オフの場合は false
で構成されます。範囲内のすべてのセルの値を false
に設定します。
const range = SpreadsheetApp.getActive().getRange('A1:B10');
// Inserts checkboxes into each cell in the range A1:B10 configured with 'true'
// for checked and 'false' for unchecked. Also, sets the value of each cell in
// the range A1:B10 to 'false'.
range.insertCheckboxes();
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertCheckboxes(checkedValue)
範囲内の各セルにチェックボックスを挿入します。チェックボックスがオンの場合はカスタム値で、オフの場合は空の文字列で構成されます。範囲内の各セルの値を空の文字列に設定します。
const range = SpreadsheetApp.getActive().getRange('A1:B10');
// Inserts checkboxes into each cell in the range A1:B10 configured with 'yes'
// for checked and the empty string for unchecked. Also, sets the value of each
// cell in the range A1:B10 to
// the empty string.
range.insertCheckboxes('yes');
パラメータ
名前 | 型 | 説明 |
---|---|---|
checked | Object | チェックボックスのデータ検証でオンになっている値。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
insertCheckboxes(checkedValue, uncheckedValue)
範囲内の各セルにチェックボックスを挿入します。チェックボックスは、オンとオフの状態のカスタム値で構成されます。範囲内の各セルの値を、未選択のカスタム値に設定します。
const range = SpreadsheetApp.getActive().getRange('A1:B10');
// Inserts checkboxes into each cell in the range A1:B10 configured with 'yes'
// for checked and 'no' for unchecked. Also, sets the value of each cell in the
// range A1:B10 to 'no'.
range.insertCheckboxes('yes', 'no');
パラメータ
名前 | 型 | 説明 |
---|---|---|
checked | Object | チェックボックスのデータ検証でオンになっている値。 |
unchecked | Object | チェックボックスのデータ検証の未選択値。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
isBlank()
範囲が完全に空白の場合、true
を返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
Logger.log(range.isBlank());
戻る
Boolean
- 範囲が空白の場合は true
、それ以外の場合は false
。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
isChecked()
範囲内のすべてのセルのチェックボックスの状態が「オン」かどうかを返します。一部のセルがオンで、残りのセルがオフの場合、または一部のセルにチェックボックスのデータ検証がない場合、null
を返します。
const range = SpreadsheetApp.getActive().getRange('A1:A3');
// Inserts checkboxes and sets each cell value to 'no' in the range A1:A3.
range.insertCheckboxes('yes', 'no');
const range1 = SpreadsheetApp.getActive().getRange('A1');
range1.setValue('yes');
// Sets the value of isRange1Checked as true as it contains the checked value.
const isRange1Checked = range1.isChecked();
const range2 = SpreadsheetApp.getActive().getRange('A2');
range2.setValue('no');
// Sets the value of isRange2Checked as false as it contains the unchecked
// value.
const isRange2Checked = range2.isChecked();
const range3 = SpreadsheetApp.getActive().getRange('A3');
range3.setValue('random');
// Sets the value of isRange3Checked as null, as it contains an invalid checkbox
// value.
const isRange3Checked = range3.isChecked();
戻る
Boolean
- 範囲内のすべてのセルがオンになっている場合は true
、範囲内のすべてのセルがオフになっている場合は false
、いずれかのセルがオフになっているか、チェックボックスのデータ検証が設定されていない場合は null
。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
isEndColumnBounded()
範囲の終了が特定の列にバインドされているかどうかを判断します。たとえば、範囲の末尾の列にバインドされている範囲 A1:B10
または B:B
の場合、このメソッドは true
を返します。範囲の末尾の特定の行にのみバインドされている範囲 3:7
または A1:5
の場合、このメソッドは false
を返します。
// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');
// Gets the range A1:D10 on Sheet1.
const range = sheet.getRange('A1:D10');
// Determines if the end of the range is bound to a particular column and logs
// it to the console.
console.log(range.isEndColumnBounded());
戻る
Boolean
- 範囲の終了が特定の列にバインドされている場合は true
、そうでない場合は false
。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
isEndRowBounded()
範囲の終了が特定の行にバインドされているかどうかを決定します。たとえば、範囲の末尾の行にバインドされている範囲 A1:B10
または 3:7
の場合、このメソッドは true
を返します。範囲の末尾の特定の列にのみバインドされている範囲 B:B
または A1:C
の場合、このメソッドは false
を返します。
// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');
// Gets the range A1:D10 on Sheet1.
const range = sheet.getRange('A1:D10');
// Determines if the end of the range is bound to a particular row and logs it
// to the console.
console.log(range.isEndRowBounded());
戻る
Boolean
- 範囲の終了が特定の行にバインドされている場合は true
、そうでない場合は false
。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
isPartOfMerge()
現在の範囲内のセルが結合セルと重複している場合は、true
を返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('A1:B3');
// True if any of the cells in A1:B3 is included in a merge.
const isPartOfMerge = range.isPartOfMerge();
戻る
Boolean
- 範囲が結合セルと重複する場合は true
、重複しない場合 false
を返します。
isStartColumnBounded()
範囲の開始が特定の列にバインドされているかどうかを決定します。たとえば、範囲の開始列にバインドされている範囲 A1:B10
または B:B
の場合、このメソッドは true
を返します。範囲の開始行にのみバインドされている範囲 3:7
の場合、このメソッドは false
を返します。
// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');
// Gets the range A1:D10 on Sheet1.
const range = sheet.getRange('A1:D10');
// Determines if the start of the range is bound to a particular column and logs
// it to the console.
console.log(range.isStartColumnBounded());
戻る
Boolean
- 範囲の開始が特定の列にバインドされている場合は true
、それ以外の場合は false
。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
isStartRowBounded()
範囲の開始が特定の行にバインドされているかどうかを決定します。たとえば、範囲の開始行にバインドされている範囲 A1:B10
または 3:7
の場合、このメソッドは true
を返します。範囲の開始の特定の列にのみバインドされている範囲 B:B
の場合、このメソッドは false
を返します。
// 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 Sheet1 by its name.
const sheet = ss.getSheetByName('Sheet1');
// Gets the range A1:D10 on Sheet1.
const range = sheet.getRange('A1:D10');
// Determines if the start of the range is bound to a particular row and logs it
// to the console.
console.log(range.isStartRowBounded());
戻る
Boolean
- 範囲の開始が特定の行にバインドされている場合は true
、それ以外の場合は false
。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
merge()
範囲内のセルを 1 つのブロックに結合します。
const sheet = SpreadsheetApp.getActiveSheet();
// The code below 2-dimensionally merges the cells in A1 to B3
sheet.getRange('A1:B3').merge();
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
mergeAcross()
範囲内のセルを範囲の列全体に結合します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
// The code below merges cells C5:E5 into one cell
const range1 = sheet.getRange('C5:E5');
range1.mergeAcross();
// The code below creates 2 horizontal cells, F5:H5 and F6:H6
const range2 = sheet.getRange('F5:H6');
range2.mergeAcross();
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
mergeVertically()
範囲内のセルを結合します。
const sheet = SpreadsheetApp.getActiveSheet();
// The code below vertically merges the cells in A1 to A10
sheet.getRange('A1:A10').mergeVertically();
// The code below creates 3 merged columns: B1 to B10, C1 to C10, and D1 to D10
sheet.getRange('B1:D10').mergeVertically();
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
moveTo(target)
この範囲から対象範囲に(形式と値の両方を)切り取って貼り付けます。
// The code below moves the first 5 columns over to the 6th column
const sheet = SpreadsheetApp.getActiveSheet();
sheet.getRange('A1:E').moveTo(sheet.getRange('F1'));
パラメータ
名前 | 型 | 説明 |
---|---|---|
target | Range | この範囲をコピーする対象範囲。左上のセルの位置のみが重要です。 |
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
offset(rowOffset, columnOffset)
この範囲から指定された行数と列数(負の値も指定可能)だけオフセットした新しい範囲を返します。新しい範囲は元の範囲と同じサイズです。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const cell = sheet.getRange('A1');
// newCell references B2
const newCell = cell.offset(1, 1);
パラメータ
名前 | 型 | 説明 |
---|---|---|
row | Integer | 範囲の左上のセルから下方向の行数。負の値は、範囲の左上のセルから上方向の行数を表します。 |
column | Integer | 範囲の左上のセルから右側の列の数。負の値は、範囲の左上のセルから左側の列を表します。 |
戻る
Range
- チェーン用のこの範囲。
offset(rowOffset, columnOffset, numRows)
現在の範囲を基準とする新しい範囲を返します。この範囲の左上は、指定された行と列で現在の範囲からオフセットされ、指定されたセルの高さになります。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const cell = sheet.getRange('A1');
// newCell references B2:B3
const newRange = cell.offset(1, 1, 2);
パラメータ
名前 | 型 | 説明 |
---|---|---|
row | Integer | 範囲の左上のセルから下方向の行数。負の値は、範囲の左上のセルから上方向の行数を表します。 |
column | Integer | 範囲の左上のセルから右側の列の数。負の値は、範囲の左上のセルから左側の列を表します。 |
num | Integer | 新しい範囲の高さ(行単位)。 |
戻る
Range
- チェーン用のこの範囲。
offset(rowOffset, columnOffset, numRows, numColumns)
現在の範囲を基準とする新しい範囲を返します。この範囲の左上は、指定された行と列で現在の範囲からオフセットされ、セルの高さと幅が指定されます。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const cell = sheet.getRange('A1');
// newCell references B2:C3
const newRange = cell.offset(1, 1, 2, 2);
パラメータ
名前 | 型 | 説明 |
---|---|---|
row | Integer | 範囲の左上のセルから下方向の行数。負の値は、範囲の左上のセルから上方向の行数を表します。 |
column | Integer | 範囲の左上のセルから右側の列の数。負の値は、範囲の左上のセルから左側の列を表します。 |
num | Integer | 新しい範囲の高さ(行単位)。 |
num | Integer | 新しい範囲の列数。 |
戻る
Range
- チェーン用のこの範囲。
protect()
権限を持つユーザーを除き、範囲の編集を保護できるオブジェクトを作成します。スクリプトが(Protection.removeEditor(emailAddress)
、Protection.removeEditor(user)
、Protection.removeEditors(emailAddresses)
、Protection.addEditor(emailAddress)
、Protection.addEditor(user)
、Protection.addEditors(emailAddresses)
を呼び出すか、Protection.setDomainEdit(editable)
に新しい値を設定して)範囲の編集者のリストを実際に変更するまで、権限はスプレッドシート自体の権限を反映します。つまり、範囲は保護されたままになります。範囲がすでに保護されている場合、このメソッドは既存の範囲と重複する新しい保護範囲を作成します。セルが複数の保護範囲で保護されており、そのうちのいずれかが特定のユーザーによるセルの編集を禁止している場合、そのユーザーはセルを編集できません。
// Protect range A1:B10, then remove all other users from the list of editors.
const ss = SpreadsheetApp.getActive();
const range = ss.getRange('A1:B10');
const protection = range.protect().setDescription('Sample protected range');
// Ensure the current user is an editor before removing others. Otherwise, if
// the user's edit permission comes from a group, the script throws an exception
// upon removing the group.
const me = Session.getEffectiveUser();
protection.addEditor(me);
protection.removeEditors(protection.getEditors());
if (protection.canDomainEdit()) {
protection.setDomainEdit(false);
}
戻る
Protection
- 保護設定を表すオブジェクト。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
randomize()
指定した範囲内の行の順序をランダムにします。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('A1:C7');
// Randomizes the range
range.randomize();
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
removeCheckboxes()
範囲内のすべてのチェックボックスを削除します。各セルのデータ検証を消去し、セルにチェック済みまたは未チェックの値が含まれている場合は、その値も消去します。
const range = SpreadsheetApp.getActive().getRange('A1:B10');
// Inserts checkboxes and sets each cell value to 'no' in the range A1:B10.
range.insertCheckboxes('yes', 'no');
const range1 = SpreadsheetApp.getActive().getRange('A1');
range1.setValue('yes');
// Removes the checkbox data validation in cell A1 and clears its value.
range1.removeCheckboxes();
const range2 = SpreadsheetApp.getActive().getRange('A2');
range2.setValue('random');
// Removes the checkbox data validation in cell A2 but does not clear its value.
range2.removeCheckboxes();
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
removeDuplicates()
この範囲内の、前の行の値と重複する値を含む行を削除します。値が同じでも、大文字と小文字の区別、書式、数式が異なる行は重複と見なされます。この方法では、(フィルタなどにより)ビューから非表示になっている重複行も削除されます。この範囲外のコンテンツは削除されません。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B1:D7');
// Remove duplicate rows in the range.
range.removeDuplicates();
戻る
Range
- 重複を削除した後の範囲。削除された行ごとに、範囲のサイズが 1 行ずつ小さくなります。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
removeDuplicates(columnsToCompare)
指定した列に、前の行の値と重複する値が含まれている行を、この範囲内で削除します。値が同じで、大文字と小文字の区別、書式、数式が異なる行は、重複と見なされます。この方法では、(フィルタが原因で)ビューから非表示になっている重複行も削除されます。この範囲外のコンテンツは削除されません。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B1:D7');
// Remove rows which have duplicate values in column B.
range.removeDuplicates([2]);
// Remove rows which have duplicate values in both columns B and D.
range.removeDuplicates([2, 4]);
パラメータ
名前 | 型 | 説明 |
---|---|---|
columns | Integer[] | 重複する値を分析する列。列を指定しない場合、すべての列が重複について分析されます。 |
戻る
Range
- 重複を削除した後の範囲。削除された行ごとに、範囲のサイズが 1 行ずつ小さくなります。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setBackground(color)
範囲内のすべてのセルの背景色を CSS 表記('#ffffff'
や 'white'
など)で設定します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D5');
range.setBackground('red');
パラメータ
名前 | 型 | 説明 |
---|---|---|
color | String | CSS 記法の色コード('#ffffff' や 'white' など)。null 値は色をリセットします。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setBackgroundObject(color)
範囲内のすべてのセルの背景色を設定します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const bgColor = SpreadsheetApp.newColor()
.setThemeColor(SpreadsheetApp.ThemeColorType.BACKGROUND)
.build();
const range = sheet.getRange('B2:D5');
range.setBackgroundObject(bgColor);
パラメータ
名前 | 型 | 説明 |
---|---|---|
color | Color | 設定する背景色。null 値は背景色をリセットします。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setBackgroundObjects(color)
背景色の長方形のグリッドを設定します(この範囲のサイズと一致している必要があります)。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const colorAccent1 = SpreadsheetApp.newColor()
.setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT1)
.build();
const colorAccent2 = SpreadsheetApp.newColor()
.setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT2)
.build();
const colorAccent3 = SpreadsheetApp.newColor()
.setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT3)
.build();
const colorAccent4 = SpreadsheetApp.newColor()
.setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT4)
.build();
const colors = [
[colorAccent1, colorAccent2],
[colorAccent3, colorAccent4],
];
const cell = sheet.getRange('B5:C6');
cell.setBackgroundObjects(colors);
パラメータ
名前 | 型 | 説明 |
---|---|---|
color | Color[][] | 色の 2 次元配列。null 値は色をリセットします。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setBackgroundRGB(red, green, blue)
RGB 値(0 ~ 255 の整数)を使用して、背景を指定された色に設定します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const cell = sheet.getRange('B2');
// Sets the background to white
cell.setBackgroundRGB(255, 255, 255);
// Sets the background to red
cell.setBackgroundRGB(255, 0, 0);
パラメータ
名前 | 型 | 説明 |
---|---|---|
red | Integer | RGB 表記の赤色値。 |
green | Integer | RGB 表記の緑色の値。 |
blue | Integer | RGB 表記の青色値。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setBackgrounds(color)
背景色の長方形のグリッドを設定します(この範囲のサイズと一致している必要があります)。色は CSS 記法('#ffffff'
や 'white'
など)で指定します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const colors = [
['red', 'white', 'blue'],
['#FF0000', '#FFFFFF', '#0000FF'], // These are the hex equivalents
];
const cell = sheet.getRange('B5:D6');
cell.setBackgrounds(colors);
パラメータ
名前 | 型 | 説明 |
---|---|---|
color | String[][] | CSS 表記の色の 2 次元配列('#ffffff' や 'white' など)。null 値は色をリセットします。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setBorder(top, left, bottom, right, vertical, horizontal)
境界プロパティを設定します。有効な値は、true
(オン)、false
(オフ)、null
(変更なし)です。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const cell = sheet.getRange('B2');
// Sets borders on the top and bottom, but leaves the left and right unchanged
cell.setBorder(true, null, true, null, false, false);
パラメータ
名前 | 型 | 説明 |
---|---|---|
top | Boolean | 枠線の場合は true 、枠線なしの場合は false 、変更なしの場合は null です。 |
left | Boolean | 枠線の場合は true 、枠線なしの場合は false 、変更なしの場合は null です。 |
bottom | Boolean | 枠線の場合は true 、枠線なしの場合は false 、変更なしの場合は null です。 |
right | Boolean | 枠線の場合は true 、枠線なしの場合は false 、変更なしの場合は null です。 |
vertical | Boolean | true : 内部の縦線、false : なし、null : 変更なし。 |
horizontal | Boolean | true : 内部水平境界、false : なし、null : 変更なし。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setBorder(top, left, bottom, right, vertical, horizontal, color, style)
色やスタイルを指定して、枠線プロパティを設定します。有効な値は、true
(オン)、false
(オフ)、null
(変更なし)です。色には、CSS の色の表記('#ffffff'
や 'white'
など)を使用します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const cell = sheet.getRange('B2');
// Sets borders on the top and bottom, but leaves the left and right unchanged
// Also sets the color to "red", and the border to "DASHED".
cell.setBorder(
true,
null,
true,
null,
false,
false,
'red',
SpreadsheetApp.BorderStyle.DASHED,
);
パラメータ
名前 | 型 | 説明 |
---|---|---|
top | Boolean | 枠線の場合は true 、枠線なしの場合は false 、変更なしの場合は null です。 |
left | Boolean | 枠線の場合は true 、枠線なしの場合は false 、変更なしの場合は null です。 |
bottom | Boolean | 枠線の場合は true 、枠線なしの場合は false 、変更なしの場合は null です。 |
right | Boolean | 枠線の場合は true 、枠線なしの場合は false 、変更なしの場合は null です。 |
vertical | Boolean | true : 内部の縦線、false : なし、null : 変更なし。 |
horizontal | Boolean | true : 内部水平境界、false : なし、null : 変更なし。 |
color | String | CSS の色記法('#ffffff' や 'white' など)。デフォルトの色(黒)の場合は null です。 |
style | Border | 枠線のスタイル。デフォルトのスタイル(実線)の場合は null です。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setDataValidation(rule)
範囲内のすべてのセルに 1 つのデータ検証ルールを設定します。
// Set the data validation rule for cell A1 to require a value from B1:B10.
const cell = SpreadsheetApp.getActive().getRange('A1');
const range = SpreadsheetApp.getActive().getRange('B1:B10');
const rule =
SpreadsheetApp.newDataValidation().requireValueInRange(range).build();
cell.setDataValidation(rule);
パラメータ
名前 | 型 | 説明 |
---|---|---|
rule | Data | 設定するデータの入力規則、またはデータの入力規則を削除する null 。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setDataValidations(rules)
範囲内のすべてのセルにデータ入力規則を設定します。このメソッドは、行と列でインデックス付けされたデータ検証の 2 次元配列を受け取ります。配列のディメンションは範囲のディメンションに対応している必要があります。
// Set the data validation rules for Sheet1!A1:B5 to require a value from
// Sheet2!A1:A10.
const destinationRange =
SpreadsheetApp.getActive().getSheetByName('Sheet1').getRange('A1:B5');
const sourceRange =
SpreadsheetApp.getActive().getSheetByName('Sheet2').getRange('A1:A10');
const rule =
SpreadsheetApp.newDataValidation().requireValueInRange(sourceRange).build();
const rules = destinationRange.getDataValidations();
for (let i = 0; i < rules.length; i++) {
for (let j = 0; j < rules[i].length; j++) {
rules[i][j] = rule;
}
}
destinationRange.setDataValidations(rules);
パラメータ
名前 | 型 | 説明 |
---|---|---|
rules | Data | 設定するデータ検証ルールの 2 次元配列。null 値はデータ検証を削除します。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFontColor(color)
CSS 記法('#ffffff'
や 'white'
など)でフォントの色を設定します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const cell = sheet.getRange('B2');
cell.setFontColor('red');
パラメータ
名前 | 型 | 説明 |
---|---|---|
color | String | CSS 表記のフォント色('#ffffff' や 'white' など)。null 値は色をリセットします。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFontColorObject(color)
指定した範囲のフォントの色を設定します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const color = SpreadsheetApp.newColor()
.setThemeColor(SpreadsheetApp.ThemeColorType.TEXT)
.build();
const cell = sheet.getRange('B2');
cell.setFontColor(color);
パラメータ
名前 | 型 | 説明 |
---|---|---|
color | Color | 設定するフォント色。null 値は色をリセットします。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFontColorObjects(colors)
フォントの色の長方形のグリッドを設定します(この範囲のサイズと一致している必要があります)。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const colorAccent1 = SpreadsheetApp.newColor()
.setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT1)
.build();
const colorAccent2 = SpreadsheetApp.newColor()
.setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT2)
.build();
const colorAccent3 = SpreadsheetApp.newColor()
.setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT3)
.build();
const colorAccent4 = SpreadsheetApp.newColor()
.setThemeColor(SpreadsheetApp.ThemeColorType.ACCENT4)
.build();
const colors = [
[colorAccent1, colorAccent2],
[colorAccent3, colorAccent4],
];
const cell = sheet.getRange('B5:C6');
cell.setFontColorObjects(colors);
パラメータ
名前 | 型 | 説明 |
---|---|---|
colors | Color[][] | 色の 2 次元配列。null 値はフォントの色をリセットします。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFontColors(colors)
フォントの色の長方形のグリッドを設定します(この範囲のディメンションと一致している必要があります)。色は CSS 記法('#ffffff'
や 'white'
など)で指定します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const colors = [
['red', 'white', 'blue'],
['#FF0000', '#FFFFFF', '#0000FF'], // These are the hex equivalents
];
const cell = sheet.getRange('B5:D6');
cell.setFontColors(colors);
パラメータ
名前 | 型 | 説明 |
---|---|---|
colors | Object[][] | CSS 表記の色の 2 次元配列('#ffffff' や 'white' など)。null 値は色をリセットします。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFontFamilies(fontFamilies)
フォント ファミリーの長方形のグリッドを設定します(この範囲のサイズと一致している必要があります)。フォント ファミリーの例としては、「Arial」や「Helvetica」などがあります。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const fonts = [
['Arial', 'Helvetica', 'Verdana'],
['Courier New', 'Arial', 'Helvetica'],
];
const cell = sheet.getRange('B2:D3');
cell.setFontFamilies(fonts);
パラメータ
名前 | 型 | 説明 |
---|---|---|
font | Object[][] | フォント ファミリーの 2 次元配列。null 値はフォント ファミリーをリセットします。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFontFamily(fontFamily)
フォント ファミリー(「Arial」や「Helvetica」など)を設定します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const cell = sheet.getRange('B2');
cell.setFontFamily('Helvetica');
パラメータ
名前 | 型 | 説明 |
---|---|---|
font | String | 設定するフォント ファミリー。null 値はフォント ファミリーをリセットします。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFontLine(fontLine)
指定した範囲のフォント線のスタイルを設定します('underline'
、'line-through'
、'none'
)。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const cell = sheet.getRange('B2');
cell.setFontLine('line-through');
パラメータ
名前 | 型 | 説明 |
---|---|---|
font | String | フォント線のスタイル('underline' 、'line-through' 、'none' )。null 値はフォント線のスタイルをリセットします。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFontLines(fontLines)
線スタイルの長方形のグリッドを設定します(この範囲のディメンションと一致している必要があります)。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
// The size of the two-dimensional array must match the size of the range.
const fontLines = [['underline', 'line-through', 'none']];
const range = sheet.getRange('B2:D2');
range.setFontLines(fontLines);
パラメータ
名前 | 型 | 説明 |
---|---|---|
font | Object[][] | フォント線のスタイル('underline' 、'line-through' 、'none' )の 2 次元配列。null 値はフォント線のスタイルをリセットします。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFontSize(size)
フォントサイズを設定します。サイズは、使用するポイントサイズです。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const cell = sheet.getRange('B2');
cell.setFontSize(20);
パラメータ
名前 | 型 | 説明 |
---|---|---|
size | Integer | フォントサイズ(ポイント単位)。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFontSizes(sizes)
フォントサイズの長方形のグリッドを設定します(この範囲のディメンションと一致している必要があります)。サイズはポイント単位です。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
// The size of the two-dimensional array must match the size of the range.
const fontSizes = [[16, 20, 24]];
const range = sheet.getRange('B2:D2');
range.setFontSizes(fontSizes);
パラメータ
名前 | 型 | 説明 |
---|---|---|
sizes | Object[][] | サイズの 2 次元配列。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFontStyle(fontStyle)
指定した範囲のフォント スタイルを設定します('italic'
または 'normal'
)。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const cell = sheet.getRange('B2');
cell.setFontStyle('italic');
パラメータ
名前 | 型 | 説明 |
---|---|---|
font | String | フォント スタイル('italic' または 'normal' )。null 値はフォント スタイルをリセットします。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFontStyles(fontStyles)
フォント スタイルの長方形のグリッドを設定します(この範囲のディメンションと一致している必要があります)。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
// The size of the two-dimensional array must match the size of the range.
const fontStyles = [['italic', 'normal']];
const range = sheet.getRange('B2:C2');
range.setFontStyles(fontStyles);
パラメータ
名前 | 型 | 説明 |
---|---|---|
font | Object[][] | フォント スタイルの 2 次元配列('italic' または 'normal' )。null 値はフォント スタイルをリセットします。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFontWeight(fontWeight)
指定した範囲のフォントウェイトを設定します(通常/太字)。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const cell = sheet.getRange('B2');
cell.setFontWeight('bold');
パラメータ
名前 | 型 | 説明 |
---|---|---|
font | String | フォントウェイト('bold' または 'normal' )。null 値はフォントウェイトをリセットします。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFontWeights(fontWeights)
フォントウェイトの長方形のグリッドを設定します(この範囲のサイズと一致している必要があります)。フォント ウェイトの例は「太字」です。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
// The size of the two-dimensional array must match the size of the range.
const fontStyles = [['bold', 'bold', 'normal']];
const range = sheet.getRange('B2:D2');
range.setFontWeights(fontStyles);
パラメータ
名前 | 型 | 説明 |
---|---|---|
font | Object[][] | フォントの太さの 2 次元配列('bold' または 'normal' )。null 値はフォントの太さをリセットします。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFormula(formula)
この範囲の数式が更新されます。指定された数式は A1 表記にする必要があります。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const cell = sheet.getRange('B5');
cell.setFormula('=SUM(B3:B4)');
パラメータ
名前 | 型 | 説明 |
---|---|---|
formula | String | セルに設定する数式を表す文字列。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFormulaR1C1(formula)
この範囲の数式が更新されます。指定する数式は R1C1 表記にする必要があります。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const cell = sheet.getRange('B5');
// This sets the formula to be the sum of the 3 rows above B5
cell.setFormulaR1C1('=SUM(R[-3]C[0]:R[-1]C[0])');
パラメータ
名前 | 型 | 説明 |
---|---|---|
formula | String | 文字列数式。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFormulas(formulas)
数式の長方形のグリッドを設定します(この範囲のサイズと一致している必要があります)。指定する数式は A1 表記にする必要があります。このメソッドは、行と列でインデックス付けされた数式の 2 次元配列を受け取ります。配列のディメンションは範囲のディメンションに対応している必要があります。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
// This sets the formulas to be a row of sums, followed by a row of averages
// right below. The size of the two-dimensional array must match the size of the
// range.
const formulas = [
['=SUM(B2:B4)', '=SUM(C2:C4)', '=SUM(D2:D4)'],
['=AVERAGE(B2:B4)', '=AVERAGE(C2:C4)', '=AVERAGE(D2:D4)'],
];
const cell = sheet.getRange('B5:D6');
cell.setFormulas(formulas);
パラメータ
名前 | 型 | 説明 |
---|---|---|
formulas | String[][] | 数式の 2 次元文字列配列。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setFormulasR1C1(formulas)
数式の長方形のグリッドを設定します(この範囲のサイズと一致している必要があります)。指定する数式は R1C1 表記にする必要があります。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
// This creates formulas for a row of sums, followed by a row of averages.
const sumOfRowsAbove = '=SUM(R[-3]C[0]:R[-1]C[0])';
const averageOfRowsAbove = '=AVERAGE(R[-4]C[0]:R[-2]C[0])';
// The size of the two-dimensional array must match the size of the range.
const formulas = [
[sumOfRowsAbove, sumOfRowsAbove, sumOfRowsAbove],
[averageOfRowsAbove, averageOfRowsAbove, averageOfRowsAbove],
];
const cell = sheet.getRange('B5:D6');
// This sets the formula to be the sum of the 3 rows above B5.
cell.setFormulasR1C1(formulas);
パラメータ
名前 | 型 | 説明 |
---|---|---|
formulas | String[][] | R1C1 形式の数式の 2 次元配列。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setHorizontalAlignment(alignment)
指定した範囲の水平方向(左から右)の配置を設定します(左揃え/中央揃え/右揃え)。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const cell = sheet.getRange('B2');
cell.setHorizontalAlignment('center');
パラメータ
名前 | 型 | 説明 |
---|---|---|
alignment | String | 配置('left' 、'center' 、'normal' )。null 値は配置をリセットします。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setHorizontalAlignments(alignments)
水平方向の配置の長方形のグリッドを設定します。set
をご覧ください。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
// The size of the two-dimensional array must match the size of the range.
const horizontalAlignments = [['left', 'right', 'center']];
const range = sheet.getRange('B2:D2');
range.setHorizontalAlignments(horizontalAlignments);
パラメータ
名前 | 型 | 説明 |
---|---|---|
alignments | Object[][] | 'left' 、'center' 、'normal' のいずれかの配置の 2 次元配列。null 値は配置をリセットします。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
関連情報
setNote(note)
メモを指定された値に設定します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const cell = sheet.getRange('B2');
cell.setNote('This is a note');
パラメータ
名前 | 型 | 説明 |
---|---|---|
note | String | 範囲に設定するメモ値。null 値を指定すると、メモが削除されます。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setNotes(notes)
メモの長方形のグリッドを設定します(この範囲のサイズと一致している必要があります)。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
// The size of the two-dimensional array must match the size of the range.
const notes = [
['it goes', 'like this', 'the fourth, the fifth'],
['the minor fall', 'and the', 'major lift'],
];
const cell = sheet.getRange('B2:D3');
cell.setNotes(notes);
パラメータ
名前 | 型 | 説明 |
---|---|---|
notes | Object[][] | メモの 2 次元配列。null 値はメモを削除します。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
関連情報
setNumberFormat(numberFormat)
数値または日付の形式を指定された書式文字列に設定します。使用可能な形式パターンについては、Sheets API のドキュメントをご覧ください。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const cell = sheet.getRange('B2');
// Always show 3 decimal points
cell.setNumberFormat('0.000');
パラメータ
名前 | 型 | 説明 |
---|---|---|
number | String | 数値形式の文字列。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setNumberFormats(numberFormats)
数値または日付形式の長方形のグリッドを設定します(この範囲のディメンションと一致する必要があります)。値は、 Sheets API のドキュメントで説明されている形式パターン文字列です。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
// The size of the two-dimensional array must match the size of the range.
const formats = [['0.000', '0,000,000', '$0.00']];
const range = sheet.getRange('B2:D2');
range.setNumberFormats(formats);
パラメータ
名前 | 型 | 説明 |
---|---|---|
number | Object[][] | 数値形式の 2 次元配列。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setRichTextValue(value)
範囲内のセルにリッチテキスト値を設定します。
// Sets all cells in range B2:D4 to have the text "Hello world", with "Hello"
// bolded.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B2:D4');
const bold = SpreadsheetApp.newTextStyle().setBold(true).build();
const richText = SpreadsheetApp.newRichTextValue()
.setText('Hello world')
.setTextStyle(0, 5, bold)
.build();
range.setRichTextValue(richText);
パラメータ
名前 | 型 | 説明 |
---|---|---|
value | Rich | 目的のリッチテキスト値。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setRichTextValues(values)
リッチテキスト値の長方形のグリッドを設定します。
// Sets the cells in range A1:A2 to have Rich Text values.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('A1:A2');
const bold = SpreadsheetApp.newTextStyle().setBold(true).build();
const italic = SpreadsheetApp.newTextStyle().setItalic(true).build();
const richTextA1 = SpreadsheetApp.newRichTextValue()
.setText('This cell is bold')
.setTextStyle(bold)
.build();
const richTextA2 = SpreadsheetApp.newRichTextValue()
.setText('bold words, italic words')
.setTextStyle(0, 11, bold)
.setTextStyle(12, 24, italic)
.build();
range.setRichTextValues([[richTextA1], [richTextA2]]);
パラメータ
名前 | 型 | 説明 |
---|---|---|
values | Rich | 目的のリッチテキスト値。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setShowHyperlink(showHyperlink)
範囲にハイパーリンクを表示するかどうかを設定します。
// Opens the spreadsheet file by its URL. If you created your script from within
// a Google Sheets file, you can useSpreadsheetApp.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 cell A30 and sets its hyperlink value.
const range = sheet.getRange('A30');
range.setValue('https://www.example.com');
// Sets cell A30 to show hyperlinks.
range.setShowHyperlink(true);
パラメータ
名前 | 型 | 説明 |
---|---|---|
show | Boolean | ハイパーリンクを表示するかどうか。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setTextDirection(direction)
範囲内のセルの文章方向を設定します。指定された方向が null
の場合、方向が推論されて設定されます。
// Sets right-to-left text direction for the range.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B5:C6');
range.setTextDirection(SpreadsheetApp.TextDirection.RIGHT_TO_LEFT);
パラメータ
名前 | 型 | 説明 |
---|---|---|
direction | Text | 目的のテキストの向き。null の場合、設定前に向きが推測されます。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setTextDirections(directions)
文章方向の長方形のグリッドを設定します。指定された方向が null
の場合、方向が推論されて設定されます。
// Copies all of the text directions from range A1:B2 over to range C5:D6.
const sheet = SpreadsheetApp.getActiveSheet();
const range1 = sheet.getRange('A1:B2');
const range2 = sheet.getRange('C5:D6');
range2.setTextRotations(range1.getTextDirections());
パラメータ
名前 | 型 | 説明 |
---|---|---|
directions | Text | 目的のテキストの向き。指定された向きが null の場合、設定前に推測されます。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setTextRotation(degrees)
範囲内のセルのテキストの回転設定を設定します。入力は、標準のテキストの向きと目的の向きの間の角度に対応します。0 を入力すると、テキストが標準の向きに設定されます。
左から右の文章方向では、正の角度は反時計回り、右から左の文章方向では時計回りになります。
// Sets all cell's in range B2:D4 to have text rotated up 45 degrees.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B2:D4');
range.setTextRotation(45);
パラメータ
名前 | 型 | 説明 |
---|---|---|
degrees | Integer | 標準の向きと目的の向きとの間の角度。左から右のテキストの場合、正の角度は反時計回りになります。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setTextRotation(rotation)
範囲内のセルのテキストの回転設定を設定します。
// Sets all cell's in range B2:D4 to have the same text rotation settings as
// cell A1.
const sheet = SpreadsheetApp.getActiveSheet();
const rotation = sheet.getRange('A1').getTextRotation();
sheet.getRange('B2:D4').setTextRotation(rotation);
パラメータ
名前 | 型 | 説明 |
---|---|---|
rotation | Text | テキストの回転設定。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setTextRotations(rotations)
テキストの回転の長方形グリッドを設定します。
// Copies all of the text rotations from range A1:B2 over to range C5:D6.
const sheet = SpreadsheetApp.getActiveSheet();
const range1 = sheet.getRange('A1:B2');
const range2 = sheet.getRange('C5:D6');
range2.setTextRotations(range1.getTextRotations());
パラメータ
名前 | 型 | 説明 |
---|---|---|
rotations | Text | テキストの回転設定。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setTextStyle(style)
範囲内のセルのテキスト スタイルを設定します。
// Sets the cells in range C5:D6 to have underlined size 15 font.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('C5:D6');
const style =
SpreadsheetApp.newTextStyle().setFontSize(15).setUnderline(true).build();
range.setTextStyle(style);
パラメータ
名前 | 型 | 説明 |
---|---|---|
style | Text | 目的のテキスト スタイル。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setTextStyles(styles)
テキスト スタイルの長方形のグリッドを設定します。
// Sets text styles for cells in range A1:B2
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('A1:B2');
const bold = SpreadsheetApp.newTextStyle().setBold(true).build();
const otherStyle = SpreadsheetApp.newTextStyle()
.setBold(true)
.setUnderline(true)
.setItalic(true)
.setForegroundColor('#335522')
.setFontSize(44)
.build();
range.setTextStyles([
[bold, otherStyle],
[otherStyle, bold],
]);
パラメータ
名前 | 型 | 説明 |
---|---|---|
styles | Text | 目的のテキスト スタイル。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setValue(value)
範囲の値を設定します。値は、数値、文字列、ブール値、日付のいずれかです。'='
で始まる場合は、数式として解釈されます。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const cell = sheet.getRange('B2');
cell.setValue(100);
パラメータ
名前 | 型 | 説明 |
---|---|---|
value | Object | 範囲の値。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setValues(values)
値の長方形のグリッドを設定します(この範囲のディメンションと一致している必要があります)。値が =
で始まる場合、数式として解釈されます。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
// The size of the two-dimensional array must match the size of the range.
const values = [['2.000', '1,000,000', '$2.99']];
const range = sheet.getRange('B2:D2');
range.setValues(values);
パラメータ
名前 | 型 | 説明 |
---|---|---|
values | Object[][] | 値の 2 次元配列。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setVerticalAlignment(alignment)
指定した範囲の垂直(上から下)の配置を設定します(上部/中央/下部)。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const cell = sheet.getRange('B2');
cell.setVerticalAlignment('middle');
パラメータ
名前 | 型 | 説明 |
---|---|---|
alignment | String | 配置('top' 、'middle' 、'bottom' )。null 値は配置をリセットします。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setVerticalAlignments(alignments)
垂直方向に配置された長方形のグリッドを設定します(この範囲のサイズと一致している必要があります)。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
// The size of the two-dimensional array must match the size of the range.
const alignments = [['top', 'middle', 'bottom']];
const range = sheet.getRange('B2:D2');
range.setVerticalAlignments(alignments);
パラメータ
名前 | 型 | 説明 |
---|---|---|
alignments | Object[][] | 'top' 、'middle' 、'bottom' のいずれかの配置の 2 次元配列。null 値は配置をリセットします。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
関連情報
setVerticalText(isVertical)
範囲内のセルのテキストを積み重ねるかどうかを設定します。テキストが縦方向に積み重ねられている場合、テキストの回転角度の設定は無視されます。
// Sets all cell's in range B2:D4 to have vertically stacked text.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B2:D4');
range.setVerticalText(true);
パラメータ
名前 | 型 | 説明 |
---|---|---|
is | Boolean | テキストを重ねるかどうか。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setWrap(isWrapEnabled)
指定した範囲のセル折り返しを設定します。
折り返しが有効になっているセル(デフォルト)は、コンテンツ全体が表示されるようにサイズが変更されます。折り返しが無効になっているセルは、サイズ変更や複数行への分割を行わずに、セル内にできるだけ多く表示されます。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const cell = sheet.getRange('B2');
cell.setWrap(true);
パラメータ
名前 | 型 | 説明 |
---|---|---|
is | Boolean | テキストを折り返すかどうか。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setWrapStrategies(strategies)
折り返し戦略の長方形のグリッドを設定します。
// Copies all of the wrap strategies from range A1:B2 over to range C5:D6.
const sheet = SpreadsheetApp.getActiveSheet();
const range1 = sheet.getRange('A1:B2');
const range2 = sheet.getRange('C5:D6');
range2.setWrapStrategies(range1.getWrapStrategies());
パラメータ
名前 | 型 | 説明 |
---|---|---|
strategies | Wrap | 目的の折り返し戦略。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setWrapStrategy(strategy)
範囲内のセルのテキストの折り返し方法を設定します。
// Sets all cells in range B2:D4 to use the clip wrap strategy.
const sheet = SpreadsheetApp.getActiveSheet();
const range = sheet.getRange('B2:D4');
range.setWrapStrategy(SpreadsheetApp.WrapStrategy.CLIP);
パラメータ
名前 | 型 | 説明 |
---|---|---|
strategy | Wrap | 目的の折り返し戦略。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
setWraps(isWrapEnabled)
折り返しポリシーの長方形のグリッドを設定します(この範囲のサイズと一致している必要があります)。折り返しが有効になっているセル(デフォルト)は、コンテンツ全体が表示されるようにサイズが変更されます。折り返しが無効になっているセルは、サイズ変更や複数行への分割を行わずに、セル内にできるだけ多く表示されます。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
// The size of the two-dimensional array must match the size of the range.
const wraps = [[true, true, false]];
const range = sheet.getRange('B2:D2');
range.setWraps(wraps);
パラメータ
名前 | 型 | 説明 |
---|---|---|
is | Object[][] | セル内のテキストを折り返すかどうかを決定する折り返し変数の 2 次元配列。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
関連情報
shiftColumnGroupDepth(delta)
範囲の列グループ化の階層を指定された量だけ変更します。
これにより、範囲と交差するグループが作成、変更、削除されます。正の差分の場合は、グループが作成または変更されます。負の差分の場合は、グループが破棄または変更されます。
グループの深さを 0 未満または 8 より大きくした場合、この設定は適用されません。
column group control position
が BEFORE
の場合、最初の行の深さをシフトしようとするとエラーがスローされます。
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getActiveRange();
// The column grouping depth is increased by 1.
range.shiftColumnGroupDepth(1);
// The column grouping depth is decreased by 1.
range.shiftColumnGroupDepth(-1);
パラメータ
名前 | 型 | 説明 |
---|---|---|
delta | Integer | この範囲の列グループの階層を変更する量。 |
戻る
Range
- チェーン用のこの範囲。
例外
Error
- コントロールの位置が Group
の場合に、最初の列の深さをシフトしようとした場合
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
shiftRowGroupDepth(delta)
範囲の行グループ化の階層を指定された量だけ変更します。
これにより、範囲と交差するグループが作成、変更、削除されます。正の差分の場合は、グループが作成または変更されます。負の差分の場合は、グループが破棄または変更されます。
グループの深さを 0 未満または 8 より大きくした場合、この設定は適用されません。
row group control position
が BEFORE
の場合、最初の行の深さをシフトしようとするとエラーがスローされます。
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getActiveRange();
// The row grouping depth is increased by 1.
range.shiftRowGroupDepth(1);
// The row grouping depth is decreased by 1.
range.shiftRowGroupDepth(-1);
パラメータ
名前 | 型 | 説明 |
---|---|---|
delta | Integer | この範囲の行グループの階層を変更する量。 |
戻る
Range
- チェーン用のこの範囲。
例外
Error
- コントロールの位置が Group
の場合に、最初の行の深さをシフトしようとした場合
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
sort(sortSpecObj)
指定された範囲内のセルを、指定された列と順序で並べ替えます。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('A1:C7');
// Sorts by the values in the first column (A)
range.sort(1);
// Sorts by the values in the second column (B)
range.sort(2);
// Sorts descending by column B
range.sort({column: 2, ascending: false});
// Sorts descending by column B, then ascending by column A
// Note the use of an array
range.sort([
{column: 2, ascending: false},
{column: 1, ascending: true},
]);
// For rows that are sorted in ascending order, the "ascending" parameter is
// optional, and just an integer with the column can be used instead. Note that
// in general, keeping the sort specification consistent results in more
// readable code. You can express the earlier sort as:
range.sort([{column: 2, ascending: false}, 1]);
// Alternatively, if you want all columns to be in ascending order, you can use
// the following (this makes column 2 ascending)
range.sort([2, 1]);
// ... which is equivalent to
range.sort([
{column: 2, ascending: true},
{column: 1, ascending: true},
]);
パラメータ
名前 | 型 | 説明 |
---|---|---|
sort | Object | 並べ替えの基準となる列。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
splitTextToColumns()
自動検出された区切り文字に基づいて、テキストの列を複数の列に分割します。
// A1:A3 has the following values:
// A B C
// 1 |one,one,one | | |
// 2 |two,two,two | | |
// 3 |three,three,three| | |
const range = SpreadsheetApp.getActiveSheet().getRange('A1:A3');
range.splitTextToColumns();
// Result after splitting the text to columns:
// A B C
// 1 |one |one |one |
// 2 |two |two |two |
// 3 |three |three |three |
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
splitTextToColumns(delimiter)
指定した文字列をカスタム区切り文字として使用して、テキストの列を複数の列に分割します。
// A1:A3 has the following values:
// A B C
// 1 |one#one#one | | |
// 2 |two#two#two | | |
// 3 |three#three#three| | |
const range = SpreadsheetApp.getActiveSheet().getRange('A1:A3');
range.splitTextToColumns('#');
// Result after splitting the text to columns:
// A B C
// 1 |one |one |one |
// 2 |two |two |two |
// 3 |three |three |three |
パラメータ
名前 | 型 | 説明 |
---|---|---|
delimiter | String | 分割するカスタムの区切り文字。 |
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
splitTextToColumns(delimiter)
指定された区切り文字に基づいて、テキストの列を複数の列に分割します。
// A1:A3 has the following values:
// A B C
// 1 |one;one;one | | |
// 2 |two;two;two | | |
// 3 |three;three;three| | |
const range = SpreadsheetApp.getActiveSheet().getRange('A1:A3');
range.splitTextToColumns(SpreadsheetApp.TextToColumnsDelimiter.SEMICOLON);
// Result after splitting the text to columns:
// A B C
// 1 |one |one |one |
// 2 |two |two |two |
// 3 |three |three |three |
パラメータ
名前 | 型 | 説明 |
---|---|---|
delimiter | Text | 分割するプリセットの区切り文字。 |
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
trimWhitespace()
この範囲内のすべてのセルの空白文字(スペース、タブ、改行など)を削除します。各セルのテキストの先頭と末尾からすべての空白を削除し、残りの空白文字の連続部分を 1 つのスペースに縮小します。
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
const range = sheet.getRange('A1:A4');
range.activate();
range.setValues([
' preceding space',
'following space ',
'two middle spaces',
' =SUM(1,2)',
]);
range.trimWhitespace();
const values = range.getValues();
// Values are ['preceding space', 'following space', 'two middle spaces',
// '=SUM(1,2)']
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
uncheck()
範囲内のチェックボックスの状態を「オフ」に変更します。現在、オンまたはオフの値が設定されていない範囲内のセルは無視されます。
// Changes the state of cells which currently contain either the checked or
// unchecked value configured in the range A1:B10 to 'unchecked'.
const range = SpreadsheetApp.getActive().getRange('A1:B10');
range.uncheck();
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
サポート終了のメソッド
getFontColor()
getFontColor()
非推奨。get
に置き換え
範囲の左上にあるセルのフォント色を CSS 表記('#ffffff'
や 'white'
など)で返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
Logger.log(range.getFontColor());
戻る
String
- CSS 記法のフォント色('#ffffff'
や 'white'
など)。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
getFontColors()
getFontColors()
非推奨。get
に置き換え
範囲内のセルのフォント色を CSS 表記('#ffffff'
や 'white'
など)で返します。
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheets()[0];
const range = sheet.getRange('B2:D4');
const results = range.getFontColors();
for (const i in results) {
for (const j in results[i]) {
Logger.log(results[i][j]);
}
}
戻る
String[][]
- 範囲内のセルに関連付けられたフォント色の 2 次元配列。
承認
このメソッドを使用するスクリプトには、次のスコープの 1 つ以上による承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets