希望
不确定代码在哪里中断
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);
}
}
}
}
答案 0 :(得分:1)
Duh ...不需要额外的功能!谢谢...
/** @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);
}
}
}