问题
I have created a Google Form that has not yet been published. I would like to extract all of the form's items, item types, and item choices (as applicable) for use in a mail merge. I can't use the Response spreadsheet, created by Google, because the form's users may not select all of the available choices for a given item.
My script functions adequately, except when trying to write the choices of a checkbox (or multiple-choice question or grid question) to the spreadsheet. When using the "getChoice" method, my spreadsheet shows an array of cells "={"Choice","Choice","Choice"}." It shows the word "Choice" over and over, instead of the actual choice that has been created on my form.
How can I write the actual choices to my spreadsheet, instead of the word "Choice" in an array? I am a javascript noob, so my apologies for any inelegant coding!
function extractForm() {
var existingform = FormApp.openByUrl('https://docs.google.com/a/forms/d/fc/viewform');
var items = existingform.getItems();
var itemcount = existingform.getItems().length
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
for (var i = 1; i <= itemcount; ++i) {
if (items[i].getType() != 'PAGE_BREAK' && items[i].getType() != 'SECTION_HEADER') {
sheet.getRange(i,1).setValue(i);
sheet.getRange(i,2).setValue(items[i].getTitle());
sheet.getRange(i,3).setValue(items[i].getType());
};
if (items[i].getType() == 'CHECKBOX') {
var chkItem = items[i].asCheckboxItem();
var choicecount = chkItem.getChoices().length
for (var j = 1; j <= choicecount; ++j) {
sheet.getRange(i,4,1,j).setValue(chkItem.getChoices());
};
};
};
};
回答1:
Shouldn't you simply get the array elements values like that ?
for (var j = 1; j <= choicecount; ++j) {
sheet.getRange(i,4,1,j).setValue(chkItem.getChoices()[j].getValue());
};
来源:https://stackoverflow.com/questions/17127393/extract-checkbox-or-multiple-choice-choices-from-a-google-form-that-already-exis