AppsScriptPulse

PDFApp and many recipes for ‘cooking’ PDFs with Google Apps Script

Unfortunately, there are no built-in methods for directly managing PDF data using Google Apps Script. Fortunately, after the V8 runtime has been released, several raw Javascript libraries could be used with Google Apps Script. pdf-lib is also one of them. When this is used, PDF data can be cooked over Google Apps Script. In this report, I would like to introduce achieving this using a Google Apps Script library.

Google Apps Script is a powerful tool for automating tasks. It can be used to process data, create spreadsheets, and send emails. One of the limitations of Apps Script is that it does not have built-in support for PDF files. However, there are a number of third-party libraries that can be used to work with PDF files and in Pulse we’ve featured a number of posts from Kanshi Tanaike where they have explored the pdf-lib is a JavaScript library.

This work has culminated in PDFApp, a dedicated Apps Script library created by Kanshi Tanaike based on the pdf-lib, but optimised for Apps Script. The source post includes a number of recipes for handling PDF files listed below:

  • Export pages from a PDF
  • Get metadata of a PDF
  • Update metadata of a PDF
  • Reorder pages of a PDF
  • Merge PDF files
  • Convert PDF pages to PNG files
  • Get values from PDF form
  • Set values to PDF form
  • Create PDF form using Google Slide as a template
  • Embed objects into a PDF

The source code for PDFApp is also on GitHub if you want to dig further.

Source: Cooking PDF over Google Apps Script

Easily merge data from Google Sheets into Google Docs and Slides with the TemplateApp Google Apps Script

This report introduces the method for easily processing the template of Google Documents and Google Slides using Google Spreadsheet as a database using Google Apps Script. Google Spreadsheet is used as a database. Google Documents and Google Slides are used as templates. The simple method for creating new Google Documents and Google Slides using the database and the templates is introduced.

Latest Apps Script magic from Kanshi Tanaike, this time they turn their addition to an easy way to use data from Google Sheets as a ‘document merge’ for templates created in Google Docs and Google Slides. This is achieved by using the TemplateApp Apps Script library, which has lots of useful features including simply methods for sheetRangeToDocuments() as well as the ability to embeded and fixed width images from placeholders. There are some llimitations documented in the GitHub repo, as well as examples for all the methods available in the library.

[In other ‘merge’ news Google have announced that you can now use Google Sheets with Google official mail merge in Gmail]

 

Source: Easily Processing Templates of Google Documents and Google Slides using Google Spreadsheet with Google Apps Script

Hiding/deleting non-consecutive rows and columns in Google Sheets using Google Apps Script

These are the sample scripts for hiding and deleting rows and columns on Google Spreadsheet [sic] using Google Apps Script. I sometimes see the questions for hiding and deleting rows and columns on Spreadsheet at Stackoverflow. So here, I would like to introduce the sample scripts for this.

In SpreadsheetApp there is the .deleteRow() and .deleteRows(), but when you have a lot of data or non-consecutive rows it can really eat into your Apps Script runtime limit. In searching for a better way of doing this I found this great solution from Kanshi Tanaike on Stack Overflow which uses the Google Sheets Advanced Service to delete multiple rows using one API call!

Using Sheets.Spreadsheets.batchUpdate isn’t just limited to deleting rows and for more examples see the source post which includes examples for hiding and deleting both rows and columns.

Source: Hiding and Deleting Rows and Columns on Google Spreadsheet using Google Apps Script

Happy Birthday Google Apps Script – In celebration a searchable community database of Apps Script libraries..

Since Google Apps Script was released on August 19th, 2009, it is used by a lot of users. By this, now there are a lot of useful libraries of Google Apps Script (GAS) in all over the world. But when I want to search a GAS library, I always use Google search engine. Unfortunately, in the current stage, the libraries cannot be directly searched by a database. On January 11th, 2020, a proposal for the database of Google Apps Script Library has been proposed by Andrew Roberts. When I have discussing about this with him, I thought that I tried to think of a sample database. So I prepared this…

Google Apps Script turns 13 years old today and in celebration we are highlighting this combined community contribution. As you will see from the source repo commit history this searchable database of Google Apps Script libraries has been around for a while, but given what it represents we thought worth celebrating.

Source: GitHub – tanaikech/Google-Apps-Script-Library-Database: This is for the Google Apps Script Library Database and a web application for searching the libraries..

Google Apps Script library for parsing HTML form objects and adding the values to a Google Sheet

This is a Google Apps Script library for parsing the form object from HTML form and appending the submitted values to the Spreadsheet.

A common Google Apps Script use case is taking data from a webform and adding it to a Google Sheet. This can sometimes be quite painful has you have to handle the various input types and also write the data to the correct columns. The HtmlFormApp library makes this very straight forward and to illustrate once the library is added to your Apps Script project you can start appending data in a couple of lines of code:

// These are all options.
const obj = {
   formData: formData,
   spreadsheetId: "###",
   sheetName: "###",
   sheetId: "###",
   folderId: "###",
   headerConversion: {"header value of Spreadsheet": "name of HTML input tag",,,},
   ignoreHeader: true,
   choiceFormat: true,
   delimiterOfMultipleAnswers: "\n",
   valueAsRaw: true
};
const res = HtmlFormApp.appendFormData(obj);
console.log(res)

Click through to the source link for more details 👇

Source: GitHub – tanaikech/HtmlFormApp: This is a Google Apps Script library for parsing the form object from HTML form and appending the submitted values to the Spreadsheet.

Redeploying Web Apps without changing the URL in the new Google Apps Script IDE

Redeploying Web Apps without Changing URL of Web Apps for new IDE

A ‘feature’ of the new Google Apps Script editor is managing your script project the deployments. A issue some developers are encountering when updating the published version of their web app is the published url changes. In this gist Kanshi Tanaike describes the problem and highlights how developers can update their published Web App without changing the URL.

Source: Redeploying Web Apps without Changing URL of Web Apps for new IDE

Trend of google-apps-script Tag on Stackoverflow 2021

Year vs. number of Questioners and Answerers. These all questions include the tag of "google-apps-script" in the tags

Year vs. number of Questioners and Answerers. These all questions include the tag of “google-apps-script” in the tags

Trend of google-apps-script Tag on Stackoverflow 2021

Kanshi Tanaike returns with an updated look at trends in the [google-apps-script] tag on Stackoverflow.  A highlight from the report is the continued growth in new questioners, indicating that the Google Apps Script community is continuing to grow.

Source: Trend of google-apps-script Tag on Stackoverflow 2021

New Google Apps Script library for working with Google Docs, MS Word, Google Sheets, MS Excel and Google Slides when core/advanced service methods are not available 

This is a Google Apps Script library for supporting Document service, Docs API, Spreadsheet service, Sheets API, Slides service and Slides API. The aim of this library is to compensate the processes that they services cannot achieve.

The purpose of this contribution from Tanaike is to extend Google Apps Script to interact with certain types of Google Drive files using methods not included in the existing core or advanced services. Features worth noting are:

  • Google Docs:
    • Retrieve table width and column width from the table. The tables inserted with the default width are included.
  • Google Sheets:
    • Retrieve all images in Google Spreadsheet as an object including the cell range and image blob.
    • Retrieve all comments in Google Spreadsheet as an object including the cell range and comments.
    • Insert images in cells of Google Spreadsheet using the image blob.
    • Create new Google Spreadsheet by setting the custom header and footer.
  • Microsoft Word:
    • Retrieve table width and column width.
  • Microsoft Excel:
    • Retrieve all values and formulas of the cells.
    • Retrieve all sheet names.
    • Retrieve all images as an object including the cell range and image blob.
    • Retrieve all comments as an object including the cell range and comments.

For more details about this library visit the source on Github

Source: tanaikech/DocsServiceApp

Highlighting Row and Column of Selected Cell in Google Sheets using Google Apps Script · tanaike

This is a sample script for highlighting the row and column of the selected cell using Google Apps Script … and the OnSelectionChange event trigger

Nice little script solution which could be a very useful addition to your script projects as an accessibility feature.

Source: Highlighting Row and Column of Selected Cell using Google Apps Script · tanaike

RichTextApp – a Google Apps Script library for copying rich text formatting from Google Docs and Sheets

This is a GAS library for copying the rich text with the text styles from Google Document to Google Spreadsheet or from Google Spreadsheet to Google Document using Google Apps Script (GAS). And, also the rich texts in the cells can be converted to HTML format.

Nice little helper library for copying rich text formatting from Google Docs and Sheets. You can view the project README for information on the formats that are currently supported. Personally,  the inclusion of the RichTextToHTMLForSpreadsheet method looks particularly useful for converting rich text formatting in Google Sheets cells to HTML for mail merge applications.

Source: tanaikech/RichTextApp