madhu madhu - 1 year ago 177
PHP Question

How to format an existing .docx file in PHPword?

I'm using PHPword library to formant an existing

file, But I could only replace a particular item from the original document. I actually want to change the styling of the whole document. Can anyone tell how to achieve this.

My Code:


require_once 'phpWord/PHPWord.php';

$PHPWord = new PHPWord();

$document = $PHPWord->loadTemplate('test.docx');

$test = 'Indian';

// Replacing The word 'British' with 'Indian'
$document->setValue('British', $test);



Thank you.

Ram Ram
Answer Source
  1. Load existing file as template.
  2. Make the desired editing
  3. Save file.

Check example here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download