PHP Word
PHP Word
Release 0.12.0
Contents
Introduction
1.1 Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.2 File formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1.3 Contributing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
3
4
5
Installing/configuring
2.1 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.2 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2.3 Using samples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7
7
7
8
General usage
3.1 Basic example . . . .
3.2 Settings . . . . . . . .
3.3 Default font . . . . . .
3.4 Document information
3.5 Measurement units . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
9
9
10
11
11
11
Containers
4.1 Sections . . . . .
4.2 Headers . . . . .
4.3 Footers . . . . .
4.4 Other containers
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
13
13
14
14
15
Elements
5.1 Texts . . . . . . . . .
5.2 Breaks . . . . . . . .
5.3 Lists . . . . . . . . .
5.4 Tables . . . . . . . . .
5.5 Images . . . . . . . .
5.6 Objects . . . . . . . .
5.7 Table of contents . . .
5.8 Footnotes & endnotes
5.9 Checkboxes . . . . . .
5.10 Textboxes . . . . . . .
5.11 Fields . . . . . . . . .
5.12 Line . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
17
18
20
20
21
23
24
24
24
25
25
25
25
Styles
6.1 Section . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
27
27
.
.
.
.
.
.
.
.
6.2
6.3
6.4
6.5
6.6
Font . . . . . . .
Paragraph . . . .
Table . . . . . .
Image . . . . . .
Numbering level
Templates processing
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
28
28
29
29
29
31
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
33
33
34
35
35
35
Recipes
9.1 Create float left image . . . . . . . . . . . . . . . . . . . .
9.2 Download the produced file automatically . . . . . . . . . .
9.3 Create numbered headings . . . . . . . . . . . . . . . . . .
9.4 Add a link within a title . . . . . . . . . . . . . . . . . . .
9.5 Remove [Compatibility Mode] text in the MS Word title bar
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
37
37
37
37
38
38
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
. .
. .
the
. .
. . . . . . . . . . . . .
. . . . . . . . . . . . .
latest PHPWord from
. . . . . . . . . . . . .
39
39
39
39
11 Credits
41
12 References
12.1 ISO/IEC 29500, Third edition, 2012-09-01 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
12.2 Formal specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
12.3 Other resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
43
43
43
43
45
ii
PHPWord is a library written in pure PHP that provides a set of classes to write to and read from different document
file formats. The current version of PHPWord supports Microsoft Office Open XML (OOXML or OpenXML), OASIS
Open Document Format for Office Applications (OpenDocument or ODF), and Rich Text Format (RTF).
Contents
Contents
CHAPTER 1
Introduction
PHPWord is a library written in pure PHP that provides a set of classes to write to and read from different document
file formats. The current version of PHPWord supports Microsoft Office Open XML (OOXML or OpenXML), OASIS
Open Document Format for Office Applications (OpenDocument or ODF), and Rich Text Format (RTF).
PHPWord is an open source project licensed under the terms of LGPL version 3. PHPWord is aimed to be a high
quality software product by incorporating continuous integration and unit testing. You can learn more about PHPWord
by reading this Developers Documentation and the API Documentation.
1.1 Features
Set document properties, e.g. title, subject, and creator.
Create document sections with different settings, e.g. portrait/landscape, page size, and page numbering
Create header and footer for each sections
Set default font type, font size, and paragraph style
Use UTF-8 and East Asia fonts/characters
Define custom font styles (e.g. bold, italic, color) and paragraph styles (e.g. centered, multicolumns, spacing)
either as named style or inline in text
Insert paragraphs, either as a simple text or complex one (a text run) that contains other elements
Insert titles (headers) and table of contents
Insert text breaks and page breaks
Insert right-to-left text
Insert and format images, either local, remote, or as page watermarks
Insert binary OLE Objects such as Excel or Visio
Insert and format table with customized properties for each rows (e.g. repeat as header row) and cells (e.g.
background color, rowspan, colspan)
Insert list items as bulleted, numbered, or multilevel
Insert hyperlinks
Insert footnotes and endnotes
Insert drawing shapes (arc, curve, line, polyline, rect, oval)
Insert charts (pie, doughnut, bar, line, area, scatter, radar)
3
1.2.1 Writers
Features
Document Properties
Element Type
Graphs
Math
Bonus
DOCX
ODT
RTF
HTML
Standard
Custom
Text
Text Run
Title
Link
Preserve Text
Text Break
Page Break
List
Table
Image
Object
Watermark
Table of Contents
Header
Footer
Footnote
Endnote
2D basic graphs
2D advanced graphs
3D graphs
OMML support
MathML support
Encryption
Protection
Chapter 1. Introduction
1.2.2 Readers
Features
Document Properties
Element Type
Graphs
Math
Bonus
DOCX
DOC
ODT
RTF
HTML
Standard
Custom
Text
Text Run
Title
Link
Preserve Text
Text Break
Page Break
List
Table
Image
Object
Watermark
Table of Contents
Header
Footer
Footnote
Endnote
2D basic graphs
2D advanced graphs
3D graphs
OMML support
MathML support
Encryption
Protection
1.3 Contributing
We welcome everyone to contribute to PHPWord. Below are some of the things that you can do to contribute.
Read our contributing guide.
Fork us and request a pull to the develop branch.
Submit bug reports or feature requests to GitHub.
Follow @PHPWord and @PHPOffice on Twitter.
1.3. Contributing
Chapter 1. Introduction
CHAPTER 2
Installing/configuring
2.1 Requirements
Mandatory:
PHP 5.3+
PHP Zip extension
PHP XML Parser extension
Optional PHP extensions:
GD
XMLWriter
XSL
2.2 Installation
There are two ways to install PHPWord, i.e. via Composer or manually by downloading the library.
If you are a developer or if you want to help us with testing then fetch the latest branch for developers. Notice: All
contributions must be done against the developer branch.
{
"require": {
"phpoffice/phpword": "dev-develop"
}
}
src/PhpWord/Autoloader.php
in
your
PHP
script
and
invoke
require_once '/path/to/src/PhpWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register();
Chapter 2. Installing/configuring
CHAPTER 3
General usage
$fontStyleName = 'oneUserDefinedStyle';
$phpWord->addFontStyle(
$fontStyleName,
array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true)
);
$section->addText(
htmlspecialchars(
'"The greatest accomplishment is not in never falling, '
. 'but in rising again after you fall." '
. '(Vince Lombardi)'
),
$fontStyleName
);
// Adding Text element with font customized using explicitly created font style object...
$fontStyle = new \PhpOffice\PhpWord\Style\Font();
$fontStyle->setBold(true);
$fontStyle->setName('Tahoma');
$fontStyle->setSize(13);
$myTextElement = $section->addText(
htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)')
);
$myTextElement->setFontStyle($fontStyle);
// Saving the document as OOXML file...
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('helloWorld.docx');
// Saving the document as ODF file...
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText');
$objWriter->save('helloWorld.odt');
// Saving the document as HTML file...
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'HTML');
$objWriter->save('helloWorld.html');
/* Note: we skip RTF, because it's not XML-based and requires a different example. */
/* Note: we skip PDF, because "HTML-to-PDF" approach is used to create PDF documents. */
3.2 Settings
The PhpOffice\PhpWord\Settings class provides some options that will affect the behavior of PHPWord.
Below are the options.
10
11
12
CHAPTER 4
Containers
Containers are objects where you can put elements (texts, lists, tables, etc). There are 3 main containers, i.e. sections,
headers, and footers. There are 3 elements that can also act as containers, i.e. textruns, table cells, and footnotes.
4.1 Sections
Every visible element in word is placed inside of a section. To create a section, use the following code:
$section = $phpWord->addSection($sectionStyle);
The $sectionStyle is an optional associative array that sets the section. Example:
$sectionStyle = array(
'orientation' => 'landscape',
'marginTop' => 600,
'colsNum' => 2,
);
4.1.2 Multicolumn
You can change a section layout to multicolumn (like in a newspaper) by using the breakType and colsNum style
of the section.
// Method 1
$section = $phpWord->addSection(array('breakType' => 'continuous', 'colsNum' => 2));
// Method 2
$section = $phpWord->addSection();
13
$section->getStyle()->setBreakType('continuous');
$section->getStyle()->setColsNum(2);
4.2 Headers
Each section can have its own header reference. To create a header use the addHeader method:
$header = $section->addHeader();
Be sure to save the result in a local object. You can use all elements that are available for the footer. See Footer
section for detail. Additionally, only inside of the header reference you can add watermarks or background pictures.
See Watermarks section.
4.3 Footers
Each section can have its own footer reference. To create a footer, use the addFooter method:
$footer = $section->addFooter();
Be sure to save the result in a local object to add elements to a footer. You can add the following elements to footers:
Texts addText and createTextrun
Text breaks
Images
Tables
Preserve text
See the Elements section for the detail of each elements.
14
Chapter 4. Containers
15
16
Chapter 4. Containers
CHAPTER 5
Elements
Below are the matrix of element availability in each container. The column shows the containers while the rows lists
the elements.
Num
1
2
Element
Text
Text Run
Section
v
v
Header
v
v
Footer
v
v
Cell
v
v
Text Run
v
Footnote
v
3
4
5
Link
Title
Preserve Text
v
v
?
v
?
v
v
?
v
v
?
v*
v
?
6
7
Text Break
Page Break
v
v
List
Table
10
11
Image
Watermark
12
13
Object
TOC
v
v
14
Footnote
15
v
?
v
v
v**
v**
Endnote
v**
v**
16
CheckBox
17
TextBox
18
19
Field
Line
v
v
v
v
v
v
v
v
v
v
v
v
Legend:
17
v Available
v* Available only when inside header/footer
v** Available only when inside section
- Not available
? Should be available
5.1 Texts
Text can be added by using addText and addTextRun method. addText is used for creating simple paragraphs
that only contain texts with the same style. addTextRun is used for creating complex paragraphs that contain text
with different style (some bold, other italics, etc) or other elements, e.g. images or links. The syntaxes are as follow:
$section->addText($text, [$fontStyle], [$paragraphStyle]);
$textrun = $section->addTextRun([$paragraphStyle]);
Font style
Available font styles:
name Font name, e.g. Arial
size Font size, e.g. 20, 22,
hint Font content type, default, eastAsia, or cs
bold Bold, true or false
italic Italic, true or false
18
Chapter 5. Elements
5.1.2 Titles
If you want to structure your document or build table of contents, you need titles or headings. To add a title to the
document, use the addTitleStyle and addTitle method.
$phpWord->addTitleStyle($depth, [$fontStyle], [$paragraphStyle]);
$section->addTitle($text, [$depth]);
Its necessary to add a title style to your document because otherwise the title wont be detected as a real title.
5.1. Texts
19
5.1.3 Links
You can add Hyperlinks to the document by using the function addLink:
$section->addLink($linkSrc, [$linkName], [$fontStyle], [$paragraphStyle]);
5.2 Breaks
5.2.1 Text breaks
Text breaks are empty new lines. To add text breaks, use the following syntax. All paramaters are optional.
$section->addTextBreak([$breakCount], [$fontStyle], [$paragraphStyle]);
5.3 Lists
To add a list item use the function addListItem.
Basic usage:
$section->addListItem($text, [$depth], [$fontStyle], [$listStyle], [$paragraphStyle]);
Parameters:
$text Text that appears in the document.
20
Chapter 5. Elements
TYPE_ALPHANUM,
$phpWord->addNumberingStyle(
'multilevel',
array('type' => 'multilevel', 'levels' => array(
array('format' => 'decimal', 'text' => '%1.', 'left' => 360, 'hanging' => 360, 'tabPos' => 36
array('format' => 'upperLetter', 'text' => '%2.', 'left' => 720, 'hanging' => 360, 'tabPos' =
)
)
);
$section->addListItem('List Item I', 0, null, 'multilevel');
$section->addListItem('List Item I.a', 1, null, 'multilevel');
$section->addListItem('List Item I.b', 1, null, 'multilevel');
$section->addListItem('List Item II', 0, null, 'multilevel');
Level styles:
start Starting value
format Numbering format bullet|decimal|upperRoman|lowerRoman|upperLetter|lowerLetter
restart Restart numbering level symbol
suffix Content between numbering symbol and paragraph text tab|space|nothing
text Numbering level text e.g. %1 for nonbullet or bullet character
align Numbering symbol align left|center|right|both
left See paragraph style
hanging See paragraph style
tabPos See paragraph style
font Font name
hint See font style
5.4 Tables
To add tables, rows, and cells, use the addTable, addRow, and addCell methods:
$table = $section->addTable([$tableStyle]);
$table->addRow([$height], [$rowStyle]);
$cell = $table->addCell($width, [$cellStyle]);
5.4. Tables
21
$tableStyle = array(
'borderColor' => '006699',
'borderSize' => 6,
'cellMargin' => 50
);
$firstRowStyle = array('bgColor' => '66BBFF');
$phpWord->addTableStyle('myTable', $tableStyle, $firstRowStyle);
$table = $section->addTable('myTable');
22
Chapter 5. Elements
5.5 Images
To add an image, use the addImage method to sections, headers, footers, textruns, or table cells.
$section->addImage($src, [$style]);
5.5.2 Watermarks
To add a watermark (or page background image), your section needs a header reference. After creating a header, you
can use the addWatermark method to add a watermark.
$section = $phpWord->addSection();
$header = $section->addHeader();
$header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55));
5.5. Images
23
5.6 Objects
You can add OLE embeddings, such as Excel spreadsheets or PowerPoint presentations to the document by using
addObject method.
$section->addObject($src, [$style]);
On text:
$section->addText('Lead text.');
$footnote = $section->addFootnote();
$footnote->addText('Footnote text.');
24
Chapter 5. Elements
The footnote reference number will be displayed with decimal number starting from 1. This number use
FooterReference style which you can redefine by addFontStyle method. Default value for this style is
array(superScript => true);
5.9 Checkboxes
Checkbox elements can be added to sections or table cells by using addCheckBox.
$section->addCheckBox($name, $text, [$fontStyle], [$paragraphStyle])
5.10 Textboxes
To be completed
5.11 Fields
To be completed
5.12 Line
Line elements can be added to sections by using addLine.
$linestyle = array('weight' => 1, 'width' => 100, 'height' => 0, 'color' => 635552);
$section->addLine($lineStyle)
5.9. Checkboxes
25
26
Chapter 5. Elements
CHAPTER 6
Styles
6.1 Section
Below are the available styles for section:
pageSizeW Page width in twips (the default is 11906/A4 size)
pageSizeH Page height in twips (the default is 16838/A4 size)
orientation Page orientation, i.e. portrait (default) or landscape
marginTop Page margin top in twips
marginLeft Page margin left in twips
marginRight Page margin right in twips
marginBottom Page margin bottom in twips
borderTopSize Border top size in twips
borderTopColor Border top color
borderLeftSize Border left size in twips
borderLeftColor Border left color
borderRightSize Border right size in twips
borderRightColor Border right color
borderBottomSize Border bottom size in twips
borderBottomColor Border bottom color
headerHeight Spacing to top of header
footerHeight Spacing to bottom of footer
gutter Page gutter spacing
colsNum Number of columns
colsSpace Spacing between columns
breakType Section break type (nextPage, nextColumn, continuous, evenPage, oddPage)
27
6.2 Font
Available font styles:
name Font name, e.g. Arial
size Font size, e.g. 20, 22,
hint Font content type, default, eastAsia, or cs
bold Bold, true or false
italic Italic, true or false
superScript Superscript, true or false
subScript Subscript, true or false
underline Underline, dash, dotted, etc.
strikethrough Strikethrough, true or false
doubleStrikethrough Double strikethrough, true or false
color Font color, e.g. FF0000
fgColor Font highlight color, e.g. yellow, green, blue
bgColor Font background color, e.g. FF0000
smallCaps Small caps, true or false
allCaps All caps, true or false
rtl Right to Left language, true or false
6.3 Paragraph
Available paragraph styles:
align Paragraph alignment, left, right or center
spaceBefore Space before paragraph
spaceAfter Space after paragraph
indent Indent by how much
hanging Hanging by how much
basedOn Parent style
next Style for next paragraph
widowControl Allow first/last line to display on a separate page, true or false
keepNext Keep paragraph with next paragraph, true or false
keepLines Keep all lines on one page, true or false
pageBreakBefore Start paragraph on next page, true or false
lineHeight text line height, e.g. 1.0, 1.5, ect...
tabs Set of custom tab stops
28
Chapter 6. Styles
6.4 Table
Table styles:
width Table width in percent
bgColor Background color, e.g. 9966CC
border(Top|Right|Bottom|Left)Size Border size in twips
border(Top|Right|Bottom|Left)Color Border color, e.g. 9966CC
cellMargin(Top|Right|Bottom|Left) Cell margin in twips
Row styles:
tblHeader Repeat table row on every new page, true or false
cantSplit Table row cannot break across pages, true or false
exactHeight Row height is exact or at least
Cell styles:
width Cell width in twips
valign Vertical alignment, top, center, both, bottom
textDirection Direction of text
bgColor Background color, e.g. 9966CC
border(Top|Right|Bottom|Left)Size Border size in twips
border(Top|Right|Bottom|Left)Color Border color, e.g. 9966CC
gridSpan Number of columns spanned
vMerge restart or continue
6.5 Image
Available image styles:
width Width in pixels
height Height in pixels
align Image alignment, left, right, or center
marginTop Top margin in inches, can be negative
marginLeft Left margin in inches, can be negative
wrappingStyle Wrapping style, inline, square, tight, behind, or infront
6.4. Table
29
30
Chapter 6. Styles
CHAPTER 7
Templates processing
You can create a .docx document template with included search-patterns which can be replaced by any value you wish.
Only single-line values can be replaced.
To deal with a template file, use new TemplateProcessor statement.
After TemplateProcessor instance creation the document template is copied into the temporary directory.
Then you can use
TemplateProcessor::setValue method to change the value of a search pattern. The search-pattern model
is: ${search-pattern}.
Example:
$templateProcessor = new TemplateProcessor('Template.docx');
$templateProcessor->setValue('Name', 'Somebody someone');
$templateProcessor->setValue('Street', 'Coming-Undone-Street 32');
It is not possible to directly add new OOXML elements to the template file being processed, but it is possible to transform main document part of the template using XSLT (see TemplateProcessor::applyXslStyleSheet).
See Sample_07_TemplateCloneRow.php for example on how to create multirow from a single row in a template by using TemplateProcessor::cloneRow.
See
Sample_23_TemplateBlock.php
for
example
on
how
to
clone
a
block
of
text
using
TemplateProcessor::cloneBlock
and
delete
a
block
of
text
using
TemplateProcessor::deleteBlock.
31
32
CHAPTER 8
8.1 OOXML
The package of OOXML document consists of the following files.
_rels/
.rels
docProps/
app.xml
core.xml
custom.xml
word/
rels/
* document.rels.xml
media/
theme/
* theme1.xml
document.xml
fontTable.xml
numbering.xml
settings.xml
styles.xml
webSettings.xml
[Content_Types].xml
33
8.2 OpenDocument
8.2.1 Package
The package of OpenDocument document consists of the following files.
META-INF/
manifest.xml
Pictures/
content.xml
meta.xml
styles.xml
8.2.2 content.xml
The structure of content.xml is described below.
office:document-content
office:font-facedecls
office:automatic-styles
office:body
* office:text
draw:*
office:forms
table:table
text:list
text:numbered-paragraph
text:p
text:table-of-contents
text:section
* office:chart
* office:image
* office:drawing
8.2.3 styles.xml
The structure of styles.xml is described below.
office:document-styles
office:styles
office:automatic-styles
34
office:master-styles
* office:master-page
8.3 RTF
To be completed.
8.4 HTML
To be completed.
8.5 PDF
To be completed.
8.3. RTF
35
36
CHAPTER 9
Recipes
37
$phpWord->addNumberingStyle(
'hNum',
array('type' => 'multilevel', 'levels' => array(
array('pStyle' => 'Heading1', 'format' => 'decimal', 'text'
array('pStyle' => 'Heading2', 'format' => 'decimal', 'text'
array('pStyle' => 'Heading3', 'format' => 'decimal', 'text'
)
)
);
$phpWord->addTitleStyle(1, array('size' => 16), array('numStyle' =>
$phpWord->addTitleStyle(2, array('size' => 14), array('numStyle' =>
$phpWord->addTitleStyle(3, array('size' => 12), array('numStyle' =>
=> '%1'),
=> '%1.%2'),
=> '%1.%2.%3'),
38
Chapter 9. Recipes
CHAPTER 10
10.3 Ive been running PHPWord from CodePlex flawlessly, but I cant
use the latest PHPWord from GitHub. Why?
PHPWord requires PHP 5.3+ since 0.8, while PHPWord 0.6.3 from CodePlex can run with PHP 5.2. Theres a lot of
new features that we can get from PHP 5.3 and its been around since 2009! You should upgrade your PHP version to
use PHPWord 0.8+.
39
40
CHAPTER 11
Credits
41
42
CHAPTER 12
References
43
44
CHAPTER 13
genindex
modindex
search
45