Google scripting tool




















For details, see the Google Developers Site Policies. Automate tasks with Apps Script. Guides Reference Samples Support. Overview Apps Script dashboard Explore the development environment. Apps Script runtimes. Google services and external APIs. Types of scripts. Extend Google Workspace. Google Sheets. Google Slides. User authentication is baked into the platform via OAuth2 and requires no code or setup by the script author.

Apps Script runs server-side, but can have user interfaces built with Html, CSS, JavaScript, or any other browser supported technologies. Unlike Nodejs, which is event driven, App Scripts runs in a threaded model. All calls to a script generate a unique instance of that script which runs in isolation of all other instances. When an instance of a script finishes execution it is destroyed. Functions in Apps Script are blocking so callback and async programming patterns are not needed.

Locking is used to prevent critical sections of code, such as file IO, from being executed simultaneously by different instances. In practice writing Apps Scripts are simple. Below is a simple script that creates a new spreadsheet from a template spreadsheet. Google Apps Script does not require setup or installation. The only requirement is a Google Account. You can create a new Google account by going to accounts.

Start your first script by going to script. Official documentation can be found at developers. For app-scripts to run they must contain a code. The script could just as easily make these changes to an existing document by replacing the call to DocumentApp. For scripts created inside a document container-bound , use DocumentApp. Most scripts that modify a Google Doc begin with a call to getBody , because the Body is a master element that contains all other elements except for the HeaderSection , FooterSection , and any Footnotes.

However, there are rules about which types of elements can contain other types. Furthermore, the Document Service in Apps Script can only insert certain types of elements. The tree below shows which elements can be contained by a certain type of element. Apps Script is often used to replace text in Google Docs. Let's say you have a spreadsheet full of client information and you want to generate a personalized Google Doc for each client.

This type of operation is often called a mail merge. There are many ways to replace text, but the simplest is the replaceText method shown in the example below.

The first function below adds several lines of placeholder text to a Google Doc; in the real world, you would be more likely to type the placeholders into the document yourself. The second function replaces the placeholders with properties defined in the client object.

Note that both of these functions use the getActiveDocument method, which only applies to scripts created inside a Google Doc; in a stand-alone script, use DocumentApp.

You can customize Google Docs by adding menus, dialog boxes, and sidebars. Keep in mind, however, that a script can only interact with the UI for the current instance of an open document, and only if the script is bound to the document.



0コメント

  • 1000 / 1000