Skip to content

Instantly share code, notes, and snippets.

@mox601
Created April 17, 2014 13:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mox601/10981608 to your computer and use it in GitHub Desktop.
Save mox601/10981608 to your computer and use it in GitHub Desktop.
/* http://webapps.stackexchange.com/questions/23861/header-numbering-in-google-docs */
var pars = DocumentApp.getActiveDocument().getBody().getParagraphs();
for(var i=0; i<pars.length; i++) {
var par = pars[i];
var hdg = par.getHeading();
if (hdg == DocumentApp.ParagraphHeading.HEADING1) {
counterh1 = counterh1+1; counterh2 = 0; counterh3 = 0; counterh4 = 0; counterh5 = 0; counterh6 = 0;
var content = par.getText();
var chunks = content.split('\t')
var result = 'ok'
if(chunks.length > 1) { par.setText(counterh1+'.\t'+chunks[1]); }
else { par.setText(counterh1+'.\t'+chunks[0]); }
}
... idem for HEADING2,3,4,5,6
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment