PHPWord template creation - Replace text on title page .docx
Ok, so I am using PHPWord to create a template. Then, using the setValue function to replace various lines in the document, it all works correctly, but I have a title page in my document and no text is replaced on that page?
Is there any way to add this functionality. Basically all that needs to happen is the replacement (setValue) to be done in the xml corresponding to the title page (title and assets) (custom xml folder?). you can see them by extracting the .docx file after changing the file extension to .zip
https://github.com/PHPOffice/PHPWord/blob/master/src/PhpWord/Template.php
How I am currently creating .docx from templated.docx file:
<?php
include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s') , " Create new PhpWord object" , EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$document = $phpWord->loadTemplate('resources/Template_Proposal.docx');
$document->setValue('CONTACTNAME', 'John');
$document->setValue('BUSINESSNAME', 'JBS Marketing');
$document->setValue('WEBSITE', 'www.website.com.au');
$document->setValue('DATE', '07/07/2014');
$name = 'test-proposal.docx';
echo date('H:i:s'), " Write to Word2007 format", EOL;
$document->saveAs($name);
rename($name, "results/{$name}");
echo getEndingNotes(array('Word2007' => 'docx'));
if (!CLI) {
include_once 'Sample_Footer.php';
}
+3
source to share
No one has answered this question yet
Check out similar questions: