下面是我用来隐藏工作表并过滤可见区域的脚本。我正在尝试过滤包含当前日期的列,并且仅在该列中显示带有文本的单元格行。过滤器应仅在上午9点至10点之间激活。有什么想法吗?
function onEdit(e) {
var sheet = e.source.getSheetByName('Sheet1'); // or .getSheets()[0]; to apply to the first sheet.
var dates = sheet.getRange(1, 4, 1, sheet.getLastColumn() - 1).getValues()[0];
var today = Date.now()
var n = d.getHours();
if (n >= 9 && n <= 10){
filterSettings.range = {
sheetId: ss.getActiveSheet().getSheetId()
};
filterSettings.criteria = {};
var columnIndex = "column with today's date";
filterSettings['criteria'][columnIndex] = {
'not null' : condition_value
};
} else {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ssId = ss.getId();
var dataSheet = ss.getActiveSheet();
var lastRow = dataSheet.getLastRow();
var lastColumn = dataSheet.getLastColumn();
var sheetId = dataSheet.getSheetId();
var filterSettings = {
"range": {
"sheetId": sheetId,
"startRowIndex": 0,
"endRowIndex": lastRow,
"startColumnIndex": 0,
"endColumnIndex": lastColumn
}
};
var requests = [{
"setBasicFilter": {
"filter": filterSettings
}
}];
Sheets.Spreadsheets.batchUpdate({'requests': requests}, ssId);
}