示例#1
0
文件: Docx.php 项目: jupitern/docx
 /**
  * @param null $outputFilePath
  * @return bool
  * @throws \Exception
  */
 public function save($outputFilePath = null)
 {
     if (!file_exists($this->templateFilePath)) {
         throw new \Exception("template file {$this->templateFilePath} not found");
     }
     if ($outputFilePath === null) {
         $outputFilePath = $this->templateFilePath;
     } elseif (!copy($this->templateFilePath, $outputFilePath)) {
         throw new \Exception("error creating output file {$outputFilePath}");
     }
     $docx = new DocxLib\Docx($outputFilePath);
     $docx->loadHeadersAndFooters();
     foreach ($this->data as $key => $value) {
         $docx->findAndReplace($key, $value);
     }
     $docx->flush();
     return true;
 }