简体   繁体   English

重命名工作表一旦复制到另一个电子表格-删除“副本”?

[英]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.

相关问题 从工作表中删除一行并复制到另一个电子表格 - Remove a row from a sheet and copy to another spreadsheet 将工作表复制到另一个电子表格[Google Apps脚本] - Copy sheet to another spreadsheet [Google Apps Script] 电子表格上的工作表副本 - copy of sheet on a Spreadsheet 使用谷歌工作表脚本时,如何将电子表格的工作表复制到另一个电子表格中而不创建新的工作表副本? - How to copy spreadsheet's sheet into another spreadsheet without creating a new sheet copy when using google sheet script? 将数据从一张纸复制到另一张电子表格,但不包括特定的列 - Copy data from one sheet to another spreadsheet exclude specific columns Apps脚本复制工作表到另一个电子表格中非常大的数据 - Apps Script Copy sheet to another spreadsheet very large data 将一行从一个Google表格电子表格复制到表单提交中的另一表格 - Copy a row from one Google Sheet Spreadsheet to Another on Form Submit 应用程序脚本将多个范围从一张工作表复制到另一个电子表格 - Apps script copy multiple range from 1 sheet to another spreadsheet 脚本将一些单元格复制到特定工作表上另一个电子表格的最后一行? - script to copy some cells to last row of another spreadsheet at specific sheet? 如何将过滤器本身复制到同一个谷歌电子表格中的另一个工作表? - How to copy the filter itself to another sheet within the same google spreadsheet?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM