【问题标题】:Google Spreadsheet Form, populate form options based on a spreadsheetGoogle 电子表格表单,根据电子表格填充表单选项
【发布时间】:2011-11-10 19:08:32
【问题描述】:

我需要找到一种方法,根据不断变化的 Google 电子表格中的一组单元格来更改 Google 表单中的多项选择选项。有什么想法吗?

【问题讨论】:

    标签: google-apps-script google-forms


    【解决方案1】:

    这是可能的。在电子表格中编写您自己的脚本以更新您的表单。如果您不熟悉编写脚本,您可能会在 Google 脚本库中找到某人的。让我们看看我的脚本示例。该脚本是更新两个列表框。

    function updateForm(){
      // a way to get the items from the form
      var form = FormApp.openById("<your form id>");
      var agentList = form.getItemById(<your item id>).asListItem();
      var hotelList = form.getItemById(<your item id>).asListItem();
    
    
      var ss = SpreadsheetApp.getActive();
      var agents = ss.getSheetByName("Agents");
      var hotels = ss.getSheetByName("Hotels");
    
      // get the values in the first column accept header row 1
      var agentValues = agents.getRange(2, 1, agents.getMaxRows() - 1).getValues();
      var hotelValues = hotels.getRange(2, 1, hotels.getMaxRows() - 1).getValues();
    
      var agentNames = [];
      var hotelNames = [];
    
      // convert 2D to 1D array and ignore empty cells
      for(var i = 0; i < agentValues.length; i++) {  
        if(agentValues[i][0] != "") {
          agentNames[i] = agentValues[i][0];
        }
      }
    
      for(var i = 0; i < hotelValues.length; i++) {
        if(hotelValues[i][0] != "") {
          hotelNames[i] = hotelValues[i][0];
        }
      }
    
      // populate the list
      agentList.setChoiceValues(agentNames);
      hotelList.setChoiceValues(hotelNames);
    }
    

    您还可以将此功能链接到电子表格编辑/更改事件,以使列表自动更新。

    【讨论】:

    • 所以我不确定我应该将这个脚本复制到哪里,以便填充我的 Google 表单。那么工作表ID呢?谢谢。
    • @monchai 如何从表单中获取项目 ID?而不是
    • 做一些研究我认为@monchai 是引用应用程序脚本developers.google.com/apps-script/quickstart/docs
    【解决方案2】:

    您请求的功能当前不存在。将 Google 的表单链接到电子表格的功能请求将是您保持两者同步的最佳选择。

    始终可以选择使用此处概述的 URL 参数创建表单:https://docs.google.com/support/bin/answer.py?hl=en&answer=160000

    【讨论】:

      猜你喜欢
      • 2014-01-27
      • 1970-01-01
      • 1970-01-01
      • 2016-03-21
      • 1970-01-01
      • 2017-08-17
      • 1970-01-01
      • 1970-01-01
      • 2011-11-21
      相关资源
      最近更新 更多