![](/img/trans.png)
[英]Alter data in google spreadsheet sheet via other sheet in the same spreadsheet
[英]Google sheet: Error on copy sheet to other spreadsheet
我正在嘗試使用此代碼將工作表復制到其他電子表格中。 但是,出現錯誤:[例外:指定的工作表必須是電子表格的一部分]
function copy_to_A() {
var source = SpreadsheetApp.getActiveSpreadsheet();
var destination = SpreadsheetApp.openById(Bestwise_id);
var tempsheet = source.getSheetByName('Bestwise-tocopy');
destination.insertSheet('New Sheet Name', 0, {template: tempsheet});
}
不幸的是,似乎當源工作表的電子表格與目標電子表格不同時, insertSheet
不能用於其他電子表格。 似乎這是當前的規范。 所以當你想使用destination.insertSheet('New Sheet Name', 0, {template: tempsheet});
,以下解決方法如何? 此變通方法的流程如下。
tempsheet
表從源電子表格復制到目標電子表格。insertSheet('New Sheet Name', 0, {template: tempsheet})
,使用復制的工作表。當這個流程反映到你的腳本時,它變成如下。
function copy_to_A() {
var source = SpreadsheetApp.getActiveSpreadsheet();
var destination = SpreadsheetApp.openById(Bestwise_id);
var tempsheet = source.getSheetByName('Bestwise-tocopy');
// 1. Copy `tempsheet` sheet from source Spreadsheet to destination Spreadsheet.
var copiedSheet = tempsheet.copyTo(destination);
// 2. Using `insertSheet('New Sheet Name', 0, {template: tempsheet})`, the copied sheet is used.
destination.insertSheet('New Sheet Name', 0, { template: copiedSheet });
// 3. Delete the copied sheet.
destination.deleteSheet(copiedSheet);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.