【问题标题】:Google Sheets - Duplicate workbook sheet and prompt for name of new worksheet in same workbookGoogle 表格 - 重复工作簿工作表并提示在同一工作簿中输入新工作表的名称
【发布时间】:2020-02-26 03:03:29
【问题描述】:

使用 Google 表格。我的工作簿中的第一张工作表是我想在同一个工作簿中复制的模板,并提示我为新工作表命名(从而保留模板工作表的名称。

我已经看到了几个这样的例子 - 无法为新工作表命名我想要的名称。

我已在 MS Excel 中完成此操作,并在模板表上放置了一个宏按钮以执行宏 - 但我无法在 Google 表格中执行相同操作。

任何帮助将不胜感激。

【问题讨论】:

    标签: google-apps-script google-sheets-macros


    【解决方案1】:

    使用新名称提示从模板创建新工作表

    function createNewSheetFromTemplate(templatename="default") {
      const ss=SpreadsheetApp.getActive();
      const template=ss.getSheetByName(templatename);//default parameter
      const r=SpreadsheetApp.getUi().prompt('New File From Template',"Enter new file name", SpreadsheetApp.getUi().ButtonSet.OK);
      ss.insertSheet(r.getResponseText(),{template});//using object literal here. If you use the object literal here it cause problems for the script editor formatting. 
    }
    

    insertSheet(sheetname,options)

    Object Intializer

    此脚本需要更新更快的 V8 引擎。如果您使用最后一行所示的模板文字,则会导致脚本编辑器出现问题。已经创建了一个问题:https://issuetracker.google.com/issues/150198182

    【讨论】:

      猜你喜欢
      • 2013-02-27
      • 1970-01-01
      • 2021-08-29
      • 1970-01-01
      • 2013-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多