[Automatic Creation of Google Form from Tables]
A short introduction to the issue
If you've ever had to create tests or surveys in Google Forms and edit them manually, you're familiar with the pain of doing useless work.
Now, imagine a situation where you need to create several tests with more than 100 questions. I encountered a similar task and remember how I sat for several days clicking the same button, wondering if it'd be easier to copy and paste small texts or quickly type them.
Market review and solutions
To avoid wasting time on routine work, I began looking for a solution and found plug-ins for Google Forms, but they didn't have all the functions I needed for flexible use and weren't free.
The closest plug-in I could find to my expectations was Form Builder, but after trying it, I understood it wasn't right for what I wanted to do. I'll skip ahead to this plug-in's downsides and explain the problems I encountered.
I expected that creating a form from my spreadsheet would require one or two steps on my part, but Form Builder complicates the process, and you need time and video instructions to understand the tool. The second downside was the limitations of the free version I was using. After finally figuring out the navigation, I launched the process, but I could only import a limited number of questions with the free version. The third downside is connected with data collection. In addition to access to spreadsheets and forms, the plug-in required other data and permission for various messages, which I obviously didn't want to give.

Solution
I became convinced there were no solutions for my situation but eventually found that you can build this type of automation in Script Editing in almost any Google instrument.

I'll explain how, in 3 steps, you can create Google forms with scripts, and I'll also give you a ready-to-go option you can use to reduce time and useless work.
Description
Let's go back to my case. Imagine that you need to create a survey with different types of questions. Each of them has a different description and several options for answers. A few questions won't require much time, but imagine that you have 40, 50, or 100 questions to work with, and this task immediately goes from simple to unpleasant.
Implementation
Step 1: Create the spreadsheet
The most important thing to do in this process is to put your questions in a spreadsheet. I've always found spreadsheets make managing questions easier because you can see all of them, make filters for any field, copy information, and invite others to comment and edit if necessary.
I've prepared an example spreadsheet that already has questions and answer options. I also indicated the type of question, wrote a description, and divided the questions into sections.
- Sections – the name of the questions group
- Question type – type of question. Could be: Multiple choice, short answer, checkboxes
- Questions – question
- Descriptions – Description of the question
- Answer 1 – answer options. Can add more if necessary
**You can copy my spreadsheet and complete it with your information. Before moving to the next step, check that your spreadsheet is completely ready for publication.
Step 2: Create a survey
When your spreadsheet is ready, you need to launch the script. Go to the menu and open the editor: Extensions → Apps Script.
Another page should open for editing scripts, such as in the example below.

**If you've copied my spreadsheet, then you'll already find a script on this page and you can launch it by clicking the button Run and go to step 3.
If you don't have the script, then you need to copy this one and add it to the editing window:
function newtForm()
{
var ss = SpreadsheetApp.getActive();
// use the active spreadsheet
var sheet = ss.getActiveSheet();
// use the active sheet
var name = ss.getName();
// use the name of the current sheet
var numberRows = (sheet.getDataRange().getNumRows()) - 1; //-1, because it’s an array
var numberColumns = (sheet.getDataRange().getNumColumns())-1;
// getting the number of filled rows and columns in the active sheet
var sections = sheet.getRange(2,1,numberRows,1).getValues();
//values of the sections
var types = sheet.getRange(2,2,numberRows,1).getValues();
//question types
var questions = sheet.getRange(2,3,numberRows,1).getValues();
// questions
var descriptions = sheet.getRange(2,4,numberRows,1).getValues();
// question description
var answeroptions = sheet.getSheetValues(2,5,numberRows,numberColumns-3);// I have reduced 3: sections, types, question
//answer options
var form = FormApp.create(name);
//create a new form with the same Title as the spreadsheet
for (var i=0; i < numberRows; i++) // the number of Rows is the same number of questions
{
if (sections[i] != '')
{
var addsec = form.addSectionHeaderItem(); //add a new section if the cell isn't empty
addsec.setTitle(sections[i]);
}
if (types[i] == 'Multiple choice') //if question type is Multiple choice
{
var item = form.addMultipleChoiceItem(); //add Multiple choice type question
item.setTitle(questions[i]);
item.setChoiceValues(answeroptions[i]);
item.setHelpText(descriptions[i]);
item.setRequired(true);
}
if (types[i] == 'Short answer') //if question type is Short answer
{
var item = form.addTextItem();
item.setTitle(questions[i]);
item.setHelpText(descriptions[i]);
item.setRequired(true);
}
if (types[i] == 'Checkboxes') //if question type is Checkboxes
{
var item = form.addCheckboxItem();
item.setTitle(questions[i]);
item.setChoiceValues(answeroptions[i]);
item.setHelpText(descriptions[i]);
item.setRequired(true);
}
} //completion of all question creation iterations
} //closing the function
Now, click Save and launch the script by clicking Run.
Step 3: Enjoy the result
After launching the script, a dialogue window should appear with a request for giving permission to this project to make chances. If this window appears, give it permission to create a new form on your Google Drive. After that, the following messages will appear:

And the form is ready! Open Google Drive and your form will be waiting. You can edit the form as you want.
**When running the script the first time, there may be an error. In this case, just click Run again, and everything will start to work.
Conclusions
As you can see in the example, this approach requires minimal effort but provides flexibility when completing routine tasks.
If you want to know how to write scripts, then check out the documentation from Google below: