function myFunction() { // ##################################################################### // // Find/Replace for fixing issues in Trimester reports. Works just fine for mass editing all Google // Docs in a Drive folder or folders. // // Put the folder id in the 'getFolderById' parens. Then in the 'replaceText' line near the bottom, // change the word before 'replaceText' with doc, header, or footer depending on whether the text is // in the doc's body, header or footer. Then enter the 'find' text followed by the 'replace' text in // the parens. // // Put folder IDs in "FolderIds" array. The script will edit all docs in these folders. var folderIds = ["1eAS3Q7w0519l-Vngg8XqSt5AZvvZqa-H","1Cki2wFqVaeUOWOefQ2InIHNRFFTCzRTM"] for (var i = 0; i < folderIds.length; i++) { Logger.log(folderIds.length); //var files = DriveApp.getFolderById("1OooKtL5L0uCjZpuDnuw0dAz4h6QhibSU").getFiles(); var files = DriveApp.getFolderById(folderIds[i]).getFiles() while (files.hasNext()) { var file = files.next(); Logger.log(file.getName()); var doc = DocumentApp.openById(file.getId()); var footer = doc.getFooter(); var header = doc.getHeader(); var body = doc.getBody(); //footer.replaceText("Trimester 1", "Trimester 2"); // In these reports, I missed adding in Joe Teacher's name body.replaceText("Teacher Name", "Joe Teacher"); /* <-- This asterisk-slash is the start of a multi-line comment. Remove it to enable the following code // ******************************************************************************** // // HEADS UP! THE FOLLOWING WAS SET UP TO BOLD SOME TEXT. Remove this // SECTION DOWN TO THE NEXT ASTERISKS IF YOU AREN'T USING IT! // // ******************************************************************************** // Look for "N/A: Not Assessed" in the body of the document. We want to bold this phrase var foundElement = body.findText("N/A: Not Assessed"); if (foundElement != null) { // Get the text object from the element var foundText = foundElement.getElement().asText(); // Where in the element is the found text? var start = foundElement.getStartOffset(); var end = foundElement.getEndOffsetInclusive(); // Set Bold foundText.setBold(start, end, true); // Find the next match foundElement = body.findText("test", foundElement); } // Like the lines above, the next several lines finds and bolds the phrase "I/D: Insufficient Data" var foundElement = body.findText("I/D: Insufficient Data"); if (foundElement != null) { // Get the text object from the element var foundText = foundElement.getElement().asText(); // Where in the element is the found text? var start = foundElement.getStartOffset(); var end = foundElement.getEndOffsetInclusive(); // Set Bold foundText.setBold(start, end, true); // Find the next match foundElement = body.findText("test", foundElement); } // ******************************************************************************** // // HEADS UP! THE ABOVE WAS SET UP TO BOLD SOME TEXT // // ******************************************************************************** */ //<-- This asterisk-slash is the end of a multi-line comment // The lines below will find/replace text in the body, footer and header. // Uncomment and edit as needed //body.replaceText("\vOur goal at Korea International School", "DabbaDabba"); //footer.replaceText("<>", "<>"); //header.replaceText("Pre-Kindergarten", "Jr-Kindergarten"); //header.replaceText("2020 5 Progress", "2020 Grade 5 Progress"); } } Logger.log("Done") }