Constants

MAXIMUM_REPLACEMENTS_DEFAULT

MAXIMUM_REPLACEMENTS_DEFAULT = -1

Properties

$zipClass

$zipClass : mixed

ZipArchive object.

Type

mixed

$tempDocumentFilename

$tempDocumentFilename : string

Type

string — Temporary document filename (with path)

$tempDocumentMainPart

$tempDocumentMainPart : string

Content of main document part (in XML format) of the temporary document

Type

string

$tempDocumentHeaders

$tempDocumentHeaders : array<mixed,string>

Content of headers (in XML format) of the temporary document

Type

array<mixed,string>

$tempDocumentFooters

$tempDocumentFooters : array<mixed,string>

Content of footers (in XML format) of the temporary document

Type

array<mixed,string>

Methods

__construct()

__construct(string  $documentTemplate) 

Parameters

string $documentTemplate

The fully qualified template filename

Throws

\PhpOffice\PhpWord\Exception\CreateTemporaryFileException
\PhpOffice\PhpWord\Exception\CopyFileException

applyXslStyleSheet()

applyXslStyleSheet(\DOMDocument  $xslDomDocument, array  $xslOptions = array(), string  $xslOptionsUri = '') 

Applies XSL style sheet to template's parts.

Note: since the method doesn't make any guess on logic of the provided XSL style sheet, make sure that output is correctly escaped. Otherwise you may get broken document.

Parameters

\DOMDocument $xslDomDocument
array $xslOptions
string $xslOptionsUri

Throws

\PhpOffice\PhpWord\Exception\Exception

setValue()

setValue(mixed  $search, mixed  $replace, integer  $limit = self::MAXIMUM_REPLACEMENTS_DEFAULT) 

Parameters

mixed $search
mixed $replace
integer $limit

getVariables()

getVariables() : array<mixed,string>

Returns array of all variables in template.

Returns

array<mixed,string>

cloneRow()

cloneRow(string  $search, integer  $numberOfClones) 

Clone a table row in a template document.

Parameters

string $search
integer $numberOfClones

Throws

\PhpOffice\PhpWord\Exception\Exception

cloneBlock()

cloneBlock(string  $blockname, integer  $clones = 1, boolean  $replace = true) : string|null

Clone a block.

Parameters

string $blockname
integer $clones
boolean $replace

Returns

string|null

replaceBlock()

replaceBlock(string  $blockname, string  $replacement) 

Replace a block.

Parameters

string $blockname
string $replacement

deleteBlock()

deleteBlock(string  $blockname) 

Delete a block of text.

Parameters

string $blockname

save()

save() : string

Saves the result document.

Throws

\PhpOffice\PhpWord\Exception\Exception

Returns

string

saveAs()

saveAs(string  $fileName) 

Saves the result document to the user defined file.

Parameters

string $fileName

transformSingleXml()

transformSingleXml(string  $xml, \XSLTProcessor  $xsltProcessor) : string

Parameters

string $xml
\XSLTProcessor $xsltProcessor

Throws

\PhpOffice\PhpWord\Exception\Exception

Returns

string

transformXml()

transformXml(mixed  $xml, \XSLTProcessor  $xsltProcessor) : mixed

Parameters

mixed $xml
\XSLTProcessor $xsltProcessor

Returns

mixed

ensureMacroCompleted()

ensureMacroCompleted(string  $macro) : string

Parameters

string $macro

Returns

string

ensureUtf8Encoded()

ensureUtf8Encoded(string  $subject) : string

Parameters

string $subject

Returns

string

fixBrokenMacros()

fixBrokenMacros(string  $documentPart) : string

Finds parts of broken macros and sticks them together.

Macros, while being edited, could be implicitly broken by some of the word processors.

Parameters

string $documentPart

The document part in XML representation

Returns

string

setValueForPart()

setValueForPart(mixed  $search, mixed  $replace, string  $documentPartXML, integer  $limit) : string

Find and replace macros in the given XML section.

Parameters

mixed $search
mixed $replace
string $documentPartXML
integer $limit

Returns

string

getVariablesForPart()

getVariablesForPart(string  $documentPartXML) : array<mixed,string>

Find all variables in $documentPartXML.

Parameters

string $documentPartXML

Returns

array<mixed,string>

getHeaderName()

getHeaderName(integer  $index) : string

Get the name of the header file for $index.

Parameters

integer $index

Returns

string

getMainPartName()

getMainPartName() : string

Returns

string

getFooterName()

getFooterName(integer  $index) : string

Get the name of the footer file for $index.

Parameters

integer $index

Returns

string

findRowStart()

findRowStart(integer  $offset) : integer

Find the start position of the nearest table row before $offset.

Parameters

integer $offset

Throws

\PhpOffice\PhpWord\Exception\Exception

Returns

integer

findRowEnd()

findRowEnd(integer  $offset) : integer

Find the end position of the nearest table row after $offset.

Parameters

integer $offset

Returns

integer

getSlice()

getSlice(integer  $startPosition, integer  $endPosition) : string

Get a slice of a string.

Parameters

integer $startPosition
integer $endPosition

Returns

string