【发布时间】:2021-10-03 22:24:15
【问题描述】:
我正在尝试将 Google 表单的问题和多项选择选项提取到 Google 表格中。我在这里找到了一个解决方案 (Is it possible to export questions and multiple choice options from a Google Form to a Google Sheet?),在 alberto vielma 的回答中(2019 年 10 月 28 日 12:06 的回答)。
但是,我在尝试 Alberto 的脚本时遇到了错误(“我们很抱歉,创建 Cloud Platform 项目时出现意外错误。错误代码 RESOURCE_EXHAUSTED。”)。
这让我很吃惊,因为几个月前我已经成功使用了这个脚本……有谁知道到底出了什么问题?
(我创建了一个新主题,因为关于回答的“提示”表明,如果我只有额外的问题,我不应该“参与”上述主题。)
为方便起见,我将在此处复制 Alberto 的脚本:
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++;
}
【问题讨论】:
-
我从电子表格创建表单。我允许用户在同一个电子表格中选择或不选择响应,并用答案填充 ss。我无法在表格中填写“简短答案”,但几乎所有其他内容都有效。 docs.google.com/spreadsheets/d/…
标签: google-apps-script google-sheets google-forms