Apps script for docs that updates all heading1 text to normal text

To create a Google Apps Script that updates all text styled as Heading 1 to Normal text in a Google Document, follow these steps. This script will iterate through all the elements in the document, check if they are styled as Heading 1, and if so, change their style to Normal text.

  1. Open Google Apps Script:
  2. Name Your Project:
    • For clarity, you might name your project something like “Heading1 to Normal Text”.
  3. Replace the Code in the Script Editor:
    • In the script editor, replace the contents of the Code.gs file with the following script:
function updateHeading1ToNormalText() {
  var doc = DocumentApp.getActiveDocument(); // Gets the active document
  var body = doc.getBody(); // Gets the body of the document
  var paragraphs = body.getParagraphs(); // Gets all the paragraphs in the document
  
  // Iterates through each paragraph
  for (var i = 0; i < paragraphs.length; i++) {
    var paragraph = paragraphs[i];
    // Checks if the paragraph style is Heading 1
    if (paragraph.getHeading() === DocumentApp.ParagraphHeading.HEADING1) {
      // Updates the paragraph style to Normal text
      paragraph.setHeading(DocumentApp.ParagraphHeading.NORMAL);
    }
  }
}
  1. Save Your Script:
    • Click the disk icon or File > Save, and give your project a name if you haven’t already.
  2. Run the Script:
    • Click on the play button (▶) next to the function updateHeading1ToNormalText in the toolbar. The first time you run the script, you will need to authorize it. Follow the on-screen instructions to grant the necessary permissions.
  3. Check Your Document:
    • Open your Google Document and run the script. You can run the script directly from the Google Apps Script interface if you’re working on the active document. Otherwise, if you want to apply this to any document from within the document itself, you will need to publish it as an add-on or use it within a bound script to that document.

This script will change all headings that are styled as Heading 1 to Normal text style throughout your document. If you need to target a specific document rather than the one currently open, you can modify the script to open the document by ID using DocumentApp.openById('YOUR_DOCUMENT_ID') instead of getActiveDocument().