madhu madhu - 3 months ago 24
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
  1. Load existing file as template.
  2. Make the desired editing
  3. Save file.

Check example here