我有一个包含20列的Google表格,其中一列是“状态”。我想将过滤器设置为工作表以过滤OUT(排除)所有具有Status ='Completed'的行。我该怎么做?在此先感谢您的帮助。
这是我到目前为止的代码......
function filterSheet() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var aSheet = ss.getSheetByName('Target Sheet');
var lastRow = aSheet.getLastRow();
var lastColumn = aSheet.getLastColumn();
var sheetId = aSheet.getSheetId();
var filterSettings = {
"range": {
"sheetId": sheetId,
"startRowIndex": 0,
"endRowIndex": lastRow,
"startColumnIndex": 0,
"endColumnIndex": lastColumn
//how do I include condition here to filter out rows where columnIndex 2 (column C) = 'Completed'?
}
};
var requests = [{
"setBasicFilter": {
"filter": filterSettings
}
}];
Sheets.Spreadsheets.batchUpdate({'requests': requests}, ssId);
}
你可以试试这个:
function filterSheet() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var aSheet = ss.getSheetByName('Target Sheet');
var lastRow = aSheet.getLastRow();
var lastColumn = aSheet.getLastColumn();
var sheetId = aSheet.getSheetId();
var filterSettings = {
"range": {
"sheetId": sheetId,
"startRowIndex": 0,
"endRowIndex": lastRow,
"startColumnIndex": 0,
"endColumnIndex": lastColumn
}
};
filterSettings.criteria[columnIndex] = {
"hiddenValues": ["Completed"]
};
var requests = [{
"setBasicFilter": {
"filter": filterSettings
}
}];
Sheets.Spreadsheets.batchUpdate({'requests': requests}, ssId);
}
有关FilterCriteria的更多信息:https://developers.google.com/sheets/api/reference/rest/v4/FilterCriteria