Next: Google Apps Script – Building a Simple GUI

Google Apps Script – Building a Simple GUI


 
/*
* This script was used in the video tutorial
* Learn how to create UI in Apps Script
*
*/
function showDialog() {
  // create a new application
  var app = UiApp.createApplication();
  app.setTitle("My Application");
  // create panels, text boxes and widgets
  var panel = app.createVerticalPanel();
  var textBox = app.createTextBox();
  textBox.setName('myTextBox').setId('myTextBox');
  var button = app.createButton('Submit');
  // add widgets to panels
  panel.add(textBox);
  panel.add(button);
  // create handler to respond to events
  var clickHandler = app.createServerClickHandler("respondToSubmit");
  button.addClickHandler(clickHandler);
  clickHandler.addCallbackElement(panel);
  // assemble everything in app
  app.add(panel);
  var doc = SpreadsheetApp.getActive();
  // show the app
  doc.show(app);
  
}

// this function responds to submit button
function respondToSubmit(e) {
 var app = UiApp.getActiveApplication();
 // get the value of the text box
 var textBoxValue = e.parameter.myTextBox;
 // put data into the spreadsheet
 var sheet = SpreadsheetApp.getActiveSheet();
 var lastRow = sheet.getLastRow()+1;
 var lastCell = sheet.getRange("A"+lastRow);
 lastCell.setValue(textBoxValue);
 // close the dialog box
 return app.close();
  
} 
 
The link of the original article is here
Questo sito utilizza cookies anche di terze parti. Scorrendo questa pagina acconsenti all’uso dei cookie. Se vuoi saperne di più leggil'informativa estesa.Ok, ho capito