Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Date 在谷歌电子表格中比较日期_Date_Google Apps Script_Google Sheets_Compare_Gs Conditional Formatting - Fatal编程技术网

Date 在谷歌电子表格中比较日期

Date 在谷歌电子表格中比较日期,date,google-apps-script,google-sheets,compare,gs-conditional-formatting,Date,Google Apps Script,Google Sheets,Compare,Gs Conditional Formatting,我想比较D列和E列中的两个日期。D列是截止日期,E列是完成日期。我想比较这两个日期,看看到期日期是否小于或等于完成日期,然后两个单元格都变为绿色,否则如果过期,则变为红色 我不擅长编程,但到目前为止我已经做到了: function myFunction() { function onEdit(e) { var cellID = e.source.getActiveCell(); //var cellValue = e.cell.getValue(); var ss = Spread

我想比较D列和E列中的两个日期。D列是截止日期,E列是完成日期。我想比较这两个日期,看看到期日期是否小于或等于完成日期,然后两个单元格都变为绿色,否则如果过期,则变为红色

我不擅长编程,但到目前为止我已经做到了:

function myFunction() {

function onEdit(e) {

var cellID = e.source.getActiveCell();
//var cellValue = e.cell.getValue();     
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0]; //”0? is the first sheet
var startRow = 2; // First row of data to process-actual row# (this is cell D2)
var numRows = 206 // Number of rows to process (goes from D2-D206)
var data = dataRange.getValues();
for (i in data) {
var row = data[i];

  if (row[4] > row[3] ) {
    cellID.setBackgroundColor('red');
  } else if(row[4] <= row[3]) {
    cellID.setBackgroundColor('green');
  }  
}  
}
}

现在,在新工作表中,您应该能够使用内置条件格式执行所需操作。你试过了吗


在脚本中,onEdit被抛出到myFunction中,这将不起作用。如果要进一步使用脚本,请进行注释。

清除ColumnsD:E中的任何条件格式,选择ColumnsD:E用标准绿色填充,然后选择Format,conditional formatting…,Format cells if。。。自定义公式是和

用红色填充并完成

=and(row()<>1,$E1<$D1)