![](/img/trans.png)
[英]How can I populate multiple choice questions in a Google Form from data within a Google Sheet
[英]Is it possible to export questions and multiple choice options from a Google Form to a Google Sheet?
我們有一系列包含多項選擇題的 Google Forms,每題都有 4 個可能的答案。
我希望能夠針對該 Google 表單中的所有問題和答案將問題和所有可能的答案導出到 Google 表格。
例如:
Q1:英格蘭的首都是哪里?
我嘗試了各種插件。 有一些負載允許 Google Sheets > Google Form,但沒有反向(我可以找到),所以我認為它會是某種腳本。
任何幫助將非常感激。
謝謝。 利亞姆。
在我使用 Apps Script 編寫的以下代碼中,您可以找到一種從 Google 表單中提取問題和答案的方法,然后將值放入您選擇的某個表格中
// Open a form by ID.
var form = FormApp.openById('YOUR-FORM-ID');
// Open a sheet by ID.
var sheet = SpreadsheetApp.openById('YOUR-SHEET-ID').getSheets()[0];
// variables for putting the questions and answers in the right position
var question_position = 0;
var answers_position = 0;
// main function to run
function getFormValues() {
form.getItems().forEach(callback);
}
// Iterate over all questions
function callback(el){
// check if the question is multiple choice
if (el.getType() == FormApp.ItemType.MULTIPLE_CHOICE) {
// change the type from Item to MultipleChoiceItem
var question = el.asMultipleChoiceItem();
var choices = question.getChoices();
// set the title of the question in the cell
sheet.getRange(question_position +1, 1).setValue(question.getTitle());
var i = 0;
// set the answers in the right cells
for (i; i < choices.length; i++){
sheet.getRange(answers_position + 1, 2).setValue(choices[i].getValue());
answers_position++;
}
question_position += i;
answers_position++;
}
question_position++;
}
如果您想知道我從哪里得到所有這些信息,您可以查看以下兩個鏈接:
我遇到了與您處理的幾乎相同的問題,我為自己的目的創建了一個帶有文檔的小腳本,但我認為它可以幫助您了解如何檢索信息。
您需要了解這兩個 API: https://developers.google.com/apps-script/reference/forms (表單)和https://developers.google.com/ )
然后,我會檢查如何通過 API 將其發布到 Google 表格中。
檢查您是否設置了所有權限。
這似乎需要一個 Apps Script 插件或手動開發的 Apps-Script 腳本。 嘗試尋找自由職業者或同事為您構建它。
表格是最容易使用的: https://developers.google.com/apps-script/reference/spreadsheet/
我需要一個腳本來將一些 Google Forms 轉換為 GIFT Moodle 格式。 我修改了@alberto-vielma 腳本以獲取帶有 Moodle GIFT 格式的問題和選擇的電子表格。
只需將電子表格中的值復制並粘貼到文本文件中即可導入 Moodle。
// Open a form by ID.
var form = FormApp.openById('YOUR-FORM-ID'); // YOU GET IT FROM THE URL
// Open a sheet by ID.
var sheet = SpreadsheetApp.openById('YOUR-SPREADSHEET-ID').getSheets()[0];
// variables for putting the questions and answers in the right position
// Change this number to the line you want the question starts
var question_position = 1;
// main function to run
function getFormValues() {
form.getItems().forEach(callback);
}
// Iterate over all questions
function callback(el){
// check if the question is multiple choice
if (el.getType() == FormApp.ItemType.MULTIPLE_CHOICE) {
// change the type from Item to MultipleChoiceItem
var question = el.asMultipleChoiceItem();
var choices = question.getChoices();
// set the title of the question in the cell
var qRange = sheet.getRange(question_position++, 1);
qRange.setValue(question.getTitle() + " {");
var i = 0;
// set the answers in the right cells
for (i; i < choices.length; i++){
var choiceRange = sheet.getRange(question_position++, 2);
var current = choices[i];
var prefix = current.isCorrectAnswer() ? "'=" : "~";
choiceRange.setValue(prefix + current.getValue());
}
var qRangeEnd = sheet.getRange(question_position++, 1);
qRangeEnd.setValue("}");
question_position ++;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.