在弹出的Google电子表格中创建Google表单。这可以做到吗? [英] Create a Google Form in Pop up of Google Spreadsheet. Could this be done?

查看:129
本文介绍了在弹出的Google电子表格中创建Google表单。这可以做到吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

参考:




Reference :

Single Google Form for multiple Sheets



Re-claim :

  1. I have a little bit hard to made my writing some good or as well to be understanding (less english).
  2. I have a little insight about a Google Apps Script (GAS).
  3. I have change "MyURLDoc" and "MyIdDoc" bellow as cosinderring of mine.




Question :

How do I make a Google Form be inside of a Pop up what I've made in Google Spreadsheet ?





Attempt 1 :

function goToURL() {
  FormApp.openByUrl(//*** MyURLDoc! ***//);
}





Attempt 2 :     Following as the reference has worte there!

function goToForm() {
var form = FormApp.openById(//*** MyIdDoc! ***//),
    formUrl = form.getPublishedUrl(),
    response = UrlFetchApp.fetch(formUrl),
    formHtml = response.getContentText(),
    htmlApp = HtmlService
  .createHtmlOutput(formHtml)
  .setSandboxMode(HtmlService.SandboxMode.IFRAME)
  .setTitle('Ta Daaa!')
  .setWidth(500) 
  .setHeight(450);  SpreadsheetApp.getActiveSpreadsheet().show(htmlApp);
}





Problem :

It says always like this:     " No item with the given ID could be found or You do not have permission "

解决方案

Creating a Sidebar with a Google Form

I just went to an old form I have and got the embed code. I loaded into a sidebar that I had on another project and pasted the embed code which is an iframe and it loaded perfectly except for the size and I ran the form and sure enough it loaded data into the spreadsheet that contains it.

I thought I'd go ahead and add a complete example. This is a simple example which creates a form for inputting time stamped text into a spreadsheet. It's done two ways. The first technique uses standard html, javascript, JQuery and Google Script. The second technique is accomplished by just creating a form and embedding it into a simple html page. Both versions fit into the side bar and both are linked to spreadsheet pages where the text is loaded and timestamped.

Code.gs:

function onOpen()
{
  SpreadsheetApp.getUi().createMenu('My Tools')
    .addItem('createTextEntryForm', 'createTextEntryForm')
    .addToUi();

  loadSideBar();
  SpreadsheetApp.getUi().createMenu('My Menu').addItem('loadSidebar', 'loadSideBar').addToUi();  
}

//This loads the text into the spreadsheet for the html version of the form.
function dispText(txt)
{
  var ss=SpreadsheetApp.getActiveSpreadsheet();
  var sht=ss.getSheetByName('Notes');
  var ts=Utilities.formatDate(new Date(), 'GMT-6', "M/dd/yyyy HH:mm:ss");
  var row=[];
  row.push(ts);
  row.push(txt);
  sht.appendRow(row);
  return true;
}

function loadSideBar()
{
  var userInterface=HtmlService.createHtmlOutputFromFile('formBar');//sidebar for html and formBar for form
  SpreadsheetApp.getUi().showSidebar(userInterface);
}


//This is the form
function createTextEntryForm()
{
   var ss=SpreadsheetApp.getActiveSpreadsheet();
   var form=FormApp.create('Form On A Sidebar');
   form.setDescription('Enter Your Message and Push Submit when complete.')
       .setConfirmationMessage('Message Saved and TimeStamped.')
       .setAllowResponseEdits(true)
       .setAcceptingResponses(false)
       .setDestination(FormApp.DestinationType.SPREADSHEET, ss.getId());
   var containerLink=form.addParagraphTextItem();
   containerLink.setTitle('Enter your comment now.')
       .isRequired();
}

sidebar.html which is the html version of the form:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  <script>
    $(function() {
        $('#txt1').val('');
      });
    function sendText()
    {
      var txt=$('#txt1').val();
      google.script.run
        .withSuccessHandler(clearText)
        .dispText(txt);
    }
    function clearText()
    {
      $('#txt1').val('');
    }
    console.log("My code");
  </script>
  </head>
  <body>
  <textarea id="txt1" rows="12" cols="35"></textarea>
<br />
  <input id="btn1" type="button" value="submit" onClick="sendText();" />
  </body>
</html>

formBar.html is where the form is embedded:

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <iframe src="FormURL?embedded=true#start=embed" width="300" height="550" frameborder="0" marginheight="0" marginwidth="0">Loading...</iframe>
  </body>
</html>

This is what the spreadsheet and sidebars look like:

这篇关于在弹出的Google电子表格中创建Google表单。这可以做到吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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