我正在尝试使用google工作表中的问题填充谷歌表单。目前,当我运行我的代码时,我正在创建问题,但只有25%左右实际上有字符串,其余的只是空白。每次运行脚本时出现的问题都会正确更改。它似乎是随机的。
function formPopulation() {
var ss = SpreadsheetApp.openById("--");
var sheet = ss.getSheetByName('Tracker');
var auditTool = ss.getSheetByName('Audit Tool');
var validatorInfo = ss.getSheetByName('Validator Info');
//Sheet Info
var rows = auditTool.getLastRow(); //Number of Rows
var columns = auditTool.getLastColumn(); //Number of Columns
var startRow = 1;
var startColumn = 1;
var dataRange = auditTool.getRange(startRow, startColumn, rows, columns);
//getRange(first row of data, first column of data, last row of data, last column of data)
var data = dataRange.getValues();
//Sets working range of script
var form = FormApp.openById("--");
var item = form.addListItem();
var entityName = "";
var arrayOfEntities = [];
var newEntity = '';
for (var i = 4; i < columns; i++) {
//4 because that is where entity names begin
entityName = data[i][2];
Logger.log('entityName: ' + entityName);
newItem = item.createChoice(entityName);
arrayOfEntities.push(newItem);
};
item.setTitle("Select Entity").setChoices(arrayOfEntities);
var requirement = "";
var arrayOfRequirements = [];
var newRequirement = '';
for (var j = 5; j < rows; j++) {
//5 because that is where Requirements begin
if (data[0][j] != null) {
requirement = data[0][j];
if (requirement != "" || requirment != null){
requirement = "question #" + j;
Logger.log('requirement: ' + requirement);
form.addMultipleChoiceItem().setTitle(requirement).setChoiceValues(['Complete', 'Incomplete']);
};
};
};
};
第一个问题应该是一个多选项,其中每个“实体”都是一个选项。问题的其余部分应该是每个“要求”是否标记为完整或不完整。 Here is the spreadsheet I am working from
答案 0 :(得分:1)
应该是'要求'
答案 1 :(得分:0)
这里是最后一个forloop
requirement =“question#”+ j;
请验证,可以吗?或者你应该使用
requirement =“question#”+ j +''+ data [0] [j];