简体   繁体   English

如何在给定时间使用Apps脚本在Google Spreadsheet中“复制-粘贴值”动态数据?

[英]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.

相关问题 Google Apps脚本:如何使用电子表格中的数据查询外部数据库? - Google Apps Script: how to use data in a spreadsheet to query a external database? 使用 Google Apps 脚本将一个 Google 电子表格中的特定数据复制到另一个 Google 电子表格 - Copy Specific Data in one Google Spreadsheet to another Google Spreadsheet with Google Apps Script 如何使用谷歌应用脚本将一行从一个谷歌电子表格复制到另一个谷歌电子表格? - How to copy a row from one google spreadsheet to another google spreadsheet using google apps script? 将工作表复制到另一个电子表格[Google Apps脚本] - Copy sheet to another spreadsheet [Google Apps Script] 如何使用 JavaScript 将 Google 电子表格数据拉入 Google Apps 脚本中的 HTML - How to use JavaScript to pull Google Spreadsheet data into HTML within Google Apps Script 如何使用Google Apps脚本自动下载Google电子表格数据 - how to automatically download Google spreadsheet data using Google Apps script 如何使用Google Apps脚本将特定的行从3个Google电子表格复制到另一个电子表格 - How to copy specific rows from 3 google spreadsheet to another spreadsheet using google apps script 如何在 Google Apps 电子表格脚本中将日期和时间合并为日期时间? - How to merge date and time as a datetime in Google Apps Spreadsheet script? Google脚本-将动态范围复制到新的电子表格 - Google Script - Copy dynamic range to new spreadsheet 如何使用 Google Apps 脚本访问外部电子表格中的数据 - How to access data from an external spreadsheet with Google Apps Script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM