从 App 脚本启动 Google 表单
Launching Google Form from App Script
我正在尝试从 Google 工作表上的脚本启动 Google 表单。目前,我正在通过表单的唯一 ID 进行操作,这就是我所拥有的:
function addtoDatabase() {
var formaddnew = FormApp.openById('uniqueformID');
}
我确定我使用的是正确的表单 ID。脚本运行时未返回任何错误或异常,但表单未启动。我是应用脚本的新手,我想我可能忽略了一些东西。
感谢您的帮助。
您(和我一样)对一个奇怪的函数名称感到困惑 openById
:
var formaddnew = FormApp.openById('uniqueformID');
此代码没有 "open" 表格,它将表格分配给变量 formaddnew
。如果添加这行代码,您可以检查它:
Logger.log(formaddnew);
运行代码并按[Ctrl]+[Enter]查看日志。
如何使用脚本打开表单
没有。没有这样的选择,因为脚本无法访问浏览器。一个Form实际上是在浏览器中打开的,google-apps-script 无法在浏览器中打开新标签。
Is there any way though to open a form from a pop-up or message box?
请尝试此处描述的方法:
Google Apps Script to open a URL
这是一个基于this answer的测试示例代码:
var C_URL = ' // change
function onOpen() {
var ui = SpreadsheetApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('Menu')
.addItem('Show Window', 'testNew')
.addToUi();
}
function testNew(){
showAnchor('Open this link',C_URL);
}
function showAnchor(name,url) {
var html = '<html><body><a href="'+url+'" target="blank" onclick="google.script.host.close()">'+name+'</a></body></html>';
var ui = HtmlService.createHtmlOutput(html)
SpreadsheetApp.getUi().showModelessDialog(ui,"demo");
}
备注:
- 脚本创建自定义菜单并使用 URL 打开 window。
用户必须单击 URL.
我正在尝试从 Google 工作表上的脚本启动 Google 表单。目前,我正在通过表单的唯一 ID 进行操作,这就是我所拥有的:
function addtoDatabase() {
var formaddnew = FormApp.openById('uniqueformID');
}
我确定我使用的是正确的表单 ID。脚本运行时未返回任何错误或异常,但表单未启动。我是应用脚本的新手,我想我可能忽略了一些东西。
感谢您的帮助。
您(和我一样)对一个奇怪的函数名称感到困惑 openById
:
var formaddnew = FormApp.openById('uniqueformID');
此代码没有 "open" 表格,它将表格分配给变量 formaddnew
。如果添加这行代码,您可以检查它:
Logger.log(formaddnew);
运行代码并按[Ctrl]+[Enter]查看日志。
如何使用脚本打开表单
没有。没有这样的选择,因为脚本无法访问浏览器。一个Form实际上是在浏览器中打开的,
Is there any way though to open a form from a pop-up or message box?
请尝试此处描述的方法:
Google Apps Script to open a URL
这是一个基于this answer的测试示例代码:
var C_URL = ' // change
function onOpen() {
var ui = SpreadsheetApp.getUi();
// Or DocumentApp or FormApp.
ui.createMenu('Menu')
.addItem('Show Window', 'testNew')
.addToUi();
}
function testNew(){
showAnchor('Open this link',C_URL);
}
function showAnchor(name,url) {
var html = '<html><body><a href="'+url+'" target="blank" onclick="google.script.host.close()">'+name+'</a></body></html>';
var ui = HtmlService.createHtmlOutput(html)
SpreadsheetApp.getUi().showModelessDialog(ui,"demo");
}
备注:
- 脚本创建自定义菜单并使用 URL 打开 window。 用户必须单击 URL.