title: PhpWord doesn't replace text with TemplateProcessor
body: <p>I encountered the same issue as @pindol in <a href="https://stackoverflow.com/questions/16794294/phpword-doesnt-replace-text">here</a>.</p>
  <p>I followed some steps provider by users in the page issue. So i tested functions in TemplateProcessor to see the outputs, and finally, the hole $TemplateProcessor with var_dump :</p>
  <pre><code>object(PhpOffice\PhpWord\TemplateProcessor)#1259 (9) { [&quot;zipClass&quot;:protected]=&gt; object(PhpOffice\PhpWord\Shared\ZipArchive)#1008 (5) { [&quot;numFiles&quot;]=&gt; int(11) [&quot;filename&quot;]=&gt; string(18) &quot;/tmp/PhpWord5qX68E&quot; [&quot;tempDir&quot;:&quot;PhpOffice\PhpWord\Shared\ZipArchive&quot;:private]=&gt; string(4) &quot;/tmp&quot; [&quot;zip&quot;:&quot;PhpOffice\PhpWord\Shared\ZipArchive&quot;:private]=&gt; object(PclZip)#1046 (5) { [&quot;zipname&quot;]=&gt; string(18) &quot;/tmp/PhpWord5qX68E&quot; [&quot;zip_fd&quot;]=&gt; int(0) [&quot;error_code&quot;]=&gt; int(0) [&quot;error_string&quot;]=&gt; string(0) &quot;&quot; [&quot;magic_quotes_status&quot;]=&gt; int(-1) } [&quot;usePclzip&quot;:&quot;PhpOffice\PhpWord\Shared\ZipArchive&quot;:private]=&gt; bool(true) } [&quot;tempDocumentFilename&quot;:protected]=&gt; string(18) &quot;/tmp/PhpWord5qX68E&quot; [&quot;tempDocumentMainPart&quot;:protected]=&gt; string(2690) &quot; Test : the test is perfect&quot; [&quot;tempDocumentSettingsPart&quot;:protected]=&gt; string(2842) &quot; &quot; [&quot;tempDocumentHeaders&quot;:protected]=&gt; array(0) { } [&quot;tempDocumentFooters&quot;:protected]=&gt; array(0) { } [&quot;tempDocumentRelations&quot;:protected]=&gt; array(1) { [&quot;word/document.xml&quot;]=&gt; string(817) &quot; &quot; } [&quot;tempDocumentContentTypes&quot;:protected]=&gt; string(1312) &quot; &quot; [&quot;tempDocumentNewImages&quot;:protected]=&gt; array(0) { } } 
  </code></pre>
  <p>As we can see in [&quot;tempDocumentMainPart&quot;:protected], the variable was replaced successfully with this function :</p>
  <pre><code>    $templateProcessor = new TemplateProcessor('results/test.docx');
      $templateProcessor-&gt;setValue('test', 'the test is perfect'); 
      var_dump($templateProcessor);
      exit();
      $templateProcessor-&gt;saveAs('results/results.docx');
      return response()-&gt;download('results/results.docx');
  </code></pre>
  <p>But when i tried to saveAs or download the file, the variable doesn't change in the downloaded file. It's the same like the template provided and i got a error message when i try to open it (After download):</p>
  <pre><code>Word found unreadable content in results.docx. Do you want to recover the contents of this document? If the source for this document is reliable, click Yes.
  </code></pre>
  <p>The function save and saveAs in the phpword :</p>
  <pre><code>    /**
   * Saves the result document.
   *
   * @throws \PhpOffice\PhpWord\Exception\Exception
   *
   * @return string
   */
  public function save()
  {
      foreach ($this-&gt;tempDocumentHeaders as $index =&gt; $xml) {
          $this-&gt;savePartWithRels($this-&gt;getHeaderName($index), $xml);
      }
  
      $this-&gt;savePartWithRels($this-&gt;getMainPartName(), $this-&gt;tempDocumentMainPart);
  
      foreach ($this-&gt;tempDocumentFooters as $index =&gt; $xml) {
          $this-&gt;savePartWithRels($this-&gt;getFooterName($index), $xml);
      }
  
      $this-&gt;zipClass-&gt;addFromString($this-&gt;getDocumentContentTypesName(), $this-&gt;tempDocumentContentTypes);
  
      // Close zip file
      if (false === $this-&gt;zipClass-&gt;close()) {
          throw new Exception('Could not close zip file.'); // @codeCoverageIgnore
      }
  
      return $this-&gt;tempDocumentFilename;
  }
  
  /**
   * @param string $fileName
   * @param string $xml
   */
  protected function savePartWithRels($fileName, $xml)
  {
      $this-&gt;zipClass-&gt;addFromString($fileName, $xml);
      if (isset($this-&gt;tempDocumentRelations[$fileName])) {
          $relsFileName = $this-&gt;getRelationsName($fileName);
          $this-&gt;zipClass-&gt;addFromString($relsFileName, $this-&gt;tempDocumentRelations[$fileName]);
      }
  }
  
  /**
   * Saves the result document to the user defined file.
   *
   * @since 0.8.0
   *
   * @param string $fileName
   */
  public function saveAs($fileName)
  {
      $tempFileName = $this-&gt;save();
  
      if (file_exists($fileName)) {
          unlink($fileName);
      }
  
      /*
       * Note: we do not use `rename` function here, because it loses file ownership data on Windows platform.
       * As a result, user cannot open the file directly getting &quot;Access denied&quot; message.
       *
       * @see https://github.com/PHPOffice/PHPWord/issues/532
       */
      copy($tempFileName, $fileName);
      unlink($tempFileName);
  }
  </code></pre>
  <p>I tested this in the PhpWord 0.16.0 and 0.17.0 and i use this with laravel (i don't think that the issue is with laravel). Php version :</p>
  <pre><code>PHP 7.4.7 (cli) (built: Jun 12 2020 07:48:26) ( NTS )
  </code></pre>
  <p>I'm using PCLZIP instead of zipArchive because he generate a <a href="https://stackoverflow.com/questions/62512857/allowed-memory-size-problem-in-phpword-src-phpword-shared-ziparchive-php">memory issue</a>.
  Thanks in advance</p>