スプレッドシートの範囲にアクセスして変更します。範囲は、シート内の単一のセルまたはシート内の隣接するセルのグループにすることができます。
メソッド
メソッド | 戻り値の型 | 概要 |
---|---|---|
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 | 範囲内のセルのリッチテキスト値を返します。 |
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 | border プロパティを設定します。 |
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 | 範囲内のチェックボックスの状態を「未チェック」に変更します。 |
詳細なドキュメント
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
- チェーン用のこの範囲。
activate As Current Cell()
指定したセルを 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
add Developer Metadata(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
add Developer Metadata(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
add Developer Metadata(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
add Developer Metadata(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
apply Column Banding()
範囲にデフォルトの列の縞模様のテーマを適用します。デフォルトでは、バンディングにはヘッダーの色が設定され、フッターの色は設定されません。
// 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
apply Column Banding(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
apply Column Banding(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
apply Row Banding()
範囲にデフォルトの行ストライプ テーマを適用します。デフォルトでは、バンディングにはヘッダーの色が設定され、フッターの色は設定されません。
// 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
apply Row Banding(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
apply Row Banding(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
auto Fill(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
auto Fill To Neighbor(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
break Apart()
範囲内の複数列のセルを個々のセルに分割します。
範囲でこの関数を呼び出すことは、範囲を選択して [表示形式] > [セルを結合] > [結合を解除] をクリックすることと同じです。
// 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
can Edit()
ユーザーが範囲内のすべてのセルを編集する権限を持っているかどうかを判断します。スプレッドシートのオーナーは、保護された範囲とシートを常に編集できます。
// 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
clear Content()
範囲の内容をクリアしますが、書式はそのまま残します。
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
clear Data Validations()
範囲のデータ入力規則をクリアします。
// 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
clear Format()
この範囲の書式設定をクリアします。
これにより、範囲内のセルまたはセルのテキスト形式がクリアされますが、数値形式のルールはリセットされません。
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
clear Note()
指定されたセル内のメモをクリアします。
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
collapse Groups()
範囲内に完全に含まれるすべてのグループを折りたたみます。範囲内に完全に収まるグループがない場合は、範囲内に部分的に収まる最も深い展開グループが折りたたまれます。
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
copy Format To Range(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
関連情報
copy Format To Range(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
copy To(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
copy To(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
copy To(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
copy Values To Range(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
関連情報
copy Values To Range(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
create Data Source Pivot Table(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
create Data Source Table(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
create Developer Metadata Finder()
この範囲内のデベロッパー メタデータを検索するための 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
- この範囲のスコープでメタデータを検索するデベロッパー メタデータ ファインダ。
create Filter()
フィルタを作成し、シートの指定された範囲に適用します。シートに作成できるフィルタは 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
create Pivot Table(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
create Text Finder(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
delete Cells(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
expand Groups()
この範囲と範囲またはコントロール トグルが交差する折りたたまれたグループを展開します。コントロールの切り替え位置は、設定に応じてグループの直前または直後にコントロールの切り替えが表示されるインデックスです。同じ場所に複数のグループがある場合は、最も浅いグループが展開されます。
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
get Background()
範囲の左上のセルの背景色を返します(例: '#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
get Background Object()
範囲の左上のセルの背景色を返します。
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
get Background Objects()
範囲内のセルの背景色を返します。
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
get Backgrounds()
範囲内のセルの背景色('#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
get Bandings()
この範囲内のセルに適用されているすべてのバンディングを返します。
// 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
get Cell(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
get Column()
この範囲の開始列の位置を返します。
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
get Data Region()
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
get Data Region(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
get Data Source Formula()
範囲内の最初のセルの 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
get Data Source Formulas()
範囲内のセルの 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
get Data Source Pivot Tables()
範囲と交差するすべてのデータソース ピボット テーブルを取得します。
// 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
get Data Source Tables()
範囲と交差するすべてのデータソース テーブルを取得します。
// 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
get Data Source Url()
この範囲のデータの URL を返します。この URL は、グラフやクエリの作成に使用できます。
コード.gs
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(); }
piechart.html
<!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
- この範囲の URL。グラフなどの他の API に渡すことができるデータソースとして使用できます。
承認
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Data Table()
このオブジェクト内のデータを 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
- データがデータテーブルとして返されます。
get Data Table(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
get Data Validation()
範囲の左上のセルのデータ入力規則を返します。セルにデータ入力規則が設定されていない場合、このメソッドは 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
get Data Validations()
範囲内のすべてのセルのデータ入力規則を返します。特定のセルにデータ検証が設定されていない場合、このメソッドは配列内のそのセルの位置に対して 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
get Developer Metadata()
この範囲に関連付けられているデベロッパー メタデータを取得します。
// 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
get Display Value()
範囲の左上のセルの表示値を返します。値は 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
get Display Values()
この範囲の値の長方形のグリッドを返します。
表示された値の 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
get Filter()
この範囲が属するシートのフィルタを返します。シートにフィルタがない場合は 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
get Font Color Object()
範囲の左上隅にあるセルのフォントの色を返します。
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
get Font Color Objects()
範囲内のセルのフォントの色を返します。
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
get Font Families()
範囲内のセルのフォント ファミリーを返します。
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
get Font Family()
範囲の左上隅のセルのフォント ファミリーを返します。
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
get Font Line()
範囲の左上隅のセルの線のスタイル('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
get Font Lines()
範囲内のセルの線のスタイル('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
get Font Size()
範囲の左上隅のセルのフォントサイズをポイント サイズで返します。
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
get Font Sizes()
範囲内のセルのフォントサイズを返します。
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
get Font Style()
範囲の左上隅にあるセルのフォント スタイル('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
get Font Styles()
範囲内のセルのフォント スタイルを返します。
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
get Font Weight()
範囲の左上にあるセルのフォントの太さ(標準/太字)を返します。
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
get Font Weights()
範囲内のセルのフォントの太さを返します。
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
get Formula()
範囲の左上のセルの数式(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
get Formula R1C1()
指定されたセルの数式(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
get Formulas()
範囲内のセルの数式(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
get Formulas R1C1()
範囲内のセルの数式(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
get Grid Id()
範囲の親シートのグリッド 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
get Height()
範囲の高さを返します。
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
get Horizontal Alignment()
範囲の左上隅にあるセルのテキストの水平方向の配置(左/中央/右)を返します。
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
get Horizontal Alignments()
範囲内のセルの水平方向の配置を返します。
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
get Last Column()
終了列の位置を返します。
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
get Last Row()
終了行の位置を返します。
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
get Merged Ranges()
現在の範囲内に完全に含まれているか、現在の範囲内のセルを少なくとも 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()); }
戻る
get Next Data Cell(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
get Note()
指定された範囲に関連付けられたメモを返します。
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
get Notes()
範囲内のセルに関連付けられたメモを返します。
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
get Num Columns()
この範囲内の列数を返します。
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
get Num Rows()
この範囲内の行数を返します。
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
get Number Format()
指定された範囲の左上のセルの数値または日付の形式を取得します。返される形式パターンについては、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
get Number Formats()
範囲内のセルの数値形式または日付形式を返します。返される形式パターンについては、スプレッドシート 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
get Rich Text Value()
範囲の左上のセルのリッチテキスト値を返します。セルの値がテキストでない場合は 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
get Rich Text Values()
範囲内のセルのリッチテキスト値を返します。
// 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
get Row()
この範囲の行の位置を返します。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
get Row Index()
この範囲の行の位置を返します。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
関連情報
get Sheet()
この範囲が属するシートを返します。
// 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
get Text Direction()
範囲の左上のセルのテキストの方向を返します。セルのテキストの方向が自動検出で決定された場合は 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
get Text Directions()
範囲内のセルのテキストの方向を返します。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
get Text Rotation()
範囲の左上のセルのテキストの回転設定を返します。
// 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
get Text Rotations()
範囲内のセルのテキストの回転設定を返します。
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
get Text Style()
範囲の左上のセルのテキスト スタイルを返します。
// 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
get Text Styles()
範囲内のセルのテキスト スタイルを返します。
// 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
get Value()
範囲の左上のセルの値を返します。値は、セルの値に応じて 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
get Values()
この範囲の値の長方形のグリッドを返します。
行、列の順にインデックスが付けられた値の 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
値を含むセルが含まれている場合、get Values()
はウェブアプリにデータを返しません。代わりに、シートから取得したすべての値を、Number
、Boolean
、String
などのサポートされている JavaScript プリミティブに変換します。戻る
Object[][]
- 値の 2 次元配列。
承認
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
get Vertical Alignment()
範囲の左上隅にあるセルの垂直方向の配置(上/中央/下)を返します。
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
get Vertical Alignments()
範囲内のセルの垂直方向の配置を返します。
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
get Width()
範囲の幅を列数で返します。
// 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
get Wrap()
セル内のテキストが折り返されるかどうかを返します。より詳細なラップ戦略を取得するには、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
get Wrap Strategies()
範囲内のセルのテキスト折り返し戦略を返します。
// 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
get Wrap Strategy()
範囲の左上のセルのテキストの折り返し戦略を返します。
// 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
get Wraps()
セル内のテキストが折り返されるかどうかを返します。より詳細なラップ戦略を取得するには、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
insert Cells(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
insert Checkboxes()
範囲内の各セルにチェックボックスを挿入します。チェックボックスがオンの場合は 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
insert Checkboxes(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
insert Checkboxes(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
is Blank()
範囲が完全に空白の場合、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
is Checked()
範囲内のすべてのセルのチェックボックスの状態が「オン」かどうかを返します。一部のセルがオンで残りのセルがオフの場合、または一部のセルにチェックボックスのデータ検証がない場合は、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
is End Column Bounded()
範囲の末尾が特定の列にバインドされているかどうかを判断します。たとえば、範囲の末尾の列にバインドされている範囲 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
is End Row Bounded()
範囲の末尾が特定の行にバインドされているかどうかを判断します。たとえば、範囲の末尾の行にバインドされている範囲 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
is Part Of Merge()
現在の範囲のセルが結合されたセルと重複している場合、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
を返します。
is Start Column Bounded()
範囲の開始が特定の列にバインドされているかどうかを判断します。たとえば、範囲の先頭の列にバインドされている範囲 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
is Start Row Bounded()
範囲の開始が特定の行にバインドされているかどうかを判断します。たとえば、範囲の先頭の行にバインドされている範囲 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
merge Across()
範囲の列にまたがって範囲内のセルを結合します。
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
merge Vertically()
範囲内のセルを結合します。
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
move To(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
remove Checkboxes()
範囲からすべてのチェックボックスを削除します。各セルのデータ検証をクリアします。また、セルにオンまたはオフの値が含まれている場合は、その値もクリアします。
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
remove Duplicates()
この範囲内で、前の行の値と重複する値を含む行を削除します。行内の大文字、小文字、書式、数式などが異なる場合でも、値自体が同じであれば重複と見なされます。このメソッドは、ビューから非表示になっている重複する行(フィルタなどによる)も削除します。この範囲外のコンテンツは削除されません。
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
remove Duplicates(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
set Background(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
set Background Object(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
set Background Objects(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
set Background RGB(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
set Backgrounds(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
set Border(top, left, bottom, right, vertical, horizontal)
border プロパティを設定します。有効な値は 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
set Border(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
set Data Validation(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
set Data Validations(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
set Font Color(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
set Font Color Object(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
set Font Color Objects(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
set Font Colors(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
set Font Families(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
set Font Family(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
set Font Line(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
set Font Lines(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
set Font Size(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
set Font Sizes(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
set Font Style(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
set Font Styles(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
set Font Weight(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
set Font Weights(fontWeights)
フォントの太さの長方形グリッドを設定します(この範囲のディメンションと一致している必要があります)。フォントの太さの例は「bold」です。
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
set Formula(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
set Formula R1C1(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
set Formulas(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
set Formulas R1C1(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
set Horizontal Alignment(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
set Horizontal Alignments(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[][] | 配置の 2 次元配列。'left' 、'center' 、'normal' のいずれか。null 値は配置をリセットします。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
関連情報
set Note(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
set Notes(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
関連情報
set Number Format(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
set Number Formats(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
set Rich Text Value(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
set Rich Text Values(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
set Show Hyperlink(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
set Text Direction(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
set Text Directions(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
set Text Rotation(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
set Text Rotation(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
set Text Rotations(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
set Text Style(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
set Text Styles(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
set Value(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
set Values(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
set Vertical Alignment(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
set Vertical Alignments(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[][] | アライメントの 2 次元配列('top' 、'middle' 、'bottom' のいずれか)。null 値はアライメントをリセットします。 |
戻る
Range
- チェーン用のこの範囲。
承認
このメソッドを使用するスクリプトには、次の 1 つ以上のスコープによる承認が必要です。
-
https://www.googleapis.com/auth/spreadsheets.currentonly
-
https://www.googleapis.com/auth/spreadsheets
関連情報
set Vertical Text(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
set Wrap(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
set Wrap Strategies(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
set Wrap Strategy(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
set Wraps(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
関連情報
shift Column Group Depth(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
shift Row Group Depth(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
split Text To Columns()
テキストの列を、自動検出された区切り文字に基づいて複数の列に分割します。
// 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
split Text To Columns(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
split Text To Columns(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
trim Whitespace()
この範囲内のすべてのセルの空白文字(スペース、タブ、改行など)を削除します。各セルのテキストの先頭と末尾の空白をすべて削除し、残りの空白文字の連続を単一のスペースに縮小します。
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