Code in Google Sheets

Do you know that Google Sheets offers scripting?

Under Tools -> Script editor You can simply write your own JavaScript code to improve your sheet.

The easiest way to fire function is to create custom menu. You just need to type in script editor following code:

function onOpen() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('First custom menu')
      .addItem('Fire alert function', 'alertFunction')

This function will be fired after document’s open. It creates custom menu option with one item which will fire ‘alertFunction’. Let’s define this function.

function alertFunction() {
   SpreadsheetApp.getUi().alert('You just implemented you first function in GSuite! Congratulations!');

Cooperating with UI is not the only thing we can do by scripts.

Google offers us much more functionalities like operating with sheet data:

function getFirstCellValue() {
   var firstCellValue = SpreadsheetApp.getActiveSheet().getRange('A1').getValue();

Sending emails:

function sendEmail() {
   var emailAddress = '';
   var subject = 'Subject';
   var message = 'Welcome message';
   MailApp.sendEmail(emailAddress, subject, message);

Emails will be send from our gmail account.

In your scripts you can use all JavaScript features. In my opinion - it’s very important that we don’t need to learn another syntax - just code!

For more information visit Official documentation.

Hope you enjoy this post. If You have any questions or problems leave a comment or send email.

See You soon!

Written on October 7, 2017