Skip to content

Instantly share code, notes, and snippets.

@vikytech
Created May 31, 2023 11:37
Show Gist options
  • Save vikytech/531f1ed1a333c94447541190137d7ed9 to your computer and use it in GitHub Desktop.
Save vikytech/531f1ed1a333c94447541190137d7ed9 to your computer and use it in GitHub Desktop.
Google app script to convert google sheet to google form
function convertSheetToForm() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getActiveSheet();
var data = sheet.getDataRange().getValues();
var form = FormApp.create(sheet.getName()).setTitle(sheet.getName());
const items = form.getItems();
items.forEach(function (item) {
form.deleteItem(item.getIndex());
});
data.forEach(function (section) {
var formSection = form.addPageBreakItem()
section.forEach(function (question, index) {
if (index == 0) formSection.setTitle(question);
else {
if (question != "") form.addParagraphTextItem().setTitle(question);
}
});
});
SpreadsheetApp.getUi().alert(form.getPublishedUrl());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment