Find And Format Specific Text In Google Document Using Script

[Solved] Find And Format Specific Text In Google Document Using Script | Go - Code Explorer | yomemimo.com
Question : find and format Specific text in google document using script

Answered by : wild-willet-6ynr14v9bwnw

// Set the whole body to Roboto 10 var FontStyle = {}; FontStyle[DocumentApp.Attribute.FONT_FAMILY] = 'Roboto'; FontStyle[DocumentApp.Attribute.FONT_SIZE] = 10; body.setAttributes(FontStyle); // Set some elements to bold var target1 = "Private & Confidential" var searchResult1 = body.findText(target1); if (searchResult1 !== null) { var thisElement1 = searchResult1.getElement(); var thisElement1Text = thisElement1.asText(); thisElement1Text.setBold(searchResult1.getStartOffset(), searchResult1.getEndOffsetInclusive(), true); } var target2 = "Your Reference:" var searchResult2 = body.findText(target2); if (searchResult2 !== null) { var thisElement2 = searchResult2.getElement(); var thisElement2Text = thisElement2.asText(); thisElement2Text.setBold(searchResult2.getStartOffset(), searchResult2.getEndOffsetInclusive(), true); } var target3 = "Our Reference:" var searchResult3 = body.findText(target3); if (searchResult3 !== null) { var thisElement3 = searchResult3.getElement(); var thisElement3Text = thisElement3.asText(); thisElement3Text.setBold(searchResult3.getStartOffset(), searchResult3.getEndOffsetInclusive(), true); } // Right align date var searchType = DocumentApp.ElementType.PARAGRAPH var target4 = "\\[Date\\]"; var searchResult4 = body.findText(target4); while (searchResult4 = body.findElement(searchType, searchResult4)) { var par = searchResult4.getElement().asParagraph(); if (searchResult4 != null) { par.setAlignment(DocumentApp.HorizontalAlignment.RIGHT); } } // Update date var date = Utilities.formatDate(new Date(), "GMT", "d MMMMM yyyy"); body.replaceText("\\[Date\\]", date); }

Source : https://stackoverflow.com/questions/47830539/formatting-text-with-apps-script-google-docs | Last Update : Sun, 25 Jul 21

Answers related to find and format specific text in google document using script

Code Explorer Popular Question For Go