google-apps-script - 如何使用 Apps 脚本指定 Google 表单目标的电子表格选项卡名称
问题描述
我正在使用谷歌脚本编辑器,并且我已经创建了一个基于谷歌表格的表单。我已经根据从工作表中选择的当前单元格为表单上的某些问题指定了帮助文本。然后,我将表单结果的目的地设置到不同的 Google 表格中。我想根据当前工作表中的当前单元格指定选项卡的名称。那可能吗?这是我现在所拥有的:
var DestinationSheet = SpreadsheetApp.openByUrl('URL here');
form.setDestination(FormApp.DestinationType.SPREADSHEET, DestinationSheet.getId(););
但是我如何指定 TAB 名称,因为现在它只是给它一个通用名称,每次都有一个新数字,即“Form Responses 5”。
我想我可以以某种方式包括这个:
DestinationSheet.insertSheet("currentcell");
但这只是插入了另一个名为“currentcell”的工作表。
解决方案
但是我如何指定 TAB 名称,因为现在它只是给它一个通用名称,每次都有一个新数字,即“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
})
参考:
推荐阅读
- javascript - 如何在 js 代码(nodejs 服务器)中获取 SCSS 变量?
- javascript - MongoDB 发出 POST 请求时返回空错误对象
- file-upload - 无法读取未定义的属性“getChildren”
- spring - 如何在 Spring 中从 AWS ECS 任务定义中读取环境变量?
- java - 双向链表在列表末尾返回 null
- arrays - Powershell 比较和合并两个数组
- python - Olx的api访问问题
- javascript - 数据表在调整大小时不尊重屏幕宽度
- kotlin - 服务器端 jvm 上的 Ktor,协程 native-mt 或 vanilla
- sql - 如何获得所有相等的TOP行