英文:
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 = ["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);
}
}
答案1
得分: 1
你应该考虑在这里提到的文档中使用工作流程:
英文:
hi you should consider using workflows as mentioned here in this documentation
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论