Download the PHP package ephpoffice/phpword without Composer
On this page you can find all versions of the php package ephpoffice/phpword. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ephpoffice/phpword
More information about ephpoffice/phpword
Files in ephpoffice/phpword
Package phpword
Short Description PHPWord - Read, Create and Write Word documents in PHP
License LGPL
Homepage http://phpoffice.github.io
Informations about the package phpword
PHPWord
OpenXML - Read, Write and Create Word documents in PHP.
PHPWord is a library written in PHP that create word documents.
No Windows operating system is needed for usage because the result are docx files (Office Open XML) that can be opened by all major office software.
Want to contribute? Fork us!
Requirements
- PHP version 5.3.0 or higher
Installation
It is recommended that you install the PHPWord library through composer. To do so, add
the following lines to your composer.json
.
Documentation
Table of contents
- Basic usage
- Measurement units
- Sections
- Section settings
- Section page numbering
- Texts
- Attributes
- Paragraph Style
- Attributes
- Tables
- Cell Style
- Images
- Attributes
Basic usage
The following is a basic example of the PHPWord library.
Measurement units
The base length unit in Open Office XML is twip. Twip means "TWentieth of an Inch Point", i.e. 1 twip = 1/1440 inch.
You can use PHPWord helper functions to convert inches, centimeters, or points to twips.
Sections
Every visible element in word is placed inside of a section. To create a section, use the following code:
The $sectionSettings
is an optional associative array that sets the section. Example:
Section settings
Below are the available settings for section:
orientation
Page orientation, i.e. 'portrait' (default) or 'landscape'marginTop
Page margin top in twipsmarginLeft
Page margin left in twipsmarginRight
Page margin right in twipsmarginBottom
Page margin bottom in twipsborderTopSize
Border top size in twipsborderTopColor
Border top colorborderLeftSize
Border left size in twipsborderLeftColor
Border left colorborderRightSize
Border right size in twipsborderRightColor
Border right colorborderBottomSize
Border bottom size in twipsborderBottomColor
Border bottom colorheaderHeight
Spacing to top of headerfooterHeight
Spacing to bottom of footercolsNum
Number of columnscolsSpace
Spacing between columnsbreakType
Section break type (nextPage, nextColumn, continuous, evenPage, oddPage)
The following two settings are automatically set by the use of the orientation
setting. You can alter them but that's not recommended.
pageSizeW
Page width in twipspageSizeH
Page height in twips
Section page numbering
You can change a section page numbering.
Texts
Text can be added by using addText
and createTextRun
method. addText
is used for creating simple paragraphs that only contain texts with the same style. createTextRun
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.
addText
sample:
createTextRun
sample:
Attributes
size
text size, e.g. 20, 22,name
font name, e.g. Arialbold
text is bold, true or falseitalic
text is italic, true or falsesuperScript
text is super script, true or falsesubScript
text is sub script, true or falseunderline
text is underline, true or falsestrikethrough
text is strikethrough, true or falsecolor
text color, e.g. FF0000fgColor
fgColorline-height
text line height, e.g. 1.0, 1.5, ect...
Paragraph Style
Attributes
line-height
text line height, e.g. 1.0, 1.5, ect...align
paragraph alignment, left, right or centerspaceBefore
space before ParagraphspaceAfter
space after Paragraphtabs
set of Custom Tab Stopsindent
indent by how much
Tables
The following illustrates how to create a table.
Cell Style
Cell Span
You can span a cell on multiple columms.
Images
You can add images easily using the following example.
Attributes
width
width in pixelsheight
height in pixelsalign
image alignment, left, right or centermarginTop
top margin in inches, can be negativemarginLeft
left margin in inches, can be negativewrappingStyle
can be inline, square, tight, behind, infront
To add an image with attributes, consider the following example.
All versions of phpword with dependencies
ext-xml Version *