Here’s a Google Apps Script that converts all Heading 3 (H3) styles to Heading 2 (H2) in a Google Docs document. It loops through all the paragraphs and updates the heading styles accordingly.
Steps to Use:
- Open your Google Docs document.
- Click on Extensions > Apps Script.
- Delete any existing code and paste the script below.
- Click the Run button to execute the script.
Apps Script:
function convertH3toH2() {
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
var paragraphs = body.getParagraphs();
for (var i = 0; i < paragraphs.length; i++) {
var para = paragraphs[i];
if (para.getHeading() === DocumentApp.ParagraphHeading.HEADING3) {
para.setHeading(DocumentApp.ParagraphHeading.HEADING2);
}
}
Logger.log("Conversion complete: All H3 headings changed to H2.");
}
What This Script Does:
- Gets the active Google Docs document.
- Loops through all paragraphs.
- Checks if the paragraph is styled as Heading 3.
- Changes the style to Heading 2.
