简体   繁体   English

使用日期选择器输入Google Apps脚本的电子表格日期

[英]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.

相关问题 HTMLService / Google Apps脚本中的日期选择器 - Date picker in HTMLService / Google Apps Script 如何在 Google Apps 电子表格脚本中将日期和时间合并为日期时间? - How to merge date and time as a datetime in Google Apps Spreadsheet script? 使用Google Apps脚本将最新日期(从API)分配给标识符(在电子表格中) - Assign latest date (from API) to identifier (in spreadsheet) using Google Apps Script 在今天的日期应用脚本之前删除电子表格中的日期 - delete date in spreadsheet prior today's date apps script 如何在 HTMLService/Google Script/Sheet 中使用日期选择器返回值? - How to return a value using Date picker in HTMLService / Google Script / Sheet? Google Sheet Script - 日期差异 - 当前日期() - 电子表格中的日期() - Google Sheet Script - Date Difference - Current Date() - Date() in spreadsheet 根据电子表格中的值在自定义日期和时间触发基于 Google Apps 脚本时间的触发器 - Google Apps Script Time based trigger at custom date and time based on value in spreadsheet 从导入日期来自电子表格创建Google日历事件时出现setHours()错误 - Apps脚本 - setHours() Error when Creating a Google Calendar Event from Imported Date Coming From Spreadsheet - Apps Script Google Spreadsheet Script-获取日期作为数字 - Google Spreadsheet Script - get Date as number Google Apps脚本-使用replaceText转换日期格式 - Google Apps Script - Using replaceText to convert date format
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM