[英]Google Apps Script for Spreadsheet date input using date picker
I have a Google Apps Script function for a spreadsheet that asks the user to input a string using Browser.inputBox(); 我有一个电子表格的Google Apps脚本功能,要求用户使用Browser.inputBox()输入字符串;
I need to add another pop-up to the script that also asks for a date, and preferably uses a date picker and returns the date in date format. 我需要在脚本中添加另一个弹出窗口,该弹出窗口也要求输入日期,最好使用日期选择器并以日期格式返回日期。
I found this page: 我找到了这个页面:
https://developers.google.com/apps-script/reference/ui/date-picker https://developers.google.com/apps-script/reference/ui/date-picker
but I couldn't figure out how to get the date picker into my spreadsheet script because it seems to only be for UiApp applications. 但我无法弄清楚如何将日期选择器放入我的电子表格脚本中,因为它似乎只适用于UiApp应用程序。 Is it possible to integrate a datepicker into a spreadsheet pop-up?
是否可以将日期选择器集成到电子表格弹出窗口中?
If not, what's the best way to get a string of the date from the user using a Browser.inputBox() (such as "6/26/13" or "1/1/12") and convert it to a date? 如果没有,使用Browser.inputBox()(例如“6/26/13”或“1/1/12”)从用户获取日期字符串的最佳方法是什么,并将其转换为日期? Thanks!
谢谢!
You can use UiApp in spreadsheet. 您可以在电子表格中使用UiApp。 Here is an example but you could also have a look at this other post I answered a few minutes ago...
这是一个例子,但你也可以看看我几分钟前回答的这篇文章 ......
in its simplest form it goes like that : 最简单的形式是这样的:
function datePicker() {
var sh = SpreadsheetApp.getActiveSpreadsheet();
var app = UiApp.createApplication().setHeight('250').setWidth('200');
var panel = app.createVerticalPanel();
var dateBox = app.createDateBox().setName("dBox");
var button = app.createButton('submit');
var handler = app.createServerHandler('getDate');
handler.addCallbackElement(panel);
button.addClickHandler(handler);
panel.add(dateBox).add(button);
app.add(panel);
sh.show(app);
}
function getDate(e){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
sheet.getRange('A1').setValue(new Date(e.parameter.dBox));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.