Apps Script to Remove Doc headings that start with a word

Creating a Google Apps Script to remove H3 headings from paragraphs in a Google Document that start with the word “Question” involves using the Google Apps Script’s Document Service. This script will iterate through the elements of the document, check if they are H3 headings, and then see if they begin with “Question”. If they do, the script will change the heading to normal text.

Here’s a basic script to achieve this:

function removeH3HeadingsStartingWithQuestion() {
  var doc = DocumentApp.getActiveDocument();
  var body = doc.getBody();
  var paragraphs = body.getParagraphs();

  for (var i = 0; i < paragraphs.length; i++) {
    var paragraph = paragraphs[i];
    if (paragraph.getHeading() === DocumentApp.ParagraphHeading.HEADING3) {
      var text = paragraph.getText();
      if (text.startsWith("Question")) {
        paragraph.setHeading(DocumentApp.ParagraphHeading.NORMAL);
      }
    }
  }
}

To use this script:

  1. Open your Google Doc.
  2. Click on Extensions > Apps Script.
  3. Copy and paste the above script into the script editor.
  4. Save and name your project.
  5. Run the function removeH3HeadingsStartingWithQuestion from the script editor.

Remember, the first time you run the script, you will need to authorize the script to modify your document. This script will only affect the document it’s attached to.

This script is quite basic and does not include advanced error checking or logging, so you may want to enhance it depending on your specific needs and the complexity of your documents.