2

寻找一点帮助我几乎就在那里,但我知道我只是错过了一件事,我一直在寻找答案。

我有一个电子表格,其中 1 列具有名字,第二列具有姓氏,我正在尝试加入它们并在列表框中以全名显示。现在它按字母水平填充值,第一列值,然后是第二列值。任何帮助,将不胜感激!

function studentBox(e) {
  var app = UiApp.getActiveApplication();

  var dateSelect = e.parameter.dateList;

  var ss = SpreadsheetApp.openById('spreadsheetID');
  var sheet = ss.getSheetByName(dateSelect);

  var studentList = app.createListBox().setName('studentList').setId('studentList');
  var cellList = sheet.getLastRow();
  var fName = sheet.getRange(1,1,cellList,1).getValues();
  var lName = sheet.getRange(1,2,cellList,1).getValues();
  var fullName = (fName+ " " +lName);


  //Add items to the list box
  for(var i=0; i<fullName.length; i++){
    studentList.addItem(fullName[i]);
  }

  app.getElementById('grid1').setWidget(1,1,studentList);




  return app;

}
4

1 回答 1

5

fName并且lName是值的矩阵。您不能像这样对它们进行求和/连接。这里的修复:

function studentBox(e) {
  var app = UiApp.getActiveApplication();
  var dateSelect = e.parameter.dateList;

  var ss = SpreadsheetApp.openById('spreadsheetID');
  var sheet = ss.getSheetByName(dateSelect);

  var studentList = app.createListBox().setName('studentList').setId('studentList');
  var cellList = sheet.getLastRow();
  var names = sheet.getRange(1,1,cellList,2).getValues(); //getting both first and last names at once

  //Add items to the list box
  for(var i=0; i<names.length; i++){
    studentList.addItem(names[i][0]+' '+names[i][1]);
  }

  app.getElementById('grid1').setWidget(1,1,studentList);
  return app;
}
于 2013-03-28T18:05:34.317 回答