Is it possible to populate a google form from a google spreadsheet?

眉间皱痕 提交于 2019-12-04 13:08:06

Google Apps Scripts.. finally a well documented way of generating Google forms programmatically. https://developers.google.com/apps-script/reference/forms/

Yes it is. Use a Form script and update the information from the spreadsheet using a trigger on the FORM OPEN. Here is an example that gets data from two different sheets and insert data in a combo box and into a multiple choice control.

function getNewNames(){
  var form = FormApp.getActiveForm();
  var items = form.getItems();

  var ss = SpreadsheetApp.openByUrl(
     'https://docs.google.com/spreadsheets/d/YOURDOCSNAMEHERE/edit');
    var assSheet1 = ss.getSheetByName('Sheet1');
    var assValues = assSheet1.getDataRange().getValues();
    var values = assValues.slice(1);
    var valSort = values.sort();

  var ss2 = SpreadsheetApp.openByUrl(
     'https://docs.google.com/spreadsheets/d/DOCSNAMEHERE/edit');
     var playerSheet1 = ss2.getSheets()[0];
     var playerValues = playerSheet1.getDataRange().getValues(); 
     var player = playerValues.slice(0);
     var plySort = player.sort();

  var names = [];

  for(var p = 0; p < plySort.length; p++){
    names.push(plySort[p][0])
  }

  var pList = items[0].asListItem();
  pList.setChoiceValues(names).setRequired(true).setHelpText('Please Select Player Name')

  var areas = [];
  for (var i = 0; i < valSort.length; i++) {
      areas.push(valSort[i][1])
    }

  var aList = items[1].asMultipleChoiceItem();
      aList.setChoiceValues(areas).setRequired(true).setHelpText('Select Area of Assessment')

}

You may want to have a look at the FormRanger plugin. It does not populate the questions of your form, but dynamically populates the possible answers in a multiple choice questions, list or grid questions. It can even pull data out of the previous responses of the form. It can set to automatically update after each submit or every hour. Beware: if you use filter questions to redirect to different sections based on the answer to a questions, you can not use Formranger for that questions as it would break the re-directs.

There is currently a feature request for us to add a Forms API that would allow you to create, retrieve, update, and delete a form for a Spreadsheet. Although the functionality does not exist at the moment, if and when it does, you would be able to link spreadsheet data to form data using a Forms API and the Spreadsheets Data API. The feature request is here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!