如何在 google 工作表中创建弹出式 google 表单?
How can I create a popup google form in google sheets?
我想创建一个弹出式 google 表单,当您按下 sheet 中的菜单项时会出现该表单。我可以显示它,但我不能回答问题。
这是我当前的代码:
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menubuttons1 = [ {name: "Input", functionName: "ask"} ];
ss.addMenu("Sales", menubuttons1);
}
function ask() {
var form = FormApp.openById("1LdHO6bazGUsrmanRUbUwj28-gTiv2pJwUEfj8NzinjA"),
formUrl = form.getPublishedUrl(),
response = UrlFetchApp.fetch(formUrl),
formHtml = response.getContentText(),
htmlApp = HtmlService
.createHtmlOutput(formHtml)
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setTitle('Sales Input')
.setWidth(450)
.setHeight(500); SpreadsheetApp.getActiveSpreadsheet().show(htmlApp);
}
这是 google sheet 和表格:
Sheet: https://docs.google.com/spreadsheets/d/1aGkZjDgMkRrFiPqCy5zy-bORGxuPKnSgYzP0vhy4bso/edit#gid=0
形式:https://docs.google.com/forms/d/1LdHO6bazGUsrmanRUbUwj28-gTiv2pJwUEfj8NzinjA/edit
你的情况,下面的修改怎么样?
修改后的脚本:
本次修改,我修改了函数ask
。
function ask() {
var form = FormApp.openById('1LdHO6bazGUsrmanRUbUwj28-gTiv2pJwUEfj8NzinjA');
var formUrl = form.getPublishedUrl();
var formHtml = `<iframe id="inlineFrameExample" src="${formUrl}" style="border:none; width:400px; height:400px;"></iframe>`;
var htmlApp = HtmlService
.createHtmlOutput(formHtml)
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setTitle('Sales Input')
.setWidth(420)
.setHeight(420);
SpreadsheetApp.getActiveSpreadsheet().show(htmlApp);
}
我想创建一个弹出式 google 表单,当您按下 sheet 中的菜单项时会出现该表单。我可以显示它,但我不能回答问题。
这是我当前的代码:
function onOpen() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var menubuttons1 = [ {name: "Input", functionName: "ask"} ];
ss.addMenu("Sales", menubuttons1);
}
function ask() {
var form = FormApp.openById("1LdHO6bazGUsrmanRUbUwj28-gTiv2pJwUEfj8NzinjA"),
formUrl = form.getPublishedUrl(),
response = UrlFetchApp.fetch(formUrl),
formHtml = response.getContentText(),
htmlApp = HtmlService
.createHtmlOutput(formHtml)
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setTitle('Sales Input')
.setWidth(450)
.setHeight(500); SpreadsheetApp.getActiveSpreadsheet().show(htmlApp);
}
这是 google sheet 和表格:
Sheet: https://docs.google.com/spreadsheets/d/1aGkZjDgMkRrFiPqCy5zy-bORGxuPKnSgYzP0vhy4bso/edit#gid=0
形式:https://docs.google.com/forms/d/1LdHO6bazGUsrmanRUbUwj28-gTiv2pJwUEfj8NzinjA/edit
你的情况,下面的修改怎么样?
修改后的脚本:
本次修改,我修改了函数ask
。
function ask() {
var form = FormApp.openById('1LdHO6bazGUsrmanRUbUwj28-gTiv2pJwUEfj8NzinjA');
var formUrl = form.getPublishedUrl();
var formHtml = `<iframe id="inlineFrameExample" src="${formUrl}" style="border:none; width:400px; height:400px;"></iframe>`;
var htmlApp = HtmlService
.createHtmlOutput(formHtml)
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setTitle('Sales Input')
.setWidth(420)
.setHeight(420);
SpreadsheetApp.getActiveSpreadsheet().show(htmlApp);
}