API Documentation
Word content
Format conversion
CryptoPHPDOCX
Digital Signature package
addTemplate
Allows to use a predefined Word document template.
PRO, PRO+ and CORPORATE PHPDocX >= 1.7
Description
public addTemplate ( string $filePath )
This method allows the user to build a Word document up from an existing template, something particularly useful when only a few elements have to be generated dinamically.
With the help of PHPDocX placeholder variables you may, among other posibilities, insert:
- text, charts and images,
- HTML with images and its associated CSS styles,
- full documents like other Word, RTF and MHT files,
- indefinite numbers of rows in cells or items in lists as well as
- replace existing placeholder images.
In order to harness the full potential of this and related methods we recommend you to visit our PHPDocX tutorial.
Parameters
filePath
Path to the document that we will use as a Word template. This document should have the .docx extension.
Return values
Void.
Code samples
Example #1: adds a template and returns it without modifying it
require_once 'classes/CreateDocx.inc';
$docx = new CreateDocx();
$docx->addTemplate('TemplateText.docx');
$docx->createDocx('template_text.docx');
The resulting Word document looks like (download .docx file):
Change log
- Available since 1.7
Available examples
- Template variable in a external Word (.docx) document.
- HTML in a Word document: table with row and col spans.
- Template variable by an external image.
- Template variable by an external MHT document.
- Template variable in a external RTF document.
- Template variable in the Word document.
- Template table example.
- Images inserted in a table.
- Template variable with multiline text.
PHPDocx. Dinamic generation of reports in .docx format 


