How to edit word documents with php?

2019-01-28 19:49发布

问题:

I have an existing word document in my computer and like to edit this file from my website (using PHP). I was able to find PHPWORD but this deals with new documents only. I don't want to code PHP for the whole document, instead wish to use it for the stuff that varies.

Does anybody know any way out?

回答1:

https://github.com/PHPOffice/PHPWord

PHPWord also features a Reader which can be used to edit existing documents.



回答2:

@nssmart,

Yes,mark a section on your word document with a variable such as {value1} and then, if you have PHPWORD downloaded, you can replace that section using code

$PHPWord = new PHPWord();

$document = $PHPWord->loadTemplate(Doc location);

$document->setValue('value1', 'Description');

This can be used to fill data in tables also.