从 BigQuery 连接表复制数据。

huangapple go评论100阅读模式
英文:

How to copy data from a BigQuery Connector Sheet

问题

有没有办法编写一个Apps Script来从一个是BigQuery数据连接器表格的工作表中复制数据到另一个工作表?

我有一个连接器运行在BigQuery中查询表格。我想要将这整个表格复制到同一工作簿中的另一个工作表。

以下是我尝试过的代码类型,但我收到了错误消息:“异常:不支持DATASOURCE工作表的操作。”

function copyData() {
  var sourceSheetNames = ["Connector Sheet 1", "Connector Sheet 2"];
  var targetSheetName = "Sheet1";
  var targetCellStartRow = [3, 16];
  var targetCellStartColumn = 1;
  
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var targetSheet = spreadsheet.getSheetByName(targetSheetName);
  
  for (var i = 0; i < sourceSheetNames.length; i++) {
    var sourceSheet = spreadsheet.getSheetByName(sourceSheetNames[i]);
    var sourceRange = sourceSheet.getDataRange();
    var targetRange = targetSheet.getRange(targetCellStartRow[i], targetCellStartColumn, sourceRange.getNumRows(), sourceRange.getNumColumns());
    
    sourceRange.copyTo(targetRange);
  }
}
英文:

Is there a way to write an Apps Script to copy data from a sheet that is a BigQuery Data Connector Sheet to another sheet?

I have a connector the runs a query in BigQuery, inputting a table. I want to copy this entire table to another sheet in that same workbook.

Below is the type of code I've tried but I get an error "Exception: The action is not supported for DATASOURCE sheet."

function copyData() {
  var sourceSheetNames = [&quot;Connector Sheet 1&quot;, &quot;Connector Sheet 2&quot;];
  var targetSheetName = &quot;Sheet1&quot;;
  var targetCellStartRow = [3, 16];
  var targetCellStartColumn = 1;
  
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var targetSheet = spreadsheet.getSheetByName(targetSheetName);
  
  for (var i = 0; i &lt; sourceSheetNames.length; i++) {
    var sourceSheet = spreadsheet.getSheetByName(sourceSheetNames[i]);
    var sourceRange = sourceSheet.getDataRange();
    var targetRange = targetSheet.getRange(targetCellStartRow[i], targetCellStartColumn, sourceRange.getNumRows(), sourceRange.getNumColumns());
    
    sourceRange.copyTo(targetRange);
  }
}

答案1

得分: 1

你应该考虑在这里提到的文档中使用工作流程:

documentation

英文:

hi you should consider using workflows as mentioned here in this documentation

huangapple
  • 本文由 发表于 2023年5月30日 13:09:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76361751.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定