Properties

$container

$container : string

Container type Section|Header|Footer|Footnote|Endnote|Cell|TextRun|TextBox|ListItemRun|TrackChange

Type

string — Container type

$sectionId

$sectionId : integer

Section Id

Type

integer

$docPart

$docPart : string

Document part type: Section|Header|Footer|Footnote|Endnote

Used by textrun and cell container to determine where the element is located because it will affect the availability of other element, e.g. footnote will not be available when $docPart is header or footer.

Type

string

$docPartId

$docPartId : integer

Document part Id

For header and footer, this will be = ($sectionId - 1) * 3 + $index because the max number of header/footer in every page is 3, i.e. AUTO, FIRST, and EVEN (AUTO = ODD)

Type

integer

$elementIndex

$elementIndex : integer

Index of element in the elements collection (start with 1)

Type

integer

$elementId

$elementId : string

Unique Id for element

Type

string

$relationId

$relationId : integer

Relation Id

Type

integer

$mediaRelation

$mediaRelation : boolean

Has media relation flag; true for Link, Image, and Object

Type

boolean

$collectionRelation

$collectionRelation : boolean

Is part of collection; true for Title, Footnote, Endnote, Chart, and Comment

Type

boolean

$nestedLevel

$nestedLevel : integer

Depth of table container nested level; Primarily used for RTF writer/reader

0 = Not in a table; 1 = in a table; 2 = in a table inside another table, etc.

Type

integer

$parentContainer

$parentContainer : string

Parent container type

Type

string

Methods

__call()

__call(mixed  $function, mixed  $args) : \PhpOffice\PhpWord\Element\AbstractElement

Magic method to catch all 'addElement' variation

This removes addText, addTextRun, etc. When adding new element, we have to add the model in the class docblock with @method.

Warning: This makes capitalization matters, e.g. addCheckbox or addcheckbox won't work.

Parameters

mixed $function
mixed $args

Returns

\PhpOffice\PhpWord\Element\AbstractElement

getElement()

getElement(integer  $index) : \PhpOffice\PhpWord\Element\AbstractElement|null

Returns the element at the requested position

Parameters

integer $index

Returns

\PhpOffice\PhpWord\Element\AbstractElement|null

countElements()

countElements() : integer

Count elements

Returns

integer

createTextRun()

createTextRun(mixed  $paragraphStyle = null) : \PhpOffice\PhpWord\Element\TextRun

Create textrun element

Parameters

mixed $paragraphStyle

Returns

\PhpOffice\PhpWord\Element\TextRun

createFootnote()

createFootnote(mixed  $paragraphStyle = null) : \PhpOffice\PhpWord\Element\Footnote

Create footnote element

Parameters

mixed $paragraphStyle

Returns

\PhpOffice\PhpWord\Element\Footnote

setPhpWord()

setPhpWord(\PhpOffice\PhpWord\PhpWord  $phpWord = null) 

Set PhpWord as reference.

Parameters

\PhpOffice\PhpWord\PhpWord $phpWord

getSectionId()

getSectionId() : integer

Get section number

Returns

integer

setDocPart()

setDocPart(string  $docPart, integer  $docPartId = 1) 

Set doc part.

Parameters

string $docPart
integer $docPartId

getDocPart()

getDocPart() : string

Get doc part

Returns

string

getDocPartId()

getDocPartId() : integer

Get doc part Id

Returns

integer

getElementIndex()

getElementIndex() : integer

Get element index

Returns

integer

setElementIndex()

setElementIndex(integer  $value) 

Set element index.

Parameters

integer $value

getElementId()

getElementId() : string

Get element unique ID

Returns

string

setElementId()

setElementId() 

Set element unique ID from 6 first digit of md5.

getRelationId()

getRelationId() : integer

Get relation Id

Returns

integer

setRelationId()

setRelationId(integer  $value) 

Set relation Id.

Parameters

integer $value

getNestedLevel()

getNestedLevel() : integer

Get nested level

Returns

integer

getParent()

getParent() 

setParentContainer()

setParentContainer(\PhpOffice\PhpWord\Element\AbstractElement  $container) 

Set parent container

Passed parameter should be a container, except for Table (contain Row) and Row (contain Cell)

Parameters

\PhpOffice\PhpWord\Element\AbstractElement $container

isInSection()

isInSection() : boolean

Check if element is located in Section doc part (as opposed to Header/Footer)

Returns

boolean

setChangeInfo()

setChangeInfo(string  $type, string  $author, null|integer|\DateTime  $date = null) 

Set changed

Parameters

string $type

INSERTED|DELETED

string $author
null|integer|\DateTime $date

allways in UTC

__construct()

__construct(mixed  $style = null) 

Create a new textbox

Parameters

mixed $style

addText()

addText(string  $text, mixed  $fStyle = null, mixed  $pStyle = null) : \PhpOffice\PhpWord\Element\Text

Parameters

string $text
mixed $fStyle
mixed $pStyle

Returns

\PhpOffice\PhpWord\Element\Text

addTextRun()

addTextRun(mixed  $pStyle = null) : \PhpOffice\PhpWord\Element\TextRun

Parameters

mixed $pStyle

Returns

\PhpOffice\PhpWord\Element\TextRun

addBookmark()

addBookmark(string  $name) : \PhpOffice\PhpWord\Element\Bookmark

Parameters

string $name

Returns

\PhpOffice\PhpWord\Element\Bookmark

addLink()

addLink(string  $target, string  $text = null, mixed  $fStyle = null, mixed  $pStyle = null, boolean  $internal = false) : \PhpOffice\PhpWord\Element\Link

Parameters

string $target
string $text
mixed $fStyle
mixed $pStyle
boolean $internal

Returns

\PhpOffice\PhpWord\Element\Link

addPreserveText()

addPreserveText(string  $text, mixed  $fStyle = null, mixed  $pStyle = null) : \PhpOffice\PhpWord\Element\PreserveText

Parameters

string $text
mixed $fStyle
mixed $pStyle

Returns

\PhpOffice\PhpWord\Element\PreserveText

addTextBreak()

addTextBreak(integer  $count = 1, mixed  $fStyle = null, mixed  $pStyle = null) : void

Parameters

integer $count
mixed $fStyle
mixed $pStyle

addListItem()

addListItem(string  $txt, integer  $depth, mixed  $font = null, mixed  $list = null, mixed  $para = null) : \PhpOffice\PhpWord\Element\ListItem

Parameters

string $txt
integer $depth
mixed $font
mixed $list
mixed $para

Returns

\PhpOffice\PhpWord\Element\ListItem

addListItemRun()

addListItemRun(integer  $depth, mixed  $listStyle = null, mixed  $pStyle = null) : \PhpOffice\PhpWord\Element\ListItemRun

Parameters

integer $depth
mixed $listStyle
mixed $pStyle

Returns

\PhpOffice\PhpWord\Element\ListItemRun

addFootnote()

addFootnote(mixed  $pStyle = null) : \PhpOffice\PhpWord\Element\Footnote

Parameters

mixed $pStyle

Returns

\PhpOffice\PhpWord\Element\Footnote

addEndnote()

addEndnote(mixed  $pStyle = null) : \PhpOffice\PhpWord\Element\Endnote

Parameters

mixed $pStyle

Returns

\PhpOffice\PhpWord\Element\Endnote

addCheckBox()

addCheckBox(string  $name, mixed  $text, mixed  $fStyle = null, mixed  $pStyle = null) : \PhpOffice\PhpWord\Element\CheckBox

Parameters

string $name
mixed $text
mixed $fStyle
mixed $pStyle

Returns

\PhpOffice\PhpWord\Element\CheckBox

addTitle()

addTitle(string  $text, integer  $depth = 1) : \PhpOffice\PhpWord\Element\Title

Parameters

string $text
integer $depth

Returns

\PhpOffice\PhpWord\Element\Title

addTOC()

addTOC(mixed  $fontStyle = null, mixed  $tocStyle = null, integer  $minDepth = 1, integer  $maxDepth = 9) : \PhpOffice\PhpWord\Element\TOC

Parameters

mixed $fontStyle
mixed $tocStyle
integer $minDepth
integer $maxDepth

Returns

\PhpOffice\PhpWord\Element\TOC

addPageBreak()

addPageBreak() : \PhpOffice\PhpWord\Element\PageBreak

Returns

\PhpOffice\PhpWord\Element\PageBreak

addTable()

addTable(mixed  $style = null) : \PhpOffice\PhpWord\Element\Table

Parameters

mixed $style

Returns

\PhpOffice\PhpWord\Element\Table

addImage()

addImage(string  $source, mixed  $style = null, boolean  $isWatermark = false, mixed  $name = null) : \PhpOffice\PhpWord\Element\Image

Parameters

string $source
mixed $style
boolean $isWatermark
mixed $name

Returns

\PhpOffice\PhpWord\Element\Image

addOLEObject()

addOLEObject(string  $source, mixed  $style = null) : \PhpOffice\PhpWord\Element\OLEObject

Parameters

string $source
mixed $style

Returns

\PhpOffice\PhpWord\Element\OLEObject

addTextBox()

addTextBox(mixed  $style = null) : \PhpOffice\PhpWord\Element\TextBox

Parameters

mixed $style

Returns

\PhpOffice\PhpWord\Element\TextBox

addField()

addField(string  $type = null, array  $properties = array() : \PhpOffice\PhpWord\Element\Field

, array $options = array(), mixed $text = null)

Parameters

string $type
array $properties

Returns

\PhpOffice\PhpWord\Element\Field

addLine()

addLine(mixed  $lineStyle = null) : \PhpOffice\PhpWord\Element\Line

Parameters

mixed $lineStyle

Returns

\PhpOffice\PhpWord\Element\Line

addShape()

addShape(string  $type, mixed  $style = null) : \PhpOffice\PhpWord\Element\Shape

Parameters

string $type
mixed $style

Returns

\PhpOffice\PhpWord\Element\Shape

addChart()

addChart(string  $type, array  $categories, array  $values, array  $style = null) : \PhpOffice\PhpWord\Element\Chart

Parameters

string $type
array $categories
array $values
array $style

Returns

\PhpOffice\PhpWord\Element\Chart

addFormField()

addFormField(string  $type, mixed  $fStyle = null, mixed  $pStyle = null) : \PhpOffice\PhpWord\Element\FormField

Parameters

string $type
mixed $fStyle
mixed $pStyle

Returns

\PhpOffice\PhpWord\Element\FormField

addSDT()

addSDT(string  $type) : \PhpOffice\PhpWord\Element\SDT

Parameters

string $type

Returns

\PhpOffice\PhpWord\Element\SDT

addObject()

addObject(string  $source, mixed  $style = null) : \PhpOffice\PhpWord\Element\OLEObject

deprecated, use addOLEObject instead

Parameters

string $source
mixed $style

Returns

\PhpOffice\PhpWord\Element\OLEObject

addElement()

addElement(string  $elementName) : \PhpOffice\PhpWord\Element\AbstractElement

Add element

Each element has different number of parameters passed

Parameters

string $elementName

Returns

\PhpOffice\PhpWord\Element\AbstractElement

setNewStyle()

setNewStyle(mixed  $styleObject, mixed  $styleValue = null, boolean  $returnObject = false) : mixed

Set new style value

Parameters

mixed $styleObject

Style object

mixed $styleValue

Style value

boolean $returnObject

Always return object

Returns

mixed

setEnumVal()

setEnumVal(string|null  $value = null, array<mixed,string>  $enum = array(), string|null  $default = null) : string|null

Set enum value

Parameters

string|null $value
array<mixed,string> $enum
string|null $default

Throws

\InvalidArgumentException

Returns

string|null

checkValidity()

checkValidity(string  $method) : boolean

Check if a method is allowed for the current container

Parameters

string $method

Throws

\BadMethodCallException

Returns

boolean

getMediaPart()

getMediaPart() : string

Return media element (image, object, link) container name

Returns

string —

section|headerx|footerx|footnote|endnote

setMediaRelation()

setMediaRelation() 

Set relation Id for media elements (link, image, object; legacy of OOXML)

  • Image element needs to be passed to Media object
  • Icon needs to be set for Object element

setCollectionRelation()

setCollectionRelation() 

Set relation Id for elements that will be registered in the Collection subnamespaces.