Skip to main content

Adding custom Menu items to Spreadsheet

You have written your first Apps Script and it runs perfectly from the script editor, good job so far. But did you know you can add custom menu items to your Spreadsheet? I briefly explained this in the post "Add / Delete Calendar event with Google Apps Script" and I will explain further here how the method responsible for adding menu works with an example script.

This guide will take approximately 5 minutes to go through and try out. It is divided into 3 sections
  • Section 1: Method addMenu from Class Spreadsheet
  • Section 2: Example script
  • Summary

Section 1: Method addMenu from Class Spreadsheet

For everything Spreadsheet, the spreadsheet class is responsible for almost all; from adding collaborators to setting the timezone.

addMenu is the method responsible for creating new menu in the Spreadsheet UI. addMenu takes two arguments:
  1. menuName: This is the name you want to give to the menu and with the data type being a string
  2. menuEntries: This is an array containing items in the menu. The fields "name" and "functionName" represents the menu options

Section 2: Example script

The example script is taken from the post Add / Delete Calendar event with Google Apps Script (line 67 - 71 in the example code). Lets analyze the script below which will add our menu items to a Spreadsheet UI when run.


The Array menuEntries contains the entries we want to create. The element in the Array defines the text to be displayed in the menu entry and the function to run when a user clicks on the menu entry. To add the menu, you need to specify a name for the menu and a menuEntries Array.


Summary

Now that was very simple and straight forward. You can add and make your script do more complex things such as automatically executing the script to load the menu items every time the Spreadsheet is loaded by a user without having to open the Script Editor.

Comments

  1. Nice , on it for some automation work am working on :-)

    ReplyDelete

Post a Comment

Popular posts from this blog

EC isn't prepared to take technology to the next level in Elections

In Election 2012, Ghana's EC introduces a new process to verify voters before they are allowed to cast their vote. This was in the form of biometric verification, a good idea but poorly not so well implemented.

Be a part of the experience, and make sure your Polling Station is represented on Google Maps!

Excited to see the number of polling stations that have been mapped by Ghanaian voters. It is validation of the belief in the internet’s role in helping to ensure that the 2012 elections will be the best ever held in Ghana.