篩選條件的建構工具。如要為篩選器新增條件,請按照下列步驟操作:
- 使用
Spreadsheet建立條件建構工具。App.newFilterCriteria() - 使用這個類別的方法,將設定新增至建構工具。
- 使用
build()依據您指定的設定組裝條件。
常見的使用方式
隱藏工作表中的值
下列範例會取得試算表的現有篩選器,並新增條件,隱藏 C 欄中含有「hello」或「world」的儲存格。本範例中的條件只能搭配Grid 工作表 (預設工作表類型) 的篩選器使用。const ss = SpreadsheetApp.getActiveSheet(); const filter = ss.getFilter(); const criteria = SpreadsheetApp.newFilterCriteria() .setHiddenValues(['hello', 'world']) .build(); filter.setColumnFilterCriteria(3, criteria);
只顯示非空白儲存格
下列範例會將篩選器新增至Data Source 試算表 (已連結至資料庫的試算表),並設定篩選條件,只顯示「類別」欄中不為空白的儲存格。// Gets the sheet named "Connected sheet," which is connected to a database. const sheet = SpreadsheetApp.getActiveSpreadsheet() .getSheetByName('Connected sheet') .asDataSourceSheet(); // Creates criteria that only shows non-empty cells. const criteria = SpreadsheetApp.newFilterCriteria().whenCellNotEmpty().build(); // Applies the criteria to the column named "Category." sheet.addFilter('Category', criteria);
方法
內容詳盡的說明文件
build()
使用您新增至條件建構工具的設定,組裝篩選條件。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); const filter = ss.getFilter(); const criteria = SpreadsheetApp .newFilterCriteria() // Creates a criteria builder. .whenCellNotEmpty() // Adds settings to the builder. .build(); // Assembles the criteria. filter.setColumnFilterCriteria(2, criteria);
回攻員
Filter:篩選條件的代表。
copy()
複製這個篩選條件,並建立可套用至其他篩選器的條件建構工具。
這個方法適用於任何類型的篩選器。如果使用工作表篩選器,您可以將條件複製到其他欄。
const ss = SpreadsheetApp.getActiveSheet(); const filter = ss.getFilter(); // Makes a copy of the filter criteria applied to column C. const 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);
回攻員
Filter:根據這個篩選條件建立篩選條件。
get Criteria Type()
傳回條件的布林值類型,例如 CELL_EMPTY。如要瞭解布林值條件類型,請參閱 Boolean 列舉。
使用者通常會採用這種方法,在篩選器中新增布林條件,而不取代現有條件。
- 如要取得條件的引數,請使用
get。Criteria Values() - 如要使用條件類型和條件值建立或修改篩選條件,請參閱
with。Criteria(criteria, args)
這個方法適用於任何類型的篩選器。如果篩選條件不是布林值條件,則會傳回 null。
const ss = SpreadsheetApp.getActiveSheet(); // Gets the filter on the active sheet. const filter = ss.getFilter(); // Gets the criteria type and returns a string representing the criteria type // object. const criteriaType = filter.getColumnFilterCriteria(2).getCriteriaType().toString(); // Logs the criteria type. console.log(criteriaType);
回攻員
Boolean:布林條件類型,或 null (如果條件不是布林條件)。
get Criteria Values()
傳回布林條件的引數陣列。部分布林值條件類型沒有引數,且會傳回空白陣列,例如 CELL_NOT_EMPTY。
使用者通常會採用這種方法,在篩選器中新增布林條件,而不取代現有條件。
- 如要取得布林條件類型,請使用
get。Criteria Type() - 如要使用條件類型和條件值建立或修改篩選條件,請參閱
with。Criteria(criteria, args) 這個方法適用於任何類型的篩選器。
const ss = SpreadsheetApp.getActiveSheet(); const 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. const criteriaValues = filter.getColumnFilterCriteria(2).getCriteriaValues(); console.log(criteriaValues);
回攻員
Object[]:適合布林值條件類型的引數陣列。引數數量和類型與Filter類別的對應Criteria Builder when...()方法相符。
get Hidden Values()
傳回篩選器隱藏的值。
在 Grid 工作表 (預設工作表類型) 中使用篩選器時,可套用這項條件。
如果您為其他類型的篩選器呼叫這個方法,系統會傳回 null。
const ss = SpreadsheetApp.getActiveSheet(); const range = ss.getRange('A1:C20'); const filter = range.getFilter(); // Gets the filter criteria applied to column B, then gets the hidden values. const filterCriteria = filter.getColumnFilterCriteria(2).getHiddenValues(); // Logs the hidden values. console.log(filterCriteria);
回攻員
String[]:篩選器隱藏的值陣列。
get Visible Background Color()
傳回用做篩選條件的背景顏色。背景顏色為此色的儲存格仍會顯示。
在 Grid 工作表 (預設工作表類型) 中使用篩選器時,可套用這項條件。
如果您為其他類型的篩選器呼叫這個方法,系統會傳回 null。
const ss = SpreadsheetApp.getActiveSheet(); const range = ss.getRange('A1:C20'); // Logs the background color that column B is filtered by as a hexadecimal // string. const filter = range.getFilter(); const color = filter.getColumnFilterCriteria(2) .getVisibleBackgroundColor() .asRgbColor() .asHexString(); console.log(color);
回攻員
Color|null:用做篩選條件的背景顏色。
get Visible Foreground Color()
傳回做為篩選條件的前景色。前景顏色為此的儲存格仍會顯示。
在 Grid 工作表 (預設工作表類型) 中使用篩選器時,可套用這項條件。
如果您為其他類型的篩選器呼叫這個方法,系統會傳回 null。
const ss = SpreadsheetApp.getActiveSheet(); const range = ss.getRange('A1:C20'); // Logs the foreground color that column B is filtered by as a hexadecimal // string. const filter = range.getFilter(); const color = filter.getColumnFilterCriteria(2) .getVisibleForegroundColor() .asRgbColor() .asHexString(); console.log(color);
回攻員
Color|null:做為篩選條件的前景色。
get Visible Values()
傳回資料透視表篩選器顯示的值。
這項條件僅適用於未連結資料庫的資料透視表篩選器。 如果是其他類型的篩選條件,則會傳回空陣列。
const ss = SpreadsheetApp.getActiveSheet(); // Gets the first pivot table on the sheet, then gets the visible values of its // first filter. const pivotTable = ss.getPivotTables()[0]; const pivotFilterValues = pivotTable.getFilters()[0].getFilterCriteria().getVisibleValues(); // Logs the visible values. console.log(pivotFilterValues);
回攻員
String[]:資料透視表篩選器顯示的值陣列。
set Hidden Values(values)
設定要隱藏的值。清除所有現有顯示或隱藏的值。
您只能在 Grid 工作表 (預設工作表類型) 上使用這項篩選條件。
// Gets the existing filter on the range. const ss = SpreadsheetApp.getActiveSheet(); const range = ss.getRange('A1:C20'); const filter = range.getFilter(); // Sets the values to hide and applies the criteria to column C. const criteria = SpreadsheetApp.newFilterCriteria() .setHiddenValues(['Hello', 'World']) .build(); filter.setColumnFilterCriteria(3, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
values | String[] | 要隱藏的值清單。 |
回攻員
Filter:用於串連的建構工具。
擲回
Error:如果任何值為 null。
set Visible Background Color(visibleBackgroundColor)
設定做為篩選條件的背景顏色。背景顏色為此色的儲存格仍會顯示。設定背景顏色篩選條件後,這個建構工具就會移除所有目前的顏色篩選條件。
您只能在 Grid 工作表 (預設工作表類型) 上使用這項篩選條件。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); const filter = ss.getFilter(); // Creates criteria that filters by background color and sets it to column B. const color = SpreadsheetApp.newColor().setRgbColor('#185ABC').build(); const criteria = SpreadsheetApp.newFilterCriteria().setVisibleBackgroundColor(color).build(); filter.setColumnFilterCriteria(2, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
visible | Color | 要設定的背景顏色。顏色必須是 RGB 樣式的顏色。這個方法不支援主題顏色。 |
回攻員
Filter:用於串連的建構工具。
set Visible Foreground Color(visibleForegroundColor)
設定做為篩選條件的前景顏色。前景顏色為此的儲存格仍會顯示。設定前景色彩篩選條件後,這個建構工具會移除所有目前的色彩篩選條件。
您只能在 Grid 工作表 (預設工作表類型) 上使用這項篩選條件。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); const filter = ss.getFilter(); // Creates criteria that filters by foreground color and sets it to column B. const color = SpreadsheetApp.newColor().setRgbColor('#185ABC').build(); const criteria = SpreadsheetApp.newFilterCriteria().setVisibleForegroundColor(color).build(); filter.setColumnFilterCriteria(2, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
visible | Color | 要設定的前景顏色。顏色必須是 RGB 樣式的顏色。這個方法不支援主題顏色。 |
回攻員
Filter:用於串連的建構工具。
set Visible Values(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." const pivotTable = ss.getPivotTables()[0]; const criteria = SpreadsheetApp.newFilterCriteria() .setVisibleValues(['Northeast', 'Southwest']) .build(); pivotTable.addFilter(2, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
values | String[] | 要顯示的值清單。 |
回攻員
Filter:用於串連的建構工具。
擲回
Error:如果任何值為 null。
when Cell Empty()
設定篩選條件,顯示空白儲存格。
您可以將這項條件與任何類型的篩選器搭配使用。
// Gets the existing filter on the range. const ss = SpreadsheetApp.getActiveSheet(); const range = ss.getRange('A1:C20'); const filter = range.getFilter(); // Sets criteria to column B that only shows empty cells. const criteria = SpreadsheetApp.newFilterCriteria().whenCellEmpty().build(); filter.setColumnFilterCriteria(2, criteria);
回攻員
Filter:用於串連的建構工具。
when Cell Not Empty()
設定篩選條件,顯示非空白的儲存格。
您可以將這項條件與任何類型的篩選器搭配使用。
// Gets the existing filter on the range. const ss = SpreadsheetApp.getActiveSheet(); const range = ss.getRange('A1:C20'); const filter = range.getFilter(); // Sets criteria to column B that only shows cells that aren't empty. const criteria = SpreadsheetApp.newFilterCriteria().whenCellNotEmpty().build(); filter.setColumnFilterCriteria(2, criteria);
回攻員
Filter:用於串連的建構工具。
when Date After(date)
設定篩選條件,顯示日期晚於指定日期的儲存格。
您可以將這項條件與任何類型的篩選器搭配使用。如果搭配與資料庫連結的資料使用這項條件,篩選依據的資料欄資料類型必須是日期。如果資料未連結至資料庫,篩選依據資料欄的資料類型就不一定要是日期,但如果不是,可能會得到非預期的結果。
// Gets the existing filter on the range. const ss = SpreadsheetApp.getActiveSheet(); const range = ss.getRange('A1:C20'); const filter = range.getFilter(); // Creates criteria that only shows cells with dates after June 1, 2022 // and sets it to column A. const date = new Date('June 1, 2022'); const criteria = SpreadsheetApp.newFilterCriteria().whenDateAfter(date).build(); filter.setColumnFilterCriteria(1, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
date | Date | 要隱藏的最新日期。 |
回攻員
Filter:用於串連的建構工具。
when Date After(date)
設定篩選條件,顯示日期晚於指定相對日期的儲存格。如要查看相對日期選項,請參閱「列舉 Relative」。
您可以將這項條件與任何類型的篩選器搭配使用。如果搭配與資料庫連結的資料使用這項條件,篩選依據的資料欄資料類型必須是日期。如果資料未連結至資料庫,篩選依據資料欄的資料類型就不一定要是日期,但如果不是,可能會得到非預期的結果。
// Gets the existing filter on the range. const ss = SpreadsheetApp.getActiveSheet(); const range = ss.getRange('A1:C20'); const filter = range.getFilter(); // Creates criteria that only shows cells with dates after today's date // and sets it to column A. const criteria = SpreadsheetApp.newFilterCriteria() .whenDateAfter(SpreadsheetApp.RelativeDate.TODAY) .build(); filter.setColumnFilterCriteria(1, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
date | Relative | 最新的相對日期。 |
回攻員
Filter:用於串連的建構工具。
when Date Before(date)
設定篩選條件,顯示日期早於指定日期的儲存格。
您可以將這項條件與任何類型的篩選器搭配使用。如果搭配與資料庫連結的資料使用這項條件,篩選依據的資料欄資料類型必須是日期。如果資料未連結至資料庫,篩選依據資料欄的資料類型就不一定要是日期,但如果不是,可能會得到非預期的結果。
// Gets the existing filter on the range. const ss = SpreadsheetApp.getActiveSheet(); const range = ss.getRange('A1:C20'); const filter = range.getFilter(); // Creates criteria that only shows cells with dates before June 1, 2022 // and sets it to column A. const date = new Date('June 1, 2022'); const criteria = SpreadsheetApp.newFilterCriteria().whenDateBefore(date).build(); filter.setColumnFilterCriteria(1, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
date | Date | 最早的隱藏日期。 |
回攻員
Filter:用於串連的建構工具。
when Date Before(date)
設定篩選條件,顯示日期早於指定相對日期的儲存格。
如要查看相對日期選項,請參閱 Enum Relative。
您可以將這項條件與任何類型的篩選器搭配使用。如果搭配與資料庫連結的資料使用這項條件,篩選依據的資料欄資料類型必須是日期。如果資料未連結至資料庫,篩選依據資料欄的資料類型就不一定要是日期,但如果不是,可能會得到非預期的結果。
// Gets the existing filter on the range. const ss = SpreadsheetApp.getActiveSheet(); const range = ss.getRange('A1:C20'); const filter = range.getFilter(); // Creates criteria that only shows cells with dates before today's date // and sets it to column A. const criteria = SpreadsheetApp.newFilterCriteria() .whenDateBefore(SpreadsheetApp.RelativeDate.TODAY) .build(); filter.setColumnFilterCriteria(1, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
date | Relative | 要隱藏的最早相對日期。 |
回攻員
Filter:用於串連的建構工具。
when Date Equal To(date)
設定篩選條件,顯示日期等於指定日期的儲存格。
您可以將這項條件與任何類型的篩選器搭配使用。如果搭配與資料庫連結的資料使用這項條件,篩選依據的資料欄資料類型必須是日期。如果資料未連結至資料庫,篩選依據資料欄的資料類型就不一定要是日期,但如果不是,可能會得到非預期的結果。
// Gets the existing filter on the range. const ss = SpreadsheetApp.getActiveSheet(); const range = ss.getRange('A1:C20'); const filter = range.getFilter(); // Creates criteria that only shows cells with dates equal to June 1, 2022 // and sets it to column A. const date = new Date('June 1, 2022'); const criteria = SpreadsheetApp.newFilterCriteria().whenDateEqualTo(date).build(); filter.setColumnFilterCriteria(1, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
date | Date | 儲存格值必須符合的日期。 |
回攻員
Filter:用於串連的建構工具。
when Date Equal To(date)
設定篩選條件,顯示日期等於指定相對日期的儲存格。
如要查看相對日期選項,請參閱 Enum Relative。
您可以將這項條件與任何類型的篩選器搭配使用。如果搭配與資料庫連結的資料使用這項條件,篩選依據的資料欄資料類型必須是日期。如果資料未連結至資料庫,篩選依據資料欄的資料類型就不一定要是日期,但如果不是,可能會得到非預期的結果。
// Gets the existing filter on the range. const ss = SpreadsheetApp.getActiveSheet(); const range = ss.getRange('A1:C20'); const filter = range.getFilter(); // Creates criteria that only shows cells with dates that fall within the past // month and sets it to column A. const criteria = SpreadsheetApp.newFilterCriteria() .whenDateEqualTo(SpreadsheetApp.RelativeDate.PAST_MONTH) .build(); filter.setColumnFilterCriteria(1, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
date | Relative | 儲存格值必須符合的相對日期。 |
回攻員
Filter:用於串連的建構工具。
when Date Equal To Any(dates)
設定篩選條件,顯示日期等於任何指定日期的儲存格。
您只能將這項條件套用至連結資料庫的資料。舉例來說,您可以在 Data 工作表、連結至資料庫的工作表,或從 Data 工作表建立的樞紐分析表 Data 中,使用這項條件搭配篩選器。
// Gets the sheet that's connected to a database. const ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Data Sheet'); const dataSheet = ss.asDataSourceSheet(); // Adds criteria to the "date" column that shows cells with any of the below // dates. const date1 = new Date('June 1, 2022'); const date2 = new Date('June 2, 2022'); const date3 = new Date('June 3, 2022'); const criteria = SpreadsheetApp.newFilterCriteria() .whenDateEqualToAny([date1, date2, date3]) .build(); dataSheet.addFilter('date', criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
dates | Date[] | 要顯示的日期。 |
回攻員
Filter:用於串連的建構工具。
when Date Not Equal To(date)
設定篩選條件,顯示不等於指定日期的儲存格。
您只能將這項條件套用至連結資料庫的資料。舉例來說,您可以在 Data 工作表、連結至資料庫的工作表,或從 Data 工作表建立的樞紐分析表 Data 中,使用這項條件搭配篩選器。
用來篩選的資料欄資料類型必須是日期。
// Gets a pivot table that's connected to a database. const ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Pivot Table Sheet'); const dataPivotTable = ss.getDataSourcePivotTables()[0]; // Creates criteria that only shows cells that don't equal June 16, 2022 // and sets it to the "date" column. const date = new Date('June 16, 2022'); const criteria = SpreadsheetApp.newFilterCriteria().whenDateNotEqualTo(date).build(); dataPivotTable.addFilter('date', criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
date | Date | 要隱藏的日期。 |
回攻員
Filter:用於串連的建構工具。
when Date Not Equal To Any(dates)
設定篩選條件,顯示日期與任何指定日期都不相等的儲存格。
您只能將這項條件套用至連結資料庫的資料。舉例來說,您可以在 Data 工作表、連結至資料庫的工作表,或從 Data 工作表建立的樞紐分析表 Data 中,使用這項條件搭配篩選器。
// Gets the sheet that's connected to a database. const ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Data Sheet'); const dataSheet = ss.asDataSourceSheet(); // Adds criteria to the "date" column that hides cells with any of the below // dates. const date1 = new Date('June 1, 2022'); const date2 = new Date('June 2, 2022'); const date3 = new Date('June 3, 2022'); const criteria = SpreadsheetApp.newFilterCriteria() .whenDateNotEqualToAny([date1, date2, date3]) .build(); dataSheet.addFilter('date', criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
dates | Date[] | 要隱藏的日期。 |
回攻員
Filter:用於串連的建構工具。
when Formula Satisfied(formula)
設定篩選條件,顯示含有指定公式 (例如 =B:B<C:C) 且評估結果為 true 的儲存格。
您只能使用這項條件,篩選未連結至資料庫的資料。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); const 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. const formula = '=B:B<C:C'; const criteria = SpreadsheetApp.newFilterCriteria().whenFormulaSatisfied(formula).build(); filter.setColumnFilterCriteria(1, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
formula | String | 如果輸入內容有效,自訂公式的評估結果為 true。 |
回攻員
Filter:用於串連的建構工具。
when Number Between(start, end)
設定篩選條件,顯示介於兩個指定數字之間或等於其中一個數字的儲存格。
您可以將這項條件與任何類型的篩選器搭配使用。如果搭配這個條件使用與資料庫連結的資料,篩選依據的資料欄資料類型必須為數字。如果資料未連結至資料庫,篩選依據資料欄的資料類型不一定要是數字,但如果不是,可能會得到非預期的結果。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); const filter = ss.getFilter(); // Creates criteria that only shows cells with numbers that fall between 1-25, // inclusively, and sets it to column A. const criteria = SpreadsheetApp.newFilterCriteria().whenNumberBetween(1, 25).build(); filter.setColumnFilterCriteria(1, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
start | Number | 要顯示的最低數字。 |
end | Number | 要顯示的最高數字。 |
回攻員
Filter:用於串連的建構工具。
when Number Equal To(number)
設定篩選條件,只顯示含有指定數字的儲存格。
您可以將這項條件與任何類型的篩選器搭配使用。如果搭配這個條件使用與資料庫連結的資料,篩選依據的資料欄資料類型必須為數字。如果資料未連結至資料庫,篩選依據資料欄的資料類型不一定要是數字,但如果不是,可能會得到非預期的結果。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); const filter = ss.getFilter(); // Creates criteria that only shows cells that are equal to 25 and sets it to // column B. const criteria = SpreadsheetApp.newFilterCriteria().whenNumberEqualTo(25).build(); filter.setColumnFilterCriteria(2, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
number | Number | 要顯示的數字。 |
回攻員
Filter:用於串連的建構工具。
when Number Equal To Any(numbers)
設定篩選條件,顯示含有指定數字的儲存格。
您只能將這項條件套用至連結資料庫的資料。舉例來說,您可以在 Data 工作表、連結至資料庫的工作表,或從 Data 工作表建立的樞紐分析表 Data 中,使用這項條件搭配篩選器。
// Gets the sheet that's connected to a database. const ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Data Sheet'); const dataSheet = ss.asDataSourceSheet(); // Adds criteria to the "amount" column that only shows cells with the number // 10, 20, or 30. const criteria = SpreadsheetApp.newFilterCriteria() .whenNumberEqualToAny([10, 20, 30]) .build(); dataSheet.addFilter('amount', criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
numbers | Number[] | 要顯示的數字。 |
回攻員
Filter:用於串連的建構工具。
when Number Greater Than(number)
設定篩選條件,顯示數字大於指定數字的儲存格
您可以將這項條件與任何類型的篩選器搭配使用。如果搭配這個條件使用與資料庫連結的資料,篩選依據的資料欄資料類型必須為數字。如果資料未連結至資料庫,篩選依據資料欄的資料類型不一定要是數字,但如果不是,可能會得到非預期的結果。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); const filter = ss.getFilter(); // Creates criteria that shows cells greater than 10 and sets it to column B. const criteria = SpreadsheetApp.newFilterCriteria().whenNumberGreaterThan(10).build(); filter.setColumnFilterCriteria(2, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
number | Number | 要隱藏的最高號碼。 |
回攻員
Filter:用於串連的建構工具。
when Number Greater Than Or Equal To(number)
設定篩選條件,顯示大於或等於指定數字的儲存格。
您可以將這項條件與任何類型的篩選器搭配使用。如果搭配這個條件使用與資料庫連結的資料,篩選依據的資料欄資料類型必須為數字。如果資料未連結至資料庫,篩選依據資料欄的資料類型不一定要是數字,但如果不是,可能會得到非預期的結果。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); const filter = ss.getFilter(); // Creates criteria that shows cells greater than or equal to 10 and sets it to // column B. const criteria = SpreadsheetApp.newFilterCriteria() .whenNumberGreaterThanOrEqualTo(10) .build(); filter.setColumnFilterCriteria(2, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
number | Number | 要顯示的最低數字。 |
回攻員
Filter:用於串連的建構工具。
when Number Less Than(number)
設定篩選條件,顯示數字小於指定數字的儲存格。
您可以將這項條件與任何類型的篩選器搭配使用。如果搭配這個條件使用與資料庫連結的資料,篩選依據的資料欄資料類型必須為數字。如果資料未連結至資料庫,篩選依據資料欄的資料類型不一定要是數字,但如果不是,可能會得到非預期的結果。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); const filter = ss.getFilter(); // Creates criteria that shows cells less than 10 and sets it to column B. const criteria = SpreadsheetApp.newFilterCriteria().whenNumberLessThan(10).build(); filter.setColumnFilterCriteria(2, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
number | Number | 要隱藏的最低號碼。 |
回攻員
Filter:用於串連的建構工具。
when Number Less Than Or Equal To(number)
設定篩選條件,顯示數字小於或等於指定數字的儲存格。
您可以將這項條件與任何類型的篩選器搭配使用。如果搭配這個條件使用與資料庫連結的資料,篩選依據的資料欄資料類型必須為數字。如果資料未連結至資料庫,篩選依據資料欄的資料類型不一定要是數字,但如果不是,可能會得到非預期的結果。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); const filter = ss.getFilter(); // Creates criteria that shows cells less than or equal to 10 and sets it to // column B. const criteria = SpreadsheetApp.newFilterCriteria().whenNumberLessThanOrEqualTo(10).build(); filter.setColumnFilterCriteria(2, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
number | Number | 要顯示的最高數字。 |
回攻員
Filter:用於串連的建構工具。
when Number Not Between(start, end)
設定篩選條件,顯示數字不在指定範圍內,且不等於指定數字的儲存格。
您可以將這項條件與任何類型的篩選器搭配使用。如果搭配這個條件使用與資料庫連結的資料,篩選依據的資料欄資料類型必須為數字。如果資料未連結至資料庫,篩選依據資料欄的資料類型不一定要是數字,但如果不是,可能會得到非預期的結果。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); const filter = ss.getFilter(); // Creates criteria that hides cells with numbers that fall between 1-25, // inclusively, and sets it to column B. const criteria = SpreadsheetApp.newFilterCriteria().whenNumberNotBetween(1, 25).build(); filter.setColumnFilterCriteria(2, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
start | Number | 隱藏的最低號碼。 |
end | Number | 要隱藏的最高號碼。 |
回攻員
Filter:用於串連的建構工具。
when Number Not Equal To(number)
設定篩選條件,顯示數字不等於指定數字的儲存格。
您可以將這項條件與任何類型的篩選器搭配使用。如果搭配這個條件使用與資料庫連結的資料,篩選依據的資料欄資料類型必須為數字。如果資料未連結至資料庫,篩選依據資料欄的資料類型不一定要是數字,但如果不是,可能會得到非預期的結果。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); const filter = ss.getFilter(); // Creates criteria that hides cells that are equal to 25 and sets it to column // B. const criteria = SpreadsheetApp.newFilterCriteria().whenNumberNotEqualTo(25).build(); filter.setColumnFilterCriteria(2, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
number | Number | 要隱藏的號碼。 |
回攻員
Filter:用於串連的建構工具。
when Number Not Equal To Any(numbers)
設定篩選條件,顯示含有不等於任何指定數字的儲存格。
您只能將這項條件套用至連結資料庫的資料。舉例來說,您可以在 Data 工作表、連結至資料庫的工作表,或從 Data 工作表建立的樞紐分析表 Data 中,使用這項條件搭配篩選器。
// Gets the sheet that's connected to a database. const ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Data Sheet'); const dataSheet = ss.asDataSourceSheet(); // Adds criteria to the "amount" column that hides cells with the number 10, 20, // or 30. const criteria = SpreadsheetApp.newFilterCriteria() .whenNumberNotEqualToAny([10, 20, 30]) .build(); dataSheet.addFilter('amount', criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
numbers | Number[] | 要隱藏的號碼。 |
回攻員
Filter:用於串連的建構工具。
when Text Contains(text)
設定篩選條件,顯示含有指定文字的儲存格。文字不區分大小寫。
您可以將這項條件與任何類型的篩選器搭配使用。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); const filter = ss.getFilter(); // Creates criteria that shows cells that contain "Northwest" and sets it to // column B. const criteria = SpreadsheetApp.newFilterCriteria().whenTextContains('Northwest').build(); filter.setColumnFilterCriteria(2, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
text | String | 儲存格必須包含的文字。 |
回攻員
Filter:用於串連的建構工具。
when Text Does Not Contain(text)
設定篩選條件,顯示文字不含指定文字的儲存格。文字不區分大小寫。
您可以將這項條件與任何類型的篩選器搭配使用。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); const filter = ss.getFilter(); // Creates criteria that hides cells that contain "Northwest" and sets it to // column B. const criteria = SpreadsheetApp.newFilterCriteria() .whenTextDoesNotContain('Northwest') .build(); filter.setColumnFilterCriteria(2, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
text | String | 儲存格不得包含的文字。 |
回攻員
Filter:用於串連的建構工具。
when Text Ends With(text)
設定篩選條件,顯示文字以指定文字結尾的儲存格。文字不區分大小寫。
您可以將這項條件與任何類型的篩選器搭配使用。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); const filter = ss.getFilter(); // Creates criteria that shows cells with text that ends with "est" and sets it // to column B. const criteria = SpreadsheetApp.newFilterCriteria().whenTextEndsWith('est').build(); filter.setColumnFilterCriteria(2, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
text | String | 儲存格文字結尾必須包含的文字。 |
回攻員
Filter:用於串連的建構工具。
when Text Equal To(text)
設定篩選條件,顯示文字與指定文字相同的儲存格。文字不區分大小寫。
您可以將這項條件與任何類型的篩選器搭配使用。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); const filter = ss.getFilter(); // Creates criteria that shows cells with text that equals "hello" and sets it // to column B. const criteria = SpreadsheetApp.newFilterCriteria().whenTextEqualTo('hello').build(); filter.setColumnFilterCriteria(2, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
text | String | 儲存格文字必須相符的文字。 |
回攻員
Filter:用於串連的建構工具。
when Text Equal To Any(texts)
設定篩選條件,顯示文字與指定文字值相等的儲存格。文字不區分大小寫。
您只能將這項條件套用至連結資料庫的資料。舉例來說,您可以在 Data 工作表、連結至資料庫的工作表,或從 Data 工作表建立的樞紐分析表 Data 中,使用這項條件搭配篩選器。
// Gets the sheet that's connected to a database. const ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Data Sheet'); const dataSheet = ss.asDataSourceSheet(); // Adds criteria to the "category" column that shows cells with the text "tech" // or "business." const criteria = SpreadsheetApp.newFilterCriteria() .whenTextEqualToAny(['tech', 'business']) .build(); dataSheet.addFilter('category', criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
texts | String[] | 儲存格必須等於的文字值。 |
回攻員
Filter:用於串連的建構工具。
when Text Not Equal To(text)
設定篩選條件,顯示文字不等於指定文字的儲存格。文字不區分大小寫。
您只能將這項條件套用至連結資料庫的資料。舉例來說,您可以在 Data 工作表、連結至資料庫的工作表,或從 Data 工作表建立的樞紐分析表 Data 中,使用這項條件搭配篩選器。
// Gets the sheet that's connected to a database. const ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Data Sheet'); const dataSheet = ss.asDataSourceSheet(); // Adds criteria to the "category" column that hides cells with text equal to // "tech." const criteria = SpreadsheetApp.newFilterCriteria().whenTextNotEqualTo('tech').build(); dataSheet.addFilter('category', criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
text | String | 儲存格文字不得等於的文字。 |
回攻員
Filter:用於串連的建構工具。
when Text Not Equal To Any(texts)
設定篩選條件,顯示文字不等於任何指定值的儲存格。文字不區分大小寫。
您只能將這項條件套用至連結資料庫的資料。舉例來說,您可以在 Data 工作表、連結至資料庫的工作表,或從 Data 工作表建立的樞紐分析表 Data 中,使用這項條件搭配篩選器。
// Gets the sheet that's connected to a database. const ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Data Sheet'); const dataSheet = ss.asDataSourceSheet(); // Adds criteria to the "category" column that hides cells with the text "tech" // or "business." const criteria = SpreadsheetApp.newFilterCriteria() .whenTextNotEqualToAny(['tech', 'business']) .build(); dataSheet.addFilter('category', criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
texts | String[] | 儲存格不得等於的文字值。 |
回攻員
Filter:用於串連的建構工具。
when Text Starts With(text)
設定篩選條件,顯示文字以指定文字開頭的儲存格。文字不區分大小寫。
您可以將這項條件與任何類型的篩選器搭配使用。
// Gets the existing filter on the sheet. const ss = SpreadsheetApp.getActiveSheet(); const filter = ss.getFilter(); // Creates criteria that shows cells with text that starts with "pre" and sets // it to column B. const criteria = SpreadsheetApp.newFilterCriteria().whenTextStartsWith('pre').build(); filter.setColumnFilterCriteria(2, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
text | String | 儲存格文字開頭必須包含的文字。 |
回攻員
Filter:用於串連的建構工具。
with Criteria(criteria, args)
將篩選條件設為 Boolean 值 (例如 CELL_EMPTY 或 NUMBER_GREATER_THAN) 定義的布林條件。如要從現有條件複製布林條件,請使用現有條件的 get 和 get 定義這個方法的參數。
您可以搭配任何類型的篩選器使用這項條件,但部分條件Boolean不適用於所有篩選器。
// 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(); const 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." const filterCriteria = filter.getColumnFilterCriteria(2); const criteria = SpreadsheetApp.newFilterCriteria() .withCriteria( filterCriteria.getCriteriaType(), filterCriteria.getCriteriaValues(), ) .setHiddenValues(['Northwest']) .build(); filter.setColumnFilterCriteria(3, criteria);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
criteria | Boolean | 布林值條件的類型。 |
args | Object[] | 符合條件類型的一系列引數;引數數量和類型與上述對應的 when...() 方法相符。 |
回攻員
Filter:用於串連的建構工具。