使用API​​v4(Google Apps脚本)过滤Google表格

时间:2018-09-07 16:02:26

标签: google-apps-script google-sheets google-sheets-api

我想在第一列中指定一个过滤器,该过滤器的数字大于1000,并且还隐藏了“英格兰”和“法国”。但是我有错误:

Invalid value at 'requests[0].set_basic_filter.filter.criteria[0].value.condition.values' 

下面的程序代码:

function setFilters() {
      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(),
        startRowIndex: 1
      };
     // Criteria for showing/hiding rows in a filter
      // https://developers.google.com/sheets/api/reference/rest/v4/FilterCriteria
      filterSettings.criteria = {};
      var columnIndex = 1;
      //

      filterSettings['criteria'][columnIndex] = {
        'hiddenValues': ["England", "France"],
        'condition': { "type": "NUMBER_GREATER","values":1000}
      };  
      var request = {
        "setBasicFilter": {
          "filter": filterSettings
        }
      };
      Sheets.Spreadsheets.batchUpdate({'requests': [request]}, ss.getId());   
    }

怎么了?

1 个答案:

答案 0 :(得分:0)

“值”:{“ userEnteredValue”:“ 1000”}-有效