Date Google脚本复制并粘贴为调试值

Date Google脚本复制并粘贴为调试值,date,google-apps-script,copy-paste,Date,Google Apps Script,Copy Paste,期待 在第一行中查找与此部件工作的昨天日期匹配的单元格 选择单元格所属的列 复制整个列并粘贴为值 不确定代码在哪里被破坏 function CopyandPasteasValues() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheets()[1]; // sheet is the first worksheet in the spreadsheet var today = new

期待

在第一行中查找与此部件工作的昨天日期匹配的单元格 选择单元格所属的列 复制整个列并粘贴为值 不确定代码在哪里被破坏

function CopyandPasteasValues() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[1]; 
  // sheet is the first worksheet in the spreadsheet

  var today = new Date();
  var yesterday = new Date();
  yesterday.setDate(today.getDate()-1);
  yesterday.setHours(3,0,0,0); //comparison doesn't seem to work without this

  for(var i=0; i< 26; i++) {
     
    var cell = sheet.getRange(1,i+2); //start getting sheet date at cell C1
    var sheetdate = cell.getValue();

    if(sheetdate.valueOf()  == yesterday.valueOf()) {

      // if there's a match, set the col
      var col = (i);
      
      // copy column and paste as values -- BELOW DOESN"T WORK --
      function copyandpastescol() {
        sheet.getRange(1, col+2, sheet.getMaxRows(), 1).activate();
        sheet.getActiveRange().copyTo(sheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
      }
    }
  }
}

嗯。。。不需要额外的功能!谢谢

/** @OnlyCurrentDoc */

function CopyandPasteasValues() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  // ss is now the spreadsheet the script is associated with
  var sheet = ss.getSheets()[1]; // sheets are counted starting from 0
  // sheet is the first worksheet in the spreadsheet

  
  // set and store a date object for today
  var today = new Date();
  var yesterday = new Date();
  yesterday.setDate(today.getDate()-1);
  yesterday.setHours(3,0,0,0);

  // iterate the values in the range object
  for(var i=0; i< 26; i++) {
     
    var cell = sheet.getRange(1,i+2); //start getting sheet date at cell C1
    var sheetdate = cell.getValue();

    // Compare only values of the objects
    if(sheetdate.valueOf()  == yesterday.valueOf()) {

      // if there's a match, set the col
      var col = (i+2);
      
      // copy column and paste as values
      sheet.getRange(1, col, sheet.getMaxRows(), 1).activate();
      sheet.getActiveRange().copyTo(sheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
     
    }
  }
}

你把copyandpastescol叫到哪里去了?它没有做什么?你有错误吗?它在做什么而不是你想要它做什么?@ThumChoonTat-duh。。。删除了该函数。这就解决了问题。天啊。非常感谢。