フィルタに条件を追加する手順は次のとおりです。
SpreadsheetApp.newFilterCriteria()
を使用して条件ビルダーを作成します。- このクラスのメソッドを使用して、設定をビルダーに追加します。
build()
を使って、指定した設定を使って条件を作成します。
一般的な用途
シート上の値を非表示にする
次のサンプルでは、シートの既存のフィルタを取得し、「hello」または「world」を含む列 C のセルを非表示にする条件を追加しています。このサンプルの条件は、Grid
シート(デフォルトのシートタイプ)のフィルタでのみ使用できます。
let ss = SpreadsheetApp.getActiveSheet(); let filter = ss.getFilter(); let criteria = SpreadsheetApp.newFilterCriteria() .setHiddenValues(["hello", "world"]) .build(); filter.setColumnFilterCriteria(3, criteria);
空でないセルのみを表示
次のサンプルでは、データベースに接続されているシートDataSource
シートにフィルタを追加します。このシートには、空ではない [Category] 列のセルのみを表示する条件を設定します。// Gets the sheet named "Connected sheet," which is connected to a database. let sheet = SpreadsheetApp.getActiveSpreadsheet() .getSheetByName("Connected sheet") .asDataSourceSheet(); // Creates criteria that only shows non-empty cells. let criteria = SpreadsheetApp.newFilterCriteria() .whenCellNotEmpty() .build(); // Applies the criteria to the column named "Category." sheet.addFilter("Category", criteria);
Methods
詳細なドキュメント
build()
条件作成ツールに追加した設定を使ってフィルタ条件を作成します。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); let filter = ss.getFilter(); let criteria = SpreadsheetApp.newFilterCriteria() // Creates a criteria builder. .whenCellNotEmpty() // Adds settings to the builder. .build(); // Assembles the criteria. filter.setColumnFilterCriteria(2, criteria);
リターン
FilterCriteria
- フィルタ条件を表します。
copy()
このフィルタ条件をコピーして、別のフィルタに適用できる条件ビルダーを作成します。
この方法は、どのタイプのフィルタでも使用できます。シートフィルタを使用している場合、 条件を別の列にコピーできます。
let ss = SpreadsheetApp.getActiveSheet(); let filter = ss.getFilter(); // Makes a copy of the filter criteria applied to column C. let criteria = filter.getColumnFilterCriteria(3).copy().build(); // Applies the copied criteria to column B. The copied criteria overwrites any existing // criteria on column B. filter.setColumnFilterCriteria(2, criteria);
リターン
FilterCriteriaBuilder
- このフィルタ条件に基づくフィルタ条件ビルダー。
getCriteriaType()
条件のブール値型を返します(例: CELL_EMPTY
)。ブール値条件のタイプについては、BooleanCriteria
列挙型をご覧ください。
多くの場合、この方法では、既存の条件を置き換えることなく、ブール条件条件をフィルタに追加します。
- 条件の引数を取得するには、
getCriteriaValues()
を使用します。 - 条件タイプと条件値を使用して、フィルタ条件を作成または変更する方法については、
withCriteria(criteria, args)
をご覧ください。
この方法は、どのタイプのフィルタにも使用できます。フィルタ条件がブール条件でない場合は、null
を返します。
let ss = SpreadsheetApp.getActiveSheet(); // Gets the filter on the active sheet. let filter = ss.getFilter(); // Gets the criteria type and returns a string representing the criteria type object. let criteriaType = filter.getColumnFilterCriteria(2) .getCriteriaType() .toString(); // Logs the criteria type. console.log(criteriaType);
リターン
BooleanCriteria
- ブール条件のタイプ。条件がブール条件でない場合は null
。
getCriteriaValues()
ブール値の条件に対応する引数の配列を返します。一部のブール値の条件タイプは引数がなく、空の配列を返します(例: CELL_NOT_EMPTY
)。
多くの場合、この方法では、既存の条件を置き換えることなく、ブール条件条件をフィルタに追加します。
- ブール値の条件タイプを取得するには、
getCriteriaType()
を使用します。 - 条件タイプと条件値を使用してフィルタ条件を作成または変更する方法については、
withCriteria(criteria, args)
をご覧ください。この方法は、どの種類のフィルタにも使用できます。
let ss = SpreadsheetApp.getActiveSheet(); let filter = ss.getFilter(); // Gets the values of the boolean criteria and logs them. For example, if the boolean // condition is whenNumberGreaterThan(10), then the logged value is 10. let criteriaValues = filter.getColumnFilterCriteria(2).getCriteriaValues(); console.log(criteriaValues);
リターン
Object[]
- ブール値の条件タイプに適した引数の配列。引数の数とその型は、FilterCriteriaBuilder
クラスの対応するwhen...()
メソッドと一致します。
getHiddenValues()
フィルタで非表示になっている値を返します。
この条件は、デフォルトのシートタイプである Grid
シートのフィルタとともに使用します。
他のタイプのフィルタに対してこのメソッドを呼び出すと、null
が返されます。
let ss = SpreadsheetApp.getActiveSheet(); let range = ss.getRange("A1:C20"); let filter = range.getFilter(); // Gets the filter criteria applied to column B, then gets the hidden values. let filterCriteria = filter.getColumnFilterCriteria(2).getHiddenValues(); // Logs the hidden values. console.log(filterCriteria);
リターン
String[]
- フィルタで非表示になる値の配列。
getVisibleBackgroundColor()
フィルタ条件に使用される背景色を返します。この背景色のセルは引き続き表示されます。
この条件は、デフォルトのシートタイプである Grid
シートのフィルタとともに使用します。
他のタイプのフィルタに対してこのメソッドを呼び出すと、null
が返されます。
let ss = SpreadsheetApp.getActiveSheet(); let range = ss.getRange("A1:C20"); // Logs the background color that column B is filtered by as a hexadecimal string. let filter = range.getFilter(); let color = filter.getColumnFilterCriteria(2) .getVisibleBackgroundColor() .asRgbColor() .asHexString(); console.log(color);
リターン
Color
- フィルタ条件に使用される背景色。
getVisibleForegroundColor()
フィルタ条件として使用する前景の色を返します。このフォアグラウンドの色のセルは引き続き表示されます。
この条件は、デフォルトのシートタイプである Grid
シートのフィルタとともに使用します。
他のタイプのフィルタに対してこのメソッドを呼び出すと、null
が返されます。
let ss = SpreadsheetApp.getActiveSheet(); let range = ss.getRange("A1:C20"); // Logs the foreground color that column B is filtered by as a hexadecimal string. let filter = range.getFilter(); let color = filter.getColumnFilterCriteria(2) .getVisibleForegroundColor() .asRgbColor() .asHexString(); console.log(color);
リターン
Color
- フィルタ条件として使用する前景の色。
getVisibleValues()
ピボット テーブルのフィルタが表示する値を返します。
この条件は、データベースに接続されていないピボット テーブルのフィルタにのみ適用されます。 他のタイプのフィルタの場合は、空の配列を返します。
let ss = SpreadsheetApp.getActiveSheet(); // Gets the first pivot table on the sheet, then gets the visible values of its first filter. pivotTable = ss.getPivotTables()[0]; pivotFilterValues = pivotTable.getFilters()[0].getFilterCriteria().getVisibleValues(); // Logs the visible values. console.log(pivotFilterValues);
リターン
String[]
- ピボット テーブルのフィルタによって表示される値の配列。
setHiddenValues(values)
非表示にする値を設定します。表示または非表示の既存の値をクリアします。
この条件は、デフォルトのシートタイプである Grid
シートのフィルタにのみ使用できます。
// Gets the existing filter on the range. const ss = SpreadsheetApp.getActiveSheet(); let range = ss.getRange("A1:C20"); let filter = range.getFilter(); // Sets the values to hide and applies the criteria to column C. let criteria = SpreadsheetApp.newFilterCriteria() .setHiddenValues(["Hello", "World"]) .build(); filter.setColumnFilterCriteria(3, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
values | String[] | 非表示にする値のリスト。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
setVisibleBackgroundColor(visibleBackgroundColor)
フィルタ条件として使用する背景色を設定します。この背景色のセルは引き続き表示されます。背景色フィルタ条件を設定すると、このビルダーから現在のカラーフィルタ条件が削除されます。
この条件は、デフォルトのシートタイプである Grid
シートのフィルタにのみ使用できます。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); let filter = ss.getFilter(); // Creates criteria that filters by background color and sets it to column B. let color = SpreadsheetApp.newColor().setRgbColor("#185ABC").build(); let criteria = SpreadsheetApp.newFilterCriteria() .setVisibleBackgroundColor(color) .build(); filter.setColumnFilterCriteria(2, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
visibleBackgroundColor | Color | 設定する背景色。色は RGB スタイルにする必要があります。このメソッドはテーマカラーをサポートしていません。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
setVisibleForegroundColor(visibleForegroundColor)
フィルタ条件として使用する前景の色を設定します。このフォアグラウンドの色のセルは引き続き表示されます。フォアグラウンド カラーフィルタ条件を設定すると、このビルダーから現在のカラーフィルタ条件が削除されます。
この条件は、デフォルトのシートタイプである Grid
シートのフィルタにのみ使用できます。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); let filter = ss.getFilter(); // Creates criteria that filters by foreground color and sets it to column B. let color = SpreadsheetApp.newColor().setRgbColor("#185ABC").build(); let criteria = SpreadsheetApp.newFilterCriteria() .setVisibleForegroundColor(color) .build(); filter.setColumnFilterCriteria(2, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
visibleForegroundColor | Color | 設定する前景の色。色は RGB スタイルにする必要があります。このメソッドはテーマカラーをサポートしていません。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
setVisibleValues(values)
ピボット テーブルに表示する値を設定します。表示または非表示の既存の値をクリアします。
この条件は、データベースに接続されていないピボット テーブルのフィルタにのみ使用できます。
// Gets the active sheet. const ss = SpreadsheetApp.getActiveSheet(); // Gets the first pivot table on the sheet and adds a filter to it that // sets the visible values to "Northeast" and "Southwest." let pivotTable = ss.getPivotTables()[0]; let criteria = SpreadsheetApp.newFilterCriteria() .setVisibleValues(["Northeast", "Southwest"]) .build(); pivotTable.addFilter(2, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
values | String[] | 表示する値のリスト。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenCellEmpty()
空のセルを表示するフィルタ条件を設定します。
この条件は、どのタイプのフィルタでも使用できます。
// Gets the existing filter on the range. const ss = SpreadsheetApp.getActiveSheet(); let range = ss.getRange("A1:C20"); let filter = range.getFilter(); // Sets criteria to column B that only shows empty cells. let criteria = SpreadsheetApp.newFilterCriteria() .whenCellEmpty() .build(); filter.setColumnFilterCriteria(2, criteria);
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenCellNotEmpty()
空でないセルを表示するフィルタ条件を設定します。
この条件は、どのタイプのフィルタでも使用できます。
// Gets the existing filter on the range. const ss = SpreadsheetApp.getActiveSheet(); let range = ss.getRange("A1:C20"); let filter = range.getFilter(); // Sets criteria to column B that only shows cells that aren't empty. let criteria = SpreadsheetApp.newFilterCriteria() .whenCellNotEmpty() .build(); filter.setColumnFilterCriteria(2, criteria);
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenDateAfter(date)
指定した日付より後の日付のセルを表示するフィルタ条件を設定します。
この条件は、どのタイプのフィルタでも使用できます。データベースに接続されているデータにこの条件を使用する場合、フィルタ条件となる列のデータ型は日付にする必要があります。データがデータベースに接続されていない場合は、フィルタする列のデータ型を日付にする必要はありませんが、日付でない場合、予期しない結果が生じる可能性があります。
// Gets the existing filter on the range. const ss = SpreadsheetApp.getActiveSheet(); let range = ss.getRange("A1:C20"); let filter = range.getFilter(); // Creates criteria that only shows cells with dates after June 1, 2022 // and sets it to column A. let date = new Date("June 1, 2022"); let criteria = SpreadsheetApp.newFilterCriteria() .whenDateAfter(date) .build(); filter.setColumnFilterCriteria(1, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
date | Date | 非表示にする最新の日付。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenDateAfter(date)
指定した相対日付より後の日付のセルを表示するフィルタ条件を設定します。相対日付オプションを表示するには、列挙型 RelativeDate
をご覧ください。
この条件は、どのタイプのフィルタでも使用できます。データベースに接続されているデータにこの条件を使用する場合、フィルタ条件となる列のデータ型は日付にする必要があります。データがデータベースに接続されていない場合は、フィルタする列のデータ型を日付にする必要はありませんが、日付でない場合、予期しない結果が生じる可能性があります。
// Gets the existing filter on the range. const ss = SpreadsheetApp.getActiveSheet(); let range = ss.getRange("A1:C20"); let filter = range.getFilter(); // Creates criteria that only shows cells with dates after today's date // and sets it to column A. let date = SpreadsheetApp.RelativeDate.TODAY; let criteria = SpreadsheetApp.newFilterCriteria() .whenDateAfter(date) .build(); filter.setColumnFilterCriteria(1, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
date | RelativeDate | 最新の相対日付。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenDateBefore(date)
指定した日付より前の日付のセルを表示するフィルタ条件を設定します。
この条件は、どのタイプのフィルタでも使用できます。データベースに接続されているデータにこの条件を使用する場合、フィルタ条件となる列のデータ型は日付にする必要があります。データがデータベースに接続されていない場合は、フィルタする列のデータ型を日付にする必要はありませんが、日付でない場合、予期しない結果が生じる可能性があります。
// Gets the existing filter on the range. const ss = SpreadsheetApp.getActiveSheet(); let range = ss.getRange("A1:C20"); let filter = range.getFilter(); // Creates criteria that only shows cells with dates before June 1, 2022 // and sets it to column A. let date = new Date("June 1, 2022"); let criteria = SpreadsheetApp.newFilterCriteria() .whenDateBefore(date) .build(); filter.setColumnFilterCriteria(1, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
date | Date | 非表示にする最も早い日付。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenDateBefore(date)
指定した相対日付より前の日付のセルを表示するフィルタ条件を設定します。相対日付オプションについては、列挙型 RelativeDate
をご覧ください。
この条件は、どのタイプのフィルタでも使用できます。データベースに接続されているデータにこの条件を使用する場合、フィルタ条件となる列のデータ型は日付にする必要があります。データがデータベースに接続されていない場合は、フィルタする列のデータ型を日付にする必要はありませんが、日付でない場合、予期しない結果が生じる可能性があります。
// Gets the existing filter on the range. const ss = SpreadsheetApp.getActiveSheet(); let range = ss.getRange("A1:C20"); let filter = range.getFilter(); // Creates criteria that only shows cells with dates before today's date // and sets it to column A. let date = SpreadsheetApp.RelativeDate.TODAY; let criteria = SpreadsheetApp.newFilterCriteria() .whenDateBefore(date) .build(); filter.setColumnFilterCriteria(1, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
date | RelativeDate | 非表示にする最も早い相対日付。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenDateEqualTo(date)
指定した日付と等しい日付のセルを表示するフィルタ条件を設定します。
この条件は、どのタイプのフィルタでも使用できます。データベースに接続されているデータにこの条件を使用する場合、フィルタ条件となる列のデータ型は日付にする必要があります。データがデータベースに接続されていない場合は、フィルタする列のデータ型を日付にする必要はありませんが、日付でない場合、予期しない結果が生じる可能性があります。
// Gets the existing filter on the range. const ss = SpreadsheetApp.getActiveSheet(); let range = ss.getRange("A1:C20"); let filter = range.getFilter(); // Creates criteria that only shows cells with dates equal to June 1, 2022 // and sets it to column A. let date = new Date("June 1, 2022"); let criteria = SpreadsheetApp.newFilterCriteria() .whenDateEqualTo(date) .build(); filter.setColumnFilterCriteria(1, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
date | Date | セル値が一致する必要がある日付。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenDateEqualTo(date)
指定した相対日付と等しい日付のセルを表示するフィルタ条件を設定します。
相対日付オプションについては、列挙型 RelativeDate
をご覧ください。
この条件は、どのタイプのフィルタでも使用できます。データベースに接続されているデータにこの条件を使用する場合、フィルタ条件となる列のデータ型は日付にする必要があります。データがデータベースに接続されていない場合は、フィルタする列のデータ型を日付にする必要はありませんが、日付でない場合、予期しない結果が生じる可能性があります。
// Gets the existing filter on the range. const ss = SpreadsheetApp.getActiveSheet(); let range = ss.getRange("A1:C20"); let filter = range.getFilter(); // Creates criteria that only shows cells with dates that fall within the past month // and sets it to column A. let date = SpreadsheetApp.RelativeDate.PAST_MONTH; let criteria = SpreadsheetApp.newFilterCriteria() .whenDateEqualTo(date) .build(); filter.setColumnFilterCriteria(1, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
date | RelativeDate | セル値が一致する必要がある相対日付。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenDateEqualToAny(dates)
指定した日付のいずれかと等しい日付のセルを表示するフィルタ条件を設定します。
この条件は、データベースに接続されているデータでのみ使用できます。たとえば、DataSource
シート、データベースに接続されているシート、DataSource
シートから作成されたピボット テーブル DataSourcePivotTable
に対するフィルタで、この条件を使用します。
// Gets the sheet that's connected to a database. let ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Data Sheet"); let dataSheet = ss.asDataSourceSheet(); // Adds criteria to the "date" column that shows cells with any of the below dates. let date1 = new Date("June 1, 2022"); let date2 = new Date("June 2, 2022"); let date3 = new Date("June 3, 2022"); let criteria = SpreadsheetApp.newFilterCriteria() .whenDateEqualToAny([date1, date2, date3]) .build(); dataSheet.addFilter("date", criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
dates | Date[] | 表示する日付。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenDateNotEqualTo(date)
指定した日付と一致しないセルを表示するフィルタ条件を設定します。
この条件は、データベースに接続されているデータでのみ使用できます。たとえば、DataSource
シート、データベースに接続されているシート、DataSource
シートから作成されたピボット テーブル DataSourcePivotTable
に対するフィルタで、この条件を使用します。
フィルタする列のデータ型は日付にする必要があります。
// Gets a pivot table that's connected to a database. let ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Pivot Table Sheet"); let dataPivotTable = ss.getDataSourcePivotTables()[0]; // Creates criteria that only shows cells that don't equal June 16, 2022 // and sets it to the "date" column. let date = new Date("June 16, 2022"); let criteria = SpreadsheetApp.newFilterCriteria() .whenDateNotEqualTo(date) .build(); dataPivotTable.addFilter("date", criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
date | Date | 非表示にする日付。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenDateNotEqualToAny(dates)
指定した日付と一致しない日付のセルを表示するフィルタ条件を設定します。
この条件は、データベースに接続されているデータでのみ使用できます。たとえば、DataSource
シート、データベースに接続されているシート、DataSource
シートから作成されたピボット テーブル DataSourcePivotTable
に対するフィルタで、この条件を使用します。
// Gets the sheet that's connected to a database. let ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Data Sheet"); let dataSheet = ss.asDataSourceSheet(); // Adds criteria to the "date" column that hides cells with any of the below dates. let date1 = new Date("June 1, 2022"); let date2 = new Date("June 2, 2022"); let date3 = new Date("June 3, 2022"); let criteria = SpreadsheetApp.newFilterCriteria() .whenDateNotEqualToAny([date1, date2, date3]) .build(); dataSheet.addFilter("date", criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
dates | Date[] | 非表示にする日付。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenFormulaSatisfied(formula)
指定された数式(=B:B<C:C
など)で true
と評価されるセルを表示するフィルタ条件を設定します。
この条件は、データベースに接続されていないデータをフィルタする場合にのみ使用できます。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); let filter = ss.getFilter(); // Creates criteria that shows the rows where the value in column B is less than the value in // column C and sets it to column A. let formula = "=B:B<C:C"; let criteria = SpreadsheetApp.newFilterCriteria() .whenFormulaSatisfied(formula) .build(); filter.setColumnFilterCriteria(1, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
formula | String | 入力が有効な場合に true と評価されるカスタム数式。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenNumberBetween(start, end)
指定した 2 つの数値の間またはいずれか 1 つの数値を持つセルを表示するフィルタ条件を設定します。
この条件は、どのタイプのフィルタでも使用できます。データベースに接続されているデータにこの条件を使用する場合は、フィルタする列のデータ型を数値にする必要があります。データがデータベースに接続されていない場合は、フィルタする列のデータ型を数値にする必要はありませんが、数値でない場合、予期しない結果が生じる可能性があります。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); let filter = ss.getFilter(); // Creates criteria that only shows cells with numbers that fall between 1-25, inclusively, // and sets it to column A. let criteria = SpreadsheetApp.newFilterCriteria() .whenNumberBetween(1, 25) .build(); filter.setColumnFilterCriteria(1, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
start | Number | 表示する最小の数値。 |
end | Number | 表示する最大数。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenNumberEqualTo(number)
指定した数値と等しい数値のセルを表示するフィルタ条件を設定します。
この条件は、どのタイプのフィルタでも使用できます。データベースに接続されているデータにこの条件を使用する場合は、フィルタする列のデータ型を数値にする必要があります。データがデータベースに接続されていない場合は、フィルタする列のデータ型を数値にする必要はありませんが、数値でない場合、予期しない結果が生じる可能性があります。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); let filter = ss.getFilter(); // Creates criteria that only shows cells that are equal to 25 and sets it to column B. let criteria = SpreadsheetApp.newFilterCriteria() .whenNumberEqualTo(25) .build(); filter.setColumnFilterCriteria(2, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
number | Number | 表示する番号。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenNumberEqualToAny(numbers)
指定した数値と等しい数値のセルを表示するフィルタ条件を設定します。
この条件は、データベースに接続されているデータでのみ使用できます。たとえば、DataSource
シート、データベースに接続されているシート、DataSource
シートから作成されたピボット テーブル DataSourcePivotTable
に対するフィルタで、この条件を使用します。
// Gets the sheet that's connected to a database. let ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Data Sheet"); let dataSheet = ss.asDataSourceSheet(); // Adds criteria to the "amount" column that only shows cells with the number 10, 20, or 30. let criteria = SpreadsheetApp.newFilterCriteria() .whenNumberEqualToAny([10,20,30]) .build(); dataSheet.addFilter("amount", criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
numbers | Number[] | 表示する数値。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenNumberGreaterThan(number)
指定した数値より大きい数値のセルを表示するフィルタ条件を設定します
この条件は、どのタイプのフィルタでも使用できます。データベースに接続されているデータにこの条件を使用する場合は、フィルタする列のデータ型を数値にする必要があります。データがデータベースに接続されていない場合は、フィルタする列のデータ型を数値にする必要はありませんが、数値でない場合、予期しない結果が生じる可能性があります。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); let filter = ss.getFilter(); // Creates criteria that shows cells greater than 10 and sets it to column B. let criteria = SpreadsheetApp.newFilterCriteria() .whenNumberGreaterThan(10) .build(); filter.setColumnFilterCriteria(2, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
number | Number | 非表示にする最大の数値。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenNumberGreaterThanOrEqualTo(number)
指定した数値以上の数値を持つセルを表示するフィルタ条件を設定します。
この条件は、どのタイプのフィルタでも使用できます。データベースに接続されているデータにこの条件を使用する場合は、フィルタする列のデータ型を数値にする必要があります。データがデータベースに接続されていない場合は、フィルタする列のデータ型を数値にする必要はありませんが、数値でない場合、予期しない結果が生じる可能性があります。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); let filter = ss.getFilter(); // Creates criteria that shows cells greater than or equal to 10 and sets it to column B. let criteria = SpreadsheetApp.newFilterCriteria() .whenNumberGreaterThanOrEqualTo(10) .build(); filter.setColumnFilterCriteria(2, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
number | Number | 表示する最小の数値。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenNumberLessThan(number)
指定した数値より小さい数値のセルを表示するフィルタ条件を設定します。
この条件は、どのタイプのフィルタでも使用できます。データベースに接続されているデータにこの条件を使用する場合は、フィルタする列のデータ型を数値にする必要があります。データがデータベースに接続されていない場合は、フィルタする列のデータ型を数値にする必要はありませんが、数値でない場合、予期しない結果が生じる可能性があります。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); let filter = ss.getFilter(); // Creates criteria that shows cells less than 10 and sets it to column B. let criteria = SpreadsheetApp.newFilterCriteria() .whenNumberLessThan(10) .build(); filter.setColumnFilterCriteria(2, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
number | Number | 非表示にする最小の数値。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenNumberLessThanOrEqualTo(number)
指定した数値以下の数値を持つセルを表示するフィルタ条件を設定します。
この条件は、どのタイプのフィルタでも使用できます。データベースに接続されているデータにこの条件を使用する場合は、フィルタする列のデータ型を数値にする必要があります。データがデータベースに接続されていない場合は、フィルタする列のデータ型を数値にする必要はありませんが、数値でない場合、予期しない結果が生じる可能性があります。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); let filter = ss.getFilter(); // Creates criteria that shows cells less than or equal to 10 and sets it to column B. let criteria = SpreadsheetApp.newFilterCriteria() .whenNumberLessThanOrEqualTo(10) .build(); filter.setColumnFilterCriteria(2, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
number | Number | 表示する最大数。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenNumberNotBetween(start, end)
ある数値を含むセルが、指定した 2 つの数値の範囲内および範囲に収まらないセルを表示するフィルタ条件を設定します。
この条件は、どのタイプのフィルタでも使用できます。データベースに接続されているデータにこの条件を使用する場合は、フィルタする列のデータ型を数値にする必要があります。データがデータベースに接続されていない場合は、フィルタする列のデータ型を数値にする必要はありませんが、数値でない場合、予期しない結果が生じる可能性があります。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); let filter = ss.getFilter(); // Creates criteria that hides cells with numbers that fall between 1-25, inclusively, // and sets it to column B. let criteria = SpreadsheetApp.newFilterCriteria() .whenNumberNotBetween(1, 25) .build(); filter.setColumnFilterCriteria(2, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
start | Number | 値が最小の非表示。 |
end | Number | 非表示にする最大の数値。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenNumberNotEqualTo(number)
指定した数値と等しくない数値のセルを表示するフィルタ条件を設定します。
この条件は、どのタイプのフィルタでも使用できます。データベースに接続されているデータにこの条件を使用する場合は、フィルタする列のデータ型を数値にする必要があります。データがデータベースに接続されていない場合は、フィルタする列のデータ型を数値にする必要はありませんが、数値でない場合、予期しない結果が生じる可能性があります。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); let filter = ss.getFilter(); // Creates criteria that hides cells that are equal to 25 and sets it to column B. let criteria = SpreadsheetApp.newFilterCriteria() .whenNumberNotEqualTo(25) .build(); filter.setColumnFilterCriteria(2, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
number | Number | 非表示にする番号です。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenNumberNotEqualToAny(numbers)
指定した数値と等しくない数値のセルを表示するフィルタ条件を設定します。
この条件は、データベースに接続されているデータでのみ使用できます。たとえば、DataSource
シート、データベースに接続されているシート、DataSource
シートから作成されたピボット テーブル DataSourcePivotTable
に対するフィルタで、この条件を使用します。
// Gets the sheet that's connected to a database. let ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Data Sheet"); let dataSheet = ss.asDataSourceSheet(); // Adds criteria to the "amount" column that hides cells with the number 10, 20, or 30. let criteria = SpreadsheetApp.newFilterCriteria() .whenNumberNotEqualToAny([10,20,30]) .build(); dataSheet.addFilter("amount", criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
numbers | Number[] | 非表示にする数字。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenTextContains(text)
指定したテキストを含むテキストを含むセルを表示するフィルタ条件を設定します。テキストの大文字と小文字は区別されません。
この条件は、どのタイプのフィルタでも使用できます。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); let filter = ss.getFilter(); // Creates criteria that shows cells that contain "Northwest" and sets it to column B. let criteria = SpreadsheetApp.newFilterCriteria() .whenTextContains("Northwest") .build(); filter.setColumnFilterCriteria(2, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
text | String | セルに含める必要があるテキスト。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenTextDoesNotContain(text)
指定したテキストを含まないテキストを含むセルを表示するフィルタ条件を設定します。テキストでは大文字と小文字は区別されません。
この条件は、どのタイプのフィルタでも使用できます。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); let filter = ss.getFilter(); // Creates criteria that hides cells that contain "Northwest" and sets it to column B. let criteria = SpreadsheetApp.newFilterCriteria() .whenTextDoesNotContain("Northwest") .build(); filter.setColumnFilterCriteria(2, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
text | String | セルに含めてはならないテキスト。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenTextEndsWith(text)
指定したテキストで終わるテキストを含むセルを表示するフィルタ条件を設定します。テキストの大文字と小文字は区別されません。
この条件は、どのタイプのフィルタでも使用できます。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); let filter = ss.getFilter(); // Creates criteria that shows cells with text that ends with "est" and sets it to column B. let criteria = SpreadsheetApp.newFilterCriteria() .whenTextEndsWith("est") .build(); filter.setColumnFilterCriteria(2, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
text | String | セルのテキストの末尾に含める必要があるテキスト。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenTextEqualTo(text)
指定したテキストに等しいテキストを含むセルを表示するフィルタ条件を設定します。テキストの大文字と小文字は区別されません。
この条件は、どのタイプのフィルタでも使用できます。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); let filter = ss.getFilter(); // Creates criteria that shows cells with text that equals "hello" and sets it to column B. let criteria = SpreadsheetApp.newFilterCriteria() .whenTextEqualTo("hello") .build(); filter.setColumnFilterCriteria(2, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
text | String | セルのテキストが等しいテキスト。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenTextEqualToAny(texts)
指定したテキスト値のいずれかに等しいテキストを含むセルを表示するフィルタ条件を設定します。テキストの大文字と小文字は区別されません。
この条件は、データベースに接続されているデータでのみ使用できます。たとえば、DataSource
シート、データベースに接続されているシート、DataSource
シートから作成されたピボット テーブル DataSourcePivotTable
に対するフィルタで、この条件を使用します。
// Gets the sheet that's connected to a database. let ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Data Sheet"); let dataSheet = ss.asDataSourceSheet(); // Adds criteria to the "category" column that shows cells with the text "tech" or "business." let criteria = SpreadsheetApp.newFilterCriteria() .whenTextEqualToAny(["tech","business"]) .build(); dataSheet.addFilter("category", criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
texts | String[] | セルが等しくなる必要があるテキスト値です。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenTextNotEqualTo(text)
指定したテキストと一致しないテキストを含むセルを表示するフィルタ条件を設定します。テキストでは大文字と小文字は区別されません。
この条件は、データベースに接続されているデータでのみ使用できます。たとえば、DataSource
シート、データベースに接続されているシート、DataSource
シートから作成されたピボット テーブル DataSourcePivotTable
に対するフィルタで、この条件を使用します。
// Gets the sheet that's connected to a database. let ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Data Sheet"); let dataSheet = ss.asDataSourceSheet(); // Adds criteria to the "category" column that hides cells with text equal to "tech." let criteria = SpreadsheetApp.newFilterCriteria() .whenTextNotEqualTo("tech") .build(); dataSheet.addFilter("category", criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
text | String | セル内のテキストが等しくないテキスト。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenTextNotEqualToAny(texts)
指定した値と等しくないテキストを含むセルを表示するフィルタ条件を設定します。テキストの大文字と小文字は区別されません。
この条件は、データベースに接続されているデータでのみ使用できます。たとえば、DataSource
シート、データベースに接続されているシート、DataSource
シートから作成されたピボット テーブル DataSourcePivotTable
に対するフィルタで、この条件を使用します。
// Gets the sheet that's connected to a database. let ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Data Sheet"); let dataSheet = ss.asDataSourceSheet(); // Adds criteria to the "category" column that hides cells with the text "tech" or "business." let criteria = SpreadsheetApp.newFilterCriteria() .whenTextNotEqualToAny(["tech","business"]) .build(); dataSheet.addFilter("category", criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
texts | String[] | セルが等しくないテキスト値です。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
whenTextStartsWith(text)
指定したテキストで始まるテキストを含むセルを表示するフィルタ条件を設定します。テキストの大文字と小文字は区別されません。
この条件は、どのタイプのフィルタでも使用できます。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); let filter = ss.getFilter(); // Creates criteria that shows cells with text that starts with "pre" and sets it to column B. let criteria = SpreadsheetApp.newFilterCriteria() .whenTextStartsWith("pre") .build(); filter.setColumnFilterCriteria(2, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
text | String | セルのテキストの先頭に含める必要があるテキスト。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。
withCriteria(criteria, args)
フィルタ条件を、BooleanCriteria
値(CELL_EMPTY
や NUMBER_GREATER_THAN
など)で定義されたブール条件に設定します。既存の条件からブール条件をコピーするには、既存の条件で getCriteriaType()
と getCriteriaValues()
を使用して、このメソッドのパラメータを定義します。
この条件はどのタイプのフィルタでも使用できますが、一部の BooleanCriteria
はすべてのフィルタに適用されるわけではありません。
// Builds a filter criteria that is based on existing boolean conditions from another criteria. // Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); let filter = ss.getFilter(); // Gets the existing boolean conditions applied to Column B and adds criteria to column C that // has the same boolean conditions and additional criteria that hides the value, "Northwest." let filter = ss.getFilter(); let filterCriteria = filter.getColumnFilterCriteria(2); let criteria = SpreadsheetApp.newFilterCriteria() .withCriteria(filterCriteria.getCriteriaType(), filterCriteria.getCriteriaValues()) .setHiddenValues(["Northwest"]) .build(); filter.setColumnFilterCriteria(3, criteria);
パラメータ
名前 | 型 | 説明 |
---|---|---|
criteria | BooleanCriteria | ブール値条件のタイプ。 |
args | Object[] | 条件のタイプに適した引数の配列。引数の数とその型は、上記の対応する when...() メソッドと同じです。 |
リターン
FilterCriteriaBuilder
- チェーン用のこのビルダー。