[英]Rename sheet once copied to another Spreadsheet - remove “Copy of”?
Hopefully relatively simple, but can't seem to find an answer. 希望相对简单,但似乎找不到答案。
I have a function that copies (archives) the current sheet to another spreadsheet, but then it's called "Copy of [sheet name]" in the destination spreadsheet. 我有一个将当前工作表复制(存档)到另一个电子表格的函数,但是在目标电子表格中它称为“ [工作表名称]的副本”。
Hoping I can get rid of the Copy of part, but setName() hasn't seemed to work. 希望我能摆脱零件的复制,但是setName()似乎没有用。
Everything in the below code works until the last two lines. 以下代码中的所有内容都可以使用到最后两行。
function archiveCurrentSheet() {
SpreadsheetApp.getUi()
var areyousure = Browser.msgBox('Are you sure you want to archive this sheet?', Browser.Buttons.OK_CANCEL);
if (areyousure == "cancel" ) {
}
else {
var source = SpreadsheetApp.getActiveSpreadsheet();
var currentSheetName = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getName();
var sheet = source.getActiveSheet();
var destination = SpreadsheetApp.openById("ID");
sheet.copyTo(destination);
var sheetRename = SpreadsheetApp.openById("ID").getSheets();
sheetRename.setName(currentSheetName);
}
}
It gives error: "TypeError: Cannot find function setName in object Sheet,Sheet,Sheet,Sheet,Sheet,Sheet,Sheet,Sheet." 它给出错误:“ TypeError:在对象Sheet,Sheet,Sheet,Sheet,Sheet,Sheet,Sheet,Sheet中找不到函数setName。”
Thanks! 谢谢!
ps bonus: would be how do I delete the current PS奖金:将如何删除当前
sheet.copyTo(destination)方法返回新的工作表,因此您可以执行以下操作。
sheet.copyTo(destination).setName(currentSheetName);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.