madhu madhu - 1 month ago 16
PHP Question

How to format an existing .docx file in PHPword?

I'm using PHPword library to formant an existing

.docx
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:

<?php

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);

$document->save('test2.docx');

?>


Thank you.

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

Check example here