Posts

Showing posts from January, 2018

Get the value of a cell in a sheet

 var varSheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("NameOfSheet");  var theVal = varSheet.getRange("A3").getValue();

Create a contact in gmail contacts

var thisContact = ContactsApp.createContact("First name", "Family Name", "theemail@gmail.com");

Debugging by logging information

Where you need to log it: Logger.log('The text you log'); To view the log, go to View->Logs. To debug a function, you can go to: Run->Debug Function->

Getting a yes/no response and text input

var userInterface = SpreadsheetApp.getUi();   var getResponse = userInterface.prompt('This is the title', 'This is the question', userInterface.ButtonSet.YES_NO);   if(getResponse.getSelectedButton() == userInterface.Button.YES)   {     Browser.msgBox("You said yes");     Browser.msgBox('You just keyed in:' + getResponse.getResponseText());   }else   {     Browser.msgBox("You said no");   }

Create a side bar

In Script editor, go to File -> New -> HTML file. Add in HTML code inside your file. function functionToShowSideBar() {  SpreadsheetApp.getUi().showSidebar(HtmlService.createHtmlOutputFromFile('NameOfHTMLFileCreated').setTitle("Hello")); } This bar will pop up at the right hand side of your sheets.

Create a submenu under Add ons

function onOpen() {   SpreadsheetApp.getUi().createAddonMenu().addItem("Show side bar", "functionToShowSideBar").addToUi();   } You use DocumentApp.getUi() if using google docs. Use SpreadsheetApp.getUi() if using google sheets.

Create a menu

Code: function makeMenu() {   DocumentApp.getUi().createMenu("Top Menu Text").addItem("Sub menu function is toastMe", "toastMe").addToUi(); } To make it load on startup, change function name to onOpen()

Popup message box

Code: Browser.msgBox("Hello!", Browser.Buttons.OK) Another popup message box is the toast, which shows up at the lower-right hand corner of the spreadsheet (this only works with sheets): SpreadsheetApp.getActiveSpreadsheet().toast("Hello", "This is the title"); If timeout seconds is set to -1, it means that the toast will be there forever. Create a modeless dialog that does not prevent you from doing other things: function showDialog() {   var html = HtmlService.createHtmlOutputFromFile('hi');   SpreadsheetApp.getUi().showModelessDialog(html, 'This is the title') }

Create a button in google sheets

Select a cell in google sheet. Insert->Drawing. Insert a textbox. Add text to it and give it an outline. Save and close. Go to Tools->Script Editor. Create a new function, for instance: function hello() { } Click on the 3 dots at the top right hand corner of the textbox you have created. Click on assign script. Assign it the name of the function - hello.

How to start writing your script

You can either write a standalone script that has less functionality: Login to your gmail account. Go to:  https://script.google.com/home Click on 'new script'. Rename the project. Change the filename. OR an integrated script that has more functionality: Login to your gmail account. Go to your documents. Click on your google app (docs, sheet, powerpoint). Go to Tools --> Script Editor. Rename the project. Change the filename.