DEV Community


How to get Google Apps Script to tell Google Docs to bold, italic, strikethrough and underline from a JSON representation?

Bruce Axtens
Programmed Canon Canola calculators in 1977. Assorted platforms and languages ever since. Assisting with I am NOT looking for work -- I've got more than enough to do.
・1 min read

I have written a function, setParagraphToRichText which accepts a GoogleAppsScript.Document.Paragraph and a string. The string is a stringified JSON blob that defines the text and attributes of a given paragraph.

 * @param {GoogleAppsScript.Document.Paragraph} paragraph
 * @param {string} jsonString
function setParagraphToRichText(paragraph, jsonString) {
  const text = paragraph.editAsText();

Discussion (1)

bugmagnet profile image
Bruce Axtens Author • Edited

Turns out it was a typo. So not Google's fault but mine. Sigh. Old and decrepit much.