If you’ve been editing a document in Google Docs, you may end up with various text styles, such as bold and italic, scattered throughout. For consistency and readability, you might want to remove these styles and reset everything to plain text. Manually clearing formatting in a long document can be tedious, but with Google Apps Script, you can automate this task!
In this guide, we’ll walk through an Apps Script that removes all bold and italic formatting from a Google Doc, effectively resetting the document to a clean, plain-text format.
Why Use Google Apps Script?
Google Apps Script is a JavaScript-based tool that enables you to automate tasks and customize Google Workspace apps, like Google Docs. With a few lines of code, you can modify text formatting, perform bulk changes, and more. In this example, we’ll use Apps Script to reset text styles, making your document uniform and free of extra formatting.
Apps Script to Clear Bold and Italic Formatting
Here’s the script to reset all text styles by clearing both bold and italic attributes across the document.
function resetTextStyles() {
const doc = DocumentApp.getActiveDocument();
const body = doc.getBody();
const paragraphs = body.getParagraphs();
paragraphs.forEach(paragraph => {
const text = paragraph.editAsText();
if (text) {
// Remove bold and italic styles for the entire paragraph
text.setBold(false);
text.setItalic(false);
}
});
}
How the Script Works
- Access the Document: The script retrieves the active Google Doc and accesses its body content.
- Loop Through Paragraphs: It iterates over each paragraph in the document.
- Reset Bold and Italic Styles: For each paragraph, the script uses a loop to go through each character and sets both the bold and italic attributes to
false
, effectively removing any applied bold or italic styling.
Setting Up the Script
To use this script in your Google Docs, follow these steps:
- Open Google Docs: Open the Google Doc you want to reset styles in.
- Access Google Apps Script:
- Go to Extensions > Apps Script to open the Apps Script editor.
- Paste the Code: Copy and paste the code above into the Apps Script editor.
- Save and Run:
- Save your project with a relevant name, such as “Reset Text Styles.”
- Select
resetTextStyles
from the dropdown and click the Run button.
- Authorize Permissions: When prompted, authorize the script to make changes to your Google Docs.
Example Use Case
Imagine you have a document with various styling, such as:
- Bold section headers
- Italicized notes
- Bold and italicized text scattered throughout
After running the script, all text will be reset to plain, removing bold and italic styles. This is particularly useful for documents that need to follow a standardized format or for clearing distracting formatting before applying new styles.
Customizing the Script
If you want to clear additional styles, you can modify the script as needed:
- Underline: Add
paragraph.setUnderline(i, i + 1, false);
to reset any underlined text. - Text Color: Add
paragraph.setForegroundColor(i, i + 1, null);
to reset any custom text colors. - Font Style: Add
paragraph.setFontFamily(i, i + 1, null);
to reset any non-standard fonts.
Conclusion
With this Google Apps Script, you can easily clear all bold and italic formatting in a Google Doc, giving you a clean, consistent text format across your document. This quick and easy script is perfect for standardizing document styles and can be adapted to clear other types of formatting as well.

