日期和时间选择器Google App脚本 [英] Date AND Time picker Google App Script
本文介绍了日期和时间选择器Google App脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在GUI中为日期和时间添加选择器框?如果不是,是否可以将两个变量(一个用于日期(选取器)和另一个用于时间(数字))合并为一个变量,以用作开始时间日历变量?
感谢!
解决方案
这是一个使用listBoxes的工作解决方案, )
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小时:分钟'))
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。添加(主)
ss = SpreadsheetApp.getActive()
ss.show(app)
}
函数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)
}
Is it possible to add a picker box for both Date AND Time within a GUI?
If not, is it possible to combine two variables, one for date (picker) and the other for time (number) into one variable to be used as a Start Time variable for calendar?
Thanks!
解决方案
here is a working solution using 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)
}
EDIT : and here is another version with an ordinary textBox :(available in 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)
}
这篇关于日期和时间选择器Google App脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文