[英]How To Use an Apps Script To “Copy-PasteValue” Dynamic Data In a Google Spreadsheet at a given time?
I have a google spreadsheet that imports and modifies data from an online source that updates every hour. 我有一个Google电子表格,可以从每小时更新一次的在线来源中导入和修改数据。 I wish to pull a static copy of the 10pm update from the spreadsheet—essentially a copy-paste special at a certain time.
我希望从电子表格中提取晚上10点更新的静态副本-本质上是特定时间的特殊复制粘贴。 I am using the following Script and set a Time-Driven trigger for 10pm.
我正在使用以下脚本,并将时间驱动触发器设置为晚上10点。 The script pulls data from cells N5:N10 of one sheet (which update every hour) and pastes only static values into cells N5:N10 of a second sheet in the same spreadsheet.
该脚本从一张工作表的单元格N5:N10(每小时更新一次)中提取数据,并将静态值仅粘贴到同一电子表格中第二张工作表的单元格N5:N10中。
function PasteValue()}
var ss = SpreadsheetApp.getActiveSpreadsheet();
var data= ss.getSheets()[1].getRange("N5:O10").getValues();
ss.getSheets()[2].getRange("N5:O10").setValues(data);
}
When I run the script manually it works perfectly. 当我手动运行脚本时,它可以完美运行。 However, when I set the Time-Driven trigger and close the sheet, all that is imported is a series of static “#######” when I check the next morning.
但是,当我设置“时间驱动”触发器并关闭工作表时,第二天早晨检查时,导入的只是一系列静态“ ########”。
Does anybody have any insight as to the problem? 有人对这个问题有见识吗? Or, if anybody has an alternative script or method to automatically copy-pastevalues in google spreadsheets using formulas or scripts, I would really appreciate it.
或者,如果有人有其他脚本或方法可以使用公式或脚本在Google电子表格中自动复制粘贴值,我将不胜感激。
Thanks, Ron 谢谢罗恩
When using triggers openById instead of getActive 使用触发器时,使用openById代替getActive
function PasteValue()}
var ss = SpreadsheetApp.openById(id);
ss.getSheets()[1].getRange("N5:O10").copyTo(ss.getSheets()[2].getRange("N5"),{contentsOnly:true});
}
I think the formula that you are using (importdata or importhtml) is not calculating when the spreadsheet is not open ie user is not online. 我认为当电子表格未打开(即用户不在线)时,您正在使用的公式(importdata或importhtml)无法计算。
You can use a script with urlfetchapp. 您可以将脚本与urlfetchapp一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.