Reputation: 155
I do have two different google sheet, I need to copy say sheet Test from one to another using script, but getting error, any thought on this?
var source_sheet= "https://address of the otgoogle sheet tho be copied over")"
//here I'm on another google sheet, add a menu to copy the source from above
var ui = SpreadsheetApp.getUi();
//var ss = SpreadsheetApp.getActiveSpreadsheet();
var result = ui.prompt(
'Add New Sheet',
'Please enter Name',
ui.ButtonSet.OK);
var button = result.getSelectedButton();
var text = result.getResponseText();
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getActiveSheet();
sheet.copyTo(link_to_src).setName(text);
Getting below error: Exception: The parameters (String) don't match the method signature for SpreadsheetApp.Sheet.copyTo. (line xx, file "copy-rename")DetailsDismiss
Any help will be appreciated in advance..
Upvotes: 2
Views: 985
Reputation: 201378
source_sheet
is the URL of Spreadsheet like https://docs.google.com/spreadsheets/d/{spreadsheetId}/edit
.I could understand like above. If my understanding is correct, how about this modification?
Please modify your script as follows. Before you run the script, please set the destination Spreadsheet URL to source_sheet
.
var sheet = ss.getActiveSheet();
sheet.copyTo(link_to_src).setName(text);
To:
var sourceSheet = SpreadsheetApp.openByUrl(source_sheet).getSheetByName(text);
if (sourceSheet) {
sourceSheet.copyTo(ss).setName(text).activate();
} else {
ui.alert(text + " sheet was not found.");
}
Upvotes: 4