简体   繁体   中英

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();

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

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. 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? Thanks!

You can use UiApp in spreadsheet. 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));
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM