Extending Google Apps/Spreadsheet using Google Apps Script

  • Published on
    23-Jan-2017

  • View
    648

  • Download
    5

Transcript

  • Presented at GDG DevFest Ahmedabad 2015

    Presented By : Dipali VyasProject Manager @ Zestard Technologies

    Date: 27-Dec-2015

    Google Apps Script

    http://www.zestard.com/

  • What is GAS - Google Apps Script?

    And What Magic we are going to see.

    Google Apps Script is a JavaScript cloud scripting language to automate tasks

    Editor in a browser & managed in cloud (no install/setup, files stored,shared, versioned)

    JavaScript runtime in the cloud ( compliant, debuggable, and performant )

    Set of APIs and hooks to Google products (extend and enhance, built in security, distribution mechanisms

    2

    11 Google apps, 1 platform in the cloud

  • Getting Started with Google Apps Script (GAS)

    Standalone script https://script.google.com Google Drive > Create > More > Script **

    Spreadsheet/App-bound script Tools >Script Editor **

    Sites-bound script More > Manage Site > Apps Scripts > Add new script **

    ** Do take care of the Authorization Step while scripting

    3

  • Standalone Script Example

    function createAndSendDocument() {

    // Create a new Google Doc named 'DevFestAhm15 GAS Demo1'

    var doc = DocumentApp.create('DevFestAhm15 GAS Demo1');

    // Access the body of the document, then add a paragraph.

    doc.getBody().appendParagraph('This document was created by Google Apps Script-Standalone Script. This is part of DevFestAhm15 GAS Demo1 provided by Dipali Vyas during the presentation in front of excellent participants of the session ');

    // Get the URL of the document.

    var url = doc.getUrl();

    // Get the email address of the active user - that's you.

    var email = Session.getActiveUser().getEmail();

    // Get the name of the document to use as an email subject line.

    var subject = doc.getName();

    // Append a new string to the "url" variable to use as an email body.

    var body = 'Link to your doc created at DevFestAhm15 : ' + url;

    // Send yourself an email with a link to the document.

    GmailApp.sendEmail(email, subject, body);

    }

    ==========End

    4

  • Spreadsheet/ App Bound Script Example

    Bound scripts can call a few methods :

    getActiveSpreadsheet(), getActiveDocument(), and getActiveForm() allow bound scripts to refer to their parent file without referring to the file's ID.

    getUi lets bound scripts access the user interface for their parent file to add custom menus, dialogs, and sidebars.

    In Google Sheets, getActiveSheet(), getActiveRange(), and getActiveCell() let the script determine the user's current sheet, selected range of cells, or selected individualcell.setActiveSheet(sheet) and setActiveRange(range) let the script change those selections.

    In Google Docs, getCursor() and getSelection() let the script determine the position of the user's cursor or selected text. setCursor(position) and setSelection(range) let the script change those locations.

    5

    https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app#getActiveSpreadsheet()https://developers.google.com/apps-script/reference/document/document-app#getActiveDocument()https://developers.google.com/apps-script/reference/forms/form-app#getActiveForm()https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app#getUi()https://developers.google.com/apps-script/guides/bound#custom_menus_dialogs_and_sidebarshttps://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app#getActiveSheet()https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app#getActiveRange()https://developers.google.com/apps-script/reference/spreadsheet/sheet#getActiveCell()https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app#setActiveSheet(Sheet)https://developers.google.com/apps-script/reference/spreadsheet/spreadsheet-app#setActiveRange(Range)https://developers.google.com/apps-script/reference/document/document#getCursor()https://developers.google.com/apps-script/reference/document/document#getSelection()https://developers.google.com/apps-script/reference/document/document#setCursor(Position)https://developers.google.com/apps-script/reference/document/document#setCursor(Position)https://developers.google.com/apps-script/reference/document/document#setSelection(Range)https://docs.google.com/spreadsheets/d/14ZHYnniaW-czGWOe5L0KjNO0_0TAX5690DpNLqnqpg4/edit#gid=0

  • Google Apps Scripts Fundamentals

    6 IntegrationTriggersCustom UICustom UI Menus Sub-Menus Dialogs SideBars

    Triggers Simple

    triggers(built-in functions)

    Installable triggers

    Integration

    With all Google apps, we can initially check

    https://docs.google.com/spreadsheets/d/14ZHYnniaW-czGWOe5L0KjNO0_0TAX5690DpNLqnqpg4/edit#gid=26440790https://docs.google.com/spreadsheets/d/14ZHYnniaW-czGWOe5L0KjNO0_0TAX5690DpNLqnqpg4/edit#gid=26440790https://docs.google.com/spreadsheets/d/14ZHYnniaW-czGWOe5L0KjNO0_0TAX5690DpNLqnqpg4/edit#gid=26440790

  • Triggers in Apps Script

    A trigger is a type of script resource that listens for a particular event and executes a function when that event fires.

    Simple triggers Specially-named built-in functions that are

    specific to spreadsheets onEdit onOpen onInstall

    Installable triggers Time-based triggers Container-bound installable triggers (let's make

    one!)

    7

  • Use Cases

    App Reference #1

    Grading made easy with Flubaroo

    Create quiz using Google Forms Automatically grades against

    answer key Can email results and answers to

    each student Provides charts to analyze the

    results

    8

    https://docs.google.com/spreadsheets/d/1NK7BWCLYyvhs-PIGXIh2FfWNR7Pofms6qm6DKYAGK3A/edit#gid=457145258https://docs.google.com/spreadsheets/d/1NK7BWCLYyvhs-PIGXIh2FfWNR7Pofms6qm6DKYAGK3A/edit#gid=457145258https://docs.google.com/spreadsheets/d/1NK7BWCLYyvhs-PIGXIh2FfWNR7Pofms6qm6DKYAGK3A/edit#gid=457145258

  • Use Cases

    App Reference #2

    Many types of mail merge

    Define a simple template using a draft email, document, sites page, or spreadsheet cell

    Add placeholder values that should be dynamically replaced

    Each spreadsheet row merged with template and sent out

    (Example of MailMerge by Amit Agrawal)

    9

    https://docs.google.com/spreadsheets/d/14ZHYnniaW-czGWOe5L0KjNO0_0TAX5690DpNLqnqpg4/edit#gid=1840749483https://docs.google.com/spreadsheets/d/14ZHYnniaW-czGWOe5L0KjNO0_0TAX5690DpNLqnqpg4/edit#gid=1840749483https://docs.google.com/spreadsheets/d/14ZHYnniaW-czGWOe5L0KjNO0_0TAX5690DpNLqnqpg4/edit#gid=1840749483https://docs.google.com/spreadsheets/d/14ZHYnniaW-czGWOe5L0KjNO0_0TAX5690DpNLqnqpg4/edit#gid=1840749483

  • Easy Reference for the Beginners

    http://developers.google.com/apps-scriptUser guide covering basic functionality30+ tutorials with code Videos

    YouTube channels

    GoogleDevelopers and GoogleApps Stack Overflow Tag questions with google-apps-script )

    Very active community, Google moderated Google Apps Developer Blog

    10

    http://developers.google.com/apps-scripthttp://developers.google.com/apps-scripthttp://developers.google.com/apps-script

  • 11 THANKS!Any questions?

    Special thanks to all the people who made and released these awesome resources for free.

  • Google Apps Script

    Presented at GDG DevFest Ahmedabad 2015

    Presented By : Dipali VyasProject Manager @ Zestard Technologies

    Date: 27-Dec-2015

    Email: dipalia@gmail.com

    Twitter: @dipalia

    http://www.zestard.com/