是否可以在GUI中为日期和时间添加选择器框?
如果没有,是否可以将两个变量(一个用于日期(选择器),另一个用于时间(数字))组合成一个变量以用作日历的开始时间变量?
谢谢!
答案 0 :(得分:3)
这是一个使用listBoxes test it in a spreadsheet(make a copy to use)
的工作解决方案function listBoxVersion() {
var app = UiApp.createApplication().setTitle('Time Picker');
var main = app.createGrid(2, 4);
var date = app.createDateBox().setName('date');
var hour = app.createListBox().setName('hour').setWidth('100');
var min = app.createListBox().setName('min').setWidth('100');
for (h=0;h<24;++h){
if(h<10){var hourstr='0'+h}else{var hourstr=h.toString()}
hour.addItem(hourstr)
}
for (m=0;m<60;++m){
if(m<10){var minstr='0'+m}else{var minstr=m.toString()}
min.addItem(minstr)
}
var button = app.createButton('validate')
main.setWidget(0,0,app.createLabel('Choose Date')).setWidget(0,1,app.createLabel('Choose Hours')).setWidget(0,2,app.createLabel('Choose minutes'))
main.setWidget(1,0,date).setWidget(1,1,hour).setWidget(1,2,min)
main.setWidget(1,3,button)
var handler = app.createServerHandler('show').addCallbackElement(main)
button.addClickHandler(handler)
app.add(main)
ss=SpreadsheetApp.getActive()
ss.show(app)
}
function show(e){
ss=SpreadsheetApp.getActive()
ss.getRange('A1').setValue(Utilities.formatDate(e.parameter.date,'GMT+02:00','MMM-dd-yyyy')+' @ '+e.parameter.hour+':'+e.parameter.min)
var date = new Date(e.parameter.date);
date.setHours(e.parameter.hour,e.parameter.min,0)
ss.getRange('A2').setValue(date)
}
编辑:,这是另一个普通textBox的版本:( the same test sheet中提供)
function textVersion() {
var app = UiApp.createApplication().setTitle('Time Picker');
var main = app.createGrid(2, 4);
var date = app.createDateBox().setName('date');
var hour = app.createTextBox().setName('time').setWidth('150');
var button = app.createButton('validate')
main.setWidget(0,0,app.createLabel('Choose Date')).setWidget(0,1,app.createLabel('Enter Hours:minutes'))
main.setWidget(1,0,date).setWidget(1,1,hour);
main.setWidget(1,3,button)
var handler = app.createServerHandler('show2').addCallbackElement(main)
button.addClickHandler(handler)
app.add(main)
ss=SpreadsheetApp.getActive()
ss.show(app)
}
function show2(e){
ss=SpreadsheetApp.getActive()
var time = e.parameter.time.split(':')
var hour = time[0]
var min = time[1]
ss.getRange('A1').setValue(Utilities.formatDate(e.parameter.date,'GMT+02:00','MMM-dd-yyyy')+' @ '+hour+':'+min)
var date = new Date(e.parameter.date);
date.setHours(hour,min,0)
ss.getRange('A2').setValue(date)
}