title: Centering in a gDoc after a replace
body: <p>I am looking to replace a string within a Google Doc via an app script.  The string will exist on a line, but after the replace, I want it to have a specific font, size and justification.</p>
  
  <p>I've created a style to address all these attributes (I included both Horiz. and Vert. alignment) and most of it works fine.  When the string is replaced, the replacement has the right font, size and bold attributes.  For some reason, I cannot get the justification to get changed.</p>
  
  <pre><code>
    // Define the style for the replacement string.
    var hdrStyle = {};
    hdrStyle[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = 
    DocumentApp.HorizontalAlignment.CENTER;
    hdrStyle[DocumentApp.Attribute.VERTICAL_ALIGNMENT] = 
    DocumentApp.VerticalAlignment.CENTER;
    hdrStyle[DocumentApp.Attribute.FONT_FAMILY] = 'Calibri'; 
    hdrStyle[DocumentApp.Attribute.FONT_SIZE] = 24;
    hdrStyle[DocumentApp.Attribute.BOLD] = true;
  
  
    { then later }
  
    documentBody = DocumentApp.openById(fileId).getBody();
  
    hdrElem = documentBody.findText("old string").getElement();            
    hdrText = hdrElem.asText().setText("new string");
  
    // Force our 'header style':
    hdrElem.setAttributes(hdrStyle);
  
  </code></pre>
  
  <p>I've tried setting the style after the findText and (as here) after, but no change in centering.  </p>
  
  <p>I see there is a paragraph centering, but I am not clear how to 'get' the paragraph associated with the element that is returned on the find.</p>
  
  <p>I'm hoping this is some simple set of calls - but have run out of ideas (and patience)..!</p>
  
  <p>Any help would be appreciated!</p>