Edit .doc or .docx file using php

后端 未结 5 1386
攒了一身酷
攒了一身酷 2021-02-07 14:24

I have to modify the uploaded .doc or .docx file in php. I googled but i only found how to read that. I want the word file as it is and put text at the bottom of that MS Word fi

5条回答
  •  旧时难觅i
    2021-02-07 15:00

    You only replace the predefined variables. In the following code

    https://github.com/PHPOffice/PHPWord I also did this problem in phpword using the following code

     if(!file_exists('file/word.docx')){
      $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('demo.docx');
      $templateProcessor->setValue('name', 'Akbarali');
      $templateProcessor->setValue('time','13.02.2021');
      $templateProcessor->setValue('month', 'January');
      $templateProcessor->setValue('state','Uzbekistan');
      $templateProcessor->saveAs('file/word.docx');
    }
    

    This will change the words in the demo.docx file. The new file is then saved in the word.docx file folder. you can define variables in the form of $ {name} in the demo word file. that is, ${name}, ${time}, ${month} and ${state}

提交回复
热议问题