谷歌表格从脚本启动表单 [英] google sheets launch form from script

查看:206
本文介绍了谷歌表格从脚本启动表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从脚本中启动一个表单,然后从这里借用代码:

单个Google表单为多个表格



其中我做了如下:

 函数CreateForm(){
var form = FormApp.create('New Form') ;
var item = form.addCheckboxItem();
item.setTitle('现在工作吗?');
item.setChoices([
item.createChoice('yes'),
item.createChoice('no')
]);
form.addMultipleChoiceItem()
.setTitle('我该怎么办?')
.setChoiceValues(['Complain','飘柔','继续尝试'))
.showOtherOption(true);
Logger.log('Published URL:'+ form.getPublishedUrl());
Logger.log('Editor URL:'+ form.getEditUrl());
Logger.log('Form ID:'+ form.getId());
}


函数launchForm(){
var formTitle ='每周报告问卷';
var formID ='1NjNO7JTlt9H2IB6L3QowGitR38o2KrnZxpKB3MWoVXE';
var form = FormApp.openById(formID);
var formUrl = form.getPublishedUrl();
var response = UrlFetchApp.fetch(formUrl);
var formHtml = response.getContentText();
var htmlApp = HtmlService
.createHtmlOutput(formHtml)
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setTitle(formTitle)
.setWidth(500)
.setHeight(450);
SpreadsheetApp.getActiveSpreadsheet()。show(htmlApp);

$ / code>

所以问题是,当我从我的菜单加载项执行launchForm时,该表单会显示,但它不起作用 - 我无法检查框,输入文本或提交表单,但当光标悬停在某个项目上时,光标会发生变化。我只能关闭表格。我希望表单将输入字段中的值存储在我的表单中作为变量,以便在以后输出到我的电子邮件html文本中。

解决方案

这个解决方法如何?在此解决方法中,直接使用表格URL并在iframe中打开。



修改后的脚本:



I只修改 launchForm()如下。

  function launchForm(){ 
var formTitle ='每周报告问卷';
var formID ='1NjNO7JTlt9H2IB6L3QowGitR38o2KrnZxpKB3MWoVXE';
var form = FormApp.openById(formID);
var formUrl = form.getPublishedUrl();
var htmlApp = HtmlService
.createHtmlOutput('< script> location.href =''+ formUrl +'< / script>')
.setSandboxMode(HtmlService.SandboxMode.IFRAME )
.setTitle(formTitle)
.setWidth(500)
.setHeight(450);
SpreadsheetApp.getActiveSpreadsheet()。show(htmlApp);
}

如果这对您没有用处,我很抱歉。


I'm trying to launch a form from a script from my script following the code I borrowed from here:

Single Google Form for multiple Sheets

which I did as follows:

function CreateForm() {
  var form = FormApp.create('New Form');
  var item = form.addCheckboxItem();
  item.setTitle('Is this working now?');
  item.setChoices([
          item.createChoice('yes'),
          item.createChoice('no')
  ]);
  form.addMultipleChoiceItem()
          .setTitle('What should I do about it?')
          .setChoiceValues(['Complain', 'Rejoice', 'Keep Trying'])
          .showOtherOption(true);
  Logger.log('Published URL: ' + form.getPublishedUrl());
  Logger.log('Editor URL: ' + form.getEditUrl());  
  Logger.log('Form ID: ' + form.getId());
}


function launchForm() {
  var formTitle = 'Weekly Report Questionnaire';
  var formID = '1NjNO7JTlt9H2IB6L3QowGitR38o2KrnZxpKB3MWoVXE';
  var form = FormApp.openById(formID);
  var formUrl = form.getPublishedUrl();
  var response = UrlFetchApp.fetch(formUrl);
  var formHtml = response.getContentText(); 
  var htmlApp = HtmlService
  .createHtmlOutput(formHtml)
  .setSandboxMode(HtmlService.SandboxMode.IFRAME)
  .setTitle(formTitle)
  .setWidth(500) 
  .setHeight(450);
  SpreadsheetApp.getActiveSpreadsheet().show(htmlApp);
}

So the problem is, when I execute launchForm from my menu add-on, the form appears, but it doesn't work - I can't check the boxes, enter text, or submit the form, although the cursor changes when I hover over an item. I can only close the form. I want the form to store the values from the input fields in my form as variables for later output in my email html text.

解决方案

How about this workaround? In this workaround, the form URL is directly used and opened in the iframe.

Modified script :

I modified only launchForm() as follows.

function launchForm() {
  var formTitle = 'Weekly Report Questionnaire';
  var formID = '1NjNO7JTlt9H2IB6L3QowGitR38o2KrnZxpKB3MWoVXE';
  var form = FormApp.openById(formID);
  var formUrl = form.getPublishedUrl();
  var htmlApp = HtmlService
  .createHtmlOutput('<script>location.href = "' + formUrl + '"</script>')
  .setSandboxMode(HtmlService.SandboxMode.IFRAME)
  .setTitle(formTitle)
  .setWidth(500) 
  .setHeight(450);
  SpreadsheetApp.getActiveSpreadsheet().show(htmlApp);
}

If this was not useful for you, I'm sorry.

这篇关于谷歌表格从脚本启动表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆