How to set background color for a row based on current date in Google Docs Spreadsheet?

后端 未结 7 1961
野性不改
野性不改 2021-01-02 04:48

I have a Google Docs SpreadSheet, where in the column A are dates (A1: 2013-11-22, A2: 2013-11-23, A3: 2013-11-24 etc). I would like to automatically highlight - set a backg

7条回答
  •  余生分开走
    2021-01-02 05:31

    You could also just have a new column in the spreadsheet do the date matching and return a flag if it's today...

    =ARRAYFORMULA(IF(A1:A =TODAY(), 1, "")) - formula in cell D1

    then try..

    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var s = ss.getSheetByName('Sheet1');
    
    function onOpen() {
      var values = ss.getRange('D1:D').getValues();  // column of date flag
    
      for ( var row = 0; row < values.length; row++ ) {
        if ( values[row][0] ) {
          break; // assuming only 1 row has today's date
        }
      }
    
      s.getRange('A1:D').setBackground(null);  // range to clear
      s.getRange(row + ":" + row).offset(1, 0).setBackground('yellow');
    
    }
    

提交回复
热议问题