title: Read and replace contents in .docx (Word) file
body: <p>I need to replace content in some word documents based on User input. I am trying to read a template file (e.g. "template.docx"), and replace First name {fname}, Address {address} etc.</p>
  
  <p>template.docx: </p>
  
  <pre><code>To,
  The Office,
  {officeaddress}
  Sub:  Authorization Letter
  Sir / Madam,
  
  I/We hereby authorize  to  {Ename}  whose signature is attested here below, to submit application and collect Residential permit for {name}  
  Kindly allow him to support our International assignee
  
  {name}                                          {Ename}  
  </code></pre>
  
  <p>Is there a way to do the same in Laravel 5.3?</p>
  
  <p>I am trying to do with phpword, but I can only see code to write new word files - but not read and replace existing ones. Also, when I simply read and write, the formatting is messed up. </p>
  
  <p>Code: </p>
  
  <pre><code>$file = public_path('template.docx');
  $phpWord = \PhpOffice\PhpWord\IOFactory::load($file);
  
  $phpWord-&gt;save('b.docx');
  </code></pre>
  
  <p>b.docx</p>
  
  <pre><code>To,
  The Office,
  {officeaddress}
  
  Sub: 
   Authorization Letter
  Sir / Madam,
  
  
  I/We hereby authorize 
   to
  
  {Ename}
  
  
  whose signature is attested here below, to submit a
  pplication and collect Residential permit
   for 
  {name}
  
  Kindly allow him to support our International assignee
  
  
  {name}
  
  
  
  
  
  
  
  
  
  
  
  
  
  {
  E
  name}
  </code></pre>