google-apps-script - 如何使用 Apps 脚本指定 Google 表单目标的电子表格选项卡名称

标签 google-apps-script google-sheets google-forms

我正在使用 Google 脚本编辑器,并使用基于 Google 表格的表单创建了一个表单。我已根据从工作表中选择的当前单元格为表单上的某些问题指定了帮助文本。然后我将表单结果的目的地设置到另一个 Google 工作表中。我想根据当前工作表中的当前单元格指定选项卡的名称。那可能吗?这是我现在拥有的:

var DestinationSheet = SpreadsheetApp.openByUrl('URL here');
  form.setDestination(FormApp.DestinationType.SPREADSHEET, DestinationSheet.getId(););

但是我如何指定 TAB 名称,因为现在它只是给它一个通用名称,每次都会有一个新的数字,即“Form Responses 5”。

我想我可以以某种方式包含这个: DestinationSheet.insertSheet("当前单元格"); 但这只是插入了另一个名为“currentcell”的工作表。

最佳答案

But how do I specify the TAB name, as right now it just gives it a generic name with a new number each time, i.e., "Form Responses 5".

目前无法设置工作表名称。但您可以重命名“Form Responses 5”工作表。

片段:

var DestinationSheet = SpreadsheetApp.openByUrl('URL here');
  form.setDestination(FormApp.DestinationType.SPREADSHEET, DestinationSheet.getId(););
  const formUrl = form.getEditUrl();
  DestinationSheet
    .getSheets()
    .forEach(function(sheet){
       var sheetUrl = sheet.getFormUrl()
      //TODO Check format of both urls
      if (sheetUrl  === formUrl) 
        sheet.setName(DestinationSheet.getCurrentCell().getValue());//Function should be called from menu/button
    })

引用文献:

关于google-apps-script - 如何使用 Apps 脚本指定 Google 表单目标的电子表格选项卡名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57511531/

相关文章:

google-forms - 谷歌表单 : Can I add a hyper link that will be opened on a new tab?

google-apps-script - 编辑时更改单元格颜色,但仅限于有限的时间

javascript - 跳至 Google 表单上的页面

google-sheets - 在 Google 电子表格的数组公式中使用 VLOOKUP

javascript - 比较日期谷歌表格脚本

google-apps-script - 提交 Gforms 时复制上一行的格式

javascript - 如何使用 Google 协作平台的 Google App 脚本创建动态组件?

javascript - 使用 Google Apps 脚本检索一个月内的所有事件

javascript - Google Sheets v4 更新效果 JSON 端点数据? 2021 年 6 月 8 日关闭

google-apps-script - Google Forms 脚本将用户移动到表单中的新页面