【发布时间】:2020-08-24 18:49:53
【问题描述】:
我希望有人能够就我在下面编写的这个脚本提供一些建议。我有一个包含大量工作表的电子表格,并希望根据与今天日期匹配的工作表内的日期“仅复制/粘贴值”到几列(目的是每天在特定时间运行脚本)。
我搜索了一些过去的主题以深入了解类似的格式类型,但似乎仍然无法使其正常运行;任何意见表示赞赏!
//Loops through individual sheets and checks to find current day's tab. Once found it copy/paste specials the values only to lock the day's values.
function lockDaysValues (){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var todaysDate = new Date();
var todaysDateFormatted = Utilities.formatDate(new Date(),"PST","MM-dd-yyyy") //formats to fit
current tab name date titles of MM/DD/YYYY
var sheets = ss.getSheets();
for(var x=0; x<sheets.length; x++){
checkSheets = sheets[x].getRange('C2').getValue();
if(checkSheets=='todaysDateFormatted'){
ss.getActiveSheet().getRange('C5:D').activate();
ss.getActiveSheet().getRange('C5:D').copyTo(ss.getActiveSheet().getRange('C5:D'), SpreadsheetApp.CopyPasteType.PASTE_NORMAL, false);
}else{
break;
}
}
}
【问题讨论】:
-
这个特定代码有什么问题?更具体地说明什么不起作用以及您收到的错误消息是什么。如果您正在寻找代码改进/建议,请在此处发布此问题:codereview.stackexchange.com
-
您的 copyTo 的源和目标范围相同
标签: google-apps-script google-sheets google-workspace