Google表格|如何使用脚本按多个列进行过滤

时间:2018-08-04 23:34:48

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

我使用下面的脚本按下面的columnIndex 8进行过滤。有人可以帮我弄清楚如何同时按两列进行过滤吗?

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

  var filterSettings = {};

  var condition_value = {
    "type": "TEXT_EQ",
    "values": [{"userEnteredValue": "D"}]
  };

  filterSettings.range = {
    sheetId: ss.getActiveSheet().getSheetId()
  };

  filterSettings.criteria = {};
  var columnIndex = 8;
  filterSettings['criteria'][columnIndex] = {
    'condition' : condition_value
  };

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

1 个答案:

答案 0 :(得分:0)

例如,当将过滤器应用于“ columnIndex”的7和8时,如何进行如下修改?

发件人:

filterSettings.criteria = {};
var columnIndex = 8;
filterSettings['criteria'][columnIndex] = {
  'condition' : condition_value
};

收件人:

filterSettings.criteria = {};
var columnIndex1 = 7;
var columnIndex2 = 8;

filterSettings['criteria'][columnIndex1] = {
  'condition' : condition_value
};

filterSettings['criteria'][columnIndex2] = {
  'condition' : condition_value
};

注意:

  • “ columnIndex”的7和8分别是H列和I列。

参考:

如果我误解了您的问题,请告诉我。我想修改它。