Home > Back-end >  Populate Google Spreadsheet from Form using Google App Script
Populate Google Spreadsheet from Form using Google App Script

Time:06-12

I create a Google Spreadsheet and a Google Form via the Google App Script and want to get all the responses from the form automatically added to a sheet in my spreadsheet.

This option is possible if you do it manually, but I can't find an option to do it automatically in Google App Script.

I have seen some answers here on StackOverflow to populate forms from spreadsheets, but I need the inverse case.

Is that possible?

CodePudding user response:

Use Form.setDestination(), like this:

const ss = SpreadsheetApp.create('Response destination spreadsheet');
const form = FormApp
  .create('New form name')
  .setDestination(FormApp.DestinationType.SPREADSHEET, ss.getId());

CodePudding user response:

Google Forms has a setting that allows you to send your form responses to Google Sheets. This can be a new or existing spreadsheet.

In your chosen form, click on the responses tab.

  • Click on the three dots button located next to the Google Sheets icon.
  • Click on Select responses destination from the drop.
  • Select existing spreadsheet.

If you want to do it by script, as the form is already created

var form = FormApp.openById('id of the form');
form.setDestination(FormApp.DestinationType.SPREADSHEET, 'id of the spreadsheet);

destination type

  • Related