Rac*_*elW 2 javascript google-apps-script
寻找一点帮助我几乎在那里,但我知道我只是缺少一件事,我一直在寻找答案.
我有一个电子表格,其中一列有第一个名字,第二列有姓氏,我正在尝试加入它们并在列表框中以全名显示.现在,它会逐字逐字地填充值,第一列为值,第二列为值.任何帮助,将不胜感激!
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;
}
Run Code Online (Sandbox Code Playgroud)
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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26719 次 |
| 最近记录: |