我使用列表框进行此操作,但是现在我想将其更改为文本框,并且不断收到错误消息:“遇到错误:无法从未定义中读取属性“ 1”。我不确定这个问题。我使用了与列表框相同的代码,并对其进行了调整。我需要帮助来解决问题,并且想知道我是否走错了路。
编辑-错误发生率
当我在表格上输入引用Google电子表格的学生证编号时,发生错误。当我按Enter键时,出现错误,并且没有任何内容自动填充我已设置的其他字段。
表单构建(部分)
//Create the form elements
//Set DateBox to Today's Date
var date = new Date()
var txtDate = app.createTextBox().setName("txtDate").setId("txtDate").setValue(Utilities.formatDate(date, 'America/New_York', 'MM/dd/yyyy | hh:mm a')).setReadOnly(true).setEnabled(false).setStyleAttributes(lockedStyle);
var lblStudentNumber = app.createLabel('Student ID#:');
var hdlStudentInfo = app.createServerHandler('getStudentInfo').addCallbackElement(vrtMainPanel);
var lbxStudentInfo = app.createTextBox().setId('lbxStudentInfo').setName('lbxStudentInfo').addChangeHandler(hdlStudentInfo).addChangeHandler(alertHideHandler);
// var txtStudentNumber = app.createTextBox().setName("txtStudentNumber").setId("txtStudentNumber").setReadOnly(false).setEnabled(true).setStyleAttributes(normalStyle);
var lblStudentName = app.createLabel('Student Name:');
var txtStudentName = app.createTextBox().setName("txtStudentName").setId("txtStudentName").setText("Student Name").setReadOnly(true).setEnabled(false).setStyleAttributes(lockedStyle);
getStudentInfo函数
function getStudentInfo(e){
var spSheet = SpreadsheetApp.openById('1OhR5i8B89uK7XXW2Izdzim0LSngSr6KQPqL5ToeZTbo');
var spStudentList = spSheet.getSheetByName('Schedule');
var lstStudentID = spStudentList.getRange(2,1,spStudentList.getLastRow(),18).getValues();
var app = UiApp.getActiveApplication();
// var currTime = new Date();
// var formattedTime = Utilities.formatDate(currTime,"hh:mm a");
var txtStudentName = app.getElementById('txtStudentName');
var txtTeacherName = app.getElementById('txtTeacherName');
// var txtExt = app.getElementById('txtExt');
var txtEmail = app.getElementById('txtEmail');
var txtPeriod = app.getElementById('txtPeriod');
var txtSubject = app.getElementById('txtSubject');
txtStudentName.setText(lstStudentID[e.parameter.lbxStudentInfo][1] + " " + lstStudentID[e.parameter.lbxStudentInfo][2]);// sets Student's Name
txtPeriod.setText("1st Period");// sets Period
txtSubject.setText(lstStudentID[e.parameter.lbxStudentInfo][6]);// sets Subject
txtTeacherName.setText(lstStudentID[e.parameter.lbxStudentInfo][7]);// sets Teacher's Name
txtEmail.setText(lstStudentID[e.parameter.lbxStudentInfo][8]);// sets Email
// txtExt.setText(lstStudentID[e.parameter.lbxStudentInfo][1]);// sets Ext
return app;
}