6

Is a way to convert all headings X into headings X + 1 or heading X - 1 in Google Documents?

E.g. I have a Google document with 100 headings 2: is there any way to convert them into headings 1 or 3 in a convenient fashion (i.e. without having to manually change the heading for each 100 of them)?

6

With this little script you can change the headings automatically. Especially useful when the different headings are convoluted.

Code

function changeHeading() {
  var pars = DocumentApp.getActiveDocument().getBody().getParagraphs();  
  for(var i in pars) {
    var p = pars[i], h = p.getHeading(), d = DocumentApp.ParagraphHeading;
    switch(h) {
      case h.HEADING1:
        p.setHeading(d.HEADING2);
        break;
      case h.HEADING2:
        p.setHeading(d.HEADING1);
        break;
    }
  }
}

Explained

First all paragraph types are collected. Then these are checked for headings. If a heading matches Heading 1, then it's changed to Heading 2 etc.

Add this script in your Google Document under Tools > Script editor.... Press the "bug" button to authenticate the script.

  • The above script has a bug in it. It changes all existing Heading 1 to Heading 2 and it changes all existing heading 2 to Heading 1, when it should be Heading 3. This version just swaps Heading 1 and Heading two instead of pushing everything down a level. – August Mohr Sep 22 at 23:04
  • @AugustMohr I thought the OP meant heading 1 or 3. You can alter the script anyway you like to see for yourself. – Jacob Jan Tuinstra Sep 23 at 5:33
5

After a couple of days of more 'normal' activity levels no better offer yet so I suggest:

Change "Heading 2" to the required style and then "Update 'Heading 2' to match.

This does not add or subtract from the Heading reference number but at least allows easy propagation across the 100 headings to be changed, by altering one only.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.