Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google sheets 如何从=importdata脚本中删除每小时更新?_Google Sheets - Fatal编程技术网

Google sheets 如何从=importdata脚本中删除每小时更新?

Google sheets 如何从=importdata脚本中删除每小时更新?,google-sheets,Google Sheets,下面是一个脚本,我必须从csv链接导入数据。但是,我注意到它每小时更新一次,除非我添加了触发器。是否有办法删除每小时更新,这样,它的唯一更新方式是将脚本附加到将用作按钮的图像上 function backlog() { SpreadsheetApp.getActive().getRange('Backend Data!A2').setValue('=importdata("samplecsvlink")') } 检查后,您将使用=importdata(“samplecsv

下面是一个脚本,我必须从csv链接导入数据。但是,我注意到它每小时更新一次,除非我添加了触发器。是否有办法删除每小时更新,这样,它的唯一更新方式是将脚本附加到将用作按钮的图像上

function backlog() 
{
SpreadsheetApp.getActive().getRange('Backend Data!A2').setValue('=importdata("samplecsvlink")')
}

检查后,您将使用=importdata(“samplecsvlink”)在A2上设置单元格。因此,即使使用触发器,工作表仍将使用
=importdata()
函数从CSV链接聚合

建议

您可以参考下面的示例代码(我在本示例中使用了一个在线公共可用的CSV链接),每次运行脚本时仅获取CSV数据,将它们放入变量数组中,然后在
后端数据
工作表上设置数组数据,从单元格
A2
开始,直到CSV数据的大小:

function importCSV() { //Imports the CSV data from the URL into the variable array 'csvData' and returns that variable array
  var csvUrl = "https://people.sc.fsu.edu/~jburkardt/data/csv/addresses.csv";
  var csvContent = UrlFetchApp.fetch(csvUrl).getContentText();
  var csvData = Utilities.parseCsv(csvContent);
  return csvData;
}

function backlog(){ //Sets the imported CSV data to the 'Backend Data' sheet starts on A2 and beyond
SpreadsheetApp.getActive().getSheetByName('Backend Data').clear().getRange(2, 1, importCSV().length, importCSV()[0].length).setValues(importCSV()); //Added a .clear() method to clean any old data that could mess your 'Backend Data' sheet before posting the new updated ones, especially on scenarios like if the updated CSV data decreases in number (row count)
}
我使用的测试“后端数据”表:

结果使用
backlog
功能单击“运行”图像后:


我在更改时为电子表格添加了一个触发器。这样行吗?