更正setBasicFilter条件语法

时间:2017-10-17 19:20:33

标签: google-apps-script

我是这种编程语言的新手。有人可以帮我修复我的语法吗? 我试图结合这个例子:

     function setFilter() {
      var ss = SpreadsheetApp.getActiveSpreadsheet();

      var filterSettings = {};

      // The range of data on which you want to apply the filter.
      // optional arguments: startRowIndex, startColumnIndex, endRowIndex, endColumnIndex
      filterSettings.range = {
        sheetId: ss.getActiveSheet().getSheetId()
      };

      // Criteria for showing/hiding rows in a filter
      //         https://developers.google.com/sheets/api/reference/rest/v4/FilterCriteria
      filterSettings.criteria = {};
      var columnIndex = 2;
      filterSettings['criteria'][columnIndex] = {
        'hiddenValues': ["England", "France"]
      };

      var request = {
        "setBasicFilter": {
          "filter": filterSettings
        }
      };
      Sheets.Spreadsheets.batchUpdate({'requests': [request]}, ss.getId());
    }

使用此JSON表示:

    {
      "hiddenValues": [
        string
      ],
      "condition": {
        object(BooleanCondition)
      },
    }

设置此类标准(这是我需要帮助的地方,我不确定对象应该是什么):

    //*original    'hiddenValues': ["England", "France"]
       'condition': {object(NOT_BLANK)}

我一直无法在互联网上找到使用"条件"只有" hiddenValues" ...任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

您要查找的对象是object(BooleanCondition)

{
  "type": enum(ConditionType),
  "values": [{ object(ConditionValue) }],
}

从符合所需过滤条件的enum(ConditionType)列表中选择。在说明中,它会告诉您是否需要添加object(ConditionValue)

如果您需要一个或多个ConditionValues,请将以下对象添加到values[] "relativeDate" || "userEnteredValue"

// object(ConditionValue) - Pick one
{
  "relativeDate": enum(RelativeDate),
  "userEnteredValue": string,
}

BooleanCondition放在您当前'condition': {object(NOT_BLANK)}的{​​{3}}内

// object(BooleanCondition) with condition "NOT_BLANK"
var condition_value = {
      "type": "NOT_BLANK"
    }

// New FilterCriteria object
filterSettings['criteria'][columnIndex] = {
  'hiddenValues': ["England", "France"],
  'condition': condition_value
}