Posts

How to Change the Font in your Google Documents with Apps Script

An organization recently migrated their Word Documents from Microsoft Office to Google Drive. The migration has been smooth but the Word documents imported as Google Docs are using Calibri, the default font family of Microsoft Word. The company is looking to replace the fonts in multiple Google Documents such that the document headings using Georgia while the body paragraphs are rendered in Droid Sans at 12 pt. Replace Font Styles in Google Docs This example show how to replace the font family of your Google Documents of specific sections - the heading titles are rendered in a different font while the tables, list items, body and table of contents are formatted with a separate font. const updateFontFamily = ( ) => { const document = DocumentApp . getActiveDocument ( ) ; const headingStyles = { [ DocumentApp . Attribute . FONT_FAMILY ] : "Georgia" , [ DocumentApp . Attribute . FONT_SIZE ] : 14 , } ; const normalParagraphStyles = {...

How to Replace Text and Hyperlinks in Google Documents with Apps Script

The company’s handbook is written in Google Docs. The document spans several pages and now the writer has been asked to create links such that all mentions of the company name in the document are linking to the company’s official website. It can be a time consuming task but with Google Apps Script, specific words in a document can be hyperlinked in bulk in one click. Add Hyperlinks in Google Docs This example show how to search and replace all occurrences of a text phrase, the company name in this case, and add links to a specific website. const addLinks = ( ) => { const searchPhrase = "Digital Inspiration" ; const hyperlink = "https://digitalinspiration.com/" ; const document = DocumentApp . getActiveDocument ( ) ; const body = document . getBody ( ) ; let search = null ; while ( ( search = body . findText ( searchPhrase , search ) ) ) { const searchElement = search . getElement ( ) ; const startIndex = ...

Google Documents - How to Replace Text in Header and Footer

Image
The upcoming release of Document Studio includes support for adding markers in the header, footer and the footnotes section of your Microsoft Word template. The add-on will automatically replace this placeholder text with actual values sourced from Google Sheets or Google Forms. Replace Header and Footer with Document API This Apps Script snippet uses the Google Docs API to find and replace multiple blocks of text in the header and footer section of your Google Document. The header and footer sections are children of the parent DOCUMENT section. const replaceHeaderFooter = ( ) => { // Returns the document with the specified ID const doc = DocumentApp . openById ( "DOCUMENT ID" ) ; // Retrieves the headers's container element which is DOCUMENT const parent = doc . getHeader ( ) . getParent ( ) ; for ( let i = 0 ; i < parent . getNumChildren ( ) ; i += 1 ) { // Retrieves the child element at the specified child index ...

How to Convert Column Numbers (e.g. 28) to A1 Notation (e.g. AB) in Google Sheets

Image
Google Sheets includes built-in functions for converting cell references in A1 notation to row and column numbers and another function for converting column alphabets (like AA) into the column index (26 in this case). =ADDRESS(23, 28, 4) - Returns the A1 style notation of the cell whose row number is 23 and column number is 28. =COLUMN(C9) - Returns the column number of a specified cell C9 where column A corresponds to 1 and column AA corresponds to 27. Get A1 Notation with JavaScript If you are working with the Google Sheets API, you may sometimes needs to calculate the A1 notation style reference of a cell whose row and column numbers are known in the JSON data of the sheet. For container bound Google Sheets, the getA1Notation() method can return the range address in A1 Notation. const sheet = SpreadsheetApp . getActiveSheet ( ) ; const range = sheet . getRange ( 1 , 2 ) ; Logger . log ( range . getA1Notation ( ) ) ; If you are not using the Spreadsheet service,...

How to Use PayPal Subscriptions API with Node.js

Our Google add-on store uses PayPal Subscriptions with Digital Goods to process recurring payments and the invoices are sent to customers through Document Studio . There are two steps. Customers makes the payment and completes the order on our website. PayPal sends a BILLING.SUBSCRIPTION.ACTIVATED webhook to a serverless function. The function (running on Firebase, Google Cloud) verifies the subscription and checks if the status is active. It invokes the Apps Script API to complete the order. The cloud function was previously using the official PayPal SDK for Node.js but it has been recently deprecated and no longer supports the new PayPal subscriptions API endpoints. Migrating from the PayPal Node SDK to your own solution is relatively simple and involves two steps: 1. Get the PayPal Access Token const { default : axios } = require ( "axios" ) ; const getPayPalAccessToken = async ( ) => { const client_id = "PayPal Client ID goes here...

How to Add a Watermark in Google Documents

Image
Microsoft Word includes a useful “Insert Watermark” feature to help you easily add your brand’s logo image or a text stamp that fades behind the content of every page in the document. A company’s policy may require employees to add watermarks to indicate if any document is in draft stage or if the document is confidential and not meant for external distribution. Insert Watermarks in Google Docs Unlike Microsoft Word, there’s no built-in support for Watermarks in Google Docs but there’s a simple workaround - create a faded image with the text of your watermark and place that image behind the text of your document pages. Here’s how: 1. Create the watermark stamp Launch MS Paint on your computer and create a simple watermark image in landscape mode with dark gray text. Please use a bold font like Impact with large font size as the large image can always be resized inside Google Docs but not vice-versa. I’ve also added some ready-to-use image stamps on Canva and Imgur . 2....

The Best Extensions for Google Chrome

Image
Here’s a comprehensive list of the best extensions for Google Chrome that will help you do more and also enhance your web browsing experience. The Best Google Chrome extensions Vimium C — Browse the web, interact with web pages, navigate browser history using keyboard shortcuts. Inspired by Vim commands . Fika - Read pages in a Kindle-style clean layout with beautiful typography while hiding the distracting parts. PushBullet — Easily transfer web page links, text notes, or push photos and files from the computer to your phone and vice-versa. OneTab — Save all your open tabs in a group and duplicate your session anytime later with a click. Gmail Sender Icons - Quickly identify the sending domain of an email in Gmail without opening the message. Bubble Cursor - The add-on makes it easy for you to click on links that are too small to select with your mouse or for typing inside input boxes. Picture in Picture - Watch YouTube videos in an always-on-top floating window w...