Google Docs provides an easy way to format text using different heading styles. However, if you ever find yourself needing to convert all Heading 3 (H3) text into bolded text while maintaining readability, you can automate the process using Google Apps Script.
In this blog post, we’ll walk through a simple script that scans a Google Doc, finds all H3 headings, applies bold formatting, and optionally converts them to normal text.
Why Use Google Apps Script?
Google Apps Script is a cloud-based JavaScript platform that lets you automate tasks across Google Workspace apps, such as Google Docs, Sheets, and Drive. Instead of manually formatting each heading, you can use a simple script to update an entire document in seconds.
The Apps Script Code
Below is the Apps Script function that will convert all H3 headings in a Google Document to bold text.
function convertDocH3ToBold() {
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
var paragraphs = body.getParagraphs();
for (var i = 0; i < paragraphs.length; i++) {
var paragraph = paragraphs[i];
// Check if the paragraph has Heading 3 style
if (paragraph.getHeading() === DocumentApp.ParagraphHeading.HEADING3) {
// Apply bold formatting to the entire paragraph
paragraph.setBold(true);
// Optionally, reset the paragraph style to normal text
paragraph.setHeading(DocumentApp.ParagraphHeading.NORMAL);
}
}
}
How the Script Works
- Access the Active Google Document:
The script retrieves the currently open Google Doc usingDocumentApp.getActiveDocument()
. - Get All Paragraphs:
It extracts all the paragraphs from the document usinggetBody().getParagraphs()
. - Check for H3 Headings:
It loops through each paragraph and checks if it is styled as Heading 3 usingparagraph.getHeading()
. - Apply Bold Formatting:
If a paragraph is an H3 heading, the script applies bold formatting usingparagraph.setBold(true)
. - Convert to Normal Text (Optional):
If you want to keep the formatting simple, the script changes the paragraph style from Heading 3 to Normal text usingparagraph.setHeading(DocumentApp.ParagraphHeading.NORMAL)
. You can remove this line if you want to keep the H3 styling.
How to Use the Script
- Open Google Docs:
Open the document where you want to convert H3 headings to bold text. - Open Apps Script Editor:
- Click on Extensions > Apps Script in the menu.
- Paste the Script:
- Delete any existing code in the script editor and paste the function above.
- Run the Script:
- Click the Run button in the Apps Script editor.
- If prompted, grant the necessary permissions.
- Check the Document:
- All H3 headings should now be bolded and optionally converted to normal text.
When Should You Use This Script?
- When you want to emphasize H3 headings without keeping the heading style.
- When you receive a document with inconsistent formatting and need a quick way to apply uniform changes.
- When you’re working with large Google Docs and need an automated solution instead of manually updating each heading.
Final Thoughts
This simple Apps Script function helps streamline formatting in Google Docs by converting H3 headings to bold text. Whether you’re working on reports, blog drafts, or collaborative documents, automating formatting tasks can save time and ensure consistency.
