设置Google Form多项选择网格项中的列选择?

问题描述 投票:0回答:3

我一直在努力获取正确的代码来设置Google Form Multi Choice Grid中的Column Choices。我的代码不断给我调试错误

TypeError:在对象Item中找不到函数setColumns。 (第26行,“人口危险选择”文件。)

我已经尝试过setColumnChoices和setColumns,而且看起来也有同样糟糕的结果。

function PopulateHazardChoices(){

// call the form and connect to the Question Item
  var form = FormApp.openById("FakeFormID");  
  var QuestionItem = form.getItemById("fakeItemID");

// identify the sheet Hazard Choices needed to populate the question selections
  var ss = SpreadsheetApp.getActive();
  var DataFactors = ss.getSheetByName("DataFactors");

// grab the Hazards in the first column of the sheet from the Group of Hazard Choices
  // use sheet Row Number for First Hazard in the group of choices; use 1 as the index column A; number of rows included in range
  // 7,1,3 would be Row 7, Column A, 4 rows in the range - therefore A7 through A10

  // [Conditions of Runway] Hazard Group
  var HazardValues = DataFactors.getRange(7,1,4);
  var HazardSelections = [];

// convert the array ignoring empty cells
  for(var i = 0; i < HazardValues.length; i++)    
    if(HazardValues[i][0] != "")
      HazardSelections[i] = HazardSelections[i][0];

// populate the Wind Question with the array data
  QuestionItem.setColumns(HazardSelections);
}  

该计划是从名为“ DataFactors”的工作表中填充网格列,以便对危险列表进行的任何更改都将在表单上完全相同。当用户提交表单时,将选择内容与工作表进行比较,并分配一个点值。希望这将解决表格提交和危险值之间的比较不正确的问题。使用下拉列表取得了不错的效果,但似乎无法使该方法适用于“多选网格”。

google-apps-script google-sheets google-form
3个回答
0
投票
function PopulateHazardChoices(){ // call the sheet and form needed to populate the question selections var ss = SpreadsheetApp.getActive(); var DataFactors = ss.getSheetByName("RiskValues"); var form = FormApp.openById("FakeFormID"); // For each Group of Hazard Choices - repeat the folowing // identify the Hazards in Column A of the sheet for each Group of Hazard Choices // Use Row Number for First Hazard in the Group of Harard Choices // Use 1 as the index Column A // Number of rows included in the Group // 2,1,3 would be Row 2, Column A, 3 rows in the range - therfore A2 through A4 //declare QuestionItem including type of item i.e. .asGridItem(); // populate the Question with the array data // Crew Compliment - Hazard Group A3 through A5 var HazardValues = DataFactors.getRange(3,1,3).getValues(); var QuestionItem = form.getItemById("FakeItemID").asGridItem(); QuestionItem.setColumns(HazardValues); //End of Hazard Group // pAve Rotorcraft - Hazard Group A40 through A43 var HazardValues = DataFactors.getRange(40,1,4).getValues(); var QuestionItem = form.getItemById("FakeItemID").asCheckboxGridItem(); QuestionItem.setColumns(HazardValues); //End of Hazard Group // paVe Runway Length - Hazard Group A72 through A75 var HazardValues = DataFactors.getRange(72,1,4).getValues(); var QuestionItem = form.getItemById("FakeItemID").asMultipleChoiceItem(); QuestionItem.setChoiceValues(HazardValues); //End of Hazard Group } //End function PopulateHazardChoices // Edit Journal - Created December 2019, Jack Gainer, TSTC Chief Pilot // Initial Implentation Tests - January 2019 // Add remaiining Hazard Group setValues code - February 2019

0
投票
var form = FormApp.openById('MyForm'); var PtjGridList = form.getItemById("MyGridItem Eg.4158415230").asGridItem(); var ss = SpreadsheetApp.openById("MySpreadsheet"); var PtjNombre = ss.getSheetByName("MySheet"); var RowValues = PtjNombre.getRange(2, 5, PtjNombre.getMaxRows() - 1).getValues(); var ValuesRow = []; for(var i = 0; i < sheetValues.length; i++) if(RowValues[i][0] != "") ValuesRow[i] = RowValues[i][0]; PtjGridList.setRows(ValuesRow) var ColumnValues = PtjNombre.getRange(2, 6, PtjNombre.getMaxRows() - 1).getValues(); var ValuesColumn = []; for(var i = 0; i < sheetValues.length; i++) if(ColumnValues[i][0] != "") ValuesColumn[i] = ColumnValues[i][0]; PtjGridList.setColumns(ValuesColumn)

希望有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.