Skip to main content

How to Write an Add-on for Google Docs

Well, it ain’t that difficult. If you know some HTML, CSS and JavaScript, you can create a Google Docs add-on.

Create a Google Add-on for Docs & Sheets

This step-by-step tutorial (download) will walk you through the process of creating your own add-on for Google Docs. The add-on used in the demo lets you insert a image of any address on Google Maps inside a Google Document without requiring any screen capture software.
Ok, lets’s get going.
Step 1. Open a new document inside Google Drive and choose Tools -> Script Editor. This is the Apps Script IDE where we’ll write the code for the add-on.
Step 2. Choose File -> New HTML to create a new HTML file inside the Script Editor and name your file as googlemaps.html (or anything you like).
Step 3. Copy-paste the following code in the HTML file and save your changes. This is the code that will be used to render the sidebar in your Google Documents.
  1. href="https://ssl.gstatic.com/docs/script/css/add-ons.css"
  2. rel="stylesheet">
  3.  
  4. class="sidebar">
  5. class="block form-group">
  6. type="text" id="search" placeholder="Enter address.. " />
  • id='maps'>
  •  
  •  
  •  
  • Step 4. Next we will write the server side JavaScript (Google Script) that will actually render the sidebar and insert Google Maps images in the document.
    1. /* What should the add-on do after it is installed */
    2. function onInstall() {
    3. onOpen();
    4. }
    5.  
    6. /* What should the add-on do when a document is opened */
    7. function onOpen() {
    8. DocumentApp.getUi()
    9. .createAddonMenu() // Add a new option in the Google Docs Add-ons Menu
    10. .addItem("Google Maps", "showSidebar")
    11. .addToUi(); // Run the showSidebar function when someone clicks the menu
    12. }
    13.  
    14. /* Show a 300px sidebar with the HTML from googlemaps.html */
    15. function showSidebar() {
    16. var html = HtmlService.createTemplateFromFile("googlemaps")
    17. .evaluate()
    18. .setTitle("Google Maps - Search"); // The title shows in the sidebar
    19. DocumentApp.getUi().showSidebar(html);
    20. }
    21.  
    22. /* This Google Script function does all the magic. */
    23. function insertGoogleMap(e) {
    24. var map = Maps.newStaticMap()
    25. .setSize(800, 600) // Insert a Google Map 800x600 px
    26. .setZoom(15)
    27. .setCenter(e); // e contains the address entered by the user
    28. DocumentApp.getActiveDocument()
    29. .getCursor() // Find the location of the cursor in the document
    30. .insertInlineImage(map.getBlob()); // insert the image at the cursor
    31. }
    Save your changes and then choose onOpen from the Run menu inside the Script editor. Authorize the script and switch to your Google Document.
    You’ll see a new Google Maps option under the Add-ons menu. Select the menu item and you’ll be able to insert maps images inside your Google Documents without using any screen capture software.

    Share your Google Add-ons with other Google Docs users

    Now that your first Google add-on is ready, you may want to distribute it to other users of Google Docs. The easiest option would be that you share your document with public and set the permission as Anyone can view. Now anyone can create a copy of your document in their own Google Drive and use your add-on.

    Popular posts from this blog

    Death of a Star! in Bollywood

    When I was flipping through my Diary 2002 the other day, my jottings about Monal’s tragic end beckoned me and brought to my mind a host of awesome nostalgic thoughts. I had a feeling of déjà vu as the dead artist again touched a chord in my heart. How would emotionally deplete artists behave when driven to wall? [Read on…] Monal, a starlet from Bollywood, hung herself to death on the Tamil New Year’s Day. A strange quirk of fate played havoc with her life, putting off her promising career of becoming an icon in the Kollywood. TV visuals showed her sleeping eternally on a bier; she was a feast to flies that were swarming her lissome body … a body that set fire to the hearts of thousands of her fans. Monal’s premature death moved me to a great extent not because she was one of the upcoming actors of the Kollywood and a diva for whom the tinsel world plumped rather madly, but because it set me thinking as to what led the young actor to kill herself savagely in the middle of her ...

    Ssc combined graduate level exam syllabus and exam detail

    q Tier-I of the Examination: General Intelligence & Reasoning : It would include questions of both verbal and non-verbal type. This component may include questions on analogies, similarities and differences, space visualization, spatial orientation, problem solving, analysis, judgment, decision making, visual memory, discrimination, observation, relationship concepts, arithmetical reasoning and figural classification, arithmetic number series, non-verbal series, coding and decoding, statement conclusion, syllogistic reasoning etc. The topics are, Semantic Analogy, Symbolic/Number Analogy, Figural Analogy, Semantic Classification, Symbolic/Number Classification, Figural Classification, Semantic Series, Number Series, Figural Series, Problem Solving, Word Building, Coding & de-coding, Numerical Operations, symbolic Operations, Trends, Space Orientation, Space Visualization, Venn Diagrams, Drawing inferences, Punched hole/pattern –folding & unfolding, Figural Pattern – folding...

    11-awesome-diwali-lighting-decoration-ideas

    Beautiful Flower Lights On Water Diwali Decoration Ideas Picture Beautiful Hanging Lighting Lanterns Diwali Decoration Beautiful Lighting Decoration For Diwali Beautiful Lighting Lamps Decoration Cool Diwali Lighting Decoration Ideas Diwali Lighting Decoration Picture Diwali Lighting Decoration Ideas Elegant Hanging Lighting Lamp Decoration Glass Bottles Hanging Lighting Lamps Diwali Decoration Hanging Beautiful Lighting Kandil Diwali Decoration Photo Shubh Labh Lighting Decoration For Diwali