Created
May 31, 2023 11:37
-
-
Save vikytech/531f1ed1a333c94447541190137d7ed9 to your computer and use it in GitHub Desktop.
Google app script to convert google sheet to google form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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