Class FilterCriteria

معیارهای فیلتر

از این کلاس برای به دست آوردن اطلاعات یا کپی کردن معیارهای فیلترهای موجود استفاده کنید.

کاربردهای رایج

کپی معیارها

نمونه زیر فیلتری را دریافت می کند که برای محدوده A1:C20 اعمال می شود، معیارهای اعمال شده در ستون C را دریافت می کند، و معیارها را در ستون B کپی می کند
let ss = SpreadsheetApp.getActiveSheet();
let range = ss.getRange("A1:C20");
// Copies the filter criteria applied to column C.
let filter = range.getFilter();
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);

مقادیر پنهان شده توسط فیلتر را دریافت کنید

نمونه زیر فیلتری را دریافت می کند که برای محدوده داده شده اعمال می شود و مقادیر ستون B را که فیلتر پنهان می کند ثبت می کند.
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);

مواد و روش ها

روش نوع برگشت توضیح مختصر
copy() FilterCriteriaBuilder این معیار فیلتر را کپی می کند و یک معیارساز ایجاد می کند که می توانید آن را روی فیلتر دیگری اعمال کنید.
getCriteriaType() BooleanCriteria نوع بولی معیار را برمی‌گرداند، به عنوان مثال، CELL_EMPTY .
getCriteriaValues() Object[] آرایه ای از آرگومان ها را برای معیارهای بولی برمی گرداند.
getHiddenValues() String[] مقادیری را که فیلتر پنهان می کند برمی گرداند.
getVisibleBackgroundColor() Color رنگ پس زمینه استفاده شده به عنوان معیار فیلتر را برمی گرداند.
getVisibleForegroundColor() Color رنگ پیش زمینه استفاده شده به عنوان معیار فیلتر را برمی گرداند.
getVisibleValues() String[] مقادیری را که فیلتر جدول محوری نشان می دهد برمی گرداند.

مستندات دقیق

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 مراجعه کنید.

مردم اغلب از این روش برای اضافه کردن معیارهای شرط بولی به یک فیلتر بدون جایگزین کردن معیارهای موجود استفاده می کنند.

برای هر نوع فیلتری می توانید از این روش استفاده کنید. اگر معیار فیلتر یک شرط بولی نباشد، 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() استفاده کنید.
  • برای استفاده از نوع معیار و مقادیر معیار برای ایجاد یا اصلاح یک معیار فیلتر، به FilterCriteriaBuilder.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[] - آرایه ای از آرگومان های متناسب با نوع معیار بولی. تعداد آرگومان ها و نوع آنها با متد when...() کلاس FilterCriteriaBuilder مطابقت دارد.


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[] - آرایه ای از مقادیری که فیلتر جدول محوری نشان می دهد.