commit
3f136501b3
16
.gitignore
vendored
16
.gitignore
vendored
@ -4,12 +4,16 @@
|
|||||||
.Trashes
|
.Trashes
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
Desktop.ini
|
Desktop.ini
|
||||||
composer.phar
|
.idea
|
||||||
|
_build
|
||||||
phpunit.xml
|
phpunit.xml
|
||||||
|
composer.lock
|
||||||
|
composer.phar
|
||||||
|
vendor
|
||||||
|
/report
|
||||||
|
/samples/resources
|
||||||
|
/samples/results
|
||||||
|
/.settings
|
||||||
phpword.ini
|
phpword.ini
|
||||||
/.buildpath
|
/.buildpath
|
||||||
/.idea
|
/.project
|
||||||
/.project
|
|
||||||
/.settings
|
|
||||||
/build
|
|
||||||
/vendor
|
|
||||||
25
.travis.yml
25
.travis.yml
@ -1,7 +1,6 @@
|
|||||||
language: php
|
language: php
|
||||||
|
|
||||||
php:
|
php:
|
||||||
- 5.3.3
|
|
||||||
- 5.3
|
- 5.3
|
||||||
- 5.4
|
- 5.4
|
||||||
- 5.5
|
- 5.5
|
||||||
@ -10,6 +9,7 @@ php:
|
|||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
allow_failures:
|
allow_failures:
|
||||||
|
- php: 5.2
|
||||||
- php: hhvm
|
- php: hhvm
|
||||||
|
|
||||||
env:
|
env:
|
||||||
@ -23,17 +23,6 @@ before_script:
|
|||||||
## Composer
|
## Composer
|
||||||
- composer self-update
|
- composer self-update
|
||||||
- composer install --prefer-source --dev
|
- composer install --prefer-source --dev
|
||||||
## PHP Copy/Paste Detector
|
|
||||||
- curl -o phpcpd.phar https://phar.phpunit.de/phpcpd.phar
|
|
||||||
## PHP Mess Detector
|
|
||||||
- pear config-set preferred_state beta
|
|
||||||
- printf "\n" | pecl install imagick
|
|
||||||
- pear channel-discover pear.phpmd.org
|
|
||||||
- pear channel-discover pear.pdepend.org
|
|
||||||
- pear install --alldeps phpmd/PHP_PMD
|
|
||||||
- phpenv rehash
|
|
||||||
## PHPLOC
|
|
||||||
#- curl -o phploc.phar https://phar.phpunit.de/phploc.phar
|
|
||||||
## PHPDocumentor
|
## PHPDocumentor
|
||||||
- mkdir -p build/docs
|
- mkdir -p build/docs
|
||||||
- mkdir -p build/coverage
|
- mkdir -p build/coverage
|
||||||
@ -42,15 +31,15 @@ script:
|
|||||||
## PHP_CodeSniffer
|
## PHP_CodeSniffer
|
||||||
- ./vendor/bin/phpcs src/ tests/ --standard=PSR2 -n --ignore=src/PhpWord/Shared/PCLZip
|
- ./vendor/bin/phpcs src/ tests/ --standard=PSR2 -n --ignore=src/PhpWord/Shared/PCLZip
|
||||||
## PHP Copy/Paste Detector
|
## PHP Copy/Paste Detector
|
||||||
- php phpcpd.phar src/ tests/ --verbose
|
- ./vendor/bin/phpcpd src/ tests/ --verbose
|
||||||
## PHP Mess Detector
|
## PHP Mess Detector
|
||||||
- phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php
|
- ./vendor/bin/phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php
|
||||||
## PHPLOC
|
|
||||||
#- php phploc.phar src/
|
|
||||||
## PHPUnit
|
## PHPUnit
|
||||||
- phpunit -c ./ --coverage-text --coverage-html ./build/coverage
|
- ./vendor/bin/phpunit -c ./ --coverage-text --coverage-html ./build/coverage
|
||||||
|
## PHPLOC
|
||||||
|
- ./vendor/bin/phploc src/
|
||||||
## PHPDocumentor
|
## PHPDocumentor
|
||||||
- vendor/bin/phpdoc.php -q -d ./src -t ./build/docs --ignore "*/src/PhpWord/Shared/*/*" --template="responsive-twig"
|
- ./vendor/bin/phpdoc -q -d ./src -t ./build/docs --ignore "*/src/PhpWord/Shared/*/*" --template="responsive-twig"
|
||||||
|
|
||||||
after_script:
|
after_script:
|
||||||
## PHPDocumentor
|
## PHPDocumentor
|
||||||
|
|||||||
279
CHANGELOG.md
279
CHANGELOG.md
@ -2,11 +2,72 @@
|
|||||||
|
|
||||||
This is the changelog between releases of PHPWord. Releases are listed in reverse chronological order with the latest version listed on top, while additions/changes in each release are listed in chronological order. Changes in each release are divided into three parts: added or change features, bugfixes, and miscellaneous improvements. Each line contains short information about the change made, the person who made it, and the related issue number(s) in GitHub.
|
This is the changelog between releases of PHPWord. Releases are listed in reverse chronological order with the latest version listed on top, while additions/changes in each release are listed in chronological order. Changes in each release are divided into three parts: added or change features, bugfixes, and miscellaneous improvements. Each line contains short information about the change made, the person who made it, and the related issue number(s) in GitHub.
|
||||||
|
|
||||||
|
## 0.12.0 - 3 January 2015
|
||||||
|
|
||||||
|
This release added form fields (textinput, checkbox, and dropdown), drawing shapes (arc, curve, line, polyline, rect, oval), and basic 2D chart (pie, doughnut, bar, line, area, scatter, radar) elements along with some new styles. Basic MsDoc reader is introduced.
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
- Element: Ability to add drawing shapes (arc, curve, line, polyline, rect, oval) using new `Shape` element - @ivanlanin #123
|
||||||
|
- Font: New `scale`, `spacing`, and `kerning` property of font style - @ivanlanin
|
||||||
|
- Paragraph: Added shading to the paragraph style for full width shading - @lrobert #264
|
||||||
|
- RTF Writer: Support for sections, margins, and borders - @ivanlanin #249
|
||||||
|
- Section: Ability to set paper size, e.g. A4, A3, and Legal - @ivanlanin #249
|
||||||
|
- General: New `PhpWord::save()` method to encapsulate `IOFactory` - @ivanlanin
|
||||||
|
- General: New `Shared\Converter` static class - @ivanlanin
|
||||||
|
- Chart: Basic 2D chart (pie, doughnut, bar, line, area, scatter, radar) - @ivanlanin #278
|
||||||
|
- Chart: 3D charts and ability to set width and height - @ivanlanin
|
||||||
|
- FormField: Ability to add textinput, checkbox, and dropdown form elements - @ivanlanin #266
|
||||||
|
- Setting: Ability to define document protection (readOnly, comments, trackedChanges, forms) - @ivanlanin
|
||||||
|
- Setting: Ability to remove [Compatibility Mode] text in the MS Word title bar - @ivanlanin
|
||||||
|
- SDT: Ability to add structured document tag elements (comboBox, dropDownList, date) - @ivanlanin
|
||||||
|
- Paragraph: Support for paragraph with borders - @ivanlanin #294
|
||||||
|
- Word2007 Writer : Support for RTL - @Progi1984 #331
|
||||||
|
- MsDOC Reader: Basic MsDOC Reader - @Progi1984 #23, #287
|
||||||
|
- "absolute" horizontal and vertical positioning of Frame - @basjan #302
|
||||||
|
- Add new-page function for PDF generation. For multiple PDF-backends - @chc88 #426
|
||||||
|
- Report style options enumerated when style unknown - @h6w
|
||||||
|
|
||||||
|
### Bugfixes
|
||||||
|
|
||||||
|
- Fix rare PclZip/realpath/PHP version problem - @andrew-kzoo #261
|
||||||
|
- `addHTML` encoding and ampersand fixes for PHP 5.3 - @bskrtich #270
|
||||||
|
- Page breaks on titles and tables - @ivanlanin #274
|
||||||
|
- Table inside vertical border does not rendered properly - @ivanlanin #280
|
||||||
|
- `add<elementName>` of container should be case insensitive, e.g. `addToc` should be accepted, not only `addTOC` - @ivanlanin #294
|
||||||
|
- Fix specific borders (and margins) were not written correctly in word2007 writer - @pscheit #327
|
||||||
|
- "HTML is not a valid writer" exception while running "Sample_36_RTL.php" - @RomanSyroeshko #340
|
||||||
|
- "addShape()" magic method in AbstractContainer is mistakenly named as "addObject()" - @GMTA #356
|
||||||
|
- `Element\Section::setPageSizeW()` and `Element\Section::setPageSizeH()` were mentioned in the docs but not implemented.
|
||||||
|
- Special Characters (ampersand) in Title break docx output - @RomanSyroeshko #401
|
||||||
|
- `<th>` tag is closed with `</td>` tag: - @franzholz #438
|
||||||
|
|
||||||
|
### Deprecated
|
||||||
|
|
||||||
|
- `Element\Link::getTarget()` replaced by `Element\Link::getSource()`
|
||||||
|
- `Element\Section::getSettings()` and `Element\Section::setSettings()` replaced by `Element\Section::getStyle()` and `Element\Section::setStyle()`
|
||||||
|
- `Shared\Drawing` and `Shared\Font` merged into `Shared\Converter`
|
||||||
|
- `DocumentProperties` replaced by `Metadata\DocInfo`
|
||||||
|
- `Template` replaced by `TemplateProcessor`
|
||||||
|
- `PhpWord->loadTemplate($filename)`
|
||||||
|
|
||||||
|
### Miscellaneous
|
||||||
|
|
||||||
|
- Docs: Add known issue on `README` about requirement for temporary folder to be writable and update `samples/index.php` for this requirement check - @ivanlanin #238
|
||||||
|
- Docs: Correct elements.rst about Line - @chrissharkman #292
|
||||||
|
- PclZip: Remove temporary file after used - @andrew-kzoo #265
|
||||||
|
- Autoloader: Add the ability to set the autoloader options - @bskrtich #267
|
||||||
|
- Element: Refactor elements to move set relation Id from container to element - @ivanlanin
|
||||||
|
- Introduced CreateTemporaryFileException, CopyFileException - @RomanSyroeshko
|
||||||
|
- Settings: added method to set user defined temporary directory - @RomanSyroeshko #310
|
||||||
|
- Renamed `Template` into `TemplateProcessor` - @RomanSyroeshko #216
|
||||||
|
- Reverted #51. All text escaping must be performed out of the library - @RomanSyroeshko #51
|
||||||
|
|
||||||
## 0.11.1 - 2 June 2014
|
## 0.11.1 - 2 June 2014
|
||||||
|
|
||||||
This is an immediate bugfix release for HTML reader.
|
This is an immediate bugfix release for HTML reader.
|
||||||
|
|
||||||
- HTML Reader: `<p>` and header tags puts no output - @canyildiz @ivanlanin GH-257
|
- HTML Reader: `<p>` and header tags puts no output - @canyildiz @ivanlanin #257
|
||||||
|
|
||||||
## 0.11.0 - 1 June 2014
|
## 0.11.0 - 1 June 2014
|
||||||
|
|
||||||
@ -14,17 +75,17 @@ This release marked the change of PHPWord license from LGPL 2.1 to LGPL 3. Four
|
|||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
- Image: Ability to define relative and absolute positioning - @basjan GH-217
|
- Image: Ability to define relative and absolute positioning - @basjan #217
|
||||||
- Footer: Conform footer with header by adding firstPage, evenPage and by inheritance - @basjan @ivanlanin GH-219
|
- Footer: Conform footer with header by adding firstPage, evenPage and by inheritance - @basjan @ivanlanin #219
|
||||||
- Element: New `TextBox` element - @basjan @ivanlanin GH-228 GH-229 GH-231
|
- Element: New `TextBox` element - @basjan @ivanlanin #228, #229, #231
|
||||||
- HTML: Ability to add elements to PHPWord object via html - @basjan GH-231
|
- HTML: Ability to add elements to PHPWord object via html - @basjan #231
|
||||||
- Element: New `ListItemRun` element that can add a list item with inline formatting like a textrun - @basjan GH-235
|
- Element: New `ListItemRun` element that can add a list item with inline formatting like a textrun - @basjan #235
|
||||||
- Table: Ability to add table inside a cell (nested table) - @ivanlanin GH-149
|
- Table: Ability to add table inside a cell (nested table) - @ivanlanin #149
|
||||||
- RTF Writer: UTF8 support for RTF: Internal UTF8 text is converted to Unicode before writing - @ivanlanin GH-158
|
- RTF Writer: UTF8 support for RTF: Internal UTF8 text is converted to Unicode before writing - @ivanlanin #158
|
||||||
- Table: Ability to define table width (in percent and twip) and position - @ivanlanin GH-237
|
- Table: Ability to define table width (in percent and twip) and position - @ivanlanin #237
|
||||||
- RTF Writer: Ability to add links and page breaks in RTF - @ivanlanin GH-196
|
- RTF Writer: Ability to add links and page breaks in RTF - @ivanlanin #196
|
||||||
- ListItemRun: Remove fontStyle parameter because ListItemRun is inherited from TextRun and TextRun doesn't have fontStyle - @ivanlanin
|
- ListItemRun: Remove fontStyle parameter because ListItemRun is inherited from TextRun and TextRun doesn't have fontStyle - @ivanlanin
|
||||||
- Config: Ability to use a config file to store various common settings - @ivanlanin GH-200
|
- Config: Ability to use a config file to store various common settings - @ivanlanin #200
|
||||||
- ODT Writer: Enable inline font style in TextRun - @ivanlanin
|
- ODT Writer: Enable inline font style in TextRun - @ivanlanin
|
||||||
- ODT Writer: Enable underline, strike/doublestrike, smallcaps/allcaps, superscript/subscript font style - @ivanlanin
|
- ODT Writer: Enable underline, strike/doublestrike, smallcaps/allcaps, superscript/subscript font style - @ivanlanin
|
||||||
- ODT Writer: Enable section and column - @ivanlanin
|
- ODT Writer: Enable section and column - @ivanlanin
|
||||||
@ -32,23 +93,23 @@ This release marked the change of PHPWord license from LGPL 2.1 to LGPL 3. Four
|
|||||||
- ODT Writer: Enable title element and custom document properties - @ivanlanin
|
- ODT Writer: Enable title element and custom document properties - @ivanlanin
|
||||||
- ODT Reader: Ability to read standard and custom document properties - @ivanlanin
|
- ODT Reader: Ability to read standard and custom document properties - @ivanlanin
|
||||||
- Word2007 Writer: Enable the missing custom document properties writer - @ivanlanin
|
- Word2007 Writer: Enable the missing custom document properties writer - @ivanlanin
|
||||||
- Image: Enable "image float left" - @ivanlanin GH-244
|
- Image: Enable "image float left" - @ivanlanin #244
|
||||||
- RTF Writer: Ability to write document properties - @ivanlanin
|
- RTF Writer: Ability to write document properties - @ivanlanin
|
||||||
- RTF Writer: Ability to write image - @ivanlanin
|
- RTF Writer: Ability to write image - @ivanlanin
|
||||||
- Element: New `Field` element - @basjan GH-251
|
- Element: New `Field` element - @basjan #251
|
||||||
- RTF Reader: Basic RTF reader - @ivanlanin GH-72 GH-252
|
- RTF Reader: Basic RTF reader - @ivanlanin #72, #252
|
||||||
- Element: New `Line` element - @basjan GH-253
|
- Element: New `Line` element - @basjan #253
|
||||||
- Title: Ability to apply numbering in heading - @ivanlanin GH-193
|
- Title: Ability to apply numbering in heading - @ivanlanin #193
|
||||||
- HTML Reader: Basic HTML reader - @ivanlanin GH-80 GH-254
|
- HTML Reader: Basic HTML reader - @ivanlanin #80, #254
|
||||||
- RTF Writer: Basic table writing - @ivanlanin GH-245
|
- RTF Writer: Basic table writing - @ivanlanin #245
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
||||||
- Header: All images added to the second header were assigned to the first header - @basjan GH-222
|
- Header: All images added to the second header were assigned to the first header - @basjan #222
|
||||||
- Conversion: Fix conversion from cm to pixel, pixel to cm, and pixel to point - @basjan GH-233 GH-234
|
- Conversion: Fix conversion from cm to pixel, pixel to cm, and pixel to point - @basjan #233, #234
|
||||||
- PageBreak: Page break adds new line in the beginning of the new page - @ivanlanin GH-150
|
- PageBreak: Page break adds new line in the beginning of the new page - @ivanlanin #150
|
||||||
- Image: `marginLeft` and `marginTop` cannot accept float value - @ivanlanin GH-248
|
- Image: `marginLeft` and `marginTop` cannot accept float value - @ivanlanin #248
|
||||||
- Title: Orphan `w:fldChar` caused OpenOffice to crash when opening DOCX - @ivanlanin GH-236
|
- Title: Orphan `w:fldChar` caused OpenOffice to crash when opening DOCX - @ivanlanin #236
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
@ -60,13 +121,13 @@ This release marked the change of PHPWord license from LGPL 2.1 to LGPL 3. Four
|
|||||||
|
|
||||||
### Miscellaneous
|
### Miscellaneous
|
||||||
|
|
||||||
- License: Change the project license from LGPL 2.1 into LGPL 3.0 - GH-211
|
- License: Change the project license from LGPL 2.1 into LGPL 3.0 - #211
|
||||||
- Word2007 Writer: New `Style\Image` class - @ivanlanin
|
- Word2007 Writer: New `Style\Image` class - @ivanlanin
|
||||||
- Refactor: Replace static classes `Footnotes`, `Endnotes`, and `TOC` with `Collections` - @ivanlanin GH-206
|
- Refactor: Replace static classes `Footnotes`, `Endnotes`, and `TOC` with `Collections` - @ivanlanin #206
|
||||||
- QA: Reactivate `phpcpd` and `phpmd` on Travis - @ivanlanin
|
- QA: Reactivate `phpcpd` and `phpmd` on Travis - @ivanlanin
|
||||||
- Refactor: PHPMD recommendation: Change all `get...` method that returns `boolean` into `is...` or `has...` - @ivanlanin
|
- Refactor: PHPMD recommendation: Change all `get...` method that returns `boolean` into `is...` or `has...` - @ivanlanin
|
||||||
- Docs: Create gh-pages branch for API documentation - @Progi1984 GH-154
|
- Docs: Create gh-pages branch for API documentation - @Progi1984 #154
|
||||||
- QA: Add `.scrutinizer.yml` and include `composer.lock` for preparation to Scrutinizer - @ivanlanin GH-186
|
- QA: Add `.scrutinizer.yml` and include `composer.lock` for preparation to Scrutinizer - @ivanlanin #186
|
||||||
- Writer: Refactor writer parts using composite pattern - @ivanlanin
|
- Writer: Refactor writer parts using composite pattern - @ivanlanin
|
||||||
- Docs: Show code quality and test code coverage badge on README
|
- Docs: Show code quality and test code coverage badge on README
|
||||||
- Style: Change behaviour of `set...` function of boolean properties; when none is defined, assumed true - @ivanlanin
|
- Style: Change behaviour of `set...` function of boolean properties; when none is defined, assumed true - @ivanlanin
|
||||||
@ -79,7 +140,7 @@ This release marked the change of PHPWord license from LGPL 2.1 to LGPL 3. Four
|
|||||||
|
|
||||||
This is a bugfix release for `php-zip` requirement in Composer.
|
This is a bugfix release for `php-zip` requirement in Composer.
|
||||||
|
|
||||||
- Change Composer requirements for php-zip from `require` to `suggest` - @bskrtich GH-246
|
- Change Composer requirements for php-zip from `require` to `suggest` - @bskrtich #246
|
||||||
|
|
||||||
## 0.10.0 - 4 May 2014
|
## 0.10.0 - 4 May 2014
|
||||||
|
|
||||||
@ -87,48 +148,48 @@ This release marked heavy refactorings on internal code structure with the creat
|
|||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
- Image: Get image dimensions without EXIF extension - @andrew-kzoo GH-184
|
- Image: Get image dimensions without EXIF extension - @andrew-kzoo #184
|
||||||
- Table: Add `tblGrid` element for Libre/Open Office table sizing - @gianis6 GH-183
|
- Table: Add `tblGrid` element for Libre/Open Office table sizing - @gianis6 #183
|
||||||
- Footnote: Ability to insert textbreak in footnote `$footnote->addTextBreak()` - @ivanlanin
|
- Footnote: Ability to insert textbreak in footnote `$footnote->addTextBreak()` - @ivanlanin
|
||||||
- Footnote: Ability to style footnote reference mark by using `FootnoteReference` style - @ivanlanin
|
- Footnote: Ability to style footnote reference mark by using `FootnoteReference` style - @ivanlanin
|
||||||
- Font: Add `bgColor` to font style to define background using HEX color - @jcarignan GH-168
|
- Font: Add `bgColor` to font style to define background using HEX color - @jcarignan #168
|
||||||
- Table: Add `exactHeight` to row style to define whether row height should be exact or atLeast - @jcarignan GH-168
|
- Table: Add `exactHeight` to row style to define whether row height should be exact or atLeast - @jcarignan #168
|
||||||
- Element: New `CheckBox` element for sections and table cells - @ozilion GH-156
|
- Element: New `CheckBox` element for sections and table cells - @ozilion #156
|
||||||
- Settings: Ability to use PCLZip as alternative to ZipArchive - @bskrtich @ivanlanin GH-106 GH-140 GH-185
|
- Settings: Ability to use PCLZip as alternative to ZipArchive - @bskrtich @ivanlanin #106, #140, #185
|
||||||
- Template: Ability to find & replace variables in headers & footers - @dgudgeon GH-190
|
- Template: Ability to find & replace variables in headers & footers - @dgudgeon #190
|
||||||
- Template: Ability to clone & delete block of text using `cloneBlock` and `deleteBlock` - @diego-vieira GH-191
|
- Template: Ability to clone & delete block of text using `cloneBlock` and `deleteBlock` - @diego-vieira #191
|
||||||
- TOC: Ability to have two or more TOC in one document and to set min and max depth for TOC - @Pyreweb GH-189
|
- TOC: Ability to have two or more TOC in one document and to set min and max depth for TOC - @Pyreweb #189
|
||||||
- Table: Ability to add footnote in table cell - @ivanlanin GH-187
|
- Table: Ability to add footnote in table cell - @ivanlanin #187
|
||||||
- Footnote: Ability to add image in footnote - @ivanlanin GH-187
|
- Footnote: Ability to add image in footnote - @ivanlanin #187
|
||||||
- ListItem: Ability to add list item in header/footer - @ivanlanin GH-187
|
- ListItem: Ability to add list item in header/footer - @ivanlanin #187
|
||||||
- CheckBox: Ability to add checkbox in header/footer - @ivanlanin GH-187
|
- CheckBox: Ability to add checkbox in header/footer - @ivanlanin #187
|
||||||
- Link: Ability to add link in header/footer - @ivanlanin GH-187
|
- Link: Ability to add link in header/footer - @ivanlanin #187
|
||||||
- Object: Ability to add object in header, footer, textrun, and footnote - @ivanlanin GH-187
|
- Object: Ability to add object in header, footer, textrun, and footnote - @ivanlanin #187
|
||||||
- Media: Add `Media::resetElements()` to reset all media data - @juzi GH-19
|
- Media: Add `Media::resetElements()` to reset all media data - @juzi #19
|
||||||
- General: Add `Style::resetStyles()` - @ivanlanin GH-187
|
- General: Add `Style::resetStyles()` - @ivanlanin #187
|
||||||
- DOCX Reader: Ability to read header, footer, footnotes, link, preservetext, textbreak, pagebreak, table, list, image, and title - @ivanlanin
|
- DOCX Reader: Ability to read header, footer, footnotes, link, preservetext, textbreak, pagebreak, table, list, image, and title - @ivanlanin
|
||||||
- Endnote: Ability to add endnotes - @ivanlanin
|
- Endnote: Ability to add endnotes - @ivanlanin
|
||||||
- ListItem: Ability to create custom list and reset list number - @ivanlanin GH-10 GH-198
|
- ListItem: Ability to create custom list and reset list number - @ivanlanin #10, #198
|
||||||
- ODT Writer: Basic table writing support - @ivanlanin
|
- ODT Writer: Basic table writing support - @ivanlanin
|
||||||
- Image: Keep image aspect ratio if only 1 dimension styled - @japonicus GH-194
|
- Image: Keep image aspect ratio if only 1 dimension styled - @japonicus #194
|
||||||
- HTML Writer: Basic HTML writer: text, textrun, link, title, textbreak, table, image (as Base64), footnote, endnote - @ivanlanin GH-203 GH-67 GH-147
|
- HTML Writer: Basic HTML writer: text, textrun, link, title, textbreak, table, image (as Base64), footnote, endnote - @ivanlanin #203, #67, #147
|
||||||
- PDF Writer: Basic PDF writer using DomPDF: All HTML element except image - @ivanlanin GH-68
|
- PDF Writer: Basic PDF writer using DomPDF: All HTML element except image - @ivanlanin #68
|
||||||
- DOCX Writer: Change `docProps/app.xml` `Application` to `PHPWord` - @ivanlanin
|
- DOCX Writer: Change `docProps/app.xml` `Application` to `PHPWord` - @ivanlanin
|
||||||
- DOCX Writer: Create `word/settings.xml` and `word/webSettings.xml` dynamically - @ivanlanin
|
- DOCX Writer: Create `word/settings.xml` and `word/webSettings.xml` dynamically - @ivanlanin
|
||||||
- ODT Writer: Basic image writing - @ivanlanin
|
- ODT Writer: Basic image writing - @ivanlanin
|
||||||
- ODT Writer: Link writing - @ivanlanin
|
- ODT Writer: Link writing - @ivanlanin
|
||||||
- ODT Reader: Basic ODText Reader - @ivanlanin GH-71
|
- ODT Reader: Basic ODText Reader - @ivanlanin #71
|
||||||
- Section: Ability to define gutter and line numbering - @ivanlanin
|
- Section: Ability to define gutter and line numbering - @ivanlanin
|
||||||
- Font: Small caps, all caps, and double strikethrough - @ivanlanin GH-151
|
- Font: Small caps, all caps, and double strikethrough - @ivanlanin #151
|
||||||
- Settings: Ability to use measurement unit other than twips with `setMeasurementUnit` - @ivanlanin GH-199
|
- Settings: Ability to use measurement unit other than twips with `setMeasurementUnit` - @ivanlanin #199
|
||||||
- Style: Remove `bgColor` from `Font`, `Table`, and `Cell` and put it into the new `Shading` style - @ivanlanin
|
- Style: Remove `bgColor` from `Font`, `Table`, and `Cell` and put it into the new `Shading` style - @ivanlanin
|
||||||
- Style: New `Indentation` and `Spacing` style - @ivanlanin
|
- Style: New `Indentation` and `Spacing` style - @ivanlanin
|
||||||
- Paragraph: Ability to define first line and right indentation - @ivanlanin
|
- Paragraph: Ability to define first line and right indentation - @ivanlanin
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
||||||
- Footnote: Footnote content doesn't show footnote reference number - @ivanlanin GH-170
|
- Footnote: Footnote content doesn't show footnote reference number - @ivanlanin #170
|
||||||
- Documentation: Error in a function - @theBeerNut GH-195
|
- Documentation: Error in a function - @theBeerNut #195
|
||||||
|
|
||||||
### Deprecated
|
### Deprecated
|
||||||
|
|
||||||
@ -148,20 +209,20 @@ This release marked heavy refactorings on internal code structure with the creat
|
|||||||
|
|
||||||
### Miscellaneous
|
### Miscellaneous
|
||||||
|
|
||||||
- Documentation: Simplify page level docblock - @ivanlanin GH-179
|
- Documentation: Simplify page level docblock - @ivanlanin #179
|
||||||
- Writer: Refactor writer classes and create a new `Write\AbstractWriter` abstract class - @ivanlanin GH-160
|
- Writer: Refactor writer classes and create a new `Write\AbstractWriter` abstract class - @ivanlanin #160
|
||||||
- General: Refactor folders: `Element` and `Exception` - @ivanlanin GH-187
|
- General: Refactor folders: `Element` and `Exception` - @ivanlanin #187
|
||||||
- General: Remove legacy `HashTable` and `Shared\ZipStreamWrapper` and all related properties/methods - @ivanlanin GH-187
|
- General: Remove legacy `HashTable` and `Shared\ZipStreamWrapper` and all related properties/methods - @ivanlanin #187
|
||||||
- Element: New `AbstractElement` abstract class - @ivanlanin GH-187
|
- Element: New `AbstractElement` abstract class - @ivanlanin #187
|
||||||
- Media: Refactor media class to use one method for all docPart (section, header, footer, footnote) - @ivanlanin GH-187
|
- Media: Refactor media class to use one method for all docPart (section, header, footer, footnote) - @ivanlanin #187
|
||||||
- General: Remove underscore prefix from all private properties name - @ivanlanin GH-187
|
- General: Remove underscore prefix from all private properties name - @ivanlanin #187
|
||||||
- General: Move Section `Settings` to `Style\Section` - @ivanlanin GH-187
|
- General: Move Section `Settings` to `Style\Section` - @ivanlanin #187
|
||||||
- General: Give `Abstract` prefix and `Interface` suffix for all abstract classes and interfaces as per [PHP-FIG recommendation](https://github.com/php-fig/fig-standards/blob/master/bylaws/002-psr-naming-conventions.md) - @ivanlanin GH-187
|
- General: Give `Abstract` prefix and `Interface` suffix for all abstract classes and interfaces as per [PHP-FIG recommendation](https://github.com/php-fig/fig-standards/blob/master/bylaws/002-psr-naming-conventions.md) - @ivanlanin #187
|
||||||
- Style: New `Style\AbstractStyle` abstract class - @ivanlanin GH-187
|
- Style: New `Style\AbstractStyle` abstract class - @ivanlanin #187
|
||||||
- Writer: New 'ODText\Base` class - @ivanlanin GH-187
|
- Writer: New 'ODText\Base` class - @ivanlanin #187
|
||||||
- General: Rename `Footnote` to `Footnotes` to reflect the nature of collection - @ivanlanin
|
- General: Rename `Footnote` to `Footnotes` to reflect the nature of collection - @ivanlanin
|
||||||
- General: Add some unit tests for Shared & Element (100%!) - @Progi1984
|
- General: Add some unit tests for Shared & Element (100%!) - @Progi1984
|
||||||
- Test: Add some samples and tests for image wrapping style - @brunocasado GH-59
|
- Test: Add some samples and tests for image wrapping style - @brunocasado #59
|
||||||
- Refactor: Remove Style\Tabs - @ivanlanin
|
- Refactor: Remove Style\Tabs - @ivanlanin
|
||||||
- Refactor: Apply composite pattern for writers - @ivanlanin
|
- Refactor: Apply composite pattern for writers - @ivanlanin
|
||||||
- Refactor: Split `AbstractContainer` from `AbstractElement` - @ivanlanin
|
- Refactor: Split `AbstractContainer` from `AbstractElement` - @ivanlanin
|
||||||
@ -188,13 +249,13 @@ This release marked the transformation to namespaces (PHP 5.3+).
|
|||||||
|
|
||||||
### Miscellaneous
|
### Miscellaneous
|
||||||
|
|
||||||
- Move documentation to [Read The Docs](http://phpword.readthedocs.org/en/develop/) - @Progi1984 @ivanlanin GH-82
|
- Move documentation to [Read The Docs](http://phpword.readthedocs.org/en/develop/) - @Progi1984 @ivanlanin #82
|
||||||
- Reorganize and redesign samples folder - @ivanlanin GH-137
|
- Reorganize and redesign samples folder - @ivanlanin #137
|
||||||
- Use `PhpOffice\PhpWord` namespace for PSR compliance - @RomanSyroeshko @gabrielbull GH-159 GH-58
|
- Use `PhpOffice\PhpWord` namespace for PSR compliance - @RomanSyroeshko @gabrielbull #159, #58
|
||||||
- Restructure folders and change folder name `Classes` to `src` and `Tests` to `test` for PSR compliance - @RomanSyroeshko @gabrielbull
|
- Restructure folders and change folder name `Classes` to `src` and `Tests` to `test` for PSR compliance - @RomanSyroeshko @gabrielbull
|
||||||
- Compliance to phpDocumentor - @ivanlanin
|
- Compliance to phpDocumentor - @ivanlanin
|
||||||
- Merge Style\TableFull into Style\Table. Style\TableFull is deprecated - @ivanlanin GH-160
|
- Merge Style\TableFull into Style\Table. Style\TableFull is deprecated - @ivanlanin #160
|
||||||
- Merge Section\MemoryImage into Section\Image. Section\Image is deprecated - @ivanlanin GH-160
|
- Merge Section\MemoryImage into Section\Image. Section\Image is deprecated - @ivanlanin #160
|
||||||
|
|
||||||
## 0.8.1 - 17 Mar 2014
|
## 0.8.1 - 17 Mar 2014
|
||||||
|
|
||||||
@ -208,44 +269,44 @@ This release merged a lot of improvements from the community. Unit tests introdu
|
|||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
- Template: Permit to save a template generated as a file (PHPWord_Template::saveAs()) - @RomanSyroeshko GH-56 GH-57
|
- Template: Permit to save a template generated as a file (PHPWord_Template::saveAs()) - @RomanSyroeshko #56, #57
|
||||||
- Word2007: Support sections page numbering - @gabrielbull
|
- Word2007: Support sections page numbering - @gabrielbull
|
||||||
- Word2007: Added line height methods to mirror the line height settings in Word in the paragraph styling - @gabrielbull
|
- Word2007: Added line height methods to mirror the line height settings in Word in the paragraph styling - @gabrielbull
|
||||||
- Word2007: Added support for page header & page footer height - @JillElaine GH-5
|
- Word2007: Added support for page header & page footer height - @JillElaine #5
|
||||||
- General: Add ability to manage line breaks after image insertion - @bskrtich GH-6 GH-66 GH-84
|
- General: Add ability to manage line breaks after image insertion - @bskrtich #6, #66, #84
|
||||||
- Template: Ability to limit number of replacements performed by setValue() method of Template class - @RomanSyroeshko GH-52 GH-53 GH-85
|
- Template: Ability to limit number of replacements performed by setValue() method of Template class - @RomanSyroeshko #52, #53, #85
|
||||||
- Table row: Repeat as header row & allow row to break across pages - @ivanlanin GH-48 GH-86
|
- Table row: Repeat as header row & allow row to break across pages - @ivanlanin #48, #86
|
||||||
- Table: Table width in percentage - @ivanlanin GH-48 GH-86
|
- Table: Table width in percentage - @ivanlanin #48, #86
|
||||||
- Font: Superscript and subscript - @ivanlanin GH-48 GH-86
|
- Font: Superscript and subscript - @ivanlanin #48, #86
|
||||||
- Paragraph: Hanging paragraph - @ivanlanin GH-48 GH-86
|
- Paragraph: Hanging paragraph - @ivanlanin #48, #86
|
||||||
- Section: Multicolumn and section break - @ivanlanin GH-48 GH-86
|
- Section: Multicolumn and section break - @ivanlanin #48, #86
|
||||||
- Template: Ability to apply XSL style sheet to Template - @RomanSyroeshko GH-46 GH-47 GH-83
|
- Template: Ability to apply XSL style sheet to Template - @RomanSyroeshko #46, #47, #83
|
||||||
- General: PHPWord_Shared_Font::pointSizeToTwips() converter - @ivanlanin GH-87
|
- General: PHPWord_Shared_Font::pointSizeToTwips() converter - @ivanlanin #87
|
||||||
- Paragraph: Ability to define normal paragraph style with PHPWord::setNormalStyle() - @ivanlanin GH-87
|
- Paragraph: Ability to define normal paragraph style with PHPWord::setNormalStyle() - @ivanlanin #87
|
||||||
- Paragraph: Ability to define parent style (basedOn) and style for following paragraph (next) - @ivanlanin GH-87
|
- Paragraph: Ability to define parent style (basedOn) and style for following paragraph (next) - @ivanlanin #87
|
||||||
- Clone table rows on the fly when using a template document - @jeroenmoors GH-44 GH-88
|
- Clone table rows on the fly when using a template document - @jeroenmoors #44, #88
|
||||||
- Initial addition of basic footnote support - @deds GH-16
|
- Initial addition of basic footnote support - @deds #16
|
||||||
- Paragraph: Ability to define paragraph pagination: widow control, keep next, keep lines, and page break before - @ivanlanin GH-92
|
- Paragraph: Ability to define paragraph pagination: widow control, keep next, keep lines, and page break before - @ivanlanin #92
|
||||||
- General: PHPWord_Style_Font refactoring - @ivanlanin GH-93
|
- General: PHPWord_Style_Font refactoring - @ivanlanin #93
|
||||||
- Font: Use points instead of halfpoints internally. Conversion to halfpoints done during XML Writing. - @ivanlanin GH-93
|
- Font: Use points instead of halfpoints internally. Conversion to halfpoints done during XML Writing. - @ivanlanin #93
|
||||||
- Paragraph: setTabs() function - @ivanlanin GH-92
|
- Paragraph: setTabs() function - @ivanlanin #92
|
||||||
- General: Basic support for TextRun on ODT and RTF - @ivanlanin GH-99
|
- General: Basic support for TextRun on ODT and RTF - @ivanlanin #99
|
||||||
- Reader: Basic Reader for Word2007 - @ivanlanin GH-104
|
- Reader: Basic Reader for Word2007 - @ivanlanin #104
|
||||||
- TextRun: Allow Text Break in Text Run - @bskrtich GH-109
|
- TextRun: Allow Text Break in Text Run - @bskrtich #109
|
||||||
- General: Support for East Asian fontstyle - @jhfangying GH-111 GH-118
|
- General: Support for East Asian fontstyle - @jhfangying #111, #118
|
||||||
- Image: Use exif_imagetype to check image format instead of extension name - @gabrielbull GH-114
|
- Image: Use exif_imagetype to check image format instead of extension name - @gabrielbull #114
|
||||||
- General: Setting for XMLWriter Compatibility option - @bskrtich GH-103
|
- General: Setting for XMLWriter Compatibility option - @bskrtich #103
|
||||||
- MemoryImage: Allow remote image when allow_url_open = on - @ivanlanin GH-122
|
- MemoryImage: Allow remote image when allow_url_open = on - @ivanlanin #122
|
||||||
- TextBreak: Allow font and paragraph style for text break - @ivanlanin GH-18
|
- TextBreak: Allow font and paragraph style for text break - @ivanlanin #18
|
||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
||||||
- Fixed bug with cell styling - @gabrielbull
|
- Fixed bug with cell styling - @gabrielbull
|
||||||
- Fixed bug list items inside of cells - @gabrielbull
|
- Fixed bug list items inside of cells - @gabrielbull
|
||||||
- Adding a value that contains "&" in a template breaks it - @SiebelsTim GH-51
|
- Adding a value that contains "&" in a template breaks it - @SiebelsTim #51
|
||||||
- Example in README.md is broken - @Progi1984 GH-89
|
- Example in README.md is broken - @Progi1984 #89
|
||||||
- General: PHPWord_Shared_Drawing::centimetersToPixels() conversion - @ivanlanin GH-94
|
- General: PHPWord_Shared_Drawing::centimetersToPixels() conversion - @ivanlanin #94
|
||||||
- Footnote: Corrupt DOCX reported by MS Word when sections > 1 and not every sections have footnote - @ivanlanin GH-125
|
- Footnote: Corrupt DOCX reported by MS Word when sections > 1 and not every sections have footnote - @ivanlanin #125
|
||||||
|
|
||||||
### Miscellaneous
|
### Miscellaneous
|
||||||
|
|
||||||
@ -257,8 +318,8 @@ This is the first release after a long development hiatus in [CodePlex](https://
|
|||||||
|
|
||||||
### Features
|
### Features
|
||||||
|
|
||||||
- Implement RTF Writer - @Progi1984 GH-1
|
- Implement RTF Writer - @Progi1984 #1
|
||||||
- Implement ODT Writer - @Progi1984 GH-2
|
- Implement ODT Writer - @Progi1984 #2
|
||||||
- Word2007: Add rowspan and colspan to cells - @kaystrobach
|
- Word2007: Add rowspan and colspan to cells - @kaystrobach
|
||||||
- Word2007: Support for tab stops - @RLovelett
|
- Word2007: Support for tab stops - @RLovelett
|
||||||
- Word2007: Support Multiple headers - @RLovelett
|
- Word2007: Support Multiple headers - @RLovelett
|
||||||
@ -267,16 +328,16 @@ This is the first release after a long development hiatus in [CodePlex](https://
|
|||||||
|
|
||||||
### Bugfixes
|
### Bugfixes
|
||||||
|
|
||||||
- "Warning: Invalid error type specified in ...\PHPWord.php on line 226" is thrown when the specified template file is not found - @RomanSyroeshko GH-32
|
- "Warning: Invalid error type specified in ...\PHPWord.php on line 226" is thrown when the specified template file is not found - @RomanSyroeshko #32
|
||||||
- PHPWord_Shared_String.IsUTF8 returns FALSE for Cyrillic UTF-8 input - @RomanSyroeshko GH-34
|
- PHPWord_Shared_String.IsUTF8 returns FALSE for Cyrillic UTF-8 input - @RomanSyroeshko #34
|
||||||
- Temporary files naming logic in PHPWord_Template can lead to a collision - @RomanSyroeshko GH-38
|
- Temporary files naming logic in PHPWord_Template can lead to a collision - @RomanSyroeshko #38
|
||||||
|
|
||||||
### Miscellaneous
|
### Miscellaneous
|
||||||
|
|
||||||
- Add superscript/subscript styling in Excel2007 Writer - @MarkBaker
|
- Add superscript/subscript styling in Excel2007 Writer - @MarkBaker
|
||||||
- add indentation support to paragraphs - @deds
|
- add indentation support to paragraphs - @deds
|
||||||
- Support for Composer - @Progi1984 GH-27
|
- Support for Composer - @Progi1984 #27
|
||||||
- Basic CI with Travis - @Progi1984
|
- Basic CI with Travis - @Progi1984
|
||||||
- Added PHPWord_Exception and exception when could not copy the template - @Progi1984
|
- Added PHPWord_Exception and exception when could not copy the template - @Progi1984
|
||||||
- IMPROVED: Moved examples out of Classes directory - @Progi1984
|
- IMPROVED: Moved examples out of Classes directory - @Progi1984
|
||||||
- IMPROVED: Advanced string replace in setValue for Template - @Esmeraldo CP-49
|
- IMPROVED: Advanced string replace in setValue for Template - @Esmeraldo [#49](http://phpword.codeplex.com/workitem/49)
|
||||||
|
|||||||
@ -1,14 +1,14 @@
|
|||||||
# Contributing to PHPWord
|
# Contributing to PHPWord
|
||||||
|
|
||||||
PHPWord is build by the crowd and for the crowd. Every contributions are welcomed; either by [submitting](https://github.com/PHPOffice/PHPWord/issues) bug issues or suggesting improvements, or in a more active form like [requesting](https://github.com/PHPOffice/PHPWord/pulls) a pull.
|
PHPWord is built by the crowd and for the crowd. Every contribution is welcome; either by [submitting](https://github.com/PHPOffice/PHPWord/issues) bug issues or suggesting improvements, or in a more active form like [requesting](https://github.com/PHPOffice/PHPWord/pulls) a pull.
|
||||||
|
|
||||||
We want to create a high quality document writer and reader library that people can use with more confidence and less bugs. We want to collaborate happily, code joyfully, and get a life merrily. Thus, below are some guidelines that we expect to be followed by each contributor.
|
We want to create a high quality document writer and reader library that people can use with more confidence and less bugs. We want to collaborate happily, code joyfully, and get alive merrily. Thus, below are some guidelines, that we expect to be followed by each contributor.
|
||||||
|
|
||||||
- **Be brief, but be bold**: State your issues briefly, but speak out your ideas loudly, even if you can't or don't know how to implement it right away. The world will be better with limitless innovations.
|
- **Be brief, but be bold**. State your issues briefly. But speak out your ideas loudly, even if you can't or don't know how to implement it right away. The world will be better with limitless innovations.
|
||||||
- **Code in PSR**: We use PHP Standards Recommendation (PSR) from as the PHP Framework Interoperability Group (PHP-FIG). If you're not familiar with this standard, please [familiarize yourself now](https://github.com/php-fig/fig-standards). Use [PHPCodeSniffer](http://pear.php.net/package/PHP_CodeSniffer/) to check your code against this standard.
|
- **Follow PHP-FIG standards**. We follow PHP Standards Recommendations (PSRs) by [PHP Framework Interoperability Group](http://www.php-fig.org/). If you're not familiar with these standards, please, [familiarize yourself now](https://github.com/php-fig/fig-standards). Also, please, use [PHPCodeSniffer](http://pear.php.net/package/PHP_CodeSniffer/) to validate your code against PSRs.
|
||||||
- **Test your code**: Nobody else knows your code better than you. So, please, test your own code before submitting your pull request. PHPWord uses [PHPUnit](http://phpunit.de/) as our testing framework.
|
- **Test your code**. Nobody else knows your code better than you. So, it's completely yours mission to test the changes you made before pull request submission. We use [PHPUnit](https://phpunit.de/) for our testing purposes and recommend you using this tool too. [Here](https://phpunit.de/presentations.html) you can find PHPUnit best practices and additional information on effective unit testing, which helps us making PHPWord better day to day. Do not hesitate to smoke it carefully. It's a great investment in quality of your work, and it saves you years of life.
|
||||||
- **Request pull in separate branch**: Do not submit your request to the master branch, but create a separate branch named specifically for the issue that you addressed. Read [GitHub manual](https://help.github.com/articles/using-pull-requests) to find out more about this. If you are new to GitHub, read [this short manual](https://help.github.com/articles/fork-a-repo) to get you familiar with forks and how git works in general.
|
- **Request pull in separate branch**. Do not submit your request to the master branch. But create a separate branch named specifically for the issue that you addressed. Read [GitHub manual](https://help.github.com/articles/using-pull-requests) to find out more about this. If you are new to GitHub, read [this short manual](https://help.github.com/articles/fork-a-repo) to get yourself familiar with forks and how git works in general. [This video](http://www.youtube.com/watch?v=-zvHQXnBO6c) explains how to synchronize your Github Fork with the Branch of PHPWord.
|
||||||
|
|
||||||
That's it. Thank you for your interest in PHPWord, and welcome!
|
That's it. Thank you for your interest in PHPWord, and welcome!
|
||||||
|
|
||||||
May the Force be with you.
|
May the Force be with you.
|
||||||
|
|||||||
109
README.md
109
README.md
@ -11,6 +11,16 @@ PHPWord is a library written in pure PHP that provides a set of classes to write
|
|||||||
|
|
||||||
PHPWord is an open source project licensed under the terms of [LGPL version 3](https://github.com/PHPOffice/PHPWord/blob/develop/COPYING.LESSER). PHPWord is aimed to be a high quality software product by incorporating [continuous integration](https://travis-ci.org/PHPOffice/PHPWord) and [unit testing](http://phpoffice.github.io/PHPWord/coverage/develop/). You can learn more about PHPWord by reading the [Developers' Documentation](http://phpword.readthedocs.org/) and the [API Documentation](http://phpoffice.github.io/PHPWord/docs/develop/).
|
PHPWord is an open source project licensed under the terms of [LGPL version 3](https://github.com/PHPOffice/PHPWord/blob/develop/COPYING.LESSER). PHPWord is aimed to be a high quality software product by incorporating [continuous integration](https://travis-ci.org/PHPOffice/PHPWord) and [unit testing](http://phpoffice.github.io/PHPWord/coverage/develop/). You can learn more about PHPWord by reading the [Developers' Documentation](http://phpword.readthedocs.org/) and the [API Documentation](http://phpoffice.github.io/PHPWord/docs/develop/).
|
||||||
|
|
||||||
|
Read more about PHPWord:
|
||||||
|
|
||||||
|
- [Features](#features)
|
||||||
|
- [Requirements](#requirements)
|
||||||
|
- [Installation](#installation)
|
||||||
|
- [Getting started](#getting-started)
|
||||||
|
- [Contributing](#contributing)
|
||||||
|
- [Developers' Documentation](http://phpword.readthedocs.org/)
|
||||||
|
- [API Documentation](http://phpoffice.github.io/PHPWord/docs/master/)
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
With PHPWord, you can create DOCX, ODT, or RTF documents dynamically using your PHP 5.3+ scripts. Below are some of the things that you can do with PHPWord library:
|
With PHPWord, you can create DOCX, ODT, or RTF documents dynamically using your PHP 5.3+ scripts. Below are some of the things that you can do with PHPWord library:
|
||||||
@ -30,6 +40,9 @@ With PHPWord, you can create DOCX, ODT, or RTF documents dynamically using your
|
|||||||
- Insert list items as bulleted, numbered, or multilevel
|
- Insert list items as bulleted, numbered, or multilevel
|
||||||
- Insert hyperlinks
|
- Insert hyperlinks
|
||||||
- Insert footnotes and endnotes
|
- Insert footnotes and endnotes
|
||||||
|
- Insert drawing shapes (arc, curve, line, polyline, rect, oval)
|
||||||
|
- Insert charts (pie, doughnut, bar, line, area, scatter, radar)
|
||||||
|
- Insert form fields (textinput, checkbox, and dropdown)
|
||||||
- Create document from templates
|
- Create document from templates
|
||||||
- Use XSL 1.0 style sheets to transform main document part of OOXML template
|
- Use XSL 1.0 style sheets to transform main document part of OOXML template
|
||||||
- ... and many more features on progress
|
- ... and many more features on progress
|
||||||
@ -67,55 +80,97 @@ require_once 'path/to/PhpWord/src/PhpWord/Autoloader.php';
|
|||||||
\PhpOffice\PhpWord\Autoloader::register();
|
\PhpOffice\PhpWord\Autoloader::register();
|
||||||
```
|
```
|
||||||
|
|
||||||
## Usages
|
## Getting started
|
||||||
|
|
||||||
The following is a basic example of the PHPWord library. More examples are provided in the [samples folder](samples/).
|
The following is a basic usage example of the PHPWord library.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
|
<?php
|
||||||
|
require_once 'src/PhpWord/Autoloader.php';
|
||||||
|
\PhpOffice\PhpWord\Autoloader::register();
|
||||||
|
|
||||||
|
// Creating the new document...
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Every element you want to append to the word document is placed in a section.
|
/* Note: any element you append to a document must reside inside of a Section. */
|
||||||
// To create a basic section:
|
|
||||||
|
// Adding an empty Section to the document...
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
// Adding Text element to the Section having font styled by default...
|
||||||
|
$section->addText(
|
||||||
|
htmlspecialchars(
|
||||||
|
'"Learn from yesterday, live for today, hope for tomorrow. '
|
||||||
|
. 'The important thing is not to stop questioning." '
|
||||||
|
. '(Albert Einstein)'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// After creating a section, you can append elements:
|
/*
|
||||||
$section->addText('Hello world!');
|
* Note: it's possible to customize font style of the Text element you add in three ways:
|
||||||
|
* - inline;
|
||||||
|
* - using named font style (new font style object will be implicitly created);
|
||||||
|
* - using explicitly created font style object.
|
||||||
|
*/
|
||||||
|
|
||||||
// You can directly style your text by giving the addText function an array:
|
// Adding Text element with font customized inline...
|
||||||
$section->addText('Hello world! I am formatted.',
|
$section->addText(
|
||||||
array('name'=>'Tahoma', 'size'=>16, 'bold'=>true));
|
htmlspecialchars(
|
||||||
|
'"Great achievement is usually born of great sacrifice, '
|
||||||
|
. 'and is never the result of selfishness." '
|
||||||
|
. '(Napoleon Hill)'
|
||||||
|
),
|
||||||
|
array('name' => 'Tahoma', 'size' => 10)
|
||||||
|
);
|
||||||
|
|
||||||
// If you often need the same style again you can create a user defined style
|
// Adding Text element with font customized using named font style...
|
||||||
// to the word document and give the addText function the name of the style:
|
$fontStyleName = 'oneUserDefinedStyle';
|
||||||
$phpWord->addFontStyle('myOwnStyle',
|
$phpWord->addFontStyle(
|
||||||
array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232'));
|
$fontStyleName,
|
||||||
$section->addText('Hello world! I am formatted by a user defined style',
|
array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true)
|
||||||
'myOwnStyle');
|
);
|
||||||
|
$section->addText(
|
||||||
|
htmlspecialchars(
|
||||||
|
'"The greatest accomplishment is not in never falling, '
|
||||||
|
. 'but in rising again after you fall." '
|
||||||
|
. '(Vince Lombardi)'
|
||||||
|
),
|
||||||
|
$fontStyleName
|
||||||
|
);
|
||||||
|
|
||||||
// You can also put the appended element to local object like this:
|
// Adding Text element with font customized using explicitly created font style object...
|
||||||
$fontStyle = new \PhpOffice\PhpWord\Style\Font();
|
$fontStyle = new \PhpOffice\PhpWord\Style\Font();
|
||||||
$fontStyle->setBold(true);
|
$fontStyle->setBold(true);
|
||||||
$fontStyle->setName('Verdana');
|
$fontStyle->setName('Tahoma');
|
||||||
$fontStyle->setSize(22);
|
$fontStyle->setSize(13);
|
||||||
$myTextElement = $section->addText('Hello World!');
|
$myTextElement = $section->addText(
|
||||||
|
htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)')
|
||||||
|
);
|
||||||
$myTextElement->setFontStyle($fontStyle);
|
$myTextElement->setFontStyle($fontStyle);
|
||||||
|
|
||||||
// Finally, write the document:
|
// Saving the document as OOXML file...
|
||||||
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
|
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
|
||||||
$objWriter->save('helloWorld.docx');
|
$objWriter->save('helloWorld.docx');
|
||||||
|
|
||||||
|
// Saving the document as ODF file...
|
||||||
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText');
|
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText');
|
||||||
$objWriter->save('helloWorld.odt');
|
$objWriter->save('helloWorld.odt');
|
||||||
|
|
||||||
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'RTF');
|
// Saving the document as HTML file...
|
||||||
$objWriter->save('helloWorld.rtf');
|
$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. */
|
||||||
```
|
```
|
||||||
|
:warning: Escape any string you pass to OOXML/ODF/HTML document, otherwise it may get broken.
|
||||||
|
|
||||||
|
More examples are provided in the [samples folder](samples/). You can also read the [Developers' Documentation](http://phpword.readthedocs.org/) and the [API Documentation](http://phpoffice.github.io/PHPWord/docs/master/) for more detail.
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
We welcome everyone to contribute to PHPWord. Below are some of the things that you can do to contribute:
|
We welcome everyone to contribute to PHPWord. Below are some of the things that you can do to contribute.
|
||||||
|
|
||||||
- Read [our contributing guide](https://github.com/PHPOffice/PHPWord/blob/master/CONTRIBUTING.md)
|
- Read [our contributing guide](https://github.com/PHPOffice/PHPWord/blob/master/CONTRIBUTING.md).
|
||||||
- [Fork us](https://github.com/PHPOffice/PHPWord/fork) and [request a pull](https://github.com/PHPOffice/PHPWord/pulls) to the [develop](https://github.com/PHPOffice/PHPWord/tree/develop) branch
|
- [Fork us](https://github.com/PHPOffice/PHPWord/fork) and [request a pull](https://github.com/PHPOffice/PHPWord/pulls) to the [develop](https://github.com/PHPOffice/PHPWord/tree/develop) branch.
|
||||||
- Submit [bug reports or feature requests](https://github.com/PHPOffice/PHPWord/issues) to GitHub
|
- Submit [bug reports or feature requests](https://github.com/PHPOffice/PHPWord/issues) to GitHub.
|
||||||
- Follow [@PHPWord](https://twitter.com/PHPWord) and [@PHPOffice](https://twitter.com/PHPOffice) on Twitter
|
- Follow [@PHPWord](https://twitter.com/PHPWord) and [@PHPOffice](https://twitter.com/PHPOffice) on Twitter.
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"name": "phpoffice/phpword",
|
"name": "phpoffice/phpword",
|
||||||
"description": "PHPWord - A pure PHP library for reading and writing word processing documents (DOCX, ODT, RTF, HTML, PDF)",
|
"description": "PHPWord - A pure PHP library for reading and writing word processing documents (DOCX, ODT, RTF, HTML, PDF)",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"PHP", "PhpOffice", "office", "PhpWord", "word", "template", "reader", "writer",
|
"PHP", "PhpOffice", "office", "PhpWord", "word", "template", "template processor", "reader", "writer",
|
||||||
"docx", "OOXML", "OpenXML", "Office Open XML", "ISO IEC 29500", "WordprocessingML",
|
"docx", "OOXML", "OpenXML", "Office Open XML", "ISO IEC 29500", "WordprocessingML",
|
||||||
"RTF", "Rich Text Format", "doc", "odt", "OpenDocument", "PDF", "HTML"
|
"RTF", "Rich Text Format", "doc", "odt", "OpenDocument", "PDF", "HTML"
|
||||||
],
|
],
|
||||||
@ -39,6 +39,9 @@
|
|||||||
"phpunit/phpunit": "3.7.*",
|
"phpunit/phpunit": "3.7.*",
|
||||||
"phpdocumentor/phpdocumentor":"2.*",
|
"phpdocumentor/phpdocumentor":"2.*",
|
||||||
"squizlabs/php_codesniffer": "1.*",
|
"squizlabs/php_codesniffer": "1.*",
|
||||||
|
"phpmd/phpmd": "2.*",
|
||||||
|
"sebastian/phpcpd": "2.*",
|
||||||
|
"phploc/phploc": "2.*",
|
||||||
"dompdf/dompdf":"0.6.*",
|
"dompdf/dompdf":"0.6.*",
|
||||||
"tecnick.com/tcpdf": "6.*",
|
"tecnick.com/tcpdf": "6.*",
|
||||||
"mpdf/mpdf": "5.*"
|
"mpdf/mpdf": "5.*"
|
||||||
@ -47,7 +50,7 @@
|
|||||||
"ext-zip": "Used to write DOCX and ODT",
|
"ext-zip": "Used to write DOCX and ODT",
|
||||||
"ext-gd2": "Used to add images",
|
"ext-gd2": "Used to add images",
|
||||||
"ext-xmlwriter": "Used to write DOCX and ODT",
|
"ext-xmlwriter": "Used to write DOCX and ODT",
|
||||||
"ext-xsl": "Used to apply XSL style sheet to template part",
|
"ext-xsl": "Used to apply XSL style sheet to main document part of OOXML template",
|
||||||
"dompdf/dompdf": "Used to write PDF"
|
"dompdf/dompdf": "Used to write PDF"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
|||||||
1578
composer.lock
generated
1578
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -41,14 +41,14 @@ master_doc = 'index'
|
|||||||
|
|
||||||
# General information about the project.
|
# General information about the project.
|
||||||
project = u'PhpWord'
|
project = u'PhpWord'
|
||||||
copyright = u'2014, Progi1984'
|
copyright = u'2014, PHPWord Contributors'
|
||||||
|
|
||||||
# The version info for the project you're documenting, acts as replacement for
|
# The version info for the project you're documenting, acts as replacement for
|
||||||
# |version| and |release|, also used in various other places throughout the
|
# |version| and |release|, also used in various other places throughout the
|
||||||
# built documents.
|
# built documents.
|
||||||
#
|
#
|
||||||
# The short X.Y version.
|
# The short X.Y version.
|
||||||
version = '0.9.0'
|
version = '0.12.0'
|
||||||
# The full version, including alpha/beta/rc tags.
|
# The full version, including alpha/beta/rc tags.
|
||||||
release = version
|
release = version
|
||||||
|
|
||||||
|
|||||||
@ -16,57 +16,24 @@ section, use the following code:
|
|||||||
|
|
||||||
.. code-block:: php
|
.. code-block:: php
|
||||||
|
|
||||||
$section = $phpWord->addSection($sectionSettings);
|
$section = $phpWord->addSection($sectionStyle);
|
||||||
|
|
||||||
The ``$sectionSettings`` is an optional associative array that sets the
|
The ``$sectionStyle`` is an optional associative array that sets the
|
||||||
section. Example:
|
section. Example:
|
||||||
|
|
||||||
.. code-block:: php
|
.. code-block:: php
|
||||||
|
|
||||||
$sectionSettings = array(
|
$sectionStyle = array(
|
||||||
'orientation' => 'landscape',
|
'orientation' => 'landscape',
|
||||||
'marginTop' => 600,
|
'marginTop' => 600,
|
||||||
'colsNum' => 2,
|
'colsNum' => 2,
|
||||||
);
|
);
|
||||||
|
|
||||||
Section settings
|
|
||||||
~~~~~~~~~~~~~~~~
|
|
||||||
|
|
||||||
Below are the available settings for section:
|
|
||||||
|
|
||||||
- ``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)
|
|
||||||
|
|
||||||
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 twips
|
|
||||||
- ``pageSizeH`` Page height in twips
|
|
||||||
|
|
||||||
Page number
|
Page number
|
||||||
~~~~~~~~~~~
|
~~~~~~~~~~~
|
||||||
|
|
||||||
You can change a section page number by using the ``pageNumberingStart``
|
You can change a section page number by using the ``pageNumberingStart``
|
||||||
property of the section.
|
style of the section.
|
||||||
|
|
||||||
.. code-block:: php
|
.. code-block:: php
|
||||||
|
|
||||||
@ -75,13 +42,13 @@ property of the section.
|
|||||||
|
|
||||||
// Method 2
|
// Method 2
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->getSettings()->setPageNumberingStart(1);
|
$section->getStyle()->setPageNumberingStart(1);
|
||||||
|
|
||||||
Multicolumn
|
Multicolumn
|
||||||
~~~~~~~~~~~
|
~~~~~~~~~~~
|
||||||
|
|
||||||
You can change a section layout to multicolumn (like in a newspaper) by
|
You can change a section layout to multicolumn (like in a newspaper) by
|
||||||
using the ``breakType`` and ``colsNum`` property of the section.
|
using the ``breakType`` and ``colsNum`` style of the section.
|
||||||
|
|
||||||
.. code-block:: php
|
.. code-block:: php
|
||||||
|
|
||||||
@ -90,14 +57,14 @@ using the ``breakType`` and ``colsNum`` property of the section.
|
|||||||
|
|
||||||
// Method 2
|
// Method 2
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->getSettings()->setBreakType('continuous');
|
$section->getStyle()->setBreakType('continuous');
|
||||||
$section->getSettings()->setColsNum(2);
|
$section->getStyle()->setColsNum(2);
|
||||||
|
|
||||||
|
Line numbering
|
||||||
### Line numbering
|
~~~~~~~~~~~~~~
|
||||||
|
|
||||||
You can apply line numbering to a section by using the ``lineNumbering``
|
You can apply line numbering to a section by using the ``lineNumbering``
|
||||||
property of the section.
|
style of the section.
|
||||||
|
|
||||||
.. code-block:: php
|
.. code-block:: php
|
||||||
|
|
||||||
@ -106,14 +73,15 @@ property of the section.
|
|||||||
|
|
||||||
// Method 2
|
// Method 2
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->getSettings()->setLineNumbering(array());
|
$section->getStyle()->setLineNumbering(array());
|
||||||
|
|
||||||
Below are the properties of the line numbering style.
|
Below are the properties of the line numbering style.
|
||||||
|
|
||||||
- ``start`` Line numbering starting value
|
- ``start`` Line numbering starting value
|
||||||
- ``increment`` Line number increments
|
- ``increment`` Line number increments
|
||||||
- ``distance`` Distance between text and line numbering in twip
|
- ``distance`` Distance between text and line numbering in twip
|
||||||
- ``restart`` Line numbering restart setting continuous|newPage|newSection
|
- ``restart`` Line numbering restart setting
|
||||||
|
continuous\|newPage\|newSection
|
||||||
|
|
||||||
Headers
|
Headers
|
||||||
-------
|
-------
|
||||||
|
|||||||
@ -3,6 +3,12 @@
|
|||||||
Frequently asked questions
|
Frequently asked questions
|
||||||
==========================
|
==========================
|
||||||
|
|
||||||
|
How contribute to PHPWord ?
|
||||||
|
---------------------------
|
||||||
|
|
||||||
|
- Improve the documentation (`Sphinx Format <http://documentation-style-guide-sphinx.readthedocs.org/en/latest/index.html>`__)
|
||||||
|
|
||||||
|
|
||||||
Is this the same with PHPWord that I found in CodePlex?
|
Is this the same with PHPWord that I found in CodePlex?
|
||||||
-------------------------------------------------------
|
-------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
101
docs/general.rst
101
docs/general.rst
@ -12,46 +12,82 @@ folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
|
|||||||
|
|
||||||
.. code-block:: php
|
.. code-block:: php
|
||||||
|
|
||||||
|
<?php
|
||||||
require_once 'src/PhpWord/Autoloader.php';
|
require_once 'src/PhpWord/Autoloader.php';
|
||||||
\PhpOffice\PhpWord\Autoloader::register();
|
\PhpOffice\PhpWord\Autoloader::register();
|
||||||
|
|
||||||
|
// Creating the new document...
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Every element you want to append to the word document is placed in a section.
|
/* Note: any element you append to a document must reside inside of a Section. */
|
||||||
// To create a basic section:
|
|
||||||
|
// Adding an empty Section to the document...
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
// Adding Text element to the Section having font styled by default...
|
||||||
|
$section->addText(
|
||||||
|
htmlspecialchars(
|
||||||
|
'"Learn from yesterday, live for today, hope for tomorrow. '
|
||||||
|
. 'The important thing is not to stop questioning." '
|
||||||
|
. '(Albert Einstein)'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// After creating a section, you can append elements:
|
/*
|
||||||
$section->addText('Hello world!');
|
* Note: it's possible to customize font style of the Text element you add in three ways:
|
||||||
|
* - inline;
|
||||||
|
* - using named font style (new font style object will be implicitly created);
|
||||||
|
* - using explicitly created font style object.
|
||||||
|
*/
|
||||||
|
|
||||||
// You can directly style your text by giving the addText function an array:
|
// Adding Text element with font customized inline...
|
||||||
$section->addText('Hello world! I am formatted.',
|
$section->addText(
|
||||||
array('name'=>'Tahoma', 'size'=>16, 'bold'=>true));
|
htmlspecialchars(
|
||||||
|
'"Great achievement is usually born of great sacrifice, '
|
||||||
|
. 'and is never the result of selfishness." '
|
||||||
|
. '(Napoleon Hill)'
|
||||||
|
),
|
||||||
|
array('name' => 'Tahoma', 'size' => 10)
|
||||||
|
);
|
||||||
|
|
||||||
// If you often need the same style again you can create a user defined style
|
// Adding Text element with font customized using named font style...
|
||||||
// to the word document and give the addText function the name of the style:
|
$fontStyleName = 'oneUserDefinedStyle';
|
||||||
$phpWord->addFontStyle('myOwnStyle',
|
$phpWord->addFontStyle(
|
||||||
array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232'));
|
$fontStyleName,
|
||||||
$section->addText('Hello world! I am formatted by a user defined style',
|
array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true)
|
||||||
'myOwnStyle');
|
);
|
||||||
|
$section->addText(
|
||||||
|
htmlspecialchars(
|
||||||
|
'"The greatest accomplishment is not in never falling, '
|
||||||
|
. 'but in rising again after you fall." '
|
||||||
|
. '(Vince Lombardi)'
|
||||||
|
),
|
||||||
|
$fontStyleName
|
||||||
|
);
|
||||||
|
|
||||||
// You can also put the appended element to local object like this:
|
// Adding Text element with font customized using explicitly created font style object...
|
||||||
$fontStyle = new \PhpOffice\PhpWord\Style\Font();
|
$fontStyle = new \PhpOffice\PhpWord\Style\Font();
|
||||||
$fontStyle->setBold(true);
|
$fontStyle->setBold(true);
|
||||||
$fontStyle->setName('Verdana');
|
$fontStyle->setName('Tahoma');
|
||||||
$fontStyle->setSize(22);
|
$fontStyle->setSize(13);
|
||||||
$myTextElement = $section->addText('Hello World!');
|
$myTextElement = $section->addText(
|
||||||
|
htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)')
|
||||||
|
);
|
||||||
$myTextElement->setFontStyle($fontStyle);
|
$myTextElement->setFontStyle($fontStyle);
|
||||||
|
|
||||||
// Finally, write the document:
|
// Saving the document as OOXML file...
|
||||||
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
|
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
|
||||||
$objWriter->save('helloWorld.docx');
|
$objWriter->save('helloWorld.docx');
|
||||||
|
|
||||||
|
// Saving the document as ODF file...
|
||||||
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText');
|
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText');
|
||||||
$objWriter->save('helloWorld.odt');
|
$objWriter->save('helloWorld.odt');
|
||||||
|
|
||||||
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'RTF');
|
// Saving the document as HTML file...
|
||||||
$objWriter->save('helloWorld.rtf');
|
$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. */
|
||||||
|
|
||||||
Settings
|
Settings
|
||||||
--------
|
--------
|
||||||
@ -79,11 +115,10 @@ during development to make the resulting XML file easier to read.
|
|||||||
Zip class
|
Zip class
|
||||||
~~~~~~~~~
|
~~~~~~~~~
|
||||||
|
|
||||||
By default, PHPWord uses PHP
|
By default, PHPWord uses `Zip extension <http://php.net/manual/en/book.zip.php>`__
|
||||||
`ZipArchive <http://php.net/manual/en/book.zip.php>`__ to read or write
|
to deal with ZIP compressed archives and files inside them. If you can't have
|
||||||
ZIP compressed archive and the files inside them. If you can't have
|
Zip extension installed on your server, you can use pure PHP library
|
||||||
ZipArchive installed on your server, you can use pure PHP library
|
alternative, `PclZip <http://www.phpconcept.net/pclzip/>`__, which
|
||||||
alternative, `PCLZip <http://www.phpconcept.net/pclzip/>`__, which
|
|
||||||
included with PHPWord.
|
included with PHPWord.
|
||||||
|
|
||||||
.. code-block:: php
|
.. code-block:: php
|
||||||
@ -101,15 +136,15 @@ default font by using the following two functions:
|
|||||||
$phpWord->setDefaultFontName('Times New Roman');
|
$phpWord->setDefaultFontName('Times New Roman');
|
||||||
$phpWord->setDefaultFontSize(12);
|
$phpWord->setDefaultFontSize(12);
|
||||||
|
|
||||||
Document properties
|
Document information
|
||||||
-------------------
|
--------------------
|
||||||
|
|
||||||
You can set the document properties such as title, creator, and company
|
You can set the document information such as title, creator, and company
|
||||||
name. Use the following functions:
|
name. Use the following functions:
|
||||||
|
|
||||||
.. code-block:: php
|
.. code-block:: php
|
||||||
|
|
||||||
$properties = $phpWord->getDocumentProperties();
|
$properties = $phpWord->getDocInfo();
|
||||||
$properties->setCreator('My name');
|
$properties->setCreator('My name');
|
||||||
$properties->setCompany('My factory');
|
$properties->setCompany('My factory');
|
||||||
$properties->setTitle('My title');
|
$properties->setTitle('My title');
|
||||||
@ -134,13 +169,13 @@ points to twips.
|
|||||||
|
|
||||||
// Paragraph with 6 points space after
|
// Paragraph with 6 points space after
|
||||||
$phpWord->addParagraphStyle('My Style', array(
|
$phpWord->addParagraphStyle('My Style', array(
|
||||||
'spaceAfter' => \PhpOffice\PhpWord\Shared\Font::pointSizeToTwips(6))
|
'spaceAfter' => \PhpOffice\PhpWord\Shared\Converter::pointToTwip(6))
|
||||||
);
|
);
|
||||||
|
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$sectionStyle = $section->getSettings();
|
$sectionStyle = $section->getStyle();
|
||||||
// half inch left margin
|
// half inch left margin
|
||||||
$sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Font::inchSizeToTwips(.5));
|
$sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Converter::inchToTwip(.5));
|
||||||
// 2 cm right margin
|
// 2 cm right margin
|
||||||
$sectionStyle->setMarginRight(\PhpOffice\PhpWord\Shared\Font::centimeterSizeToTwips(2));
|
$sectionStyle->setMarginRight(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(2));
|
||||||
|
|
||||||
|
|||||||
@ -18,11 +18,12 @@ Format (RTF).
|
|||||||
:maxdepth: 2
|
:maxdepth: 2
|
||||||
|
|
||||||
intro
|
intro
|
||||||
setup
|
installing
|
||||||
general
|
general
|
||||||
containers
|
containers
|
||||||
elements
|
elements
|
||||||
templates
|
styles
|
||||||
|
templates-processing
|
||||||
writersreaders
|
writersreaders
|
||||||
recipes
|
recipes
|
||||||
faq
|
faq
|
||||||
|
|||||||
@ -41,13 +41,32 @@ To install via Composer, add the following lines to your
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
.. code-block:: json
|
||||||
|
|
||||||
|
{
|
||||||
|
"require": {
|
||||||
|
"phpoffice/phpword": "dev-develop"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Manual install
|
Manual install
|
||||||
~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~
|
||||||
|
|
||||||
To install manually, `download PHPWord package from
|
To install manually, you change to the webserver directory of your file system .
|
||||||
github <https://github.com/PHPOffice/PHPWord/archive/master.zip>`__.
|
Then you have 2 possibilities.
|
||||||
Extract the package and put the contents to your machine. To use the
|
|
||||||
library, include ``src/PhpWord/Autoloader.php`` in your script and
|
1. `download PHPWord package from github <https://github.com/PHPOffice/PHPWord/archive/master.zip>`__.
|
||||||
|
Extract the package and put the contents to your machine.
|
||||||
|
2. Alternatively you can use Git to install it:
|
||||||
|
.. code-block:: console
|
||||||
|
|
||||||
|
git clone https://github.com/PHPOffice/PHPWord.git
|
||||||
|
|
||||||
|
To use the library, include ``src/PhpWord/Autoloader.php`` in your PHP script and
|
||||||
invoke ``Autoloader::register``.
|
invoke ``Autoloader::register``.
|
||||||
|
|
||||||
.. code-block:: php
|
.. code-block:: php
|
||||||
@ -55,6 +74,7 @@ invoke ``Autoloader::register``.
|
|||||||
require_once '/path/to/src/PhpWord/Autoloader.php';
|
require_once '/path/to/src/PhpWord/Autoloader.php';
|
||||||
\PhpOffice\PhpWord\Autoloader::register();
|
\PhpOffice\PhpWord\Autoloader::register();
|
||||||
|
|
||||||
|
|
||||||
Using samples
|
Using samples
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
128
docs/intro.rst
128
docs/intro.rst
@ -37,6 +37,7 @@ Features
|
|||||||
run) that contains other elements
|
run) that contains other elements
|
||||||
- Insert titles (headers) and table of contents
|
- Insert titles (headers) and table of contents
|
||||||
- Insert text breaks and page breaks
|
- Insert text breaks and page breaks
|
||||||
|
- Insert right-to-left text
|
||||||
- Insert and format images, either local, remote, or as page watermarks
|
- Insert and format images, either local, remote, or as page watermarks
|
||||||
- Insert binary OLE Objects such as Excel or Visio
|
- Insert binary OLE Objects such as Excel or Visio
|
||||||
- Insert and format table with customized properties for each rows
|
- Insert and format table with customized properties for each rows
|
||||||
@ -45,6 +46,9 @@ Features
|
|||||||
- Insert list items as bulleted, numbered, or multilevel
|
- Insert list items as bulleted, numbered, or multilevel
|
||||||
- Insert hyperlinks
|
- Insert hyperlinks
|
||||||
- Insert footnotes and endnotes
|
- Insert footnotes and endnotes
|
||||||
|
- Insert drawing shapes (arc, curve, line, polyline, rect, oval)
|
||||||
|
- Insert charts (pie, doughnut, bar, line, area, scatter, radar)
|
||||||
|
- Insert form fields (textinput, checkbox, and dropdown)
|
||||||
- Create document from templates
|
- Create document from templates
|
||||||
- Use XSL 1.0 style sheets to transform main document part of OOXML
|
- Use XSL 1.0 style sheets to transform main document part of OOXML
|
||||||
template
|
template
|
||||||
@ -99,11 +103,11 @@ Writers
|
|||||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||||
| | Endnote | ✓ | | | ✓ | |
|
| | Endnote | ✓ | | | ✓ | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||||
| **Graphs** | 2D basic graphs | | | | | |
|
| **Graphs** | 2D basic graphs | ✓ | | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||||
| | 2D advanced graphs | | | | | |
|
| | 2D advanced graphs | | | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||||
| | 3D graphs | | | | | |
|
| | 3D graphs | ✓ | | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||||
| **Math** | OMML support | | | | | |
|
| **Math** | OMML support | | | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
+---------------------------+----------------------+--------+-------+-------+--------+-------+
|
||||||
@ -117,75 +121,75 @@ Writers
|
|||||||
Readers
|
Readers
|
||||||
~~~~~~~
|
~~~~~~~
|
||||||
|
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| Features | | DOCX | ODT | RTF | HTML |
|
| Features | | DOCX | DOC | ODT | RTF | HTML |
|
||||||
+===========================+======================+========+=======+=======+=======+
|
+===========================+======================+========+=======+=======+=======+=======+
|
||||||
| **Document Properties** | Standard | ✓ | | | |
|
| **Document Properties** | Standard | ✓ | | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| | Custom | ✓ | | | |
|
| | Custom | ✓ | | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| **Element Type** | Text | ✓ | ✓ | ✓ | ✓ |
|
| **Element Type** | Text | ✓ | ✓ | ✓ | ✓ | ✓ |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| | Text Run | ✓ | | | |
|
| | Text Run | ✓ | | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| | Title | ✓ | ✓ | | |
|
| | Title | ✓ | | ✓ | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| | Link | ✓ | | | |
|
| | Link | ✓ | ✓ | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| | Preserve Text | ✓ | | | |
|
| | Preserve Text | ✓ | | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| | Text Break | ✓ | | | |
|
| | Text Break | ✓ | ✓ | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| | Page Break | ✓ | | | |
|
| | Page Break | ✓ | | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| | List | ✓ | ✓ | | ✓ |
|
| | List | ✓ | | ✓ | | ✓ |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| | Table | ✓ | | | ✓ |
|
| | Table | ✓ | | | | ✓ |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| | Image | ✓ | | | |
|
| | Image | ✓ | ✓ | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| | Object | | | | |
|
| | Object | | | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| | Watermark | | | | |
|
| | Watermark | | | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| | Table of Contents | | | | |
|
| | Table of Contents | | | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| | Header | ✓ | | | |
|
| | Header | ✓ | | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| | Footer | ✓ | | | |
|
| | Footer | ✓ | | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| | Footnote | ✓ | | | |
|
| | Footnote | ✓ | | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| | Endnote | ✓ | | | |
|
| | Endnote | ✓ | | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| **Graphs** | 2D basic graphs | | | | |
|
| **Graphs** | 2D basic graphs | | | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| | 2D advanced graphs | | | | |
|
| | 2D advanced graphs | | | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| | 3D graphs | | | | |
|
| | 3D graphs | | | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| **Math** | OMML support | | | | |
|
| **Math** | OMML support | | | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| | MathML support | | | | |
|
| | MathML support | | | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| **Bonus** | Encryption | | | | |
|
| **Bonus** | Encryption | | | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
| | Protection | | | | |
|
| | Protection | | | | | |
|
||||||
+---------------------------+----------------------+--------+-------+-------+-------+
|
+---------------------------+----------------------+--------+-------+-------+-------+-------+
|
||||||
|
|
||||||
Contributing
|
Contributing
|
||||||
------------
|
------------
|
||||||
|
|
||||||
We welcome everyone to contribute to PHPWord. Below are some of the
|
We welcome everyone to contribute to PHPWord. Below are some of the
|
||||||
things that you can do to contribute:
|
things that you can do to contribute.
|
||||||
|
|
||||||
- Read `our contributing
|
- Read `our contributing
|
||||||
guide <https://github.com/PHPOffice/PHPWord/blob/master/CONTRIBUTING.md>`__
|
guide <https://github.com/PHPOffice/PHPWord/blob/master/CONTRIBUTING.md>`__.
|
||||||
- `Fork us <https://github.com/PHPOffice/PHPWord/fork>`__ and `request
|
- `Fork us <https://github.com/PHPOffice/PHPWord/fork>`__ and `request
|
||||||
a pull <https://github.com/PHPOffice/PHPWord/pulls>`__ to the
|
a pull <https://github.com/PHPOffice/PHPWord/pulls>`__ to the
|
||||||
`develop <https://github.com/PHPOffice/PHPWord/tree/develop>`__
|
`develop <https://github.com/PHPOffice/PHPWord/tree/develop>`__
|
||||||
branch
|
branch.
|
||||||
- Submit `bug reports or feature
|
- Submit `bug reports or feature
|
||||||
requests <https://github.com/PHPOffice/PHPWord/issues>`__ to GitHub
|
requests <https://github.com/PHPOffice/PHPWord/issues>`__ to GitHub.
|
||||||
- Follow `@PHPWord <https://twitter.com/PHPWord>`__ and
|
- Follow `@PHPWord <https://twitter.com/PHPWord>`__ and
|
||||||
`@PHPOffice <https://twitter.com/PHPOffice>`__ on Twitter
|
`@PHPOffice <https://twitter.com/PHPOffice>`__ on Twitter.
|
||||||
|
|||||||
@ -65,3 +65,34 @@ Define a numbering style and title styles, and match the two styles (with ``pSty
|
|||||||
$section->addTitle('Heading 1', 1);
|
$section->addTitle('Heading 1', 1);
|
||||||
$section->addTitle('Heading 2', 2);
|
$section->addTitle('Heading 2', 2);
|
||||||
$section->addTitle('Heading 3', 3);
|
$section->addTitle('Heading 3', 3);
|
||||||
|
|
||||||
|
Add a link within a title
|
||||||
|
-------------------------
|
||||||
|
|
||||||
|
Apply 'HeadingN' paragraph style to TextRun or Link. Sample code:
|
||||||
|
|
||||||
|
.. code-block:: php
|
||||||
|
|
||||||
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
$phpWord->addTitleStyle(1, array('size' => 16, 'bold' => true));
|
||||||
|
$phpWord->addTitleStyle(2, array('size' => 14, 'bold' => true));
|
||||||
|
$phpWord->addFontStyle('Link', array('color' => '0000FF', 'underline' => 'single'));
|
||||||
|
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
|
// Textrun
|
||||||
|
$textrun = $section->addTextRun('Heading1');
|
||||||
|
$textrun->addText('The ');
|
||||||
|
$textrun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord', 'Link');
|
||||||
|
|
||||||
|
// Link
|
||||||
|
$section->addLink('https://github.com/', 'GitHub', 'Link', 'Heading2');
|
||||||
|
|
||||||
|
Remove [Compatibility Mode] text in the MS Word title bar
|
||||||
|
---------------------------------------------------------
|
||||||
|
|
||||||
|
Use the ``Metadata\Compatibility\setOoxmlVersion(n)`` method with ``n`` is the version of Office (14 = Office 2010, 15 = Office 2013).
|
||||||
|
|
||||||
|
.. code-block:: php
|
||||||
|
|
||||||
|
$phpWord->getCompatibility()->setOoxmlVersion(15);
|
||||||
|
|||||||
@ -36,7 +36,15 @@ Don't forget to change `code::` directive to `code-block::` in the resulting rst
|
|||||||
- [Textboxes](#textboxes)
|
- [Textboxes](#textboxes)
|
||||||
- [Fields](#fields)
|
- [Fields](#fields)
|
||||||
- [Lines](#lines)
|
- [Lines](#lines)
|
||||||
- [Templates](#templates)
|
- [Shapes](#shapes)
|
||||||
|
- [Charts](#charts)
|
||||||
|
- [FormFields](#form-fields)
|
||||||
|
- [Styles](#styles)
|
||||||
|
- [Section](#section)
|
||||||
|
- [Font](#font)
|
||||||
|
- [Paragraph](#paragraph)
|
||||||
|
- [Table](#table)
|
||||||
|
- [Templates processing](#templates-processing)
|
||||||
- [Writers & readers](#writers-readers)
|
- [Writers & readers](#writers-readers)
|
||||||
- [OOXML](#ooxml)
|
- [OOXML](#ooxml)
|
||||||
- [OpenDocument](#opendocument)
|
- [OpenDocument](#opendocument)
|
||||||
@ -70,6 +78,9 @@ PHPWord is an open source project licensed under the terms of [LGPL version 3](h
|
|||||||
- Insert list items as bulleted, numbered, or multilevel
|
- Insert list items as bulleted, numbered, or multilevel
|
||||||
- Insert hyperlinks
|
- Insert hyperlinks
|
||||||
- Insert footnotes and endnotes
|
- Insert footnotes and endnotes
|
||||||
|
- Insert drawing shapes (arc, curve, line, polyline, rect, oval)
|
||||||
|
- Insert charts (pie, doughnut, bar, line, area, scatter, radar)
|
||||||
|
- Insert form fields (textinput, checkbox, and dropdown)
|
||||||
- Create document from templates
|
- Create document from templates
|
||||||
- Use XSL 1.0 style sheets to transform main document part of OOXML template
|
- Use XSL 1.0 style sheets to transform main document part of OOXML template
|
||||||
- ... and many more features on progress
|
- ... and many more features on progress
|
||||||
@ -101,9 +112,9 @@ Below are the supported features for each file formats.
|
|||||||
| | Footer | ✓ | | | | |
|
| | Footer | ✓ | | | | |
|
||||||
| | Footnote | ✓ | | | ✓ | |
|
| | Footnote | ✓ | | | ✓ | |
|
||||||
| | Endnote | ✓ | | | ✓ | |
|
| | Endnote | ✓ | | | ✓ | |
|
||||||
| **Graphs** | 2D basic graphs | | | | | |
|
| **Graphs** | 2D basic graphs | ✓ | | | | |
|
||||||
| | 2D advanced graphs | | | | | |
|
| | 2D advanced graphs | | | | | |
|
||||||
| | 3D graphs | | | | | |
|
| | 3D graphs | ✓ | | | | |
|
||||||
| **Math** | OMML support | | | | | |
|
| **Math** | OMML support | | | | | |
|
||||||
| | MathML support | | | | | |
|
| | MathML support | | | | | |
|
||||||
| **Bonus** | Encryption | | | | | |
|
| **Bonus** | Encryption | | | | | |
|
||||||
@ -201,46 +212,82 @@ After installation, you can browse and use the samples that we've provided, eith
|
|||||||
The following is a basic example of the PHPWord library. More examples are provided in the [samples folder](https://github.com/PHPOffice/PHPWord/tree/master/samples/).
|
The following is a basic example of the PHPWord library. More examples are provided in the [samples folder](https://github.com/PHPOffice/PHPWord/tree/master/samples/).
|
||||||
|
|
||||||
```php
|
```php
|
||||||
|
<?php
|
||||||
require_once 'src/PhpWord/Autoloader.php';
|
require_once 'src/PhpWord/Autoloader.php';
|
||||||
\PhpOffice\PhpWord\Autoloader::register();
|
\PhpOffice\PhpWord\Autoloader::register();
|
||||||
|
|
||||||
|
// Creating the new document...
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Every element you want to append to the word document is placed in a section.
|
/* Note: any element you append to a document must reside inside of a Section. */
|
||||||
// To create a basic section:
|
|
||||||
|
// Adding an empty Section to the document...
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
// Adding Text element to the Section having font styled by default...
|
||||||
|
$section->addText(
|
||||||
|
htmlspecialchars(
|
||||||
|
'"Learn from yesterday, live for today, hope for tomorrow. '
|
||||||
|
. 'The important thing is not to stop questioning." '
|
||||||
|
. '(Albert Einstein)'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// After creating a section, you can append elements:
|
/*
|
||||||
$section->addText('Hello world!');
|
* Note: it's possible to customize font style of the Text element you add in three ways:
|
||||||
|
* - inline;
|
||||||
|
* - using named font style (new font style object will be implicitly created);
|
||||||
|
* - using explicitly created font style object.
|
||||||
|
*/
|
||||||
|
|
||||||
// You can directly style your text by giving the addText function an array:
|
// Adding Text element with font customized inline...
|
||||||
$section->addText('Hello world! I am formatted.',
|
$section->addText(
|
||||||
array('name'=>'Tahoma', 'size'=>16, 'bold'=>true));
|
htmlspecialchars(
|
||||||
|
'"Great achievement is usually born of great sacrifice, '
|
||||||
|
. 'and is never the result of selfishness." '
|
||||||
|
. '(Napoleon Hill)'
|
||||||
|
),
|
||||||
|
array('name' => 'Tahoma', 'size' => 10)
|
||||||
|
);
|
||||||
|
|
||||||
// If you often need the same style again you can create a user defined style
|
// Adding Text element with font customized using named font style...
|
||||||
// to the word document and give the addText function the name of the style:
|
$fontStyleName = 'oneUserDefinedStyle';
|
||||||
$phpWord->addFontStyle('myOwnStyle',
|
$phpWord->addFontStyle(
|
||||||
array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232'));
|
$fontStyleName,
|
||||||
$section->addText('Hello world! I am formatted by a user defined style',
|
array('name' => 'Tahoma', 'size' => 10, 'color' => '1B2232', 'bold' => true)
|
||||||
'myOwnStyle');
|
);
|
||||||
|
$section->addText(
|
||||||
|
htmlspecialchars(
|
||||||
|
'"The greatest accomplishment is not in never falling, '
|
||||||
|
. 'but in rising again after you fall." '
|
||||||
|
. '(Vince Lombardi)'
|
||||||
|
),
|
||||||
|
$fontStyleName
|
||||||
|
);
|
||||||
|
|
||||||
// You can also put the appended element to local object like this:
|
// Adding Text element with font customized using explicitly created font style object...
|
||||||
$fontStyle = new \PhpOffice\PhpWord\Style\Font();
|
$fontStyle = new \PhpOffice\PhpWord\Style\Font();
|
||||||
$fontStyle->setBold(true);
|
$fontStyle->setBold(true);
|
||||||
$fontStyle->setName('Verdana');
|
$fontStyle->setName('Tahoma');
|
||||||
$fontStyle->setSize(22);
|
$fontStyle->setSize(13);
|
||||||
$myTextElement = $section->addText('Hello World!');
|
$myTextElement = $section->addText(
|
||||||
|
htmlspecialchars('"Believe you can and you\'re halfway there." (Theodor Roosevelt)')
|
||||||
|
);
|
||||||
$myTextElement->setFontStyle($fontStyle);
|
$myTextElement->setFontStyle($fontStyle);
|
||||||
|
|
||||||
// Finally, write the document:
|
// Saving the document as OOXML file...
|
||||||
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
|
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
|
||||||
$objWriter->save('helloWorld.docx');
|
$objWriter->save('helloWorld.docx');
|
||||||
|
|
||||||
|
// Saving the document as ODF file...
|
||||||
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText');
|
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText');
|
||||||
$objWriter->save('helloWorld.odt');
|
$objWriter->save('helloWorld.odt');
|
||||||
|
|
||||||
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'RTF');
|
// Saving the document as HTML file...
|
||||||
$objWriter->save('helloWorld.rtf');
|
$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. */
|
||||||
```
|
```
|
||||||
|
|
||||||
## Settings
|
## Settings
|
||||||
@ -272,12 +319,12 @@ $phpWord->setDefaultFontName('Times New Roman');
|
|||||||
$phpWord->setDefaultFontSize(12);
|
$phpWord->setDefaultFontSize(12);
|
||||||
```
|
```
|
||||||
|
|
||||||
## Document properties
|
## Document information
|
||||||
|
|
||||||
You can set the document properties such as title, creator, and company name. Use the following functions:
|
You can set the document information such as title, creator, and company name. Use the following functions:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$properties = $phpWord->getDocumentProperties();
|
$properties = $phpWord->getDocInfo();
|
||||||
$properties->setCreator('My name');
|
$properties->setCreator('My name');
|
||||||
$properties->setCompany('My factory');
|
$properties->setCompany('My factory');
|
||||||
$properties->setTitle('My title');
|
$properties->setTitle('My title');
|
||||||
@ -299,15 +346,15 @@ You can use PHPWord helper functions to convert inches, centimeters, or points t
|
|||||||
```php
|
```php
|
||||||
// Paragraph with 6 points space after
|
// Paragraph with 6 points space after
|
||||||
$phpWord->addParagraphStyle('My Style', array(
|
$phpWord->addParagraphStyle('My Style', array(
|
||||||
'spaceAfter' => \PhpOffice\PhpWord\Shared\Font::pointSizeToTwips(6))
|
'spaceAfter' => \PhpOffice\PhpWord\Shared\Converter::pointToTwip(6))
|
||||||
);
|
);
|
||||||
|
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$sectionStyle = $section->getSettings();
|
$sectionStyle = $section->getStyle();
|
||||||
// half inch left margin
|
// half inch left margin
|
||||||
$sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Font::inchSizeToTwips(.5));
|
$sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Converter::inchToTwip(.5));
|
||||||
// 2 cm right margin
|
// 2 cm right margin
|
||||||
$sectionStyle->setMarginRight(\PhpOffice\PhpWord\Shared\Font::centimeterSizeToTwips(2));
|
$sectionStyle->setMarginRight(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(2));
|
||||||
```
|
```
|
||||||
|
|
||||||
# Containers
|
# Containers
|
||||||
@ -319,51 +366,23 @@ Containers are objects where you can put elements (texts, lists, tables, etc). T
|
|||||||
Every visible element in word is placed inside of a section. To create a section, use the following code:
|
Every visible element in word is placed inside of a section. To create a section, use the following code:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$section = $phpWord->addSection($sectionSettings);
|
$section = $phpWord->addSection($sectionStyle);
|
||||||
```
|
```
|
||||||
|
|
||||||
The `$sectionSettings` is an optional associative array that sets the section. Example:
|
The `$sectionStyle` is an optional associative array that sets the section. Example:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$sectionSettings = array(
|
$sectionStyle = array(
|
||||||
'orientation' => 'landscape',
|
'orientation' => 'landscape',
|
||||||
'marginTop' => 600,
|
'marginTop' => 600,
|
||||||
'colsNum' => 2,
|
'colsNum' => 2,
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Section settings
|
|
||||||
|
|
||||||
Below are the available settings for section:
|
|
||||||
|
|
||||||
- `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)
|
|
||||||
|
|
||||||
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 twips
|
|
||||||
- `pageSizeH` Page height in twips
|
|
||||||
|
|
||||||
### Page number
|
### Page number
|
||||||
|
|
||||||
You can change a section page number by using the `pageNumberingStart` property of the section.
|
You can change a section page number by using the `pageNumberingStart` style of the section.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
// Method 1
|
// Method 1
|
||||||
@ -371,12 +390,12 @@ $section = $phpWord->addSection(array('pageNumberingStart' => 1));
|
|||||||
|
|
||||||
// Method 2
|
// Method 2
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->getSettings()->setPageNumberingStart(1);
|
$section->getStyle()->setPageNumberingStart(1);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Multicolumn
|
### Multicolumn
|
||||||
|
|
||||||
You can change a section layout to multicolumn (like in a newspaper) by using the `breakType` and `colsNum` property of the section.
|
You can change a section layout to multicolumn (like in a newspaper) by using the `breakType` and `colsNum` style of the section.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
// Method 1
|
// Method 1
|
||||||
@ -384,13 +403,13 @@ $section = $phpWord->addSection(array('breakType' => 'continuous', 'colsNum' =>
|
|||||||
|
|
||||||
// Method 2
|
// Method 2
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->getSettings()->setBreakType('continuous');
|
$section->getStyle()->setBreakType('continuous');
|
||||||
$section->getSettings()->setColsNum(2);
|
$section->getStyle()->setColsNum(2);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Line numbering
|
### Line numbering
|
||||||
|
|
||||||
You can apply line numbering to a section by using the `lineNumbering` property of the section.
|
You can apply line numbering to a section by using the `lineNumbering` style of the section.
|
||||||
|
|
||||||
```php
|
```php
|
||||||
// Method 1
|
// Method 1
|
||||||
@ -398,7 +417,7 @@ $section = $phpWord->addSection(array('lineNumbering' => array()));
|
|||||||
|
|
||||||
// Method 2
|
// Method 2
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->getSettings()->setLineNumbering(array());
|
$section->getStyle()->setLineNumbering(array());
|
||||||
```
|
```
|
||||||
|
|
||||||
Below are the properties of the line numbering style.
|
Below are the properties of the line numbering style.
|
||||||
@ -465,6 +484,9 @@ Below are the matrix of element availability in each container. The column shows
|
|||||||
| 17 | TextBox | v | v | v | v | - | - |
|
| 17 | TextBox | v | v | v | v | - | - |
|
||||||
| 18 | Field | v | v | v | v | v | v |
|
| 18 | Field | v | v | v | v | v | v |
|
||||||
| 19 | Line | v | v | v | v | v | v |
|
| 19 | Line | v | v | v | v | v | v |
|
||||||
|
| 20 | Shape | v | v | v | v | v | v |
|
||||||
|
| 21 | Chart | v | - | - | - | - | - |
|
||||||
|
| 22 | Form Fields | v | v | v | v | v | v |
|
||||||
|
|
||||||
Legend:
|
Legend:
|
||||||
|
|
||||||
@ -483,8 +505,6 @@ $section->addText($text, [$fontStyle], [$paragraphStyle]);
|
|||||||
$textrun = $section->addTextRun([$paragraphStyle]);
|
$textrun = $section->addTextRun([$paragraphStyle]);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Text styles
|
|
||||||
|
|
||||||
You can use the `$fontStyle` and `$paragraphStyle` variable to define text formatting. There are 2 options to style the inserted text elements, i.e. inline style by using array or defined style by adding style definition.
|
You can use the `$fontStyle` and `$paragraphStyle` variable to define text formatting. There are 2 options to style the inserted text elements, i.e. inline style by using array or defined style by adding style definition.
|
||||||
|
|
||||||
Inline style examples:
|
Inline style examples:
|
||||||
@ -512,44 +532,6 @@ $phpWord->addParagraphStyle('pStyle', $paragraphStyle);
|
|||||||
$text = $section->addText('Hello world!', 'pStyle');
|
$text = $section->addText('Hello world!', 'pStyle');
|
||||||
```
|
```
|
||||||
|
|
||||||
#### 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*
|
|
||||||
- `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*
|
|
||||||
|
|
||||||
#### Paragraph style
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
### Titles
|
### 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.
|
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.
|
||||||
@ -600,9 +582,9 @@ $section->addTextBreak([$breakCount], [$fontStyle], [$paragraphStyle]);
|
|||||||
|
|
||||||
There are two ways to insert a page breaks, using the `addPageBreak` method or using the `pageBreakBefore` style of paragraph.
|
There are two ways to insert a page breaks, using the `addPageBreak` method or using the `pageBreakBefore` style of paragraph.
|
||||||
|
|
||||||
:: code-block:: php
|
```php
|
||||||
|
$section->addPageBreak();
|
||||||
> \$section-\>addPageBreak();
|
```
|
||||||
|
|
||||||
## Lists
|
## Lists
|
||||||
|
|
||||||
@ -641,20 +623,6 @@ $section->addListItem('List Item I.b', 1, null, 'multilevel');
|
|||||||
$section->addListItem('List Item II', 0, 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
|
|
||||||
|
|
||||||
## Tables
|
## Tables
|
||||||
|
|
||||||
To add tables, rows, and cells, use the `addTable`, `addRow`, and `addCell` methods:
|
To add tables, rows, and cells, use the `addTable`, `addRow`, and `addCell` methods:
|
||||||
@ -678,33 +646,6 @@ $phpWord->addTableStyle('myTable', $tableStyle, $firstRowStyle);
|
|||||||
$table = $section->addTable('myTable');
|
$table = $section->addTable('myTable');
|
||||||
```
|
```
|
||||||
|
|
||||||
### Table, row, and cell styles
|
|
||||||
|
|
||||||
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*
|
|
||||||
|
|
||||||
### Cell span
|
### Cell span
|
||||||
|
|
||||||
You can span a cell on multiple columns by using `gridSpan` or multiple rows by using `vMerge`.
|
You can span a cell on multiple columns by using `gridSpan` or multiple rows by using `vMerge`.
|
||||||
@ -747,17 +688,6 @@ $textrun = $section->addTextRun();
|
|||||||
$textrun->addImage('http://php.net/logo.jpg');
|
$textrun->addImage('http://php.net/logo.jpg');
|
||||||
```
|
```
|
||||||
|
|
||||||
### Image styles
|
|
||||||
|
|
||||||
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*
|
|
||||||
|
|
||||||
### Watermarks
|
### 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.
|
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.
|
||||||
@ -850,21 +780,158 @@ To be completed.
|
|||||||
|
|
||||||
To be completed.
|
To be completed.
|
||||||
|
|
||||||
# Templates
|
## Shapes
|
||||||
|
|
||||||
You can create a docx template with included search-patterns that can be replaced by any value you wish. Only single-line values can be replaced. To load a template file, use the `loadTemplate` method. After loading the docx template, you can use the `setValue` method to change the value of a search pattern. The search-pattern model is: `${search-pattern}`. It is not possible to add new PHPWord elements to a loaded template file.
|
To be completed.
|
||||||
|
|
||||||
|
## Charts
|
||||||
|
|
||||||
|
To be completed.
|
||||||
|
|
||||||
|
## Form fields
|
||||||
|
|
||||||
|
To be completed.
|
||||||
|
|
||||||
|
# Styles
|
||||||
|
|
||||||
|
## Section
|
||||||
|
|
||||||
|
Below are the available styles for section:
|
||||||
|
|
||||||
|
- `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)
|
||||||
|
|
||||||
|
The following two styles are automatically set by the use of the `orientation` style. You can alter them but that's not recommended.
|
||||||
|
|
||||||
|
- `pageSizeW` Page width in twips
|
||||||
|
- `pageSizeH` Page height in twips
|
||||||
|
|
||||||
|
## 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*
|
||||||
|
|
||||||
|
## 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
|
||||||
|
|
||||||
|
## 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*
|
||||||
|
|
||||||
|
## 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*
|
||||||
|
|
||||||
|
## Numbering level
|
||||||
|
|
||||||
|
- `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
|
||||||
|
|
||||||
|
# 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:
|
Example:
|
||||||
|
|
||||||
```php
|
```php
|
||||||
$template = $phpWord->loadTemplate('Template.docx');
|
$templateProcessor = new TemplateProcessor('Template.docx');
|
||||||
$template->setValue('Name', 'Somebody someone');
|
$templateProcessor->setValue('Name', 'Somebody someone');
|
||||||
$template->setValue('Street', 'Coming-Undone-Street 32');
|
$templateProcessor->setValue('Street', 'Coming-Undone-Street 32');
|
||||||
```
|
```
|
||||||
|
|
||||||
See `Sample_07_TemplateCloneRow.php` for example on how to create multirow from a single row in a template by using `cloneRow`.
|
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_23_TemplateBlock.php` for example on how to clone a block of text using `cloneBlock` and delete a block of text using `deleteBlock`.
|
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`.
|
||||||
|
|
||||||
# Writers & readers
|
# Writers & readers
|
||||||
|
|
||||||
@ -1009,6 +1076,35 @@ $section->addTitle('Heading 2', 2);
|
|||||||
$section->addTitle('Heading 3', 3);
|
$section->addTitle('Heading 3', 3);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Add a link within a title
|
||||||
|
|
||||||
|
Apply 'HeadingN' paragraph style to TextRun or Link. Sample code:
|
||||||
|
|
||||||
|
```php
|
||||||
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
$phpWord->addTitleStyle(1, array('size' => 16, 'bold' => true));
|
||||||
|
$phpWord->addTitleStyle(2, array('size' => 14, 'bold' => true));
|
||||||
|
$phpWord->addFontStyle('Link', array('color' => '0000FF', 'underline' => 'single'));
|
||||||
|
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
|
// Textrun
|
||||||
|
$textrun = $section->addTextRun('Heading1');
|
||||||
|
$textrun->addText('The ');
|
||||||
|
$textrun->addLink('https://github.com/PHPOffice/PHPWord', 'PHPWord', 'Link');
|
||||||
|
|
||||||
|
// Link
|
||||||
|
$section->addLink('https://github.com/', 'GitHub', 'Link', 'Heading2');
|
||||||
|
```
|
||||||
|
|
||||||
|
## Remove [Compatibility Mode] text in the MS Word title bar
|
||||||
|
|
||||||
|
Use the `Metadata\Compatibility\setOoxmlVersion(n)` method with `n` is the version of Office (14 = Office 2010, 15 = Office 2013).
|
||||||
|
|
||||||
|
```php
|
||||||
|
$phpWord->getCompatibility()->setOoxmlVersion(15);
|
||||||
|
```
|
||||||
|
|
||||||
# Frequently asked questions
|
# Frequently asked questions
|
||||||
|
|
||||||
## Is this the same with PHPWord that I found in CodePlex?
|
## Is this the same with PHPWord that I found in CodePlex?
|
||||||
|
|||||||
134
docs/styles.rst
Normal file
134
docs/styles.rst
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
.. _styles:
|
||||||
|
|
||||||
|
Styles
|
||||||
|
======
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
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*
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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*
|
||||||
|
|
||||||
|
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*
|
||||||
|
|
||||||
|
Numbering level
|
||||||
|
---------------
|
||||||
|
|
||||||
|
- ``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
|
||||||
25
docs/templates-processing.rst
Normal file
25
docs/templates-processing.rst
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
.. _templates-processing:
|
||||||
|
|
||||||
|
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:
|
||||||
|
|
||||||
|
.. code-block:: php
|
||||||
|
|
||||||
|
$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``.
|
||||||
@ -1,27 +0,0 @@
|
|||||||
.. _templates:
|
|
||||||
|
|
||||||
Templates
|
|
||||||
=========
|
|
||||||
|
|
||||||
You can create a docx template with included search-patterns that can be
|
|
||||||
replaced by any value you wish. Only single-line values can be replaced.
|
|
||||||
To load a template file, use the ``loadTemplate`` method. After loading
|
|
||||||
the docx template, you can use the ``setValue`` method to change the
|
|
||||||
value of a search pattern. The search-pattern model is:
|
|
||||||
``${search-pattern}``. It is not possible to add new PHPWord elements to
|
|
||||||
a loaded template file.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
.. code-block:: php
|
|
||||||
|
|
||||||
$template = $phpWord->loadTemplate('Template.docx');
|
|
||||||
$template->setValue('Name', 'Somebody someone');
|
|
||||||
$template->setValue('Street', 'Coming-Undone-Street 32');
|
|
||||||
|
|
||||||
See ``Sample_07_TemplateCloneRow.php`` for example on how to create
|
|
||||||
multirow from a single row in a template by using ``cloneRow``.
|
|
||||||
|
|
||||||
See ``Sample_23_TemplateBlock.php`` for example on how to clone a block
|
|
||||||
of text using ``cloneBlock`` and delete a block of text using
|
|
||||||
``deleteBlock``.
|
|
||||||
@ -18,7 +18,7 @@
|
|||||||
<rule ref="rulesets/design.xml/NumberOfChildren">
|
<rule ref="rulesets/design.xml/NumberOfChildren">
|
||||||
<!-- AbstractStyle needs more children (default: 15) -->
|
<!-- AbstractStyle needs more children (default: 15) -->
|
||||||
<properties>
|
<properties>
|
||||||
<property name="minimum" value="20" />
|
<property name="minimum" value="30" />
|
||||||
</properties>
|
</properties>
|
||||||
</rule>
|
</rule>
|
||||||
<rule ref="rulesets/unusedcode.xml" />
|
<rule ref="rulesets/unusedcode.xml" />
|
||||||
|
|||||||
@ -7,6 +7,7 @@ compatibility = true
|
|||||||
zipClass = ZipArchive
|
zipClass = ZipArchive
|
||||||
pdfRendererName = DomPDF
|
pdfRendererName = DomPDF
|
||||||
pdfRendererPath =
|
pdfRendererPath =
|
||||||
|
; tempDir = "C:\PhpWordTemp"
|
||||||
|
|
||||||
[Font]
|
[Font]
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word Document
|
// New Word Document
|
||||||
echo date('H:i:s') , " Create new PhpWord object" , EOL;
|
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
$phpWord->addFontStyle('rStyle', array('bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true));
|
$phpWord->addFontStyle('rStyle', array('bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true));
|
||||||
$phpWord->addParagraphStyle('pStyle', array('align' => 'center', 'spaceAfter' => 100));
|
$phpWord->addParagraphStyle('pStyle', array('align' => 'center', 'spaceAfter' => 100));
|
||||||
@ -12,36 +12,57 @@ $phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240));
|
|||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
// Simple text
|
// Simple text
|
||||||
$section->addTitle('Welcome to PhpWord', 1);
|
$section->addTitle(htmlspecialchars('Welcome to PhpWord'), 1);
|
||||||
$section->addText('Hello World!');
|
$section->addText(htmlspecialchars('Hello World!'));
|
||||||
|
|
||||||
// Two text break
|
// Two text break
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
// Defined style
|
// Defined style
|
||||||
$section->addText('I am styled by a font style definition.', 'rStyle');
|
$section->addText(htmlspecialchars('I am styled by a font style definition.'), 'rStyle');
|
||||||
$section->addText('I am styled by a paragraph style definition.', null, 'pStyle');
|
$section->addText(htmlspecialchars('I am styled by a paragraph style definition.'), null, 'pStyle');
|
||||||
$section->addText('I am styled by both font and paragraph style.', 'rStyle', 'pStyle');
|
$section->addText(htmlspecialchars('I am styled by both font and paragraph style.'), 'rStyle', 'pStyle');
|
||||||
|
|
||||||
$section->addPageBreak();
|
$section->addTextBreak();
|
||||||
|
|
||||||
// Inline font style
|
// Inline font style
|
||||||
$fontStyle['name'] = 'Times New Roman';
|
$fontStyle['name'] = 'Times New Roman';
|
||||||
$fontStyle['size'] = 20;
|
$fontStyle['size'] = 20;
|
||||||
$fontStyle['bold'] = true;
|
|
||||||
$fontStyle['italic'] = true;
|
|
||||||
$fontStyle['underline'] = 'dash';
|
|
||||||
$fontStyle['strikethrough'] = true;
|
|
||||||
$fontStyle['superScript'] = true;
|
|
||||||
$fontStyle['color'] = 'FF0000';
|
|
||||||
$fontStyle['fgColor'] = 'yellow';
|
|
||||||
$fontStyle['smallCaps'] = true;
|
|
||||||
$section->addText('I am inline styled.', $fontStyle);
|
|
||||||
|
|
||||||
$section->addTextBreak();
|
$textrun = $section->addTextRun();
|
||||||
|
$textrun->addText(htmlspecialchars('I am inline styled '), $fontStyle);
|
||||||
|
$textrun->addText(htmlspecialchars('with '));
|
||||||
|
$textrun->addText(htmlspecialchars('color'), array('color' => '996699'));
|
||||||
|
$textrun->addText(htmlspecialchars(', '));
|
||||||
|
$textrun->addText(htmlspecialchars('bold'), array('bold' => true));
|
||||||
|
$textrun->addText(htmlspecialchars(', '));
|
||||||
|
$textrun->addText(htmlspecialchars('italic'), array('italic' => true));
|
||||||
|
$textrun->addText(htmlspecialchars(', '));
|
||||||
|
$textrun->addText(htmlspecialchars('underline'), array('underline' => 'dash'));
|
||||||
|
$textrun->addText(htmlspecialchars(', '));
|
||||||
|
$textrun->addText(htmlspecialchars('strikethrough'), array('strikethrough' => true));
|
||||||
|
$textrun->addText(htmlspecialchars(', '));
|
||||||
|
$textrun->addText(htmlspecialchars('doubleStrikethrough'), array('doubleStrikethrough' => true));
|
||||||
|
$textrun->addText(htmlspecialchars(', '));
|
||||||
|
$textrun->addText(htmlspecialchars('superScript'), array('superScript' => true));
|
||||||
|
$textrun->addText(htmlspecialchars(', '));
|
||||||
|
$textrun->addText(htmlspecialchars('subScript'), array('subScript' => true));
|
||||||
|
$textrun->addText(htmlspecialchars(', '));
|
||||||
|
$textrun->addText(htmlspecialchars('smallCaps'), array('smallCaps' => true));
|
||||||
|
$textrun->addText(htmlspecialchars(', '));
|
||||||
|
$textrun->addText(htmlspecialchars('allCaps'), array('allCaps' => true));
|
||||||
|
$textrun->addText(htmlspecialchars(', '));
|
||||||
|
$textrun->addText(htmlspecialchars('fgColor'), array('fgColor' => 'yellow'));
|
||||||
|
$textrun->addText(htmlspecialchars(', '));
|
||||||
|
$textrun->addText(htmlspecialchars('scale'), array('scale' => 200));
|
||||||
|
$textrun->addText(htmlspecialchars(', '));
|
||||||
|
$textrun->addText(htmlspecialchars('spacing'), array('spacing' => 120));
|
||||||
|
$textrun->addText(htmlspecialchars(', '));
|
||||||
|
$textrun->addText(htmlspecialchars('kerning'), array('kerning' => 10));
|
||||||
|
$textrun->addText(htmlspecialchars('. '));
|
||||||
|
|
||||||
// Link
|
// Link
|
||||||
$section->addLink('http://www.google.com', 'Google');
|
$section->addLink('http://www.google.com', htmlspecialchars('Google'));
|
||||||
$section->addTextBreak();
|
$section->addTextBreak();
|
||||||
|
|
||||||
// Image
|
// Image
|
||||||
|
|||||||
@ -2,35 +2,36 @@
|
|||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word Document
|
// New Word Document
|
||||||
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Ads styles
|
// Ads styles
|
||||||
$phpWord->addParagraphStyle('multipleTab', array(
|
$phpWord->addParagraphStyle(
|
||||||
'tabs' => array(
|
'multipleTab',
|
||||||
new \PhpOffice\PhpWord\Style\Tab('left', 1550),
|
array(
|
||||||
new \PhpOffice\PhpWord\Style\Tab('center', 3200),
|
'tabs' => array(
|
||||||
new \PhpOffice\PhpWord\Style\Tab('right', 5300)
|
new \PhpOffice\PhpWord\Style\Tab('left', 1550),
|
||||||
)
|
new \PhpOffice\PhpWord\Style\Tab('center', 3200),
|
||||||
));
|
new \PhpOffice\PhpWord\Style\Tab('right', 5300),
|
||||||
$phpWord->addParagraphStyle('rightTab', array(
|
)
|
||||||
'tabs' => array(
|
)
|
||||||
new \PhpOffice\PhpWord\Style\Tab('right', 9090)
|
);
|
||||||
)
|
$phpWord->addParagraphStyle(
|
||||||
));
|
'rightTab',
|
||||||
$phpWord->addParagraphStyle('centerTab', array(
|
array('tabs' => array(new \PhpOffice\PhpWord\Style\Tab('right', 9090)))
|
||||||
'tabs' => array(
|
);
|
||||||
new \PhpOffice\PhpWord\Style\Tab('center', 4680)
|
$phpWord->addParagraphStyle(
|
||||||
)
|
'centerTab',
|
||||||
));
|
array('tabs' => array(new \PhpOffice\PhpWord\Style\Tab('center', 4680)))
|
||||||
|
);
|
||||||
|
|
||||||
// New portrait section
|
// New portrait section
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
// Add listitem elements
|
// Add listitem elements
|
||||||
$section->addText("Multiple Tabs:\tOne\tTwo\tThree", null, 'multipleTab');
|
$section->addText(htmlspecialchars("Multiple Tabs:\tOne\tTwo\tThree"), null, 'multipleTab');
|
||||||
$section->addText("Left Aligned\tRight Aligned", null, 'rightTab');
|
$section->addText(htmlspecialchars("Left Aligned\tRight Aligned"), null, 'rightTab');
|
||||||
$section->addText("\tCenter Aligned", null, 'centerTab');
|
$section->addText(htmlspecialchars("\tCenter Aligned"), null, 'centerTab');
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|||||||
@ -2,28 +2,43 @@
|
|||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word Document
|
// New Word Document
|
||||||
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// New portrait section
|
// New portrait section
|
||||||
$section = $phpWord->addSection(array('borderColor' => '00FF00', 'borderSize' => 12));
|
$section = $phpWord->addSection(array('borderColor' => '00FF00', 'borderSize' => 12));
|
||||||
$section->addText('I am placed on a default section.');
|
$section->addText(htmlspecialchars('I am placed on a default section.'));
|
||||||
|
|
||||||
// New landscape section
|
// New landscape section
|
||||||
$section = $phpWord->addSection(array('orientation' => 'landscape'));
|
$section = $phpWord->addSection(array('orientation' => 'landscape'));
|
||||||
$section->addText('I am placed on a landscape section. Every page starting from this section will be landscape style.');
|
$section->addText(
|
||||||
|
htmlspecialchars(
|
||||||
|
'I am placed on a landscape section. Every page starting from this section will be landscape style.'
|
||||||
|
)
|
||||||
|
);
|
||||||
$section->addPageBreak();
|
$section->addPageBreak();
|
||||||
$section->addPageBreak();
|
$section->addPageBreak();
|
||||||
|
|
||||||
// New portrait section
|
// New portrait section
|
||||||
$section = $phpWord->addSection(array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600));
|
$section = $phpWord->addSection(
|
||||||
$section->addText('This section uses other margins.');
|
array('paperSize' => 'Folio', 'marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600)
|
||||||
|
);
|
||||||
|
$section->addText(htmlspecialchars('This section uses other margins with folio papersize.'));
|
||||||
|
|
||||||
// New portrait section with Header & Footer
|
// New portrait section with Header & Footer
|
||||||
$section = $phpWord->addSection(array('marginLeft' => 200, 'marginRight' => 200, 'marginTop' => 200, 'marginBottom' => 200, 'headerHeight' => 50, 'footerHeight' => 50,));
|
$section = $phpWord->addSection(
|
||||||
$section->addText('This section and we play with header/footer height.');
|
array(
|
||||||
$section->addHeader()->addText('Header');
|
'marginLeft' => 200,
|
||||||
$section->addFooter()->addText('Footer');
|
'marginRight' => 200,
|
||||||
|
'marginTop' => 200,
|
||||||
|
'marginBottom' => 200,
|
||||||
|
'headerHeight' => 50,
|
||||||
|
'footerHeight' => 50,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$section->addText(htmlspecialchars('This section and we play with header/footer height.'));
|
||||||
|
$section->addHeader()->addText(htmlspecialchars('Header'));
|
||||||
|
$section->addFooter()->addText(htmlspecialchars('Footer'));
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|||||||
@ -2,14 +2,17 @@
|
|||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word Document
|
// New Word Document
|
||||||
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Ads styles
|
// Ads styles
|
||||||
$phpWord->addParagraphStyle('pStyle', array('spacing'=>100));
|
$phpWord->addParagraphStyle('pStyle', array('spacing' => 100));
|
||||||
$phpWord->addFontStyle('BoldText', array('bold'=>true));
|
$phpWord->addFontStyle('BoldText', array('bold' => true));
|
||||||
$phpWord->addFontStyle('ColoredText', array('color'=>'FF8080', 'bgColor' => 'FFFFCC'));
|
$phpWord->addFontStyle('ColoredText', array('color' => 'FF8080', 'bgColor' => 'FFFFCC'));
|
||||||
$phpWord->addLinkStyle('NLink', array('color'=>'0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
|
$phpWord->addLinkStyle(
|
||||||
|
'NLink',
|
||||||
|
array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE)
|
||||||
|
);
|
||||||
|
|
||||||
// New portrait section
|
// New portrait section
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
@ -17,21 +20,24 @@ $section = $phpWord->addSection();
|
|||||||
// Add text run
|
// Add text run
|
||||||
$textrun = $section->addTextRun('pStyle');
|
$textrun = $section->addTextRun('pStyle');
|
||||||
|
|
||||||
$textrun->addText('Each textrun can contain native text, link elements or an image.');
|
$textrun->addText(htmlspecialchars('Each textrun can contain native text, link elements or an image.'));
|
||||||
$textrun->addText(' No break is placed after adding an element.', 'BoldText');
|
$textrun->addText(htmlspecialchars(' No break is placed after adding an element.'), 'BoldText');
|
||||||
$textrun->addText(' Both ');
|
$textrun->addText(htmlspecialchars(' Both '));
|
||||||
$textrun->addText('superscript', array('superScript' => true));
|
$textrun->addText(htmlspecialchars('superscript'), array('superScript' => true));
|
||||||
$textrun->addText(' and ');
|
$textrun->addText(htmlspecialchars(' and '));
|
||||||
$textrun->addText('subscript', array('subScript' => true));
|
$textrun->addText(htmlspecialchars('subscript'), array('subScript' => true));
|
||||||
$textrun->addText(' are also available.');
|
$textrun->addText(htmlspecialchars(' are also available.'));
|
||||||
$textrun->addText(' All elements are placed inside a paragraph with the optionally given p-Style.', 'ColoredText');
|
$textrun->addText(
|
||||||
$textrun->addText(' Sample Link: ');
|
htmlspecialchars(' All elements are placed inside a paragraph with the optionally given p-Style.'),
|
||||||
|
'ColoredText'
|
||||||
|
);
|
||||||
|
$textrun->addText(htmlspecialchars(' Sample Link: '));
|
||||||
$textrun->addLink('http://www.google.com', null, 'NLink');
|
$textrun->addLink('http://www.google.com', null, 'NLink');
|
||||||
$textrun->addText(' Sample Image: ');
|
$textrun->addText(htmlspecialchars(' Sample Image: '));
|
||||||
$textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
|
$textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
|
||||||
$textrun->addText(' Sample Object: ');
|
$textrun->addText(htmlspecialchars(' Sample Object: '));
|
||||||
$textrun->addObject('resources/_sheet.xls');
|
$textrun->addObject('resources/_sheet.xls');
|
||||||
$textrun->addText(' Here is some more text. ');
|
$textrun->addText(htmlspecialchars(' Here is some more text. '));
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|||||||
@ -2,38 +2,44 @@
|
|||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word Document
|
// New Word Document
|
||||||
echo date('H:i:s') , " Create new PhpWord object" , EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
$filler = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' .
|
$filler = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. '
|
||||||
'Nulla fermentum, tortor id adipiscing adipiscing, tortor turpis commodo. ' .
|
. 'Nulla fermentum, tortor id adipiscing adipiscing, tortor turpis commodo. '
|
||||||
'Donec vulputate iaculis metus, vel luctus dolor hendrerit ac. ' .
|
. 'Donec vulputate iaculis metus, vel luctus dolor hendrerit ac. '
|
||||||
'Suspendisse congue congue leo sed pellentesque.';
|
. 'Suspendisse congue congue leo sed pellentesque.';
|
||||||
|
|
||||||
// Normal
|
// Normal
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addText('Normal paragraph. ' . $filler);
|
$section->addText(htmlspecialchars("Normal paragraph. {$filler}"));
|
||||||
|
|
||||||
// Two columns
|
// Two columns
|
||||||
$section = $phpWord->addSection(array(
|
$section = $phpWord->addSection(
|
||||||
'colsNum' => 2,
|
array(
|
||||||
'colsSpace' => 1440,
|
'colsNum' => 2,
|
||||||
'breakType' => 'continuous'));
|
'colsSpace' => 1440,
|
||||||
$section->addText('Two columns, one inch (1440 twips) spacing. ' . $filler);
|
'breakType' => 'continuous',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$section->addText(htmlspecialchars("Two columns, one inch (1440 twips) spacing. {$filler}"));
|
||||||
|
|
||||||
// Normal
|
// Normal
|
||||||
$section = $phpWord->addSection(array('breakType' => 'continuous'));
|
$section = $phpWord->addSection(array('breakType' => 'continuous'));
|
||||||
$section->addText('Normal paragraph again. ' . $filler);
|
$section->addText(htmlspecialchars("Normal paragraph again. {$filler}"));
|
||||||
|
|
||||||
// Three columns
|
// Three columns
|
||||||
$section = $phpWord->addSection(array(
|
$section = $phpWord->addSection(
|
||||||
'colsNum' => 3,
|
array(
|
||||||
'colsSpace' => 720,
|
'colsNum' => 3,
|
||||||
'breakType' => 'continuous'));
|
'colsSpace' => 720,
|
||||||
$section->addText('Three columns, half inch (720 twips) spacing. ' . $filler);
|
'breakType' => 'continuous',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$section->addText(htmlspecialchars("Three columns, half inch (720 twips) spacing. {$filler}"));
|
||||||
|
|
||||||
// Normal
|
// Normal
|
||||||
$section = $phpWord->addSection(array('breakType' => 'continuous'));
|
$section = $phpWord->addSection(array('breakType' => 'continuous'));
|
||||||
$section->addText('Normal paragraph again.');
|
$section->addText(htmlspecialchars('Normal paragraph again.'));
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word Document
|
// New Word Document
|
||||||
echo date('H:i:s') , " Create new PhpWord object" , EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
\PhpOffice\PhpWord\Settings::setCompatibility(false);
|
\PhpOffice\PhpWord\Settings::setCompatibility(false);
|
||||||
|
|
||||||
@ -10,32 +10,40 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
// Add style definitions
|
// Add style definitions
|
||||||
$phpWord->addParagraphStyle('pStyle', array('spacing'=>100));
|
$phpWord->addParagraphStyle('pStyle', array('spacing' => 100));
|
||||||
$phpWord->addFontStyle('BoldText', array('bold'=>true));
|
$phpWord->addFontStyle('BoldText', array('bold' => true));
|
||||||
$phpWord->addFontStyle('ColoredText', array('color'=>'FF8080'));
|
$phpWord->addFontStyle('ColoredText', array('color' => 'FF8080'));
|
||||||
$phpWord->addLinkStyle('NLink', array('color'=>'0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
|
$phpWord->addLinkStyle(
|
||||||
|
'NLink',
|
||||||
|
array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE)
|
||||||
|
);
|
||||||
|
|
||||||
// Add text elements
|
// Add text elements
|
||||||
$textrun = $section->addTextRun('pStyle');
|
$textrun = $section->addTextRun('pStyle');
|
||||||
$textrun->addText('This is some lead text in a paragraph with a following footnote. ','pStyle');
|
$textrun->addText(htmlspecialchars('This is some lead text in a paragraph with a following footnote. '), 'pStyle');
|
||||||
|
|
||||||
$footnote = $textrun->addFootnote();
|
$footnote = $textrun->addFootnote();
|
||||||
$footnote->addText('Just like a textrun, a footnote can contain native texts. ');
|
$footnote->addText(htmlspecialchars('Just like a textrun, a footnote can contain native texts. '));
|
||||||
$footnote->addText('No break is placed after adding an element. ', 'BoldText');
|
$footnote->addText(htmlspecialchars('No break is placed after adding an element. '), 'BoldText');
|
||||||
$footnote->addText('All elements are placed inside a paragraph. ', 'ColoredText');
|
$footnote->addText(htmlspecialchars('All elements are placed inside a paragraph. '), 'ColoredText');
|
||||||
$footnote->addTextBreak();
|
$footnote->addTextBreak();
|
||||||
$footnote->addText('But you can insert a manual text break like above, ');
|
$footnote->addText(htmlspecialchars('But you can insert a manual text break like above, '));
|
||||||
$footnote->addText('links like ');
|
$footnote->addText(htmlspecialchars('links like '));
|
||||||
$footnote->addLink('http://www.google.com', null, 'NLink');
|
$footnote->addLink('http://www.google.com', null, 'NLink');
|
||||||
$footnote->addText(', image like ');
|
$footnote->addText(htmlspecialchars(', image like '));
|
||||||
$footnote->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
|
$footnote->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
|
||||||
$footnote->addText(', or object like ');
|
$footnote->addText(htmlspecialchars(', or object like '));
|
||||||
$footnote->addObject('resources/_sheet.xls');
|
$footnote->addObject('resources/_sheet.xls');
|
||||||
$footnote->addText('But you can only put footnote in section, not in header or footer.');
|
$footnote->addText(htmlspecialchars('But you can only put footnote in section, not in header or footer.'));
|
||||||
|
|
||||||
$section->addText('You can also create the footnote directly from the section making it wrap in a paragraph like the footnote below this paragraph. But is is best used from within a textrun.');
|
$section->addText(
|
||||||
|
htmlspecialchars(
|
||||||
|
'You can also create the footnote directly from the section making it wrap in a paragraph '
|
||||||
|
. 'like the footnote below this paragraph. But is is best used from within a textrun.'
|
||||||
|
)
|
||||||
|
);
|
||||||
$footnote = $section->addFootnote();
|
$footnote = $section->addFootnote();
|
||||||
$footnote->addText('The reference for this is wrapped in its own line');
|
$footnote->addText(htmlspecialchars('The reference for this is wrapped in its own line'));
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|||||||
@ -1,64 +1,60 @@
|
|||||||
<?php
|
<?php
|
||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word document
|
// Template processor instance creation
|
||||||
echo date('H:i:s') , " Create new PhpWord object" , EOL;
|
echo date('H:i:s'), ' Creating new TemplateProcessor instance...', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('resources/Sample_07_TemplateCloneRow.docx');
|
||||||
|
|
||||||
$document = $phpWord->loadTemplate('resources/Sample_07_TemplateCloneRow.docx');
|
|
||||||
|
|
||||||
// Variables on different parts of document
|
// Variables on different parts of document
|
||||||
$document->setValue('weekday', date('l')); // On section/content
|
$templateProcessor->setValue('weekday', htmlspecialchars(date('l'))); // On section/content
|
||||||
$document->setValue('time', date('H:i')); // On footer
|
$templateProcessor->setValue('time', htmlspecialchars(date('H:i'))); // On footer
|
||||||
$document->setValue('serverName', realpath(__DIR__)); // On header
|
$templateProcessor->setValue('serverName', htmlspecialchars(realpath(__DIR__))); // On header
|
||||||
|
|
||||||
// Simple table
|
// Simple table
|
||||||
$document->cloneRow('rowValue', 10);
|
$templateProcessor->cloneRow('rowValue', 10);
|
||||||
|
|
||||||
$document->setValue('rowValue#1', 'Sun');
|
$templateProcessor->setValue('rowValue#1', htmlspecialchars('Sun'));
|
||||||
$document->setValue('rowValue#2', 'Mercury');
|
$templateProcessor->setValue('rowValue#2', htmlspecialchars('Mercury'));
|
||||||
$document->setValue('rowValue#3', 'Venus');
|
$templateProcessor->setValue('rowValue#3', htmlspecialchars('Venus'));
|
||||||
$document->setValue('rowValue#4', 'Earth');
|
$templateProcessor->setValue('rowValue#4', htmlspecialchars('Earth'));
|
||||||
$document->setValue('rowValue#5', 'Mars');
|
$templateProcessor->setValue('rowValue#5', htmlspecialchars('Mars'));
|
||||||
$document->setValue('rowValue#6', 'Jupiter');
|
$templateProcessor->setValue('rowValue#6', htmlspecialchars('Jupiter'));
|
||||||
$document->setValue('rowValue#7', 'Saturn');
|
$templateProcessor->setValue('rowValue#7', htmlspecialchars('Saturn'));
|
||||||
$document->setValue('rowValue#8', 'Uranus');
|
$templateProcessor->setValue('rowValue#8', htmlspecialchars('Uranus'));
|
||||||
$document->setValue('rowValue#9', 'Neptun');
|
$templateProcessor->setValue('rowValue#9', htmlspecialchars('Neptun'));
|
||||||
$document->setValue('rowValue#10', 'Pluto');
|
$templateProcessor->setValue('rowValue#10', htmlspecialchars('Pluto'));
|
||||||
|
|
||||||
$document->setValue('rowNumber#1', '1');
|
$templateProcessor->setValue('rowNumber#1', htmlspecialchars('1'));
|
||||||
$document->setValue('rowNumber#2', '2');
|
$templateProcessor->setValue('rowNumber#2', htmlspecialchars('2'));
|
||||||
$document->setValue('rowNumber#3', '3');
|
$templateProcessor->setValue('rowNumber#3', htmlspecialchars('3'));
|
||||||
$document->setValue('rowNumber#4', '4');
|
$templateProcessor->setValue('rowNumber#4', htmlspecialchars('4'));
|
||||||
$document->setValue('rowNumber#5', '5');
|
$templateProcessor->setValue('rowNumber#5', htmlspecialchars('5'));
|
||||||
$document->setValue('rowNumber#6', '6');
|
$templateProcessor->setValue('rowNumber#6', htmlspecialchars('6'));
|
||||||
$document->setValue('rowNumber#7', '7');
|
$templateProcessor->setValue('rowNumber#7', htmlspecialchars('7'));
|
||||||
$document->setValue('rowNumber#8', '8');
|
$templateProcessor->setValue('rowNumber#8', htmlspecialchars('8'));
|
||||||
$document->setValue('rowNumber#9', '9');
|
$templateProcessor->setValue('rowNumber#9', htmlspecialchars('9'));
|
||||||
$document->setValue('rowNumber#10', '10');
|
$templateProcessor->setValue('rowNumber#10', htmlspecialchars('10'));
|
||||||
|
|
||||||
// Table with a spanned cell
|
// Table with a spanned cell
|
||||||
$document->cloneRow('userId', 3);
|
$templateProcessor->cloneRow('userId', 3);
|
||||||
|
|
||||||
$document->setValue('userId#1', '1');
|
$templateProcessor->setValue('userId#1', htmlspecialchars('1'));
|
||||||
$document->setValue('userFirstName#1', 'James');
|
$templateProcessor->setValue('userFirstName#1', htmlspecialchars('James'));
|
||||||
$document->setValue('userName#1', 'Taylor');
|
$templateProcessor->setValue('userName#1', htmlspecialchars('Taylor'));
|
||||||
$document->setValue('userPhone#1', '+1 428 889 773');
|
$templateProcessor->setValue('userPhone#1', htmlspecialchars('+1 428 889 773'));
|
||||||
|
|
||||||
$document->setValue('userId#2', '2');
|
$templateProcessor->setValue('userId#2', htmlspecialchars('2'));
|
||||||
$document->setValue('userFirstName#2', 'Robert');
|
$templateProcessor->setValue('userFirstName#2', htmlspecialchars('Robert'));
|
||||||
$document->setValue('userName#2', 'Bell');
|
$templateProcessor->setValue('userName#2', htmlspecialchars('Bell'));
|
||||||
$document->setValue('userPhone#2', '+1 428 889 774');
|
$templateProcessor->setValue('userPhone#2', htmlspecialchars('+1 428 889 774'));
|
||||||
|
|
||||||
$document->setValue('userId#3', '3');
|
$templateProcessor->setValue('userId#3', htmlspecialchars('3'));
|
||||||
$document->setValue('userFirstName#3', 'Michael');
|
$templateProcessor->setValue('userFirstName#3', htmlspecialchars('Michael'));
|
||||||
$document->setValue('userName#3', 'Ray');
|
$templateProcessor->setValue('userName#3', htmlspecialchars('Ray'));
|
||||||
$document->setValue('userPhone#3', '+1 428 889 775');
|
$templateProcessor->setValue('userPhone#3', htmlspecialchars('+1 428 889 775'));
|
||||||
|
|
||||||
$name = 'Sample_07_TemplateCloneRow.docx';
|
echo date('H:i:s'), ' Saving the result document...', EOL;
|
||||||
echo date('H:i:s'), " Write to Word2007 format", EOL;
|
$templateProcessor->saveAs('results/Sample_07_TemplateCloneRow.docx');
|
||||||
$document->saveAs($name);
|
|
||||||
rename($name, "results/{$name}");
|
|
||||||
|
|
||||||
echo getEndingNotes(array('Word2007' => 'docx'));
|
echo getEndingNotes(array('Word2007' => 'docx'));
|
||||||
if (!CLI) {
|
if (!CLI) {
|
||||||
|
|||||||
@ -2,48 +2,75 @@
|
|||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s') , " Create new PhpWord object" , EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
$phpWord->setDefaultParagraphStyle(array(
|
$phpWord->setDefaultParagraphStyle(
|
||||||
'align' => 'both',
|
array(
|
||||||
'spaceAfter' => \PhpOffice\PhpWord\Shared\Font::pointSizeToTwips(12),
|
'align' => 'both',
|
||||||
'spacing' => 120,
|
'spaceAfter' => \PhpOffice\PhpWord\Shared\Converter::pointToTwip(12),
|
||||||
));
|
'spacing' => 120,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// Sample
|
// Sample
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
$section->addText('Below are the samples on how to control your paragraph ' .
|
$section->addText(
|
||||||
'pagination. See "Line and Page Break" tab on paragraph properties ' .
|
htmlspecialchars(
|
||||||
'window to see the attribute set by these controls.',
|
'Below are the samples on how to control your paragraph '
|
||||||
array('bold' => true), array('space' => array('before' => 360, 'after' => 480)));
|
. 'pagination. See "Line and Page Break" tab on paragraph properties '
|
||||||
|
. 'window to see the attribute set by these controls.'
|
||||||
|
),
|
||||||
|
array('bold' => true),
|
||||||
|
array('space' => array('before' => 360, 'after' => 480))
|
||||||
|
);
|
||||||
|
|
||||||
$section->addText('Paragraph with widowControl = false (default: true). ' .
|
$section->addText(
|
||||||
'A "widow" is the last line of a paragraph printed by itself at the top ' .
|
htmlspecialchars(
|
||||||
'of a page. An "orphan" is the first line of a paragraph printed by ' .
|
'Paragraph with widowControl = false (default: true). '
|
||||||
'itself at the bottom of a page. Set this option to "false" if you want ' .
|
. 'A "widow" is the last line of a paragraph printed by itself at the top '
|
||||||
'to disable this automatic control.',
|
. 'of a page. An "orphan" is the first line of a paragraph printed by '
|
||||||
null, array('widowControl' => false, 'indentation' => array('left' => 240, 'right' => 120)));
|
. 'itself at the bottom of a page. Set this option to "false" if you want '
|
||||||
|
. 'to disable this automatic control.'
|
||||||
|
),
|
||||||
|
null,
|
||||||
|
array('widowControl' => false, 'indentation' => array('left' => 240, 'right' => 120))
|
||||||
|
);
|
||||||
|
|
||||||
$section->addText('Paragraph with keepNext = true (default: false). ' .
|
$section->addText(
|
||||||
'"Keep with next" is used to prevent Word from inserting automatic page ' .
|
htmlspecialchars(
|
||||||
'breaks between paragraphs. Set this option to "true" if you do not want ' .
|
'Paragraph with keepNext = true (default: false). '
|
||||||
'your paragraph to be separated with the next paragraph.',
|
. '"Keep with next" is used to prevent Word from inserting automatic page '
|
||||||
null, array('keepNext' => true, 'indentation' => array('firstLine' => 240)));
|
. 'breaks between paragraphs. Set this option to "true" if you do not want '
|
||||||
|
. 'your paragraph to be separated with the next paragraph.'
|
||||||
|
),
|
||||||
|
null,
|
||||||
|
array('keepNext' => true, 'indentation' => array('firstLine' => 240))
|
||||||
|
);
|
||||||
|
|
||||||
$section->addText('Paragraph with keepLines = true (default: false). ' .
|
$section->addText(
|
||||||
'"Keep lines together" will prevent Word from inserting an automatic page ' .
|
htmlspecialchars(
|
||||||
'break within a paragraph. Set this option to "true" if you do not want ' .
|
'Paragraph with keepLines = true (default: false). '
|
||||||
'all lines of your paragraph to be in the same page.',
|
. '"Keep lines together" will prevent Word from inserting an automatic page '
|
||||||
null, array('keepLines' => true, 'indentation' => array('left' => 240, 'hanging' => 240)));
|
. 'break within a paragraph. Set this option to "true" if you do not want '
|
||||||
|
. 'all lines of your paragraph to be in the same page.'
|
||||||
|
),
|
||||||
|
null,
|
||||||
|
array('keepLines' => true, 'indentation' => array('left' => 240, 'hanging' => 240))
|
||||||
|
);
|
||||||
|
|
||||||
$section->addText('Keep scrolling. More below.');
|
$section->addText(htmlspecialchars('Keep scrolling. More below.'));
|
||||||
|
|
||||||
$section->addText('Paragraph with pageBreakBefore = true (default: false). ' .
|
$section->addText(
|
||||||
'Different with all other control above, "page break before" separates ' .
|
htmlspecialchars(
|
||||||
'your paragraph into the next page. This option is most useful for ' .
|
'Paragraph with pageBreakBefore = true (default: false). '
|
||||||
'heading styles.',
|
. 'Different with all other control above, "page break before" separates '
|
||||||
null, array('pageBreakBefore' => true));
|
. 'your paragraph into the next page. This option is most useful for '
|
||||||
|
. 'heading styles.'
|
||||||
|
),
|
||||||
|
null,
|
||||||
|
array('pageBreakBefore' => true)
|
||||||
|
);
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word Document
|
// New Word Document
|
||||||
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$header = array('size' => 16, 'bold' => true);
|
$header = array('size' => 16, 'bold' => true);
|
||||||
@ -11,20 +11,20 @@ $header = array('size' => 16, 'bold' => true);
|
|||||||
|
|
||||||
$rows = 10;
|
$rows = 10;
|
||||||
$cols = 5;
|
$cols = 5;
|
||||||
$section->addText("Basic table", $header);
|
$section->addText(htmlspecialchars('Basic table'), $header);
|
||||||
|
|
||||||
$table = $section->addTable();
|
$table = $section->addTable();
|
||||||
for($r = 1; $r <= 8; $r++) {
|
for ($r = 1; $r <= 8; $r++) {
|
||||||
$table->addRow();
|
$table->addRow();
|
||||||
for($c = 1; $c <= 5; $c++) {
|
for ($c = 1; $c <= 5; $c++) {
|
||||||
$table->addCell(1750)->addText("Row $r, Cell $c");
|
$table->addCell(1750)->addText(htmlspecialchars("Row {$r}, Cell {$c}"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Advanced table
|
// 2. Advanced table
|
||||||
|
|
||||||
$section->addTextBreak(1);
|
$section->addTextBreak(1);
|
||||||
$section->addText("Fancy table", $header);
|
$section->addText(htmlspecialchars('Fancy table'), $header);
|
||||||
|
|
||||||
$styleTable = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80);
|
$styleTable = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80);
|
||||||
$styleFirstRow = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF');
|
$styleFirstRow = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF');
|
||||||
@ -34,25 +34,25 @@ $fontStyle = array('bold' => true, 'align' => 'center');
|
|||||||
$phpWord->addTableStyle('Fancy Table', $styleTable, $styleFirstRow);
|
$phpWord->addTableStyle('Fancy Table', $styleTable, $styleFirstRow);
|
||||||
$table = $section->addTable('Fancy Table');
|
$table = $section->addTable('Fancy Table');
|
||||||
$table->addRow(900);
|
$table->addRow(900);
|
||||||
$table->addCell(2000, $styleCell)->addText('Row 1', $fontStyle);
|
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 1'), $fontStyle);
|
||||||
$table->addCell(2000, $styleCell)->addText('Row 2', $fontStyle);
|
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 2'), $fontStyle);
|
||||||
$table->addCell(2000, $styleCell)->addText('Row 3', $fontStyle);
|
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 3'), $fontStyle);
|
||||||
$table->addCell(2000, $styleCell)->addText('Row 4', $fontStyle);
|
$table->addCell(2000, $styleCell)->addText(htmlspecialchars('Row 4'), $fontStyle);
|
||||||
$table->addCell(500, $styleCellBTLR)->addText('Row 5', $fontStyle);
|
$table->addCell(500, $styleCellBTLR)->addText(htmlspecialchars('Row 5'), $fontStyle);
|
||||||
for($i = 1; $i <= 8; $i++) {
|
for ($i = 1; $i <= 8; $i++) {
|
||||||
$table->addRow();
|
$table->addRow();
|
||||||
$table->addCell(2000)->addText("Cell $i");
|
$table->addCell(2000)->addText(htmlspecialchars("Cell {$i}"));
|
||||||
$table->addCell(2000)->addText("Cell $i");
|
$table->addCell(2000)->addText(htmlspecialchars("Cell {$i}"));
|
||||||
$table->addCell(2000)->addText("Cell $i");
|
$table->addCell(2000)->addText(htmlspecialchars("Cell {$i}"));
|
||||||
$table->addCell(2000)->addText("Cell $i");
|
$table->addCell(2000)->addText(htmlspecialchars("Cell {$i}"));
|
||||||
$text = ($i % 2 == 0) ? 'X' : '';
|
$text = (0== $i % 2) ? 'X' : '';
|
||||||
$table->addCell(500)->addText($text);
|
$table->addCell(500)->addText(htmlspecialchars($text));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. colspan (gridSpan) and rowspan (vMerge)
|
// 3. colspan (gridSpan) and rowspan (vMerge)
|
||||||
|
|
||||||
$section->addPageBreak();
|
$section->addPageBreak();
|
||||||
$section->addText("Table with colspan and rowspan", $header);
|
$section->addText(htmlspecialchars('Table with colspan and rowspan'), $header);
|
||||||
|
|
||||||
$styleTable = array('borderSize' => 6, 'borderColor' => '999999');
|
$styleTable = array('borderSize' => 6, 'borderColor' => '999999');
|
||||||
$cellRowSpan = array('vMerge' => 'restart', 'valign' => 'center', 'bgColor' => 'FFFF00');
|
$cellRowSpan = array('vMerge' => 'restart', 'valign' => 'center', 'bgColor' => 'FFFF00');
|
||||||
@ -68,32 +68,32 @@ $table->addRow();
|
|||||||
|
|
||||||
$cell1 = $table->addCell(2000, $cellRowSpan);
|
$cell1 = $table->addCell(2000, $cellRowSpan);
|
||||||
$textrun1 = $cell1->addTextRun($cellHCentered);
|
$textrun1 = $cell1->addTextRun($cellHCentered);
|
||||||
$textrun1->addText('A');
|
$textrun1->addText(htmlspecialchars('A'));
|
||||||
$textrun1->addFootnote()->addText('Row span');
|
$textrun1->addFootnote()->addText(htmlspecialchars('Row span'));
|
||||||
|
|
||||||
$cell2 = $table->addCell(4000, $cellColSpan);
|
$cell2 = $table->addCell(4000, $cellColSpan);
|
||||||
$textrun2 = $cell2->addTextRun($cellHCentered);
|
$textrun2 = $cell2->addTextRun($cellHCentered);
|
||||||
$textrun2->addText('B');
|
$textrun2->addText(htmlspecialchars('B'));
|
||||||
$textrun2->addFootnote()->addText('Colspan span');
|
$textrun2->addFootnote()->addText(htmlspecialchars('Colspan span'));
|
||||||
|
|
||||||
$table->addCell(2000, $cellRowSpan)->addText('E', null, $cellHCentered);
|
$table->addCell(2000, $cellRowSpan)->addText(htmlspecialchars('E'), null, $cellHCentered);
|
||||||
|
|
||||||
$table->addRow();
|
$table->addRow();
|
||||||
$table->addCell(null, $cellRowContinue);
|
$table->addCell(null, $cellRowContinue);
|
||||||
$table->addCell(2000, $cellVCentered)->addText('C', null, $cellHCentered);
|
$table->addCell(2000, $cellVCentered)->addText(htmlspecialchars('C'), null, $cellHCentered);
|
||||||
$table->addCell(2000, $cellVCentered)->addText('D', null, $cellHCentered);
|
$table->addCell(2000, $cellVCentered)->addText(htmlspecialchars('D'), null, $cellHCentered);
|
||||||
$table->addCell(null, $cellRowContinue);
|
$table->addCell(null, $cellRowContinue);
|
||||||
|
|
||||||
// 4. Nested table
|
// 4. Nested table
|
||||||
|
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
$section->addText('Nested table in a centered and 50% width table.', $header);
|
$section->addText(htmlspecialchars('Nested table in a centered and 50% width table.'), $header);
|
||||||
|
|
||||||
$table = $section->addTable(array('width' => 50 * 50, 'unit' => 'pct', 'align' => 'center'));
|
$table = $section->addTable(array('width' => 50 * 50, 'unit' => 'pct', 'align' => 'center'));
|
||||||
$cell = $table->addRow()->addCell();
|
$cell = $table->addRow()->addCell();
|
||||||
$cell->addText('This cell contains nested table.');
|
$cell->addText(htmlspecialchars('This cell contains nested table.'));
|
||||||
$innerCell = $cell->addTable(array('align' => 'center'))->addRow()->addCell();
|
$innerCell = $cell->addTable(array('align' => 'center'))->addRow()->addCell();
|
||||||
$innerCell->addText('Inside nested table');
|
$innerCell->addText(htmlspecialchars('Inside nested table'));
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|||||||
@ -2,12 +2,12 @@
|
|||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word Document
|
// New Word Document
|
||||||
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$header = array('size' => 16, 'bold' => true);
|
$header = array('size' => 16, 'bold' => true);
|
||||||
//1.Use EastAisa FontStyle
|
//1.Use EastAisa FontStyle
|
||||||
$section->addText('中文楷体样式测试',array('name' => '楷体', 'size' => 16, 'color' => '1B2232'));
|
$section->addText(htmlspecialchars('中文楷体样式测试'), array('name' => '楷体', 'size' => 16, 'color' => '1B2232'));
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|||||||
19
samples/Sample_11_ReadWord97.php
Normal file
19
samples/Sample_11_ReadWord97.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
|
// Read contents
|
||||||
|
$name = basename(__FILE__, '.php');
|
||||||
|
$source = "resources/{$name}.doc";
|
||||||
|
echo date('H:i:s'), " Reading contents from `{$source}`", EOL;
|
||||||
|
$phpWord = \PhpOffice\PhpWord\IOFactory::load($source, 'MsDoc');
|
||||||
|
|
||||||
|
// (Re)write contents
|
||||||
|
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
|
||||||
|
foreach ($writers as $writer => $extension) {
|
||||||
|
echo date('H:i:s'), " Write to {$writer} format", EOL;
|
||||||
|
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
|
||||||
|
$xmlWriter->save("{$name}.{$extension}");
|
||||||
|
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
|
||||||
|
}
|
||||||
|
|
||||||
|
include_once 'Sample_Footer.php';
|
||||||
@ -2,7 +2,7 @@
|
|||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s') , " Create new PhpWord object" , EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// New portrait section
|
// New portrait section
|
||||||
@ -15,8 +15,8 @@ $table = $header->addTable();
|
|||||||
$table->addRow();
|
$table->addRow();
|
||||||
$cell = $table->addCell(4500);
|
$cell = $table->addCell(4500);
|
||||||
$textrun = $cell->addTextRun();
|
$textrun = $cell->addTextRun();
|
||||||
$textrun->addText('This is the header with ');
|
$textrun->addText(htmlspecialchars('This is the header with '));
|
||||||
$textrun->addLink('http://google.com', 'link to Google');
|
$textrun->addLink('http://google.com', htmlspecialchars('link to Google'));
|
||||||
$table->addCell(4500)->addImage(
|
$table->addCell(4500)->addImage(
|
||||||
'resources/PhpWord.png',
|
'resources/PhpWord.png',
|
||||||
array('width' => 80, 'height' => 80, 'align' => 'right')
|
array('width' => 80, 'height' => 80, 'align' => 'right')
|
||||||
@ -24,41 +24,41 @@ $table->addCell(4500)->addImage(
|
|||||||
|
|
||||||
// Add header for all other pages
|
// Add header for all other pages
|
||||||
$subsequent = $section->addHeader();
|
$subsequent = $section->addHeader();
|
||||||
$subsequent->addText("Subsequent pages in Section 1 will Have this!");
|
$subsequent->addText(htmlspecialchars('Subsequent pages in Section 1 will Have this!'));
|
||||||
$subsequent->addImage('resources/_mars.jpg', array('width' => 80, 'height' => 80));
|
$subsequent->addImage('resources/_mars.jpg', array('width' => 80, 'height' => 80));
|
||||||
|
|
||||||
// Add footer
|
// Add footer
|
||||||
$footer = $section->addFooter();
|
$footer = $section->addFooter();
|
||||||
$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.', array('align' => 'center'));
|
$footer->addPreserveText(htmlspecialchars('Page {PAGE} of {NUMPAGES}.'), array('align' => 'center'));
|
||||||
$footer->addLink('http://google.com', 'Direct Google');
|
$footer->addLink('http://google.com', htmlspecialchars('Direct Google'));
|
||||||
|
|
||||||
// Write some text
|
// Write some text
|
||||||
$section->addTextBreak();
|
$section->addTextBreak();
|
||||||
$section->addText('Some text...');
|
$section->addText(htmlspecialchars('Some text...'));
|
||||||
|
|
||||||
// Create a second page
|
// Create a second page
|
||||||
$section->addPageBreak();
|
$section->addPageBreak();
|
||||||
|
|
||||||
// Write some text
|
// Write some text
|
||||||
$section->addTextBreak();
|
$section->addTextBreak();
|
||||||
$section->addText('Some text...');
|
$section->addText(htmlspecialchars('Some text...'));
|
||||||
|
|
||||||
// Create a third page
|
// Create a third page
|
||||||
$section->addPageBreak();
|
$section->addPageBreak();
|
||||||
|
|
||||||
// Write some text
|
// Write some text
|
||||||
$section->addTextBreak();
|
$section->addTextBreak();
|
||||||
$section->addText('Some text...');
|
$section->addText(htmlspecialchars('Some text...'));
|
||||||
|
|
||||||
// New portrait section
|
// New portrait section
|
||||||
$section2 = $phpWord->addSection();
|
$section2 = $phpWord->addSection();
|
||||||
|
|
||||||
$sec2Header = $section2->addHeader();
|
$sec2Header = $section2->addHeader();
|
||||||
$sec2Header->addText("All pages in Section 2 will Have this!");
|
$sec2Header->addText(htmlspecialchars('All pages in Section 2 will Have this!'));
|
||||||
|
|
||||||
// Write some text
|
// Write some text
|
||||||
$section2->addTextBreak();
|
$section2->addTextBreak();
|
||||||
$section2->addText('Some text...');
|
$section2->addText(htmlspecialchars('Some text...'));
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|||||||
@ -2,22 +2,22 @@
|
|||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Begin code
|
// Begin code
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addText('Local image without any styles:');
|
$section->addText(htmlspecialchars('Local image without any styles:'));
|
||||||
$section->addImage('resources/_mars.jpg');
|
$section->addImage('resources/_mars.jpg');
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
$section->addText('Local image with styles:');
|
$section->addText(htmlspecialchars('Local image with styles:'));
|
||||||
$section->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'align' => 'center'));
|
$section->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'align' => 'center'));
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
// Remote image
|
// Remote image
|
||||||
$source = 'http://php.net/images/logos/php-med-trans-light.gif';
|
$source = 'http://php.net/images/logos/php-med-trans-light.gif';
|
||||||
$section->addText("Remote image from: {$source}");
|
$section->addText(htmlspecialchars("Remote image from: {$source}"));
|
||||||
$section->addImage($source);
|
$section->addImage($source);
|
||||||
|
|
||||||
//Wrapping style
|
//Wrapping style
|
||||||
@ -25,43 +25,52 @@ $text = str_repeat('Hello World! ', 15);
|
|||||||
$wrappingStyles = array('inline', 'behind', 'infront', 'square', 'tight');
|
$wrappingStyles = array('inline', 'behind', 'infront', 'square', 'tight');
|
||||||
foreach ($wrappingStyles as $wrappingStyle) {
|
foreach ($wrappingStyles as $wrappingStyle) {
|
||||||
$section->addTextBreak(5);
|
$section->addTextBreak(5);
|
||||||
$section->addText('Wrapping style ' . $wrappingStyle);
|
$section->addText(htmlspecialchars("Wrapping style {$wrappingStyle}"));
|
||||||
$section->addImage('resources/_earth.jpg', array('positioning' => 'relative', 'marginTop' => -1, 'marginLeft' => 1,
|
$section->addImage(
|
||||||
'width' => 80, 'height' => 80, 'wrappingStyle' => $wrappingStyle));
|
'resources/_earth.jpg',
|
||||||
$section->addText($text);
|
array(
|
||||||
|
'positioning' => 'relative',
|
||||||
|
'marginTop' => -1,
|
||||||
|
'marginLeft' => 1,
|
||||||
|
'width' => 80,
|
||||||
|
'height' => 80,
|
||||||
|
'wrappingStyle' => $wrappingStyle,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$section->addText(htmlspecialchars($text));
|
||||||
}
|
}
|
||||||
|
|
||||||
//Absolute positioning
|
//Absolute positioning
|
||||||
$section->addTextBreak(3);
|
$section->addTextBreak(3);
|
||||||
$section->addText('Absolute positioning: see top right corner of page');
|
$section->addText(htmlspecialchars('Absolute positioning: see top right corner of page'));
|
||||||
$section->addImage(
|
$section->addImage(
|
||||||
'resources/_mars.jpg',
|
'resources/_mars.jpg',
|
||||||
array(
|
array(
|
||||||
'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(3),
|
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3),
|
||||||
'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(3),
|
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3),
|
||||||
'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_ABSOLUTE,
|
'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_ABSOLUTE,
|
||||||
'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_RIGHT,
|
'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_RIGHT,
|
||||||
'posHorizontalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_PAGE,
|
'posHorizontalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_PAGE,
|
||||||
'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_PAGE,
|
'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_PAGE,
|
||||||
'marginLeft' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(15.5),
|
'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15.5),
|
||||||
'marginTop' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(1.55)
|
'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(1.55),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
//Relative positioning
|
//Relative positioning
|
||||||
$section->addTextBreak(3);
|
$section->addTextBreak(3);
|
||||||
$section->addText('Relative positioning: Horizontal position center relative to column,');
|
$section->addText(htmlspecialchars('Relative positioning: Horizontal position center relative to column,'));
|
||||||
$section->addText('Vertical position top relative to line');
|
$section->addText(htmlspecialchars('Vertical position top relative to line'));
|
||||||
$section->addImage(
|
$section->addImage(
|
||||||
'resources/_mars.jpg',
|
'resources/_mars.jpg',
|
||||||
array(
|
array(
|
||||||
'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(3),
|
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3),
|
||||||
'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(3),
|
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(3),
|
||||||
'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE,
|
'positioning' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE,
|
||||||
'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_CENTER,
|
'posHorizontal' => \PhpOffice\PhpWord\Style\Image::POSITION_HORIZONTAL_CENTER,
|
||||||
'posHorizontalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_COLUMN,
|
'posHorizontalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_COLUMN,
|
||||||
'posVertical' => \PhpOffice\PhpWord\Style\Image::POSITION_VERTICAL_TOP,
|
'posVertical' => \PhpOffice\PhpWord\Style\Image::POSITION_VERTICAL_TOP,
|
||||||
'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_LINE
|
'posVerticalRel' => \PhpOffice\PhpWord\Style\Image::POSITION_RELATIVE_TO_LINE,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Begin code
|
// Begin code
|
||||||
@ -10,80 +10,83 @@ $section = $phpWord->addSection();
|
|||||||
|
|
||||||
// Style definition
|
// Style definition
|
||||||
|
|
||||||
$phpWord->addFontStyle('myOwnStyle', array('color'=>'FF0000'));
|
$phpWord->addFontStyle('myOwnStyle', array('color' => 'FF0000'));
|
||||||
$phpWord->addParagraphStyle('P-Style', array('spaceAfter'=>95));
|
$phpWord->addParagraphStyle('P-Style', array('spaceAfter' => 95));
|
||||||
$phpWord->addNumberingStyle(
|
$phpWord->addNumberingStyle(
|
||||||
'multilevel',
|
'multilevel',
|
||||||
array('type' => 'multilevel', 'levels' => array(
|
array(
|
||||||
array('format' => 'decimal', 'text' => '%1.', 'left' => 360, 'hanging' => 360, 'tabPos' => 360),
|
'type' => 'multilevel',
|
||||||
array('format' => 'upperLetter', 'text' => '%2.', 'left' => 720, 'hanging' => 360, 'tabPos' => 720),
|
'levels' => array(
|
||||||
)
|
array('format' => 'decimal', 'text' => '%1.', 'left' => 360, 'hanging' => 360, 'tabPos' => 360),
|
||||||
|
array('format' => 'upperLetter', 'text' => '%2.', 'left' => 720, 'hanging' => 360, 'tabPos' => 720),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$predefinedMultilevel = array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER_NESTED);
|
$predefinedMultilevel = array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER_NESTED);
|
||||||
|
|
||||||
// Lists
|
// Lists
|
||||||
|
|
||||||
$section->addText('Multilevel list.');
|
$section->addText(htmlspecialchars('Multilevel list.'));
|
||||||
$section->addListItem('List Item I', 0, null, 'multilevel');
|
$section->addListItem(htmlspecialchars('List Item I'), 0, null, 'multilevel');
|
||||||
$section->addListItem('List Item I.a', 1, null, 'multilevel');
|
$section->addListItem(htmlspecialchars('List Item I.a'), 1, null, 'multilevel');
|
||||||
$section->addListItem('List Item I.b', 1, null, 'multilevel');
|
$section->addListItem(htmlspecialchars('List Item I.b'), 1, null, 'multilevel');
|
||||||
$section->addListItem('List Item II', 0, null, 'multilevel');
|
$section->addListItem(htmlspecialchars('List Item II'), 0, null, 'multilevel');
|
||||||
$section->addListItem('List Item II.a', 1, null, 'multilevel');
|
$section->addListItem(htmlspecialchars('List Item II.a'), 1, null, 'multilevel');
|
||||||
$section->addListItem('List Item III', 0, null, 'multilevel');
|
$section->addListItem(htmlspecialchars('List Item III'), 0, null, 'multilevel');
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
$section->addText('Basic simple bulleted list.');
|
$section->addText(htmlspecialchars('Basic simple bulleted list.'));
|
||||||
$section->addListItem('List Item 1');
|
$section->addListItem(htmlspecialchars('List Item 1'));
|
||||||
$section->addListItem('List Item 2');
|
$section->addListItem(htmlspecialchars('List Item 2'));
|
||||||
$section->addListItem('List Item 3');
|
$section->addListItem(htmlspecialchars('List Item 3'));
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
$section->addText('Continue from multilevel list above.');
|
$section->addText(htmlspecialchars('Continue from multilevel list above.'));
|
||||||
$section->addListItem('List Item IV', 0, null, 'multilevel');
|
$section->addListItem(htmlspecialchars('List Item IV'), 0, null, 'multilevel');
|
||||||
$section->addListItem('List Item IV.a', 1, null, 'multilevel');
|
$section->addListItem(htmlspecialchars('List Item IV.a'), 1, null, 'multilevel');
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
$section->addText('Multilevel predefined list.');
|
$section->addText(htmlspecialchars('Multilevel predefined list.'));
|
||||||
$section->addListItem('List Item 1', 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
$section->addListItem(htmlspecialchars('List Item 1'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
||||||
$section->addListItem('List Item 2', 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
$section->addListItem(htmlspecialchars('List Item 2'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
||||||
$section->addListItem('List Item 3', 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
$section->addListItem(htmlspecialchars('List Item 3'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
||||||
$section->addListItem('List Item 4', 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
$section->addListItem(htmlspecialchars('List Item 4'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
||||||
$section->addListItem('List Item 5', 2, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
$section->addListItem(htmlspecialchars('List Item 5'), 2, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
||||||
$section->addListItem('List Item 6', 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
$section->addListItem(htmlspecialchars('List Item 6'), 1, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
||||||
$section->addListItem('List Item 7', 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
$section->addListItem(htmlspecialchars('List Item 7'), 0, 'myOwnStyle', $predefinedMultilevel, 'P-Style');
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
$section->addText('List with inline formatting.');
|
$section->addText(htmlspecialchars('List with inline formatting.'));
|
||||||
$listItemRun = $section->addListItemRun();
|
$listItemRun = $section->addListItemRun();
|
||||||
$listItemRun->addText('List item 1');
|
$listItemRun->addText(htmlspecialchars('List item 1'));
|
||||||
$listItemRun->addText(' in bold', array('bold'=>true));
|
$listItemRun->addText(htmlspecialchars(' in bold'), array('bold' => true));
|
||||||
$listItemRun = $section->addListItemRun();
|
$listItemRun = $section->addListItemRun();
|
||||||
$listItemRun->addText('List item 2');
|
$listItemRun->addText(htmlspecialchars('List item 2'));
|
||||||
$listItemRun->addText(' in italic', array('italic'=>true));
|
$listItemRun->addText(htmlspecialchars(' in italic'), array('italic' => true));
|
||||||
$listItemRun = $section->addListItemRun();
|
$listItemRun = $section->addListItemRun();
|
||||||
$listItemRun->addText('List item 3');
|
$listItemRun->addText(htmlspecialchars('List item 3'));
|
||||||
$listItemRun->addText(' underlined', array('underline'=>'dash'));
|
$listItemRun->addText(htmlspecialchars(' underlined'), array('underline' => 'dash'));
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
// Numbered heading
|
// Numbered heading
|
||||||
|
|
||||||
$phpWord->addNumberingStyle(
|
$phpWord->addNumberingStyle(
|
||||||
'headingNumbering',
|
'headingNumbering',
|
||||||
array('type' => 'multilevel', 'levels' => array(
|
array('type' => 'multilevel',
|
||||||
array('pStyle' => 'Heading1', 'format' => 'decimal', 'text' => '%1'),
|
'levels' => array(
|
||||||
array('pStyle' => 'Heading2', 'format' => 'decimal', 'text' => '%1.%2'),
|
array('pStyle' => 'Heading1', 'format' => 'decimal', 'text' => '%1'),
|
||||||
array('pStyle' => 'Heading3', 'format' => 'decimal', 'text' => '%1.%2.%3'),
|
array('pStyle' => 'Heading2', 'format' => 'decimal', 'text' => '%1.%2'),
|
||||||
)
|
array('pStyle' => 'Heading3', 'format' => 'decimal', 'text' => '%1.%2.%3'),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$phpWord->addTitleStyle(1, array('size' => 16), array('numStyle' => 'headingNumbering', 'numLevel' => 0));
|
$phpWord->addTitleStyle(1, array('size' => 16), array('numStyle' => 'headingNumbering', 'numLevel' => 0));
|
||||||
$phpWord->addTitleStyle(2, array('size' => 14), array('numStyle' => 'headingNumbering', 'numLevel' => 1));
|
$phpWord->addTitleStyle(2, array('size' => 14), array('numStyle' => 'headingNumbering', 'numLevel' => 1));
|
||||||
$phpWord->addTitleStyle(3, array('size' => 12), array('numStyle' => 'headingNumbering', 'numLevel' => 2));
|
$phpWord->addTitleStyle(3, array('size' => 12), array('numStyle' => 'headingNumbering', 'numLevel' => 2));
|
||||||
|
|
||||||
$section->addTitle('Heading 1', 1);
|
$section->addTitle(htmlspecialchars('Heading 1'), 1);
|
||||||
$section->addTitle('Heading 2', 2);
|
$section->addTitle(htmlspecialchars('Heading 2'), 2);
|
||||||
$section->addTitle('Heading 3', 3);
|
$section->addTitle(htmlspecialchars('Heading 3'), 3);
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|||||||
@ -2,17 +2,21 @@
|
|||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Begin code
|
// Begin code
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
// Add hyperlink elements
|
// Add hyperlink elements
|
||||||
$section->addLink('http://www.google.com', 'Best search engine', array('color'=>'0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
|
$section->addLink(
|
||||||
|
'http://www.google.com',
|
||||||
|
htmlspecialchars('Best search engine'),
|
||||||
|
array('color' => '0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE)
|
||||||
|
);
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
$phpWord->addLinkStyle('myOwnLinkStyle', array('bold'=>true, 'color'=>'808000'));
|
$phpWord->addLinkStyle('myOwnLinkStyle', array('bold' => true, 'color' => '808000'));
|
||||||
$section->addLink('http://www.bing.com', null, 'myOwnLinkStyle');
|
$section->addLink('http://www.bing.com', null, 'myOwnLinkStyle');
|
||||||
$section->addLink('http://www.yahoo.com', null, 'myOwnLinkStyle');
|
$section->addLink('http://www.yahoo.com', null, 'myOwnLinkStyle');
|
||||||
|
|
||||||
|
|||||||
@ -2,12 +2,12 @@
|
|||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Begin code
|
// Begin code
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addText('You can open this OLE object by double clicking on the icon:');
|
$section->addText(htmlspecialchars('You can open this OLE object by double clicking on the icon:'));
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
$section->addObject('resources/_sheet.xls');
|
$section->addObject('resources/_sheet.xls');
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Begin code
|
// Begin code
|
||||||
@ -19,7 +19,7 @@ $phpWord->addTitleStyle(3, array('size' => 14, 'italic' => true));
|
|||||||
$phpWord->addTitleStyle(4, array('size' => 12));
|
$phpWord->addTitleStyle(4, array('size' => 12));
|
||||||
|
|
||||||
// Add text elements
|
// Add text elements
|
||||||
$section->addText('Table of contents 1');
|
$section->addText(htmlspecialchars('Table of contents 1'));
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
// Add TOC #1
|
// Add TOC #1
|
||||||
@ -27,11 +27,11 @@ $toc = $section->addTOC($fontStyle);
|
|||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
// Filler
|
// Filler
|
||||||
$section->addText('Text between TOC');
|
$section->addText(htmlspecialchars('Text between TOC'));
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
// Add TOC #1
|
// Add TOC #1
|
||||||
$section->addText('Table of contents 2');
|
$section->addText(htmlspecialchars('Table of contents 2'));
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
$toc2 = $section->addTOC($fontStyle2);
|
$toc2 = $section->addTOC($fontStyle2);
|
||||||
$toc2->setMinDepth(2);
|
$toc2->setMinDepth(2);
|
||||||
@ -40,33 +40,33 @@ $toc2->setMaxDepth(3);
|
|||||||
|
|
||||||
// Add Titles
|
// Add Titles
|
||||||
$section->addPageBreak();
|
$section->addPageBreak();
|
||||||
$section->addTitle('I am Title 1', 1);
|
$section->addTitle(htmlspecialchars('Foo & Bar'), 1);
|
||||||
$section->addText('Some text...');
|
$section->addText(htmlspecialchars('Some text...'));
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
$section->addTitle('I am a Subtitle of Title 1', 2);
|
$section->addTitle(htmlspecialchars('I am a Subtitle of Title 1'), 2);
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
$section->addText('Some more text...');
|
$section->addText(htmlspecialchars('Some more text...'));
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
|
|
||||||
$section->addTitle('Another Title (Title 2)', 1);
|
$section->addTitle(htmlspecialchars('Another Title (Title 2)'), 1);
|
||||||
$section->addText('Some text...');
|
$section->addText(htmlspecialchars('Some text...'));
|
||||||
$section->addPageBreak();
|
$section->addPageBreak();
|
||||||
$section->addTitle('I am Title 3', 1);
|
$section->addTitle(htmlspecialchars('I am Title 3'), 1);
|
||||||
$section->addText('And more text...');
|
$section->addText(htmlspecialchars('And more text...'));
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
$section->addTitle('I am a Subtitle of Title 3', 2);
|
$section->addTitle(htmlspecialchars('I am a Subtitle of Title 3'), 2);
|
||||||
$section->addText('Again and again, more text...');
|
$section->addText(htmlspecialchars('Again and again, more text...'));
|
||||||
$section->addTitle('Subtitle 3.1.1', 3);
|
$section->addTitle(htmlspecialchars('Subtitle 3.1.1'), 3);
|
||||||
$section->addText('Text');
|
$section->addText(htmlspecialchars('Text'));
|
||||||
$section->addTitle('Subtitle 3.1.1.1', 4);
|
$section->addTitle(htmlspecialchars('Subtitle 3.1.1.1'), 4);
|
||||||
$section->addText('Text');
|
$section->addText(htmlspecialchars('Text'));
|
||||||
$section->addTitle('Subtitle 3.1.1.2', 4);
|
$section->addTitle(htmlspecialchars('Subtitle 3.1.1.2'), 4);
|
||||||
$section->addText('Text');
|
$section->addText(htmlspecialchars('Text'));
|
||||||
$section->addTitle('Subtitle 3.1.2', 3);
|
$section->addTitle(htmlspecialchars('Subtitle 3.1.2'), 3);
|
||||||
$section->addText('Text');
|
$section->addText(htmlspecialchars('Text'));
|
||||||
|
|
||||||
echo date('H:i:s'), " Note: Please refresh TOC manually.", EOL;
|
echo date('H:i:s'), ' Note: Please refresh TOC manually.', EOL;
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Begin code
|
// Begin code
|
||||||
@ -10,7 +10,7 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
|
|||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$header = $section->addHeader();
|
$header = $section->addHeader();
|
||||||
$header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55));
|
$header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55));
|
||||||
$section->addText('The header reference to the current section includes a watermark image.');
|
$section->addText(htmlspecialchars('The header reference to the current section includes a watermark image.'));
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Begin code
|
// Begin code
|
||||||
@ -13,17 +13,17 @@ $phpWord->addParagraphStyle('paragraphStyle', array('spacing' => 480));
|
|||||||
$fontStyle = array('size' => 24);
|
$fontStyle = array('size' => 24);
|
||||||
|
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addText('Text break with no style:');
|
$section->addText(htmlspecialchars('Text break with no style:'));
|
||||||
$section->addTextBreak();
|
$section->addTextBreak();
|
||||||
$section->addText('Text break with defined font style:');
|
$section->addText(htmlspecialchars('Text break with defined font style:'));
|
||||||
$section->addTextBreak(1, 'fontStyle');
|
$section->addTextBreak(1, 'fontStyle');
|
||||||
$section->addText('Text break with defined paragraph style:');
|
$section->addText(htmlspecialchars('Text break with defined paragraph style:'));
|
||||||
$section->addTextBreak(1, null, 'paragraphStyle');
|
$section->addTextBreak(1, null, 'paragraphStyle');
|
||||||
$section->addText('Text break with inline font style:');
|
$section->addText(htmlspecialchars('Text break with inline font style:'));
|
||||||
$section->addTextBreak(1, $fontStyle);
|
$section->addTextBreak(1, $fontStyle);
|
||||||
$section->addText('Text break with inline paragraph style:');
|
$section->addText(htmlspecialchars('Text break with inline paragraph style:'));
|
||||||
$section->addTextBreak(1, null, $paragraphStyle);
|
$section->addTextBreak(1, null, $paragraphStyle);
|
||||||
$section->addText('Done.');
|
$section->addText(htmlspecialchars('Done.'));
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|||||||
@ -2,13 +2,19 @@
|
|||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
$section->addText("This is some text highlighted using fgColor (limited to 15 colors) ", array("fgColor" => \PhpOffice\PhpWord\Style\Font::FGCOLOR_YELLOW));
|
$section->addText(
|
||||||
$section->addText("This one uses bgColor and is using hex value (0xfbbb10)", array("bgColor" => "fbbb10"));
|
htmlspecialchars('This is some text highlighted using fgColor (limited to 15 colors) '),
|
||||||
$section->addText("Compatible with font colors", array("color"=>"0000ff", "bgColor" => "fbbb10"));
|
array('fgColor' => \PhpOffice\PhpWord\Style\Font::FGCOLOR_YELLOW)
|
||||||
|
);
|
||||||
|
$section->addText(
|
||||||
|
htmlspecialchars('This one uses bgColor and is using hex value (0xfbbb10)'),
|
||||||
|
array('bgColor' => 'fbbb10')
|
||||||
|
);
|
||||||
|
$section->addText(htmlspecialchars('Compatible with font colors'), array('color' => '0000ff', 'bgColor' => 'fbbb10'));
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|||||||
@ -2,30 +2,50 @@
|
|||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
$section->addText("By default, when you insert an image, it adds a textbreak after its content.");
|
$section->addText(htmlspecialchars('By default, when you insert an image, it adds a textbreak after its content.'));
|
||||||
$section->addText("If we want a simple border around an image, we wrap the image inside a table->row->cell");
|
$section->addText(
|
||||||
$section->addText("On the image with the red border, even if we set the row height to the height of the image, the textbreak is still there:");
|
htmlspecialchars('If we want a simple border around an image, we wrap the image inside a table->row->cell')
|
||||||
|
);
|
||||||
|
$section->addText(
|
||||||
|
htmlspecialchars(
|
||||||
|
'On the image with the red border, even if we set the row height to the height of the image, '
|
||||||
|
. 'the textbreak is still there:'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$table1 = $section->addTable(array("cellMargin" => 0, "cellMarginRight" => 0, "cellMarginBottom" => 0, "cellMarginLeft" => 0));
|
$table1 = $section->addTable(array('cellMargin' => 0, 'cellMarginRight' => 0, 'cellMarginBottom' => 0, 'cellMarginLeft' => 0));
|
||||||
$table1->addRow(3750);
|
$table1->addRow(3750);
|
||||||
$cell1 = $table1->addCell(null, array("valign" => "top", "borderSize" => 30, "borderColor" => "ff0000"));
|
$cell1 = $table1->addCell(null, array('valign' => 'top', 'borderSize' => 30, 'borderColor' => 'ff0000'));
|
||||||
$cell1->addImage("./resources/_earth.jpg", array("width" => 250, "height" => 250, "align" => "center"));
|
$cell1->addImage('./resources/_earth.jpg', array('width' => 250, 'height' => 250, 'align' => 'center'));
|
||||||
|
|
||||||
$section->addTextBreak();
|
$section->addTextBreak();
|
||||||
$section->addText("But if we set the rowStyle 'exactHeight' to true, the real row height is used, removing the textbreak:");
|
$section->addText(
|
||||||
|
htmlspecialchars(
|
||||||
|
"But if we set the rowStyle 'exactHeight' to true, the real row height is used, removing the textbreak:"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$table2 = $section->addTable(array("cellMargin" => 0, "cellMarginRight" => 0, "cellMarginBottom" => 0, "cellMarginLeft" => 0));
|
$table2 = $section->addTable(
|
||||||
$table2->addRow(3750, array("exactHeight" => true));
|
array(
|
||||||
$cell2 = $table2->addCell(null, array("valign" => "top", "borderSize" => 30, "borderColor" => "00ff00"));
|
'cellMargin' => 0,
|
||||||
$cell2->addImage("./resources/_earth.jpg", array("width" => 250, "height" => 250, "align" => "center"));
|
'cellMarginRight' => 0,
|
||||||
|
'cellMarginBottom' => 0,
|
||||||
|
'cellMarginLeft' => 0,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$table2->addRow(3750, array('exactHeight' => true));
|
||||||
|
$cell2 = $table2->addCell(null, array('valign' => 'top', 'borderSize' => 30, 'borderColor' => '00ff00'));
|
||||||
|
$cell2->addImage('./resources/_earth.jpg', array('width' => 250, 'height' => 250, 'align' => 'center'));
|
||||||
|
|
||||||
$section->addTextBreak();
|
$section->addTextBreak();
|
||||||
$section->addText("In this example, image is 250px height. Rows are calculated in twips, and 1px = 15twips.");
|
$section->addText(
|
||||||
$section->addText("So: $"."table2->addRow(3750, array('exactHeight'=>true));");
|
htmlspecialchars('In this example, image is 250px height. Rows are calculated in twips, and 1px = 15twips.')
|
||||||
|
);
|
||||||
|
$section->addText(htmlspecialchars('So: $' . "table2->addRow(3750, array('exactHeight'=>true));"));
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|||||||
@ -2,17 +2,17 @@
|
|||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
$section->addText('Check box in section');
|
$section->addText(htmlspecialchars('Check box in section'));
|
||||||
$section->addCheckBox('chkBox1', 'Checkbox 1');
|
$section->addCheckBox('chkBox1', htmlspecialchars('Checkbox 1'));
|
||||||
$section->addText('Check box in table cell');
|
$section->addText(htmlspecialchars('Check box in table cell'));
|
||||||
$table = $section->addTable();
|
$table = $section->addTable();
|
||||||
$table->addRow();
|
$table->addRow();
|
||||||
$cell = $table->addCell();
|
$cell = $table->addCell();
|
||||||
$cell->addCheckBox('chkBox2', 'Checkbox 2');
|
$cell->addCheckBox('chkBox2', htmlspecialchars('Checkbox 2'));
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|||||||
@ -1,22 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word document
|
// Template processor instance creation
|
||||||
echo date('H:i:s') , " Create new PhpWord object" , EOL;
|
echo date('H:i:s') , ' Creating new TemplateProcessor instance...' , EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('resources/Sample_23_TemplateBlock.docx');
|
||||||
|
|
||||||
$document = $phpWord->loadTemplate('resources/Sample_23_TemplateBlock.docx');
|
|
||||||
|
|
||||||
// Will clone everything between ${tag} and ${/tag}, the number of times. By default, 1.
|
// Will clone everything between ${tag} and ${/tag}, the number of times. By default, 1.
|
||||||
$document->cloneBlock('CLONEME', 3);
|
$templateProcessor->cloneBlock('CLONEME', 3);
|
||||||
|
|
||||||
// Everything between ${tag} and ${/tag}, will be deleted/erased.
|
// Everything between ${tag} and ${/tag}, will be deleted/erased.
|
||||||
$document->deleteBlock('DELETEME');
|
$templateProcessor->deleteBlock('DELETEME');
|
||||||
|
|
||||||
$name = 'Sample_23_TemplateBlock.docx';
|
echo date('H:i:s'), ' Saving the result document...', EOL;
|
||||||
echo date('H:i:s'), " Write to Word2007 format", EOL;
|
$templateProcessor->saveAs('results/Sample_23_TemplateBlock.docx');
|
||||||
$document->saveAs($name);
|
|
||||||
rename($name, "results/{$name}");
|
|
||||||
|
|
||||||
echo getEndingNotes(array('Word2007' => 'docx'));
|
echo getEndingNotes(array('Word2007' => 'docx'));
|
||||||
if (!CLI) {
|
if (!CLI) {
|
||||||
|
|||||||
@ -2,35 +2,43 @@
|
|||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word Document
|
// New Word Document
|
||||||
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
$section = $phpWord->addSection();
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
// In section
|
// In section
|
||||||
$textbox = $section->addTextBox(array('align' => 'center', 'width' => 400, 'height' => 150, 'borderSize' => 1, 'borderColor' => '#FF0000'));
|
$textbox = $section->addTextBox(
|
||||||
$textbox->addText('Text box content in section.');
|
array(
|
||||||
$textbox->addText('Another line.');
|
'align' => 'center',
|
||||||
|
'width' => 400,
|
||||||
|
'height' => 150,
|
||||||
|
'borderSize' => 1,
|
||||||
|
'borderColor' => '#FF0000',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$textbox->addText(htmlspecialchars('Text box content in section.'));
|
||||||
|
$textbox->addText(htmlspecialchars('Another line.'));
|
||||||
$cell = $textbox->addTable()->addRow()->addCell();
|
$cell = $textbox->addTable()->addRow()->addCell();
|
||||||
$cell->addText('Table inside textbox');
|
$cell->addText(htmlspecialchars('Table inside textbox'));
|
||||||
|
|
||||||
// Inside table
|
// Inside table
|
||||||
$section->addTextBreak(2);
|
$section->addTextBreak(2);
|
||||||
$cell = $section->addTable()->addRow()->addCell(300);
|
$cell = $section->addTable()->addRow()->addCell(300);
|
||||||
$textbox = $cell->addTextBox(array('borderSize' => 1, 'borderColor' => '#0000FF', 'innerMargin' => 100));
|
$textbox = $cell->addTextBox(array('borderSize' => 1, 'borderColor' => '#0000FF', 'innerMargin' => 100));
|
||||||
$textbox->addText('Textbox inside table');
|
$textbox->addText(htmlspecialchars('Textbox inside table'));
|
||||||
|
|
||||||
// Inside header with textrun
|
// Inside header with textrun
|
||||||
$header = $section->addHeader();
|
$header = $section->addHeader();
|
||||||
$textbox = $header->addTextBox(array('width' => 600, 'borderSize' => 1, 'borderColor' => '#00FF00'));
|
$textbox = $header->addTextBox(array('width' => 600, 'borderSize' => 1, 'borderColor' => '#00FF00'));
|
||||||
$textrun = $textbox->addTextRun();
|
$textrun = $textbox->addTextRun();
|
||||||
$textrun->addText('TextBox in header. TextBox can contain a TextRun ');
|
$textrun->addText(htmlspecialchars('TextBox in header. TextBox can contain a TextRun '));
|
||||||
$textrun->addText('with bold text', array('bold' => true));
|
$textrun->addText(htmlspecialchars('with bold text'), array('bold' => true));
|
||||||
$textrun->addText(', ');
|
$textrun->addText(htmlspecialchars(', '));
|
||||||
$textrun->addLink('http://www.google.com', 'link');
|
$textrun->addLink('http://www.google.com', htmlspecialchars('link'));
|
||||||
$textrun->addText(', and image ');
|
$textrun->addText(htmlspecialchars(', and image '));
|
||||||
$textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
|
$textrun->addImage('resources/_earth.jpg', array('width' => 18, 'height' => 18));
|
||||||
$textrun->addText('.');
|
$textrun->addText(htmlspecialchars('.'));
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|||||||
@ -20,4 +20,4 @@ $html .= '<ol><li>Item 1</li><li>Item 2</li></ol>';
|
|||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
if (!CLI) {
|
if (!CLI) {
|
||||||
include_once 'Sample_Footer.php';
|
include_once 'Sample_Footer.php';
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Begin code
|
// Begin code
|
||||||
@ -10,19 +10,19 @@ $section = $phpWord->addSection();
|
|||||||
|
|
||||||
// Add Field elements
|
// Add Field elements
|
||||||
// See Element/Field.php for all options
|
// See Element/Field.php for all options
|
||||||
$section->addText('Date field:');
|
$section->addText(htmlspecialchars('Date field:'));
|
||||||
$section->addField('DATE', array('dateformat'=>'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat'));
|
$section->addField('DATE', array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat'));
|
||||||
|
|
||||||
$section->addText('Page field:');
|
$section->addText(htmlspecialchars('Page field:'));
|
||||||
$section->addField('PAGE', array('format'=>'ArabicDash'));
|
$section->addField('PAGE', array('format' => 'ArabicDash'));
|
||||||
|
|
||||||
$section->addText('Number of pages field:');
|
$section->addText(htmlspecialchars('Number of pages field:'));
|
||||||
$section->addField('NUMPAGES', array('format'=>'Arabic', 'numformat'=>'0,00'), array('PreserveFormat'));
|
$section->addField('NUMPAGES', array('format' => 'Arabic', 'numformat' => '0,00'), array('PreserveFormat'));
|
||||||
|
|
||||||
$textrun = $section->addTextRun(array('align' => 'center'));
|
$textrun = $section->addTextRun(array('align' => 'center'));
|
||||||
$textrun->addText('This is the date of lunar calendar ');
|
$textrun->addText(htmlspecialchars('This is the date of lunar calendar '));
|
||||||
$textrun->addField('DATE', array('dateformat'=>'d-M-yyyy H:mm:ss'), array('PreserveFormat', 'LunarCalendar'));
|
$textrun->addField('DATE', array('dateformat' => 'd-M-yyyy H:mm:ss'), array('PreserveFormat', 'LunarCalendar'));
|
||||||
$textrun->addText(' written in a textrun.');
|
$textrun->addText(htmlspecialchars(' written in a textrun.'));
|
||||||
|
|
||||||
// Save file
|
// Save file
|
||||||
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
// New Word document
|
// New Word document
|
||||||
echo date('H:i:s'), " Create new PhpWord object", EOL;
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
// Begin code
|
// Begin code
|
||||||
@ -10,50 +10,50 @@ $section = $phpWord->addSection();
|
|||||||
|
|
||||||
// Add Line elements
|
// Add Line elements
|
||||||
// See Element/Line.php for all options
|
// See Element/Line.php for all options
|
||||||
$section->addText('Horizontal Line (Inline style):');
|
$section->addText(htmlspecialchars('Horizontal Line (Inline style):'));
|
||||||
$section->addLine(
|
$section->addLine(
|
||||||
array(
|
array(
|
||||||
'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(4),
|
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4),
|
||||||
'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(0),
|
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0),
|
||||||
'positioning' => 'absolute'
|
'positioning' => 'absolute',
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
$section->addText('Vertical Line (Inline style):');
|
$section->addText(htmlspecialchars('Vertical Line (Inline style):'));
|
||||||
$section->addLine(
|
$section->addLine(
|
||||||
array(
|
array(
|
||||||
'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(0),
|
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0),
|
||||||
'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(1),
|
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(1),
|
||||||
'positioning' => 'absolute'
|
'positioning' => 'absolute',
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// Two text break
|
// Two text break
|
||||||
$section->addTextBreak(1);
|
$section->addTextBreak(1);
|
||||||
|
|
||||||
$section->addText('Positioned Line (red):');
|
$section->addText(htmlspecialchars('Positioned Line (red):'));
|
||||||
$section->addLine(
|
$section->addLine(
|
||||||
array(
|
array(
|
||||||
'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(4),
|
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(4),
|
||||||
'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(1),
|
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(1),
|
||||||
'positioning' => 'absolute',
|
'positioning' => 'absolute',
|
||||||
'posHorizontalRel' => 'page',
|
'posHorizontalRel' => 'page',
|
||||||
'posVerticalRel' => 'page',
|
'posVerticalRel' => 'page',
|
||||||
'marginLeft' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(10),
|
'marginLeft' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(10),
|
||||||
'marginTop' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(8),
|
'marginTop' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(8),
|
||||||
'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_SQUARE,
|
'wrappingStyle' => \PhpOffice\PhpWord\Style\Image::WRAPPING_STYLE_SQUARE,
|
||||||
'color' => 'red'
|
'color' => 'red',
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$section->addText('Horizontal Formatted Line');
|
$section->addText(htmlspecialchars('Horizontal Formatted Line'));
|
||||||
$section->addLine(
|
$section->addLine(
|
||||||
array(
|
array(
|
||||||
'width' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(15),
|
'width' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(15),
|
||||||
'height' => \PhpOffice\PhpWord\Shared\Drawing::centimetersToPixels(0),
|
'height' => \PhpOffice\PhpWord\Shared\Converter::cmToPixel(0),
|
||||||
'positioning' => 'absolute',
|
'positioning' => 'absolute',
|
||||||
'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK,
|
'beginArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_BLOCK,
|
||||||
'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL,
|
'endArrow' => \PhpOffice\PhpWord\Style\Line::ARROW_STYLE_OVAL,
|
||||||
'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT,
|
'dash' => \PhpOffice\PhpWord\Style\Line::DASH_STYLE_LONG_DASH_DOT_DOT,
|
||||||
'weight' => 10
|
'weight' => 10,
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
95
samples/Sample_31_Shape.php
Normal file
95
samples/Sample_31_Shape.php
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
<?php
|
||||||
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
|
// New Word document
|
||||||
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
|
|
||||||
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
$phpWord->addTitleStyle(1, array('size' => 14, 'bold' => true));
|
||||||
|
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
|
// Arc
|
||||||
|
$section->addTitle(htmlspecialchars('Arc'), 1);
|
||||||
|
$section->addShape(
|
||||||
|
'arc',
|
||||||
|
array(
|
||||||
|
'points' => '-90 20',
|
||||||
|
'frame' => array('width' => 120, 'height' => 120),
|
||||||
|
'outline' => array('color' => '#333333', 'weight' => 2, 'startArrow' => 'oval', 'endArrow' => 'open'),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Curve
|
||||||
|
$section->addTitle(htmlspecialchars('Curve'), 1);
|
||||||
|
$section->addShape(
|
||||||
|
'curve',
|
||||||
|
array(
|
||||||
|
'points' => '1,100 200,1 1,50 200,50',
|
||||||
|
'connector' => 'elbow',
|
||||||
|
'outline' => array(
|
||||||
|
'color' => '#66cc00',
|
||||||
|
'weight' => 2,
|
||||||
|
'dash' => 'dash',
|
||||||
|
'startArrow' => 'diamond',
|
||||||
|
'endArrow' => 'block',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Line
|
||||||
|
$section->addTitle(htmlspecialchars('Line'), 1);
|
||||||
|
$section->addShape(
|
||||||
|
'line',
|
||||||
|
array(
|
||||||
|
'points' => '1,1 150,30',
|
||||||
|
'outline' => array(
|
||||||
|
'color' => '#cc00ff',
|
||||||
|
'line' => 'thickThin',
|
||||||
|
'weight' => 3,
|
||||||
|
'startArrow' => 'oval',
|
||||||
|
'endArrow' => 'classic',
|
||||||
|
),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Polyline
|
||||||
|
$section->addTitle(htmlspecialchars('Polyline'), 1);
|
||||||
|
$section->addShape(
|
||||||
|
'polyline',
|
||||||
|
array(
|
||||||
|
'points' => '1,30 20,10 55,20 75,10 100,40 115,50, 120,15 200,50',
|
||||||
|
'outline' => array('color' => '#cc6666', 'weight' => 2, 'startArrow' => 'none', 'endArrow' => 'classic'),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Rectangle
|
||||||
|
$section->addTitle(htmlspecialchars('Rectangle'), 1);
|
||||||
|
$section->addShape(
|
||||||
|
'rect',
|
||||||
|
array(
|
||||||
|
'roundness' => 0.2,
|
||||||
|
'frame' => array('width' => 100, 'height' => 100, 'left' => 1, 'top' => 1),
|
||||||
|
'fill' => array('color' => '#FFCC33'),
|
||||||
|
'outline' => array('color' => '#990000', 'weight' => 1),
|
||||||
|
'shadow' => array(),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Oval
|
||||||
|
$section->addTitle(htmlspecialchars('Oval'), 1);
|
||||||
|
$section->addShape(
|
||||||
|
'oval',
|
||||||
|
array(
|
||||||
|
'frame' => array('width' => 100, 'height' => 70, 'left' => 1, 'top' => 1),
|
||||||
|
'fill' => array('color' => '#33CC99'),
|
||||||
|
'outline' => array('color' => '#333333', 'weight' => 2),
|
||||||
|
'extrusion' => array(),
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Save file
|
||||||
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
if (!CLI) {
|
||||||
|
include_once 'Sample_Footer.php';
|
||||||
|
}
|
||||||
61
samples/Sample_32_Chart.php
Normal file
61
samples/Sample_32_Chart.php
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Shared\Converter;
|
||||||
|
|
||||||
|
// New Word document
|
||||||
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
|
|
||||||
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
$phpWord->addTitleStyle(1, array('size' => 14, 'bold' => true), array('keepNext' => true, 'spaceBefore' => 240));
|
||||||
|
$phpWord->addTitleStyle(2, array('size' => 14, 'bold' => true), array('keepNext' => true, 'spaceBefore' => 240));
|
||||||
|
|
||||||
|
// 2D charts
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
$section->addTitle(htmlspecialchars('2D charts'), 1);
|
||||||
|
$section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous'));
|
||||||
|
|
||||||
|
$chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'radar');
|
||||||
|
$twoSeries = array('bar', 'column', 'line', 'area', 'scatter', 'radar');
|
||||||
|
$threeSeries = array('bar', 'line');
|
||||||
|
$categories = array('A', 'B', 'C', 'D', 'E');
|
||||||
|
$series1 = array(1, 3, 2, 5, 4);
|
||||||
|
$series2 = array(3, 1, 7, 2, 6);
|
||||||
|
$series3 = array(8, 3, 2, 5, 4);
|
||||||
|
|
||||||
|
foreach ($chartTypes as $chartType) {
|
||||||
|
$section->addTitle(ucfirst($chartType), 2);
|
||||||
|
$chart = $section->addChart($chartType, $categories, $series1);
|
||||||
|
$chart->getStyle()->setWidth(Converter::inchToEmu(2.5))->setHeight(Converter::inchToEmu(2));
|
||||||
|
if (in_array($chartType, $twoSeries)) {
|
||||||
|
$chart->addSeries($categories, $series2);
|
||||||
|
}
|
||||||
|
if (in_array($chartType, $threeSeries)) {
|
||||||
|
$chart->addSeries($categories, $series3);
|
||||||
|
}
|
||||||
|
$section->addTextBreak();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3D charts
|
||||||
|
$section = $phpWord->addSection(array('breakType' => 'continuous'));
|
||||||
|
$section->addTitle(htmlspecialchars('3D charts'), 1);
|
||||||
|
$section = $phpWord->addSection(array('colsNum' => 2, 'breakType' => 'continuous'));
|
||||||
|
|
||||||
|
$chartTypes = array('pie', 'bar', 'column', 'line', 'area');
|
||||||
|
$multiSeries = array('bar', 'column', 'line', 'area');
|
||||||
|
$style = array('width' => Converter::cmToEmu(5), 'height' => Converter::cmToEmu(4), '3d' => true);
|
||||||
|
foreach ($chartTypes as $chartType) {
|
||||||
|
$section->addTitle(ucfirst($chartType), 2);
|
||||||
|
$chart = $section->addChart($chartType, $categories, $series1, $style);
|
||||||
|
if (in_array($chartType, $multiSeries)) {
|
||||||
|
$chart->addSeries($categories, $series2);
|
||||||
|
$chart->addSeries($categories, $series3);
|
||||||
|
}
|
||||||
|
$section->addTextBreak();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save file
|
||||||
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
if (!CLI) {
|
||||||
|
include_once 'Sample_Footer.php';
|
||||||
|
}
|
||||||
27
samples/Sample_33_FormField.php
Normal file
27
samples/Sample_33_FormField.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
|
// New Word document
|
||||||
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
$phpWord->getProtection()->setEditing('forms');
|
||||||
|
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
|
$textrun = $section->addTextRun();
|
||||||
|
$textrun->addText(htmlspecialchars('Form fields can be added in a text run and can be in form of textinput '));
|
||||||
|
$textrun->addFormField('textinput')->setName('MyTextBox');
|
||||||
|
$textrun->addText(htmlspecialchars(', checkbox '));
|
||||||
|
$textrun->addFormField('checkbox')->setDefault(true);
|
||||||
|
$textrun->addText(htmlspecialchars(', or dropdown '));
|
||||||
|
$textrun->addFormField('dropdown')->setEntries(array('Choice 1', 'Choice 2', 'Choice 3'));
|
||||||
|
$textrun->addText(htmlspecialchars('. You have to set document protection to "forms" to enable dropdown.'));
|
||||||
|
|
||||||
|
$section->addText(htmlspecialchars('They can also be added as a stand alone paragraph.'));
|
||||||
|
$section->addFormField('textinput')->setValue('Your name');
|
||||||
|
|
||||||
|
// Save file
|
||||||
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
if (!CLI) {
|
||||||
|
include_once 'Sample_Footer.php';
|
||||||
|
}
|
||||||
26
samples/Sample_34_SDT.php
Normal file
26
samples/Sample_34_SDT.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
|
// New Word document
|
||||||
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
|
||||||
|
$textrun = $section->addTextRun();
|
||||||
|
$textrun->addText(htmlspecialchars('Combobox: '));
|
||||||
|
$textrun->addSDT('comboBox')->setListItems(array('1' => 'Choice 1', '2' => 'Choice 2'));
|
||||||
|
|
||||||
|
$textrun = $section->addTextRun();
|
||||||
|
$textrun->addText(htmlspecialchars('Date: '));
|
||||||
|
$textrun->addSDT('date');
|
||||||
|
|
||||||
|
$textrun = $section->addTextRun();
|
||||||
|
$textrun->addText(htmlspecialchars('Drop down list: '));
|
||||||
|
$textrun->addSDT('dropDownList')->setListItems(array('1' => 'Choice 1', '2' => 'Choice 2'));
|
||||||
|
|
||||||
|
// Save file
|
||||||
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
if (!CLI) {
|
||||||
|
include_once 'Sample_Footer.php';
|
||||||
|
}
|
||||||
22
samples/Sample_35_InternalLink.php
Normal file
22
samples/Sample_35_InternalLink.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
|
// New Word document
|
||||||
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
$section->addTitle(htmlspecialchars('This is page 1'), 1);
|
||||||
|
$linkIsInternal = true;
|
||||||
|
$section->addLink('MyBookmark', htmlspecialchars('Take me to page 3'), null, null, $linkIsInternal);
|
||||||
|
$section->addPageBreak();
|
||||||
|
$section->addTitle(htmlspecialchars('This is page 2'), 1);
|
||||||
|
$section->addPageBreak();
|
||||||
|
$section->addTitle(htmlspecialchars('This is page 3'), 1);
|
||||||
|
$section->addBookmark('MyBookmark');
|
||||||
|
|
||||||
|
// Save file
|
||||||
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
if (!CLI) {
|
||||||
|
include_once 'Sample_Footer.php';
|
||||||
|
}
|
||||||
19
samples/Sample_36_RTL.php
Normal file
19
samples/Sample_36_RTL.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
|
// New Word document
|
||||||
|
echo date('H:i:s'), ' Create new PhpWord object', EOL;
|
||||||
|
$phpWord = new \PhpOffice\PhpWord\PhpWord();
|
||||||
|
|
||||||
|
$section = $phpWord->addSection();
|
||||||
|
$textrun = $section->addTextRun();
|
||||||
|
$textrun->addText(htmlspecialchars('This is a Left to Right paragraph.'));
|
||||||
|
|
||||||
|
$textrun = $section->addTextRun(array('align' => 'right'));
|
||||||
|
$textrun->addText(htmlspecialchars('سلام این یک پاراگراف راست به چپ است'), array('rtl' => true));
|
||||||
|
|
||||||
|
// Save file
|
||||||
|
echo write($phpWord, basename(__FILE__, '.php'), $writers);
|
||||||
|
if (!CLI) {
|
||||||
|
include_once 'Sample_Footer.php';
|
||||||
|
}
|
||||||
@ -2,6 +2,9 @@
|
|||||||
/**
|
/**
|
||||||
* Footer file
|
* Footer file
|
||||||
*/
|
*/
|
||||||
|
if (CLI) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
<script src="bootstrap/js/jquery.min.js"></script>
|
<script src="bootstrap/js/jquery.min.js"></script>
|
||||||
|
|||||||
@ -1,10 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
require_once __DIR__ . '/../src/PhpWord/Autoloader.php';
|
||||||
|
|
||||||
|
date_default_timezone_set('UTC');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Header file
|
* Header file
|
||||||
*/
|
*/
|
||||||
use PhpOffice\PhpWord\Autoloader;
|
use PhpOffice\PhpWord\Autoloader;
|
||||||
use PhpOffice\PhpWord\Settings;
|
use PhpOffice\PhpWord\Settings;
|
||||||
use PhpOffice\PhpWord\IOFactory;
|
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
define('CLI', (PHP_SAPI == 'cli') ? true : false);
|
define('CLI', (PHP_SAPI == 'cli') ? true : false);
|
||||||
@ -12,7 +15,6 @@ define('EOL', CLI ? PHP_EOL : '<br />');
|
|||||||
define('SCRIPT_FILENAME', basename($_SERVER['SCRIPT_FILENAME'], '.php'));
|
define('SCRIPT_FILENAME', basename($_SERVER['SCRIPT_FILENAME'], '.php'));
|
||||||
define('IS_INDEX', SCRIPT_FILENAME == 'index');
|
define('IS_INDEX', SCRIPT_FILENAME == 'index');
|
||||||
|
|
||||||
require_once __DIR__ . '/../src/PhpWord/Autoloader.php';
|
|
||||||
Autoloader::register();
|
Autoloader::register();
|
||||||
Settings::loadConfig();
|
Settings::loadConfig();
|
||||||
|
|
||||||
@ -20,7 +22,7 @@ Settings::loadConfig();
|
|||||||
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf', 'HTML' => 'html', 'PDF' => 'pdf');
|
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf', 'HTML' => 'html', 'PDF' => 'pdf');
|
||||||
|
|
||||||
// Set PDF renderer
|
// Set PDF renderer
|
||||||
if (Settings::getPdfRendererPath() === null) {
|
if (null === Settings::getPdfRendererPath()) {
|
||||||
$writers['PDF'] = null;
|
$writers['PDF'] = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,18 +55,19 @@ if ($handle = opendir('.')) {
|
|||||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||||
* @param string $filename
|
* @param string $filename
|
||||||
* @param array $writers
|
* @param array $writers
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
*/
|
*/
|
||||||
function write($phpWord, $filename, $writers)
|
function write($phpWord, $filename, $writers)
|
||||||
{
|
{
|
||||||
$result = '';
|
$result = '';
|
||||||
|
|
||||||
// Write documents
|
// Write documents
|
||||||
foreach ($writers as $writer => $extension) {
|
foreach ($writers as $format => $extension) {
|
||||||
$result .= date('H:i:s') . " Write to {$writer} format";
|
$result .= date('H:i:s') . " Write to {$format} format";
|
||||||
if (!is_null($extension)) {
|
if (null !== $extension) {
|
||||||
$xmlWriter = IOFactory::createWriter($phpWord, $writer);
|
$targetFile = __DIR__ . "/results/{$filename}.{$extension}";
|
||||||
$xmlWriter->save(__DIR__ . "/{$filename}.{$extension}");
|
$phpWord->save($targetFile, $format);
|
||||||
rename(__DIR__ . "/{$filename}.{$extension}", __DIR__ . "/results/{$filename}.{$extension}");
|
|
||||||
} else {
|
} else {
|
||||||
$result .= ' ... NOT DONE!';
|
$result .= ' ... NOT DONE!';
|
||||||
}
|
}
|
||||||
@ -80,6 +83,8 @@ function write($phpWord, $filename, $writers)
|
|||||||
* Get ending notes
|
* Get ending notes
|
||||||
*
|
*
|
||||||
* @param array $writers
|
* @param array $writers
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
*/
|
*/
|
||||||
function getEndingNotes($writers)
|
function getEndingNotes($writers)
|
||||||
{
|
{
|
||||||
@ -144,7 +149,7 @@ function getEndingNotes($writers)
|
|||||||
</ul>
|
</ul>
|
||||||
<ul class="nav navbar-nav navbar-right">
|
<ul class="nav navbar-nav navbar-right">
|
||||||
<li><a href="https://github.com/PHPOffice/PHPWord"><i class="fa fa-github fa-lg" title="GitHub"></i> </a></li>
|
<li><a href="https://github.com/PHPOffice/PHPWord"><i class="fa fa-github fa-lg" title="GitHub"></i> </a></li>
|
||||||
<li><a href="http://phpword.readthedocs.org/en/develop/"><i class="fa fa-book fa-lg" title="Docs"></i> </a></li>
|
<li><a href="http://phpword.readthedocs.org/"><i class="fa fa-book fa-lg" title="Docs"></i> </a></li>
|
||||||
<li><a href="http://twitter.com/PHPWord"><i class="fa fa-twitter fa-lg" title="Twitter"></i> </a></li>
|
<li><a href="http://twitter.com/PHPWord"><i class="fa fa-twitter fa-lg" title="Twitter"></i> </a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,8 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
include_once 'Sample_Header.php';
|
include_once 'Sample_Header.php';
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Settings;
|
||||||
|
|
||||||
$requirements = array(
|
$requirements = array(
|
||||||
'php' => array('PHP 5.3.0', version_compare(phpversion(), '5.3.0', '>=')),
|
'php' => array('PHP 5.3.3', version_compare(PHP_VERSION, '5.3.3', '>=')),
|
||||||
'xml' => array('PHP extension XML', extension_loaded('xml')),
|
'xml' => array('PHP extension XML', extension_loaded('xml')),
|
||||||
|
'temp' => array('Temp folder "<code>' . Settings::getTempDir() . '</code>" is writable', is_writable(Settings::getTempDir())),
|
||||||
'zip' => array('PHP extension ZipArchive (optional)', extension_loaded('zip')),
|
'zip' => array('PHP extension ZipArchive (optional)', extension_loaded('zip')),
|
||||||
'gd' => array('PHP extension GD (optional)', extension_loaded('gd')),
|
'gd' => array('PHP extension GD (optional)', extension_loaded('gd')),
|
||||||
'xmlw' => array('PHP extension XMLWriter (optional)', extension_loaded('xmlwriter')),
|
'xmlw' => array('PHP extension XMLWriter (optional)', extension_loaded('xmlwriter')),
|
||||||
@ -15,7 +19,7 @@ if (!CLI) {
|
|||||||
<p> </p>
|
<p> </p>
|
||||||
<p>
|
<p>
|
||||||
<a class="btn btn-lg btn-primary" href="https://github.com/PHPOffice/PHPWord" role="button"><i class="fa fa-github fa-lg" title="GitHub"></i> Fork us on Github!</a>
|
<a class="btn btn-lg btn-primary" href="https://github.com/PHPOffice/PHPWord" role="button"><i class="fa fa-github fa-lg" title="GitHub"></i> Fork us on Github!</a>
|
||||||
<a class="btn btn-lg btn-primary" href="http://phpword.readthedocs.org/en/develop/" role="button"><i class="fa fa-book fa-lg" title="Docs"></i> Read the Docs</a>
|
<a class="btn btn-lg btn-primary" href="http://phpword.readthedocs.org/" role="button"><i class="fa fa-book fa-lg" title="Docs"></i> Read the Docs</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
@ -34,6 +38,7 @@ if (!CLI) {
|
|||||||
echo 'Requirement check:' . PHP_EOL;
|
echo 'Requirement check:' . PHP_EOL;
|
||||||
foreach ($requirements as $key => $value) {
|
foreach ($requirements as $key => $value) {
|
||||||
list($label, $result) = $value;
|
list($label, $result) = $value;
|
||||||
|
$label = strip_tags($label);
|
||||||
$status = $result ? '32m passed' : '31m failed';
|
$status = $result ? '32m passed' : '31m failed';
|
||||||
echo "{$label} ... \033[{$status}\033[0m" . PHP_EOL;
|
echo "{$label} ... \033[{$status}\033[0m" . PHP_EOL;
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
samples/resources/Sample_11_ReadWord97.doc
Normal file
BIN
samples/resources/Sample_11_ReadWord97.doc
Normal file
Binary file not shown.
@ -28,17 +28,20 @@ class Autoloader
|
|||||||
/**
|
/**
|
||||||
* Register
|
* Register
|
||||||
*
|
*
|
||||||
|
* @param bool $throw
|
||||||
|
* @param bool $prepend
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function register()
|
public static function register($throw = true, $prepend = false)
|
||||||
{
|
{
|
||||||
spl_autoload_register(array(new self, 'autoload'));
|
spl_autoload_register(array(new self, 'autoload'), $throw, $prepend);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Autoload
|
* Autoload
|
||||||
*
|
*
|
||||||
* @param string $class
|
* @param string $class
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function autoload($class)
|
public static function autoload($class)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -57,10 +57,11 @@ abstract class AbstractCollection
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set item
|
* Set item.
|
||||||
*
|
*
|
||||||
* @param int $index
|
* @param int $index
|
||||||
* @param mixed $item
|
* @param mixed $item
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setItem($index, $item)
|
public function setItem($index, $item)
|
||||||
{
|
{
|
||||||
|
|||||||
27
src/PhpWord/Collection/Bookmarks.php
Normal file
27
src/PhpWord/Collection/Bookmarks.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||||
|
* word processing documents.
|
||||||
|
*
|
||||||
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||||
|
* General Public License version 3 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please read the LICENSE
|
||||||
|
* file that was distributed with this source code. For the full list of
|
||||||
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2010-2014 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bookmarks collection
|
||||||
|
*
|
||||||
|
* @since 0.12.0
|
||||||
|
*/
|
||||||
|
class Bookmarks extends AbstractCollection
|
||||||
|
{
|
||||||
|
}
|
||||||
27
src/PhpWord/Collection/Charts.php
Normal file
27
src/PhpWord/Collection/Charts.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||||
|
* word processing documents.
|
||||||
|
*
|
||||||
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||||
|
* General Public License version 3 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please read the LICENSE
|
||||||
|
* file that was distributed with this source code. For the full list of
|
||||||
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2010-2014 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Collection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Charts collection
|
||||||
|
*
|
||||||
|
* @since 0.12.0
|
||||||
|
*/
|
||||||
|
class Charts extends AbstractCollection
|
||||||
|
{
|
||||||
|
}
|
||||||
@ -17,28 +17,34 @@
|
|||||||
|
|
||||||
namespace PhpOffice\PhpWord\Element;
|
namespace PhpOffice\PhpWord\Element;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\Media;
|
|
||||||
use PhpOffice\PhpWord\PhpWord;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Container abstract class
|
* Container abstract class
|
||||||
*
|
*
|
||||||
* @method Text addText($text, $fStyle = null, $pStyle = null)
|
* @method Text addText(string $text, mixed $fStyle = null, mixed $pStyle = null)
|
||||||
* @method TextRun addTextRun($pStyle = null)
|
* @method TextRun addTextRun(mixed $pStyle = null)
|
||||||
* @method Link addLink($target, $text = null, $fStyle = null, $pStyle = null)
|
* @method Bookmark addBookmark(string $name)
|
||||||
* @method PreserveText addPreserveText($text, $fStyle = null, $pStyle = null)
|
* @method Link addLink(string $target, string $text = null, mixed $fStyle = null, mixed $pStyle = null)
|
||||||
* @method void addTextBreak($count = 1, $fStyle = null, $pStyle = null)
|
* @method PreserveText addPreserveText(string $text, mixed $fStyle = null, mixed $pStyle = null)
|
||||||
* @method ListItem addListItem($text, $depth = 0, $fStyle = null, $listStyle = null, $pStyle = null)
|
* @method void addTextBreak(int $count = 1, mixed $fStyle = null, mixed $pStyle = null)
|
||||||
* @method ListItemRun addListItemRun($depth = 0, $listStyle = null, $pStyle = null)
|
* @method ListItem addListItem(string $txt, int $depth = 0, mixed $font = null, mixed $list = null, mixed $para = null)
|
||||||
* @method Table addTable($style = null)
|
* @method ListItemRun addListItemRun(int $depth = 0, mixed $listStyle = null, mixed $pStyle = null)
|
||||||
* @method Image addImage($source, $style = null, $isWatermark = false)
|
* @method Footnote addFootnote(mixed $pStyle = null)
|
||||||
* @method Object addObject($source, $style = null)
|
* @method Endnote addEndnote(mixed $pStyle = null)
|
||||||
* @method Footnote addFootnote($pStyle = null)
|
* @method CheckBox addCheckBox(string $name, $text, mixed $fStyle = null, mixed $pStyle = null)
|
||||||
* @method Endnote addEndnote($pStyle = null)
|
* @method Title addTitle(string $text, int $depth = 1)
|
||||||
* @method CheckBox addCheckBox($name, $text, $fStyle = null, $pStyle = null)
|
* @method TOC addTOC(mixed $fontStyle = null, mixed $tocStyle = null, int $minDepth = 1, int $maxDepth = 9)
|
||||||
* @method TextBox addTextBox($style = null)
|
*
|
||||||
* @method Field addField($type = null, $properties = array(), $options = array())
|
* @method PageBreak addPageBreak()
|
||||||
* @method Line addLine($lineStyle = null)
|
* @method Table addTable(mixed $style = null)
|
||||||
|
* @method Image addImage(string $source, mixed $style = null, bool $isWatermark = false)
|
||||||
|
* @method Object addObject(string $source, mixed $style = null)
|
||||||
|
* @method TextBox addTextBox(mixed $style = null)
|
||||||
|
* @method Field addField(string $type = null, array $properties = array(), array $options = array())
|
||||||
|
* @method Line addLine(mixed $lineStyle = null)
|
||||||
|
* @method Shape addShape(string $type, mixed $style = null)
|
||||||
|
* @method Chart addChart(string $type, array $categories, array $values, array $style = null)
|
||||||
|
* @method FormField addFormField(string $type, mixed $fStyle = null, mixed $pStyle = null)
|
||||||
|
* @method SDT addSDT(string $type)
|
||||||
*
|
*
|
||||||
* @since 0.10.0
|
* @since 0.10.0
|
||||||
*/
|
*/
|
||||||
@ -72,17 +78,22 @@ abstract class AbstractContainer extends AbstractElement
|
|||||||
*/
|
*/
|
||||||
public function __call($function, $args)
|
public function __call($function, $args)
|
||||||
{
|
{
|
||||||
$elements = array('Text', 'TextRun', 'Link', 'PreserveText', 'TextBreak',
|
$elements = array(
|
||||||
'ListItem', 'ListItemRun', 'Table', 'Image', 'Object', 'Footnote',
|
'Text', 'TextRun', 'Bookmark', 'Link', 'PreserveText', 'TextBreak',
|
||||||
'Endnote', 'CheckBox', 'TextBox', 'Field', 'Line');
|
'ListItem', 'ListItemRun', 'Table', 'Image', 'Object',
|
||||||
|
'Footnote', 'Endnote', 'CheckBox', 'TextBox', 'Field',
|
||||||
|
'Line', 'Shape', 'Title', 'TOC', 'PageBreak',
|
||||||
|
'Chart', 'FormField', 'SDT'
|
||||||
|
);
|
||||||
$functions = array();
|
$functions = array();
|
||||||
for ($i = 0; $i < count($elements); $i++) {
|
foreach ($elements as $element) {
|
||||||
$functions[$i] = 'add' . $elements[$i];
|
$functions['add' . strtolower($element)] = $element;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run valid `add` command
|
// Run valid `add` command
|
||||||
if (in_array($function, $functions)) {
|
$function = strtolower($function);
|
||||||
$element = str_replace('add', '', $function);
|
if (isset($functions[$function])) {
|
||||||
|
$element = $functions[$function];
|
||||||
|
|
||||||
// Special case for TextBreak
|
// Special case for TextBreak
|
||||||
// @todo Remove the `$count` parameter in 1.0.0 to make this element similiar to other elements?
|
// @todo Remove the `$count` parameter in 1.0.0 to make this element similiar to other elements?
|
||||||
@ -124,10 +135,6 @@ abstract class AbstractContainer extends AbstractElement
|
|||||||
if ($withoutP && ($elementName == 'Text' || $elementName == 'PreserveText')) {
|
if ($withoutP && ($elementName == 'Text' || $elementName == 'PreserveText')) {
|
||||||
$args[3] = null; // Remove paragraph style for texts in textrun
|
$args[3] = null; // Remove paragraph style for texts in textrun
|
||||||
}
|
}
|
||||||
$source = '';
|
|
||||||
if (count($args) > 1) {
|
|
||||||
$source = $args[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create element using reflection
|
// Create element using reflection
|
||||||
$reflection = new \ReflectionClass($elementClass);
|
$reflection = new \ReflectionClass($elementClass);
|
||||||
@ -137,15 +144,10 @@ abstract class AbstractContainer extends AbstractElement
|
|||||||
/** @var \PhpOffice\PhpWord\Element\AbstractElement $element Type hint */
|
/** @var \PhpOffice\PhpWord\Element\AbstractElement $element Type hint */
|
||||||
$element = $reflection->newInstanceArgs($elementArgs);
|
$element = $reflection->newInstanceArgs($elementArgs);
|
||||||
|
|
||||||
// Set nested level and relation Id
|
// Set parent container
|
||||||
$this->setElementNestedLevel($element);
|
$element->setParentContainer($this);
|
||||||
$this->setElementRelationId($element, $elementName, $source);
|
|
||||||
|
|
||||||
// Set other properties and add element into collection
|
|
||||||
$element->setDocPart($this->getDocPart(), $this->getDocPartId());
|
|
||||||
$element->setElementIndex($this->countElements() + 1);
|
$element->setElementIndex($this->countElements() + 1);
|
||||||
$element->setElementId();
|
$element->setElementId();
|
||||||
$element->setPhpWord($this->phpWord);
|
|
||||||
|
|
||||||
$this->elements[] = $element;
|
$this->elements[] = $element;
|
||||||
|
|
||||||
@ -172,54 +174,6 @@ abstract class AbstractContainer extends AbstractElement
|
|||||||
return count($this->elements);
|
return count($this->elements);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set element nested level based on container; add one when it's inside a cell
|
|
||||||
*/
|
|
||||||
private function setElementNestedLevel(AbstractElement $element)
|
|
||||||
{
|
|
||||||
if ($this->container == 'Cell') {
|
|
||||||
$element->setNestedLevel($this->getNestedLevel() + 1);
|
|
||||||
} else {
|
|
||||||
$element->setNestedLevel($this->getNestedLevel());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set relation Id
|
|
||||||
*
|
|
||||||
* @param string $elementName
|
|
||||||
* @param string $source
|
|
||||||
*/
|
|
||||||
private function setElementRelationId(AbstractElement $element, $elementName, $source)
|
|
||||||
{
|
|
||||||
$mediaContainer = $this->getMediaContainer();
|
|
||||||
$hasMediaRelation = in_array($elementName, array('Link', 'Image', 'Object'));
|
|
||||||
$hasOtherRelation = in_array($elementName, array('Footnote', 'Endnote', 'Title'));
|
|
||||||
|
|
||||||
// Set relation Id for media elements (link, image, object; legacy of OOXML)
|
|
||||||
// Only Image that needs to be passed to Media class
|
|
||||||
if ($hasMediaRelation) {
|
|
||||||
/** @var \PhpOffice\PhpWord\Element\Image $element Type hint */
|
|
||||||
$image = ($elementName == 'Image') ? $element : null;
|
|
||||||
$rId = Media::addElement($mediaContainer, strtolower($elementName), $source, $image);
|
|
||||||
$element->setRelationId($rId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set relation Id for icon of object element
|
|
||||||
if ($elementName == 'Object') {
|
|
||||||
/** @var \PhpOffice\PhpWord\Element\Object $element Type hint */
|
|
||||||
$rIdIcon = Media::addElement($mediaContainer, 'image', $element->getIcon(), new Image($element->getIcon()));
|
|
||||||
$element->setImageRelationId($rIdIcon);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set relation Id for elements that will be registered in the Collection subnamespaces
|
|
||||||
if ($hasOtherRelation && $this->phpWord instanceof PhpWord) {
|
|
||||||
$addMethod = "add{$elementName}";
|
|
||||||
$rId = $this->phpWord->$addMethod($element);
|
|
||||||
$element->setRelationId($rId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a method is allowed for the current container
|
* Check if a method is allowed for the current container
|
||||||
*
|
*
|
||||||
@ -229,19 +183,22 @@ abstract class AbstractContainer extends AbstractElement
|
|||||||
*/
|
*/
|
||||||
private function checkValidity($method)
|
private function checkValidity($method)
|
||||||
{
|
{
|
||||||
// Valid containers for each element
|
$generalContainers = array(
|
||||||
$allContainers = array(
|
'Section', 'Header', 'Footer', 'Footnote', 'Endnote', 'Cell', 'TextRun', 'TextBox', 'ListItemRun',
|
||||||
'Section', 'Header', 'Footer', 'Footnote', 'Endnote',
|
|
||||||
'Cell', 'TextRun', 'TextBox', 'ListItemRun',
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$validContainers = array(
|
$validContainers = array(
|
||||||
'Text' => $allContainers,
|
'Text' => $generalContainers,
|
||||||
'Link' => $allContainers,
|
'Bookmark' => $generalContainers,
|
||||||
'TextBreak' => $allContainers,
|
'Link' => $generalContainers,
|
||||||
'Image' => $allContainers,
|
'TextBreak' => $generalContainers,
|
||||||
'Object' => $allContainers,
|
'Image' => $generalContainers,
|
||||||
'Field' => $allContainers,
|
'Object' => $generalContainers,
|
||||||
'Line' => $allContainers,
|
'Field' => $generalContainers,
|
||||||
|
'Line' => $generalContainers,
|
||||||
|
'Shape' => $generalContainers,
|
||||||
|
'FormField' => $generalContainers,
|
||||||
|
'SDT' => $generalContainers,
|
||||||
'TextRun' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
|
'TextRun' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
|
||||||
'ListItem' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
|
'ListItem' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
|
||||||
'ListItemRun' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
|
'ListItemRun' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
|
||||||
@ -251,7 +208,12 @@ abstract class AbstractContainer extends AbstractElement
|
|||||||
'Footnote' => array('Section', 'TextRun', 'Cell'),
|
'Footnote' => array('Section', 'TextRun', 'Cell'),
|
||||||
'Endnote' => array('Section', 'TextRun', 'Cell'),
|
'Endnote' => array('Section', 'TextRun', 'Cell'),
|
||||||
'PreserveText' => array('Header', 'Footer', 'Cell'),
|
'PreserveText' => array('Header', 'Footer', 'Cell'),
|
||||||
|
'Title' => array('Section'),
|
||||||
|
'TOC' => array('Section'),
|
||||||
|
'PageBreak' => array('Section'),
|
||||||
|
'Chart' => array('Section'),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Special condition, e.g. preservetext can only exists in cell when
|
// Special condition, e.g. preservetext can only exists in cell when
|
||||||
// the cell is located in header or footer
|
// the cell is located in header or footer
|
||||||
$validSubcontainers = array(
|
$validSubcontainers = array(
|
||||||
@ -261,19 +223,20 @@ abstract class AbstractContainer extends AbstractElement
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Check if a method is valid for current container
|
// Check if a method is valid for current container
|
||||||
if (array_key_exists($method, $validContainers)) {
|
if (isset($validContainers[$method])) {
|
||||||
if (!in_array($this->container, $validContainers[$method])) {
|
if (!in_array($this->container, $validContainers[$method])) {
|
||||||
throw new \BadMethodCallException("Cannot add $method in $this->container.");
|
throw new \BadMethodCallException("Cannot add {$method} in {$this->container}.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if a method is valid for current container, located in other container
|
// Check if a method is valid for current container, located in other container
|
||||||
if (array_key_exists($method, $validSubcontainers)) {
|
if (isset($validSubcontainers[$method])) {
|
||||||
$rules = $validSubcontainers[$method];
|
$rules = $validSubcontainers[$method];
|
||||||
$containers = $rules[0];
|
$containers = $rules[0];
|
||||||
$allowedDocParts = $rules[1];
|
$allowedDocParts = $rules[1];
|
||||||
foreach ($containers as $container) {
|
foreach ($containers as $container) {
|
||||||
if ($this->container == $container && !in_array($this->getDocPart(), $allowedDocParts)) {
|
if ($this->container == $container && !in_array($this->getDocPart(), $allowedDocParts)) {
|
||||||
throw new \BadMethodCallException("Cannot add $method in $this->container.");
|
throw new \BadMethodCallException("Cannot add {$method} in {$this->container}.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -281,24 +244,6 @@ abstract class AbstractContainer extends AbstractElement
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return media element (image, object, link) container name
|
|
||||||
*
|
|
||||||
* @return string section|headerx|footerx|footnote|endnote
|
|
||||||
*/
|
|
||||||
private function getMediaContainer()
|
|
||||||
{
|
|
||||||
$partName = $this->container;
|
|
||||||
if (in_array($partName, array('Cell', 'TextRun', 'TextBox', 'ListItemRun'))) {
|
|
||||||
$partName = $this->getDocPart();
|
|
||||||
}
|
|
||||||
if ($partName == 'Header' || $partName == 'Footer') {
|
|
||||||
$partName .= $this->getDocPartId();
|
|
||||||
}
|
|
||||||
|
|
||||||
return strtolower($partName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add memory image element
|
* Add memory image element
|
||||||
*
|
*
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
namespace PhpOffice\PhpWord\Element;
|
namespace PhpOffice\PhpWord\Element;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Media;
|
||||||
use PhpOffice\PhpWord\PhpWord;
|
use PhpOffice\PhpWord\PhpWord;
|
||||||
use PhpOffice\PhpWord\Style;
|
use PhpOffice\PhpWord\Style;
|
||||||
|
|
||||||
@ -42,7 +43,7 @@ abstract class AbstractElement
|
|||||||
protected $sectionId;
|
protected $sectionId;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Document part type: section|header|footer
|
* Document part type: Section|Header|Footer|Footnote|Endnote
|
||||||
*
|
*
|
||||||
* Used by textrun and cell container to determine where the element is
|
* Used by textrun and cell container to determine where the element is
|
||||||
* located because it will affect the availability of other element,
|
* located because it will affect the availability of other element,
|
||||||
@ -93,6 +94,27 @@ abstract class AbstractElement
|
|||||||
*/
|
*/
|
||||||
private $nestedLevel = 0;
|
private $nestedLevel = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parent container type
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $parentContainer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Has media relation flag; true for Link, Image, and Object
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $mediaRelation = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is part of collection; true for Title, Footnote, Endnote, and Chart
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $collectionRelation = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get PhpWord
|
* Get PhpWord
|
||||||
*
|
*
|
||||||
@ -104,13 +126,14 @@ abstract class AbstractElement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set PhpWord as reference
|
* Set PhpWord as reference.
|
||||||
*
|
*
|
||||||
* @param \PhpOffice\PhpWord\PhpWord
|
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setPhpWord(PhpWord &$phpWord = null)
|
public function setPhpWord(PhpWord $phpWord = null)
|
||||||
{
|
{
|
||||||
$this->phpWord = &$phpWord;
|
$this->phpWord = $phpWord;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -124,10 +147,11 @@ abstract class AbstractElement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set doc part
|
* Set doc part.
|
||||||
*
|
*
|
||||||
* @param string $docPart
|
* @param string $docPart
|
||||||
* @param int $docPartId
|
* @param int $docPartId
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setDocPart($docPart, $docPartId = 1)
|
public function setDocPart($docPart, $docPartId = 1)
|
||||||
{
|
{
|
||||||
@ -155,6 +179,21 @@ abstract class AbstractElement
|
|||||||
return $this->docPartId;
|
return $this->docPartId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return media element (image, object, link) container name
|
||||||
|
*
|
||||||
|
* @return string section|headerx|footerx|footnote|endnote
|
||||||
|
*/
|
||||||
|
private function getMediaPart()
|
||||||
|
{
|
||||||
|
$mediaPart = $this->docPart;
|
||||||
|
if ($mediaPart == 'Header' || $mediaPart == 'Footer') {
|
||||||
|
$mediaPart .= $this->docPartId;
|
||||||
|
}
|
||||||
|
|
||||||
|
return strtolower($mediaPart);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get element index
|
* Get element index
|
||||||
*
|
*
|
||||||
@ -166,9 +205,10 @@ abstract class AbstractElement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set element index
|
* Set element index.
|
||||||
*
|
*
|
||||||
* @param int $value
|
* @param int $value
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setElementIndex($value)
|
public function setElementIndex($value)
|
||||||
{
|
{
|
||||||
@ -186,7 +226,9 @@ abstract class AbstractElement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set element unique ID from 6 first digit of md5
|
* Set element unique ID from 6 first digit of md5.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setElementId()
|
public function setElementId()
|
||||||
{
|
{
|
||||||
@ -204,9 +246,10 @@ abstract class AbstractElement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set relation Id
|
* Set relation Id.
|
||||||
*
|
*
|
||||||
* @param int $value
|
* @param int $value
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setRelationId($value)
|
public function setRelationId($value)
|
||||||
{
|
{
|
||||||
@ -224,13 +267,79 @@ abstract class AbstractElement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set nested level
|
* Set parent container
|
||||||
*
|
*
|
||||||
* @param int $value
|
* Passed parameter should be a container, except for Table (contain Row) and Row (contain Cell)
|
||||||
|
*
|
||||||
|
* @param \PhpOffice\PhpWord\Element\AbstractElement $container
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setNestedLevel($value)
|
public function setParentContainer(AbstractElement $container)
|
||||||
{
|
{
|
||||||
$this->nestedLevel = $value;
|
$this->parentContainer = substr(get_class($container), strrpos(get_class($container), '\\') + 1);
|
||||||
|
|
||||||
|
// Set nested level
|
||||||
|
$this->nestedLevel = $container->getNestedLevel();
|
||||||
|
if ($this->parentContainer == 'Cell') {
|
||||||
|
$this->nestedLevel++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set phpword
|
||||||
|
$this->setPhpWord($container->getPhpWord());
|
||||||
|
|
||||||
|
// Set doc part
|
||||||
|
if (!$this instanceof Footnote) {
|
||||||
|
$this->setDocPart($container->getDocPart(), $container->getDocPartId());
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->setMediaRelation();
|
||||||
|
$this->setCollectionRelation();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function setMediaRelation()
|
||||||
|
{
|
||||||
|
if (!$this instanceof Link && !$this instanceof Image && !$this instanceof Object) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$elementName = substr(get_class($this), strrpos(get_class($this), '\\') + 1);
|
||||||
|
$mediaPart = $this->getMediaPart();
|
||||||
|
$source = $this->getSource();
|
||||||
|
$image = null;
|
||||||
|
if ($this instanceof Image) {
|
||||||
|
$image = $this;
|
||||||
|
}
|
||||||
|
$rId = Media::addElement($mediaPart, strtolower($elementName), $source, $image);
|
||||||
|
$this->setRelationId($rId);
|
||||||
|
|
||||||
|
if ($this instanceof Object) {
|
||||||
|
$icon = $this->getIcon();
|
||||||
|
$rId = Media::addElement($mediaPart, 'image', $icon, new Image($icon));
|
||||||
|
$this->setImageRelationId($rId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set relation Id for elements that will be registered in the Collection subnamespaces.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function setCollectionRelation()
|
||||||
|
{
|
||||||
|
if ($this->collectionRelation === true && $this->phpWord instanceof PhpWord) {
|
||||||
|
$elementName = substr(get_class($this), strrpos(get_class($this), '\\') + 1);
|
||||||
|
$addMethod = "add{$elementName}";
|
||||||
|
$rId = $this->phpWord->$addMethod($this);
|
||||||
|
$this->setRelationId($rId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -244,14 +353,14 @@ abstract class AbstractElement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set style value
|
* Set new style value
|
||||||
*
|
*
|
||||||
* @param mixed $styleObject Style object
|
* @param mixed $styleObject Style object
|
||||||
* @param mixed $styleValue Style value
|
* @param mixed $styleValue Style value
|
||||||
* @param bool $returnObject Always return object
|
* @param bool $returnObject Always return object
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
protected function setStyle($styleObject, $styleValue = null, $returnObject = false)
|
protected function setNewStyle($styleObject, $styleValue = null, $returnObject = false)
|
||||||
{
|
{
|
||||||
if (!is_null($styleValue) && is_array($styleValue)) {
|
if (!is_null($styleValue) && is_array($styleValue)) {
|
||||||
$styleObject->setStyleByArray($styleValue);
|
$styleObject->setStyleByArray($styleValue);
|
||||||
@ -262,4 +371,25 @@ abstract class AbstractElement
|
|||||||
|
|
||||||
return $style;
|
return $style;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set enum value
|
||||||
|
*
|
||||||
|
* @param mixed $value
|
||||||
|
* @param array $enum
|
||||||
|
* @param mixed $default
|
||||||
|
* @return mixed
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
|
* @todo Merge with the same method in AbstractStyle
|
||||||
|
*/
|
||||||
|
protected function setEnumVal($value = null, $enum = array(), $default = null)
|
||||||
|
{
|
||||||
|
if ($value != null && trim($value) != '' && !empty($enum) && !in_array($value, $enum)) {
|
||||||
|
throw new \InvalidArgumentException("Invalid style value: {$value}");
|
||||||
|
} elseif ($value === null || trim($value) == '') {
|
||||||
|
$value = $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
63
src/PhpWord/Element/Bookmark.php
Normal file
63
src/PhpWord/Element/Bookmark.php
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||||
|
* word processing documents.
|
||||||
|
*
|
||||||
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||||
|
* General Public License version 3 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please read the LICENSE
|
||||||
|
* file that was distributed with this source code. For the full list of
|
||||||
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2010-2014 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Element;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Shared\String;
|
||||||
|
use PhpOffice\PhpWord\Style;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bookmark element
|
||||||
|
*/
|
||||||
|
class Bookmark extends AbstractElement
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Bookmark Name
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is part of collection
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $collectionRelation = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new Bookmark Element
|
||||||
|
*
|
||||||
|
* @param string $name
|
||||||
|
*/
|
||||||
|
public function __construct($name)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->name = String::toUTF8($name);
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Bookmark name
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -52,7 +52,7 @@ class Cell extends AbstractContainer
|
|||||||
public function __construct($width = null, $style = null)
|
public function __construct($width = null, $style = null)
|
||||||
{
|
{
|
||||||
$this->width = $width;
|
$this->width = $width;
|
||||||
$this->style = $this->setStyle(new CellStyle(), $style, true);
|
$this->style = $this->setNewStyle(new CellStyle(), $style, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
125
src/PhpWord/Element/Chart.php
Normal file
125
src/PhpWord/Element/Chart.php
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||||
|
* word processing documents.
|
||||||
|
*
|
||||||
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||||
|
* General Public License version 3 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please read the LICENSE
|
||||||
|
* file that was distributed with this source code. For the full list of
|
||||||
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2010-2014 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Element;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Style\Chart as ChartStyle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chart element
|
||||||
|
*
|
||||||
|
* @since 0.12.0
|
||||||
|
*/
|
||||||
|
class Chart extends AbstractElement
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Is part of collection
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $collectionRelation = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $type = 'pie';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Series
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $series = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Chart style
|
||||||
|
*
|
||||||
|
* @var \PhpOffice\PhpWord\Style\Chart
|
||||||
|
*/
|
||||||
|
private $style;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new instance
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param array $categories
|
||||||
|
* @param array $values
|
||||||
|
* @param array $style
|
||||||
|
*/
|
||||||
|
public function __construct($type, $categories, $values, $style = null)
|
||||||
|
{
|
||||||
|
$this->setType($type);
|
||||||
|
$this->addSeries($categories, $values);
|
||||||
|
$this->style = $this->setNewStyle(new ChartStyle(), $style, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get type
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getType()
|
||||||
|
{
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set type.
|
||||||
|
*
|
||||||
|
* @param string $value
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function setType($value)
|
||||||
|
{
|
||||||
|
$enum = array('pie', 'doughnut', 'line', 'bar', 'column', 'area', 'radar', 'scatter');
|
||||||
|
$this->type = $this->setEnumVal($value, $enum, 'pie');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add series
|
||||||
|
*
|
||||||
|
* @param array $categories
|
||||||
|
* @param array $values
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function addSeries($categories, $values)
|
||||||
|
{
|
||||||
|
$this->series[] = array('categories' => $categories, 'values' => $values);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get series
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getSeries()
|
||||||
|
{
|
||||||
|
return $this->series;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get chart style
|
||||||
|
*
|
||||||
|
* @return \PhpOffice\PhpWord\Style\Chart
|
||||||
|
*/
|
||||||
|
public function getStyle()
|
||||||
|
{
|
||||||
|
return $this->style;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -21,6 +21,8 @@ use PhpOffice\PhpWord\Shared\String;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check box element
|
* Check box element
|
||||||
|
*
|
||||||
|
* @since 0.10.0
|
||||||
*/
|
*/
|
||||||
class CheckBox extends Text
|
class CheckBox extends Text
|
||||||
{
|
{
|
||||||
|
|||||||
@ -38,6 +38,6 @@ class Endnote extends Footnote
|
|||||||
*/
|
*/
|
||||||
public function __construct($paragraphStyle = null)
|
public function __construct($paragraphStyle = null)
|
||||||
{
|
{
|
||||||
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
|
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -100,7 +100,7 @@ class Field extends AbstractElement
|
|||||||
public function setType($type = null)
|
public function setType($type = null)
|
||||||
{
|
{
|
||||||
if (isset($type)) {
|
if (isset($type)) {
|
||||||
if (array_key_exists($type, $this->fieldsArray)) {
|
if (isset($this->fieldsArray[$type])) {
|
||||||
$this->type = $type;
|
$this->type = $type;
|
||||||
} else {
|
} else {
|
||||||
throw new \InvalidArgumentException("Invalid type");
|
throw new \InvalidArgumentException("Invalid type");
|
||||||
@ -130,7 +130,7 @@ class Field extends AbstractElement
|
|||||||
{
|
{
|
||||||
if (is_array($properties)) {
|
if (is_array($properties)) {
|
||||||
foreach (array_keys($properties) as $propkey) {
|
foreach (array_keys($properties) as $propkey) {
|
||||||
if (!(array_key_exists($propkey, $this->fieldsArray[$this->type]['properties']))) {
|
if (!(isset($this->fieldsArray[$this->type]['properties'][$propkey]))) {
|
||||||
throw new \InvalidArgumentException("Invalid property");
|
throw new \InvalidArgumentException("Invalid property");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -160,7 +160,7 @@ class Field extends AbstractElement
|
|||||||
{
|
{
|
||||||
if (is_array($options)) {
|
if (is_array($options)) {
|
||||||
foreach (array_keys($options) as $optionkey) {
|
foreach (array_keys($options) as $optionkey) {
|
||||||
if (!(array_key_exists($optionkey, $this->fieldsArray[$this->type]['options']))) {
|
if (!(isset($this->fieldsArray[$this->type]['options'][$optionkey]))) {
|
||||||
throw new \InvalidArgumentException("Invalid option");
|
throw new \InvalidArgumentException("Invalid option");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -59,10 +59,12 @@ class Footer extends AbstractContainer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set type
|
* Set type.
|
||||||
|
*
|
||||||
|
* @since 0.10.0
|
||||||
*
|
*
|
||||||
* @param string $value
|
* @param string $value
|
||||||
* @since 0.10.0
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setType($value = self::AUTO)
|
public function setType($value = self::AUTO)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -36,6 +36,13 @@ class Footnote extends AbstractContainer
|
|||||||
*/
|
*/
|
||||||
protected $paragraphStyle;
|
protected $paragraphStyle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is part of collection
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $collectionRelation = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new instance
|
* Create new instance
|
||||||
*
|
*
|
||||||
@ -43,7 +50,8 @@ class Footnote extends AbstractContainer
|
|||||||
*/
|
*/
|
||||||
public function __construct($paragraphStyle = null)
|
public function __construct($paragraphStyle = null)
|
||||||
{
|
{
|
||||||
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
|
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
|
||||||
|
$this->setDocPart($this->container);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
195
src/PhpWord/Element/FormField.php
Normal file
195
src/PhpWord/Element/FormField.php
Normal file
@ -0,0 +1,195 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||||
|
* word processing documents.
|
||||||
|
*
|
||||||
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||||
|
* General Public License version 3 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please read the LICENSE
|
||||||
|
* file that was distributed with this source code. For the full list of
|
||||||
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2010-2014 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form field element
|
||||||
|
*
|
||||||
|
* @since 0.12.0
|
||||||
|
* @link http://www.datypic.com/sc/ooxml/t-w_CT_FFData.html
|
||||||
|
*/
|
||||||
|
class FormField extends Text
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Form field type: textinput|checkbox|dropdown
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $type = 'textinput';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Form field name
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default value
|
||||||
|
*
|
||||||
|
* - TextInput: string
|
||||||
|
* - CheckBox: bool
|
||||||
|
* - DropDown: int Index of entries (zero based)
|
||||||
|
*
|
||||||
|
* @var string|bool|int
|
||||||
|
*/
|
||||||
|
private $default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Value
|
||||||
|
*
|
||||||
|
* @var string|bool|int
|
||||||
|
*/
|
||||||
|
private $value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dropdown entries
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $entries = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new instance
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param mixed $fontStyle
|
||||||
|
* @param mixed $paragraphStyle
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function __construct($type, $fontStyle = null, $paragraphStyle = null)
|
||||||
|
{
|
||||||
|
$this->setType($type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get type
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getType()
|
||||||
|
{
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set type
|
||||||
|
*
|
||||||
|
* @param string $value
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setType($value)
|
||||||
|
{
|
||||||
|
$enum = array('textinput', 'checkbox', 'dropdown');
|
||||||
|
$this->type = $this->setEnumVal($value, $enum, $this->type);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get name
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set name
|
||||||
|
*
|
||||||
|
* @param string|bool|int $value
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setName($value)
|
||||||
|
{
|
||||||
|
$this->name = $value;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get default
|
||||||
|
*
|
||||||
|
* @return string|bool|int
|
||||||
|
*/
|
||||||
|
public function getDefault()
|
||||||
|
{
|
||||||
|
return $this->default;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set default
|
||||||
|
*
|
||||||
|
* @param string|bool|int $value
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setDefault($value)
|
||||||
|
{
|
||||||
|
$this->default = $value;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get value
|
||||||
|
*
|
||||||
|
* @return string|bool|int
|
||||||
|
*/
|
||||||
|
public function getValue()
|
||||||
|
{
|
||||||
|
return $this->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set value
|
||||||
|
*
|
||||||
|
* @param string|bool|int $value
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setValue($value)
|
||||||
|
{
|
||||||
|
$this->value = $value;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get entries
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getEntries()
|
||||||
|
{
|
||||||
|
return $this->entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set entries
|
||||||
|
*
|
||||||
|
* @param array $value
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setEntries($value)
|
||||||
|
{
|
||||||
|
$this->entries = $value;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -17,8 +17,10 @@
|
|||||||
|
|
||||||
namespace PhpOffice\PhpWord\Element;
|
namespace PhpOffice\PhpWord\Element;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Exception\CreateTemporaryFileException;
|
||||||
use PhpOffice\PhpWord\Exception\InvalidImageException;
|
use PhpOffice\PhpWord\Exception\InvalidImageException;
|
||||||
use PhpOffice\PhpWord\Exception\UnsupportedImageTypeException;
|
use PhpOffice\PhpWord\Exception\UnsupportedImageTypeException;
|
||||||
|
use PhpOffice\PhpWord\Settings;
|
||||||
use PhpOffice\PhpWord\Shared\ZipArchive;
|
use PhpOffice\PhpWord\Shared\ZipArchive;
|
||||||
use PhpOffice\PhpWord\Style\Image as ImageStyle;
|
use PhpOffice\PhpWord\Style\Image as ImageStyle;
|
||||||
|
|
||||||
@ -111,6 +113,13 @@ class Image extends AbstractElement
|
|||||||
*/
|
*/
|
||||||
private $mediaIndex;
|
private $mediaIndex;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Has media relation flag; true for Link, Image, and Object
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $mediaRelation = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new image element
|
* Create new image element
|
||||||
*
|
*
|
||||||
@ -124,7 +133,7 @@ class Image extends AbstractElement
|
|||||||
{
|
{
|
||||||
$this->source = $source;
|
$this->source = $source;
|
||||||
$this->setIsWatermark($watermark);
|
$this->setIsWatermark($watermark);
|
||||||
$this->style = $this->setStyle(new ImageStyle(), $style, true);
|
$this->style = $this->setNewStyle(new ImageStyle(), $style, true);
|
||||||
|
|
||||||
$this->checkImage($source);
|
$this->checkImage($source);
|
||||||
}
|
}
|
||||||
@ -250,9 +259,10 @@ class Image extends AbstractElement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set target file name
|
* Set target file name.
|
||||||
*
|
*
|
||||||
* @param string $value
|
* @param string $value
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setTarget($value)
|
public function setTarget($value)
|
||||||
{
|
{
|
||||||
@ -270,9 +280,10 @@ class Image extends AbstractElement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set media index
|
* Set media index.
|
||||||
*
|
*
|
||||||
* @param integer $value
|
* @param integer $value
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setMediaIndex($value)
|
public function setMediaIndex($value)
|
||||||
{
|
{
|
||||||
@ -304,8 +315,8 @@ class Image extends AbstractElement
|
|||||||
if ($zip->open($zipFilename) !== false) {
|
if ($zip->open($zipFilename) !== false) {
|
||||||
if ($zip->locateName($imageFilename)) {
|
if ($zip->locateName($imageFilename)) {
|
||||||
$isTemp = true;
|
$isTemp = true;
|
||||||
$zip->extractTo(sys_get_temp_dir(), $imageFilename);
|
$zip->extractTo(Settings::getTempDir(), $imageFilename);
|
||||||
$actualSource = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $imageFilename;
|
$actualSource = Settings::getTempDir() . DIRECTORY_SEPARATOR . $imageFilename;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$zip->close();
|
$zip->close();
|
||||||
@ -351,9 +362,10 @@ class Image extends AbstractElement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check memory image, supported type, image functions, and proportional width/height
|
* Check memory image, supported type, image functions, and proportional width/height.
|
||||||
*
|
*
|
||||||
* @param string $source
|
* @param string $source
|
||||||
|
* @return void
|
||||||
* @throws \PhpOffice\PhpWord\Exception\InvalidImageException
|
* @throws \PhpOffice\PhpWord\Exception\InvalidImageException
|
||||||
* @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
|
* @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
|
||||||
*/
|
*/
|
||||||
@ -388,9 +400,10 @@ class Image extends AbstractElement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set source type
|
* Set source type.
|
||||||
*
|
*
|
||||||
* @param string $source
|
* @param string $source
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function setSourceType($source)
|
private function setSourceType($source)
|
||||||
{
|
{
|
||||||
@ -409,15 +422,22 @@ class Image extends AbstractElement
|
|||||||
/**
|
/**
|
||||||
* Get image size from archive
|
* Get image size from archive
|
||||||
*
|
*
|
||||||
|
* @since 0.12.0 Throws CreateTemporaryFileException.
|
||||||
|
*
|
||||||
* @param string $source
|
* @param string $source
|
||||||
* @return array|null
|
* @return array|null
|
||||||
|
* @throws \PhpOffice\PhpWord\Exception\CreateTemporaryFileException
|
||||||
*/
|
*/
|
||||||
private function getArchiveImageSize($source)
|
private function getArchiveImageSize($source)
|
||||||
{
|
{
|
||||||
$imageData = null;
|
$imageData = null;
|
||||||
$source = substr($source, 6);
|
$source = substr($source, 6);
|
||||||
list($zipFilename, $imageFilename) = explode('#', $source);
|
list($zipFilename, $imageFilename) = explode('#', $source);
|
||||||
$tempFilename = tempnam(sys_get_temp_dir(), 'PHPWordImage');
|
|
||||||
|
$tempFilename = tempnam(Settings::getTempDir(), 'PHPWordImage');
|
||||||
|
if (false === $tempFilename) {
|
||||||
|
throw new CreateTemporaryFileException();
|
||||||
|
}
|
||||||
|
|
||||||
$zip = new ZipArchive();
|
$zip = new ZipArchive();
|
||||||
if ($zip->open($zipFilename) !== false) {
|
if ($zip->open($zipFilename) !== false) {
|
||||||
@ -425,7 +445,7 @@ class Image extends AbstractElement
|
|||||||
$imageContent = $zip->getFromName($imageFilename);
|
$imageContent = $zip->getFromName($imageFilename);
|
||||||
if ($imageContent !== false) {
|
if ($imageContent !== false) {
|
||||||
file_put_contents($tempFilename, $imageContent);
|
file_put_contents($tempFilename, $imageContent);
|
||||||
$imageData = @getimagesize($tempFilename);
|
$imageData = getimagesize($tempFilename);
|
||||||
unlink($tempFilename);
|
unlink($tempFilename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -436,7 +456,9 @@ class Image extends AbstractElement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set image functions and extensions
|
* Set image functions and extensions.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function setFunctions()
|
private function setFunctions()
|
||||||
{
|
{
|
||||||
@ -469,10 +491,11 @@ class Image extends AbstractElement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set proportional width/height if one dimension not available
|
* Set proportional width/height if one dimension not available.
|
||||||
*
|
*
|
||||||
* @param integer $actualWidth
|
* @param integer $actualWidth
|
||||||
* @param integer $actualHeight
|
* @param integer $actualHeight
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function setProportionalSize($actualWidth, $actualHeight)
|
private function setProportionalSize($actualWidth, $actualHeight)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -38,7 +38,7 @@ class Line extends AbstractElement
|
|||||||
*/
|
*/
|
||||||
public function __construct($style = null)
|
public function __construct($style = null)
|
||||||
{
|
{
|
||||||
$this->style = $this->setStyle(new LineStyle(), $style);
|
$this->style = $this->setNewStyle(new LineStyle(), $style);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -27,11 +27,11 @@ use PhpOffice\PhpWord\Style\Paragraph;
|
|||||||
class Link extends AbstractElement
|
class Link extends AbstractElement
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Link target
|
* Link source
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private $target;
|
private $source;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Link text
|
* Link text
|
||||||
@ -54,33 +54,46 @@ class Link extends AbstractElement
|
|||||||
*/
|
*/
|
||||||
private $paragraphStyle;
|
private $paragraphStyle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Has media relation flag; true for Link, Image, and Object
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $mediaRelation = true;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Has internal flag - anchor to internal bookmark
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $internal = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Link Element
|
* Create a new Link Element
|
||||||
*
|
*
|
||||||
* @param string $target
|
* @param string $source
|
||||||
* @param string $text
|
* @param string $text
|
||||||
* @param mixed $fontStyle
|
* @param mixed $fontStyle
|
||||||
* @param mixed $paragraphStyle
|
* @param mixed $paragraphStyle
|
||||||
*/
|
*/
|
||||||
public function __construct($target, $text = null, $fontStyle = null, $paragraphStyle = null)
|
public function __construct($source, $text = null, $fontStyle = null, $paragraphStyle = null, $internal = false)
|
||||||
{
|
{
|
||||||
$this->target = String::toUTF8($target);
|
$this->source = String::toUTF8($source);
|
||||||
$this->text = is_null($text) ? $this->target : String::toUTF8($text);
|
$this->text = is_null($text) ? $this->source : String::toUTF8($text);
|
||||||
$this->fontStyle = $this->setStyle(new Font('text'), $fontStyle);
|
$this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle);
|
||||||
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
|
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
|
||||||
|
$this->internal = $internal;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get link target
|
* Get link source
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function getTarget()
|
public function getSource()
|
||||||
{
|
{
|
||||||
return $this->target;
|
return $this->source;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -113,6 +126,18 @@ class Link extends AbstractElement
|
|||||||
return $this->paragraphStyle;
|
return $this->paragraphStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get link target
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* @deprecated 0.12.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
public function getTarget()
|
||||||
|
{
|
||||||
|
return $this->source;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Link source
|
* Get Link source
|
||||||
*
|
*
|
||||||
@ -122,7 +147,7 @@ class Link extends AbstractElement
|
|||||||
*/
|
*/
|
||||||
public function getLinkSrc()
|
public function getLinkSrc()
|
||||||
{
|
{
|
||||||
return $this->getTarget();
|
return $this->getSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -136,4 +161,14 @@ class Link extends AbstractElement
|
|||||||
{
|
{
|
||||||
return $this->getText();
|
return $this->getText();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* is internal
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isInternal()
|
||||||
|
{
|
||||||
|
return $this->internal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -64,7 +64,7 @@ class ListItem extends AbstractElement
|
|||||||
if (!is_null($listStyle) && is_string($listStyle)) {
|
if (!is_null($listStyle) && is_string($listStyle)) {
|
||||||
$this->style = new ListItemStyle($listStyle);
|
$this->style = new ListItemStyle($listStyle);
|
||||||
} else {
|
} else {
|
||||||
$this->style = $this->setStyle(new ListItemStyle(), $listStyle, true);
|
$this->style = $this->setNewStyle(new ListItemStyle(), $listStyle, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -59,13 +59,15 @@ class ListItemRun extends TextRun
|
|||||||
if (!is_null($listStyle) && is_string($listStyle)) {
|
if (!is_null($listStyle) && is_string($listStyle)) {
|
||||||
$this->style = new ListItemStyle($listStyle);
|
$this->style = new ListItemStyle($listStyle);
|
||||||
} else {
|
} else {
|
||||||
$this->style = $this->setStyle(new ListItemStyle(), $listStyle, true);
|
$this->style = $this->setNewStyle(new ListItemStyle(), $listStyle, true);
|
||||||
}
|
}
|
||||||
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
|
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get ListItem style
|
* Get ListItem style.
|
||||||
|
*
|
||||||
|
* @return \PhpOffice\PhpWord\Style\ListItem
|
||||||
*/
|
*/
|
||||||
public function getStyle()
|
public function getStyle()
|
||||||
{
|
{
|
||||||
@ -73,7 +75,9 @@ class ListItemRun extends TextRun
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get ListItem depth
|
* Get ListItem depth.
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
*/
|
*/
|
||||||
public function getDepth()
|
public function getDepth()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -53,6 +53,13 @@ class Object extends AbstractElement
|
|||||||
*/
|
*/
|
||||||
private $imageRelationId;
|
private $imageRelationId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Has media relation flag; true for Link, Image, and Object
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $mediaRelation = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Ole-Object Element
|
* Create a new Ole-Object Element
|
||||||
*
|
*
|
||||||
@ -72,7 +79,7 @@ class Object extends AbstractElement
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->source = $source;
|
$this->source = $source;
|
||||||
$this->style = $this->setStyle(new ImageStyle(), $style, true);
|
$this->style = $this->setNewStyle(new ImageStyle(), $style, true);
|
||||||
$this->icon = realpath(__DIR__ . "/../resources/{$ext}.png");
|
$this->icon = realpath(__DIR__ . "/../resources/{$ext}.png");
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -122,9 +129,10 @@ class Object extends AbstractElement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Image Relation ID
|
* Set Image Relation ID.
|
||||||
*
|
*
|
||||||
* @param int $rId
|
* @param int $rId
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setImageRelationId($rId)
|
public function setImageRelationId($rId)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -58,8 +58,8 @@ class PreserveText extends AbstractElement
|
|||||||
*/
|
*/
|
||||||
public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
|
public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
|
||||||
{
|
{
|
||||||
$this->fontStyle = $this->setStyle(new Font('text'), $fontStyle);
|
$this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle);
|
||||||
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
|
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
|
||||||
|
|
||||||
$this->text = String::toUTF8($text);
|
$this->text = String::toUTF8($text);
|
||||||
$matches = preg_split('/({.*?})/', $this->text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
$matches = preg_split('/({.*?})/', $this->text, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
|
||||||
|
|||||||
@ -56,7 +56,7 @@ class Row extends AbstractElement
|
|||||||
public function __construct($height = null, $style = null)
|
public function __construct($height = null, $style = null)
|
||||||
{
|
{
|
||||||
$this->height = $height;
|
$this->height = $height;
|
||||||
$this->style = $this->setStyle(new RowStyle(), $style, true);
|
$this->style = $this->setNewStyle(new RowStyle(), $style, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,9 +69,7 @@ class Row extends AbstractElement
|
|||||||
public function addCell($width = null, $style = null)
|
public function addCell($width = null, $style = null)
|
||||||
{
|
{
|
||||||
$cell = new Cell($width, $style);
|
$cell = new Cell($width, $style);
|
||||||
$cell->setDocPart($this->getDocPart(), $this->getDocPartId());
|
$cell->setParentContainer($this);
|
||||||
$cell->setPhpWord($this->phpWord);
|
|
||||||
$cell->setNestedLevel($this->getNestedLevel());
|
|
||||||
$this->cells[] = $cell;
|
$this->cells[] = $cell;
|
||||||
|
|
||||||
return $cell;
|
return $cell;
|
||||||
|
|||||||
130
src/PhpWord/Element/SDT.php
Normal file
130
src/PhpWord/Element/SDT.php
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||||
|
* word processing documents.
|
||||||
|
*
|
||||||
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||||
|
* General Public License version 3 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please read the LICENSE
|
||||||
|
* file that was distributed with this source code. For the full list of
|
||||||
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2010-2014 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Element;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Structured document tag (SDT) element
|
||||||
|
*
|
||||||
|
* @since 0.12.0
|
||||||
|
*/
|
||||||
|
class SDT extends Text
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Form field type: comboBox|dropDownList|date
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Value
|
||||||
|
*
|
||||||
|
* @var string|bool|int
|
||||||
|
*/
|
||||||
|
private $value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* CheckBox/DropDown list entries
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $listItems = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new instance
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param mixed $fontStyle
|
||||||
|
* @param mixed $paragraphStyle
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function __construct($type, $fontStyle = null, $paragraphStyle = null)
|
||||||
|
{
|
||||||
|
$this->setType($type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get type
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getType()
|
||||||
|
{
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set type
|
||||||
|
*
|
||||||
|
* @param string $value
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setType($value)
|
||||||
|
{
|
||||||
|
$enum = array('comboBox', 'dropDownList', 'date');
|
||||||
|
$this->type = $this->setEnumVal($value, $enum, 'comboBox');
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get value
|
||||||
|
*
|
||||||
|
* @return string|bool|int
|
||||||
|
*/
|
||||||
|
public function getValue()
|
||||||
|
{
|
||||||
|
return $this->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set value
|
||||||
|
*
|
||||||
|
* @param string|bool|int $value
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setValue($value)
|
||||||
|
{
|
||||||
|
$this->value = $value;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get listItems
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getListItems()
|
||||||
|
{
|
||||||
|
return $this->listItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set listItems
|
||||||
|
*
|
||||||
|
* @param array $value
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setListItems($value)
|
||||||
|
{
|
||||||
|
$this->listItems = $value;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -18,7 +18,7 @@
|
|||||||
namespace PhpOffice\PhpWord\Element;
|
namespace PhpOffice\PhpWord\Element;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\Exception\Exception;
|
use PhpOffice\PhpWord\Exception\Exception;
|
||||||
use PhpOffice\PhpWord\Style\Section as SectionSettings;
|
use PhpOffice\PhpWord\Style\Section as SectionStyle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Section
|
* Section
|
||||||
@ -31,11 +31,11 @@ class Section extends AbstractContainer
|
|||||||
protected $container = 'Section';
|
protected $container = 'Section';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Section settings
|
* Section style
|
||||||
*
|
*
|
||||||
* @var \PhpOffice\PhpWord\Style\Section
|
* @var \PhpOffice\PhpWord\Style\Section
|
||||||
*/
|
*/
|
||||||
private $settings;
|
private $style;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Section headers, indexed from 1, not zero
|
* Section headers, indexed from 1, not zero
|
||||||
@ -55,75 +55,37 @@ class Section extends AbstractContainer
|
|||||||
* Create new instance
|
* Create new instance
|
||||||
*
|
*
|
||||||
* @param int $sectionCount
|
* @param int $sectionCount
|
||||||
* @param array $settings
|
* @param array $style
|
||||||
*/
|
*/
|
||||||
public function __construct($sectionCount, $settings = null)
|
public function __construct($sectionCount, $style = null)
|
||||||
{
|
{
|
||||||
$this->sectionId = $sectionCount;
|
$this->sectionId = $sectionCount;
|
||||||
$this->setDocPart($this->container, $this->sectionId);
|
$this->setDocPart($this->container, $this->sectionId);
|
||||||
$this->settings = new SectionSettings();
|
$this->style = new SectionStyle();
|
||||||
$this->setSettings($settings);
|
$this->setStyle($style);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set section settings
|
* Set section style.
|
||||||
*
|
*
|
||||||
* @param array $settings
|
* @param array $style
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setSettings($settings = null)
|
public function setStyle($style = null)
|
||||||
{
|
{
|
||||||
if (!is_null($settings) && is_array($settings)) {
|
if (!is_null($style) && is_array($style)) {
|
||||||
foreach ($settings as $key => $value) {
|
$this->style->setStyleByArray($style);
|
||||||
if (is_null($value)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$this->settings->setSettingValue($key, $value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Section Settings
|
* Get section style
|
||||||
*
|
*
|
||||||
* @return \PhpOffice\PhpWord\Style\Section
|
* @return \PhpOffice\PhpWord\Style\Section
|
||||||
*/
|
*/
|
||||||
public function getSettings()
|
public function getStyle()
|
||||||
{
|
{
|
||||||
return $this->settings;
|
return $this->style;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a Title Element
|
|
||||||
*
|
|
||||||
* @param string $text
|
|
||||||
* @param int $depth
|
|
||||||
* @return \PhpOffice\PhpWord\Element\Title
|
|
||||||
*/
|
|
||||||
public function addTitle($text, $depth = 1)
|
|
||||||
{
|
|
||||||
return $this->addElement('Title', $text, $depth);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a PageBreak Element
|
|
||||||
*/
|
|
||||||
public function addPageBreak()
|
|
||||||
{
|
|
||||||
return $this->addElement('PageBreak');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add a Table-of-Contents Element
|
|
||||||
*
|
|
||||||
* @param mixed $fontStyle
|
|
||||||
* @param mixed $tocStyle
|
|
||||||
* @param integer $minDepth
|
|
||||||
* @param integer $maxDepth
|
|
||||||
* @return \PhpOffice\PhpWord\Element\TOC
|
|
||||||
*/
|
|
||||||
public function addTOC($fontStyle = null, $tocStyle = null, $minDepth = 1, $maxDepth = 9)
|
|
||||||
{
|
|
||||||
return $this->addElement('TOC', $fontStyle, $tocStyle, $minDepth, $maxDepth);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -218,6 +180,30 @@ class Section extends AbstractContainer
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set section style
|
||||||
|
*
|
||||||
|
* @param array $settings
|
||||||
|
* @deprecated 0.12.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
public function setSettings($settings = null)
|
||||||
|
{
|
||||||
|
$this->setStyle($settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get section style
|
||||||
|
*
|
||||||
|
* @return \PhpOffice\PhpWord\Style\Section
|
||||||
|
* @deprecated 0.12.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
public function getSettings()
|
||||||
|
{
|
||||||
|
return $this->getStyle();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create header
|
* Create header
|
||||||
*
|
*
|
||||||
|
|||||||
88
src/PhpWord/Element/Shape.php
Normal file
88
src/PhpWord/Element/Shape.php
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||||
|
* word processing documents.
|
||||||
|
*
|
||||||
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||||
|
* General Public License version 3 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please read the LICENSE
|
||||||
|
* file that was distributed with this source code. For the full list of
|
||||||
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2010-2014 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Element;
|
||||||
|
|
||||||
|
use PhpOffice\PhpWord\Style\Shape as ShapeStyle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shape element
|
||||||
|
*
|
||||||
|
* @since 0.12.0
|
||||||
|
*/
|
||||||
|
class Shape extends AbstractElement
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Shape type arc|curve|line|polyline|rect|oval
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private $type;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shape style
|
||||||
|
*
|
||||||
|
* @var \PhpOffice\PhpWord\Style\Shape
|
||||||
|
*/
|
||||||
|
private $style;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new instance
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param mixed $style
|
||||||
|
*/
|
||||||
|
public function __construct($type, $style = null)
|
||||||
|
{
|
||||||
|
$this->setType($type);
|
||||||
|
$this->style = $this->setNewStyle(new ShapeStyle(), $style);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get type
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getType()
|
||||||
|
{
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set pattern
|
||||||
|
*
|
||||||
|
* @param string $value
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setType($value = null)
|
||||||
|
{
|
||||||
|
$enum = array('arc', 'curve', 'line', 'polyline', 'rect', 'oval');
|
||||||
|
$this->type = $this->setEnumVal($value, $enum, null);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get shape style
|
||||||
|
*
|
||||||
|
* @return \PhpOffice\PhpWord\Style\Shape
|
||||||
|
*/
|
||||||
|
public function getStyle()
|
||||||
|
{
|
||||||
|
return $this->style;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -129,9 +129,10 @@ class TOC extends AbstractElement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set max depth
|
* Set max depth.
|
||||||
*
|
*
|
||||||
* @param int $value
|
* @param int $value
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setMaxDepth($value)
|
public function setMaxDepth($value)
|
||||||
{
|
{
|
||||||
@ -149,9 +150,10 @@ class TOC extends AbstractElement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set min depth
|
* Set min depth.
|
||||||
*
|
*
|
||||||
* @param int $value
|
* @param int $value
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setMinDepth($value)
|
public function setMinDepth($value)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -52,7 +52,7 @@ class Table extends AbstractElement
|
|||||||
*/
|
*/
|
||||||
public function __construct($style = null)
|
public function __construct($style = null)
|
||||||
{
|
{
|
||||||
$this->style = $this->setStyle(new TableStyle(), $style);
|
$this->style = $this->setNewStyle(new TableStyle(), $style);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,9 +65,7 @@ class Table extends AbstractElement
|
|||||||
public function addRow($height = null, $style = null)
|
public function addRow($height = null, $style = null)
|
||||||
{
|
{
|
||||||
$row = new Row($height, $style);
|
$row = new Row($height, $style);
|
||||||
$row->setDocPart($this->getDocPart(), $this->getDocPartId());
|
$row->setParentContainer($this);
|
||||||
$row->setPhpWord($this->phpWord);
|
|
||||||
$row->setNestedLevel($this->getNestedLevel());
|
|
||||||
$this->rows[] = $row;
|
$this->rows[] = $row;
|
||||||
|
|
||||||
return $row;
|
return $row;
|
||||||
@ -120,9 +118,10 @@ class Table extends AbstractElement
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set table width
|
* Set table width.
|
||||||
*
|
*
|
||||||
* @param int $width
|
* @param int $width
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setWidth($width)
|
public function setWidth($width)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -45,7 +45,7 @@ class TextBox extends AbstractContainer
|
|||||||
*/
|
*/
|
||||||
public function __construct($style = null)
|
public function __construct($style = null)
|
||||||
{
|
{
|
||||||
$this->style = $this->setStyle(new TextBoxStyle(), $style);
|
$this->style = $this->setNewStyle(new TextBoxStyle(), $style);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -43,7 +43,7 @@ class TextRun extends AbstractContainer
|
|||||||
*/
|
*/
|
||||||
public function __construct($paragraphStyle = null)
|
public function __construct($paragraphStyle = null)
|
||||||
{
|
{
|
||||||
$this->paragraphStyle = $this->setStyle(new Paragraph(), $paragraphStyle);
|
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -46,6 +46,13 @@ class Title extends AbstractElement
|
|||||||
*/
|
*/
|
||||||
private $style;
|
private $style;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is part of collection
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $collectionRelation = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Title Element
|
* Create a new Title Element
|
||||||
*
|
*
|
||||||
@ -54,11 +61,10 @@ class Title extends AbstractElement
|
|||||||
*/
|
*/
|
||||||
public function __construct($text, $depth = 1)
|
public function __construct($text, $depth = 1)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->text = String::toUTF8($text);
|
$this->text = String::toUTF8($text);
|
||||||
$this->depth = $depth;
|
$this->depth = $depth;
|
||||||
if (array_key_exists('Heading_' . $this->depth, Style::getStyles())) {
|
if (array_key_exists("Heading_{$this->depth}", Style::getStyles())) {
|
||||||
$this->style = 'Heading' . $this->depth;
|
$this->style = "Heading{$this->depth}";
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|||||||
39
src/PhpWord/Exception/CopyFileException.php
Normal file
39
src/PhpWord/Exception/CopyFileException.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||||
|
* word processing documents.
|
||||||
|
*
|
||||||
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||||
|
* General Public License version 3 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please read the LICENSE
|
||||||
|
* file that was distributed with this source code. For the full list of
|
||||||
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2010-2014 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 0.12.0
|
||||||
|
*/
|
||||||
|
final class CopyFileException extends Exception
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param string $source The fully qualified source file name.
|
||||||
|
* @param string $destination The fully qualified destination file name.
|
||||||
|
* @param integer $code The user defined exception code.
|
||||||
|
* @param \Exception $previous The previous exception used for the exception chaining.
|
||||||
|
*/
|
||||||
|
final public function __construct($source, $destination, $code = 0, \Exception $previous = null)
|
||||||
|
{
|
||||||
|
parent::__construct(
|
||||||
|
sprintf('Could not copy \'%s\' file to \'%s\'.', $source, $destination),
|
||||||
|
$code,
|
||||||
|
$previous
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
37
src/PhpWord/Exception/CreateTemporaryFileException.php
Normal file
37
src/PhpWord/Exception/CreateTemporaryFileException.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||||
|
* word processing documents.
|
||||||
|
*
|
||||||
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||||
|
* General Public License version 3 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please read the LICENSE
|
||||||
|
* file that was distributed with this source code. For the full list of
|
||||||
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2010-2014 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Exception;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 0.12.0
|
||||||
|
*/
|
||||||
|
final class CreateTemporaryFileException extends Exception
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param integer $code The user defined exception code.
|
||||||
|
* @param \Exception $previous The previous exception used for the exception chaining.
|
||||||
|
*/
|
||||||
|
final public function __construct($code = 0, \Exception $previous = null)
|
||||||
|
{
|
||||||
|
parent::__construct(
|
||||||
|
'Could not create a temporary file with unique name in the specified directory.',
|
||||||
|
$code,
|
||||||
|
$previous
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,27 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* This file is part of PHPWord - A pure PHP library for reading and writing
|
* PHPWord
|
||||||
* word processing documents.
|
|
||||||
*
|
|
||||||
* PHPWord is free software distributed under the terms of the GNU Lesser
|
|
||||||
* General Public License version 3 as published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please read the LICENSE
|
|
||||||
* file that was distributed with this source code. For the full list of
|
|
||||||
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
|
||||||
*
|
*
|
||||||
* @link https://github.com/PHPOffice/PHPWord
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
* @copyright 2010-2014 PHPWord contributors
|
* @copyright 2014 PHPWord
|
||||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord;
|
namespace PhpOffice\PhpWord;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\Exception\Exception;
|
use PhpOffice\PhpWord\Exception\Exception;
|
||||||
|
use PhpOffice\PhpWord\Reader\ReaderInterface;
|
||||||
|
use PhpOffice\PhpWord\Writer\WriterInterface;
|
||||||
|
|
||||||
/**
|
|
||||||
* IO Factory
|
|
||||||
*/
|
|
||||||
abstract class IOFactory
|
abstract class IOFactory
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -29,50 +20,63 @@ abstract class IOFactory
|
|||||||
*
|
*
|
||||||
* @param PhpWord $phpWord
|
* @param PhpWord $phpWord
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return \PhpOffice\PhpWord\Writer\WriterInterface
|
* @return WriterInterface
|
||||||
* @throws \PhpOffice\PhpWord\Exception\Exception
|
* @throws \PhpOffice\PhpWord\Exception\Exception
|
||||||
*/
|
*/
|
||||||
public static function createWriter(PhpWord $phpWord, $name = 'Word2007')
|
public static function createWriter(PhpWord $phpWord, $name = 'Word2007')
|
||||||
{
|
{
|
||||||
$class = 'PhpOffice\\PhpWord\\Writer\\' . $name;
|
if ($name !== 'WriterInterface' && !in_array($name, array('ODText', 'RTF', 'Word2007', 'HTML', 'PDF'), true)) {
|
||||||
if (class_exists($class) && self::isConcreteClass($class)) {
|
|
||||||
return new $class($phpWord);
|
|
||||||
} else {
|
|
||||||
throw new Exception("\"{$name}\" is not a valid writer.");
|
throw new Exception("\"{$name}\" is not a valid writer.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$fqName = "PhpOffice\\PhpWord\\Writer\\{$name}";
|
||||||
|
|
||||||
|
return new $fqName($phpWord);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new reader
|
* Create new reader
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @return \PhpOffice\PhpWord\Reader\ReaderInterface
|
* @return ReaderInterface
|
||||||
* @throws \PhpOffice\PhpWord\Exception\Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static function createReader($name = 'Word2007')
|
public static function createReader($name = 'Word2007')
|
||||||
{
|
{
|
||||||
$class = 'PhpOffice\\PhpWord\\Reader\\' . $name;
|
return self::createObject('Reader', $name);
|
||||||
if (class_exists($class) && self::isConcreteClass($class)) {
|
|
||||||
return new $class();
|
|
||||||
} else {
|
|
||||||
throw new Exception("\"{$name}\" is not a valid reader.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new object
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
* @param string $name
|
||||||
|
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||||
|
* @return \PhpOffice\PhpWord\Writer\WriterInterface|\PhpOffice\PhpWord\Reader\ReaderInterface
|
||||||
|
* @throws \PhpOffice\PhpWord\Exception\Exception
|
||||||
|
*/
|
||||||
|
private static function createObject($type, $name, $phpWord = null)
|
||||||
|
{
|
||||||
|
$class = "PhpOffice\\PhpWord\\{$type}\\{$name}";
|
||||||
|
if (class_exists($class) && self::isConcreteClass($class)) {
|
||||||
|
return new $class($phpWord);
|
||||||
|
} else {
|
||||||
|
throw new Exception("\"{$name}\" is not a valid {$type}.");
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Loads PhpWord from file
|
* Loads PhpWord from file
|
||||||
*
|
*
|
||||||
* @param string $filename The name of the file
|
* @param string $filename The name of the file
|
||||||
* @param string $readerName
|
* @param string $readerName
|
||||||
* @return PhpWord
|
* @return \PhpOffice\PhpWord\PhpWord $phpWord
|
||||||
*/
|
*/
|
||||||
public static function load($filename, $readerName = 'Word2007')
|
public static function load($filename, $readerName = 'Word2007')
|
||||||
{
|
{
|
||||||
|
/** @var \PhpOffice\PhpWord\Reader\ReaderInterface $reader */
|
||||||
$reader = self::createReader($readerName);
|
$reader = self::createReader($readerName);
|
||||||
|
|
||||||
return $reader->load($filename);
|
return $reader->load($filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if it's a concrete class (not abstract nor interface)
|
* Check if it's a concrete class (not abstract nor interface)
|
||||||
*
|
*
|
||||||
@ -82,7 +86,6 @@ abstract class IOFactory
|
|||||||
private static function isConcreteClass($class)
|
private static function isConcreteClass($class)
|
||||||
{
|
{
|
||||||
$reflection = new \ReflectionClass($class);
|
$reflection = new \ReflectionClass($class);
|
||||||
|
|
||||||
return !$reflection->isAbstract() && !$reflection->isInterface();
|
return !$reflection->isAbstract() && !$reflection->isInterface();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,16 +44,16 @@ class Media
|
|||||||
* @since 0.9.2
|
* @since 0.9.2
|
||||||
* @since 0.10.0
|
* @since 0.10.0
|
||||||
*/
|
*/
|
||||||
public static function addElement($container, $mediaType, $source, Image &$image = null)
|
public static function addElement($container, $mediaType, $source, Image $image = null)
|
||||||
{
|
{
|
||||||
// Assign unique media Id and initiate media container if none exists
|
// Assign unique media Id and initiate media container if none exists
|
||||||
$mediaId = md5($container . $source);
|
$mediaId = md5($container . $source);
|
||||||
if (!array_key_exists($container, self::$elements)) {
|
if (!isset(self::$elements[$container])) {
|
||||||
self::$elements[$container] = array();
|
self::$elements[$container] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add media if not exists or point to existing media
|
// Add media if not exists or point to existing media
|
||||||
if (!array_key_exists($mediaId, self::$elements[$container])) {
|
if (!isset(self::$elements[$container][$mediaId])) {
|
||||||
$mediaCount = self::countElements($container);
|
$mediaCount = self::countElements($container);
|
||||||
$mediaTypeCount = self::countElements($container, $mediaType);
|
$mediaTypeCount = self::countElements($container, $mediaType);
|
||||||
$mediaTypeCount++;
|
$mediaTypeCount++;
|
||||||
@ -120,7 +120,7 @@ class Media
|
|||||||
{
|
{
|
||||||
$mediaCount = 0;
|
$mediaCount = 0;
|
||||||
|
|
||||||
if (array_key_exists($container, self::$elements)) {
|
if (isset(self::$elements[$container])) {
|
||||||
foreach (self::$elements[$container] as $mediaData) {
|
foreach (self::$elements[$container] as $mediaData) {
|
||||||
if (!is_null($mediaType)) {
|
if (!is_null($mediaType)) {
|
||||||
if ($mediaType == $mediaData['type']) {
|
if ($mediaType == $mediaData['type']) {
|
||||||
@ -156,7 +156,7 @@ class Media
|
|||||||
}
|
}
|
||||||
return $elements;
|
return $elements;
|
||||||
} else {
|
} else {
|
||||||
if (!array_key_exists($container, self::$elements)) {
|
if (!isset(self::$elements[$container])) {
|
||||||
return $elements;
|
return $elements;
|
||||||
}
|
}
|
||||||
return self::getElementsByType($container, $type);
|
return self::getElementsByType($container, $type);
|
||||||
|
|||||||
62
src/PhpWord/Metadata/Compatibility.php
Normal file
62
src/PhpWord/Metadata/Compatibility.php
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||||
|
* word processing documents.
|
||||||
|
*
|
||||||
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||||
|
* General Public License version 3 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please read the LICENSE
|
||||||
|
* file that was distributed with this source code. For the full list of
|
||||||
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2010-2014 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Metadata;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compatibility setting class
|
||||||
|
*
|
||||||
|
* @since 0.12.0
|
||||||
|
* @link http://www.datypic.com/sc/ooxml/t-w_CT_Compat.html
|
||||||
|
*/
|
||||||
|
class Compatibility
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* OOXML version
|
||||||
|
*
|
||||||
|
* 12 = 2007
|
||||||
|
* 14 = 2010
|
||||||
|
* 15 = 2013
|
||||||
|
*
|
||||||
|
* @var int
|
||||||
|
* @link http://msdn.microsoft.com/en-us/library/dd909048%28v=office.12%29.aspx
|
||||||
|
*/
|
||||||
|
private $ooxmlVersion = 12;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get OOXML version
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getOoxmlVersion()
|
||||||
|
{
|
||||||
|
return $this->ooxmlVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set OOXML version
|
||||||
|
*
|
||||||
|
* @param int $value
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setOoxmlVersion($value)
|
||||||
|
{
|
||||||
|
$this->ooxmlVersion = $value;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -15,12 +15,12 @@
|
|||||||
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace PhpOffice\PhpWord;
|
namespace PhpOffice\PhpWord\Metadata;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Document properties
|
* Document information
|
||||||
*/
|
*/
|
||||||
class DocumentProperties
|
class DocInfo
|
||||||
{
|
{
|
||||||
/** @const string Property type constants */
|
/** @const string Property type constants */
|
||||||
const PROPERTY_TYPE_BOOLEAN = 'b';
|
const PROPERTY_TYPE_BOOLEAN = 'b';
|
||||||
@ -115,7 +115,7 @@ class DocumentProperties
|
|||||||
private $customProperties = array();
|
private $customProperties = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new DocumentProperties
|
* Create new instance
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
69
src/PhpWord/Metadata/Protection.php
Normal file
69
src/PhpWord/Metadata/Protection.php
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of PHPWord - A pure PHP library for reading and writing
|
||||||
|
* word processing documents.
|
||||||
|
*
|
||||||
|
* PHPWord is free software distributed under the terms of the GNU Lesser
|
||||||
|
* General Public License version 3 as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please read the LICENSE
|
||||||
|
* file that was distributed with this source code. For the full list of
|
||||||
|
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
|
||||||
|
*
|
||||||
|
* @link https://github.com/PHPOffice/PHPWord
|
||||||
|
* @copyright 2010-2014 PHPWord contributors
|
||||||
|
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhpOffice\PhpWord\Metadata;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Document protection class
|
||||||
|
*
|
||||||
|
* @since 0.12.0
|
||||||
|
* @link http://www.datypic.com/sc/ooxml/t-w_CT_DocProtect.html
|
||||||
|
* @todo Password!
|
||||||
|
*/
|
||||||
|
class Protection
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Editing restriction readOnly|comments|trackedChanges|forms
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
* @link http://www.datypic.com/sc/ooxml/a-w_edit-1.html
|
||||||
|
*/
|
||||||
|
private $editing;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance
|
||||||
|
*
|
||||||
|
* @param string $editing
|
||||||
|
*/
|
||||||
|
public function __construct($editing = null)
|
||||||
|
{
|
||||||
|
$this->setEditing($editing);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get editing protection
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getEditing()
|
||||||
|
{
|
||||||
|
return $this->editing;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set editing protection
|
||||||
|
*
|
||||||
|
* @param string $editing
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setEditing($editing = null)
|
||||||
|
{
|
||||||
|
$this->editing = $editing;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -17,14 +17,28 @@
|
|||||||
|
|
||||||
namespace PhpOffice\PhpWord;
|
namespace PhpOffice\PhpWord;
|
||||||
|
|
||||||
use PhpOffice\PhpWord\Collection\Endnotes;
|
|
||||||
use PhpOffice\PhpWord\Collection\Footnotes;
|
|
||||||
use PhpOffice\PhpWord\Collection\Titles;
|
|
||||||
use PhpOffice\PhpWord\Element\Section;
|
use PhpOffice\PhpWord\Element\Section;
|
||||||
use PhpOffice\PhpWord\Exception\Exception;
|
use PhpOffice\PhpWord\Exception\Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PHPWord main class
|
* PHPWord main class
|
||||||
|
*
|
||||||
|
* @method Collection\Titles getTitles()
|
||||||
|
* @method Collection\Footnotes getFootnotes()
|
||||||
|
* @method Collection\Endnotes getEndnotes()
|
||||||
|
* @method Collection\Charts getCharts()
|
||||||
|
* @method int addBookmark(Element\Bookmark $bookmark)
|
||||||
|
* @method int addTitle(Element\Title $title)
|
||||||
|
* @method int addFootnote(Element\Footnote $footnote)
|
||||||
|
* @method int addEndnote(Element\Endnote $endnote)
|
||||||
|
* @method int addChart(Element\Chart $chart)
|
||||||
|
*
|
||||||
|
* @method Style\Paragraph addParagraphStyle(string $styleName, array $styles)
|
||||||
|
* @method Style\Font addFontStyle(string $styleName, mixed $fontStyle, mixed $paragraphStyle = null)
|
||||||
|
* @method Style\Font addLinkStyle(string $styleName, mixed $styles)
|
||||||
|
* @method Style\Font addTitleStyle(int $depth, mixed $fontStyle, mixed $paragraphStyle = null)
|
||||||
|
* @method Style\Table addTableStyle(string $styleName, mixed $styleTable, mixed $styleFirstRow = null)
|
||||||
|
* @method Style\Numbering addNumberingStyle(string $styleName, mixed $styles)
|
||||||
*/
|
*/
|
||||||
class PhpWord
|
class PhpWord
|
||||||
{
|
{
|
||||||
@ -39,13 +53,6 @@ class PhpWord
|
|||||||
const DEFAULT_FONT_COLOR = Settings::DEFAULT_FONT_COLOR;
|
const DEFAULT_FONT_COLOR = Settings::DEFAULT_FONT_COLOR;
|
||||||
const DEFAULT_FONT_CONTENT_TYPE = Settings::DEFAULT_FONT_CONTENT_TYPE;
|
const DEFAULT_FONT_CONTENT_TYPE = Settings::DEFAULT_FONT_CONTENT_TYPE;
|
||||||
|
|
||||||
/**
|
|
||||||
* Document properties object
|
|
||||||
*
|
|
||||||
* @var DocumentProperties
|
|
||||||
*/
|
|
||||||
private $documentProperties;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collection of sections
|
* Collection of sections
|
||||||
*
|
*
|
||||||
@ -54,58 +61,126 @@ class PhpWord
|
|||||||
private $sections = array();
|
private $sections = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collection of titles
|
* Collections
|
||||||
*
|
*
|
||||||
* @var \PhpOffice\PhpWord\Collection\Titles
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $titles;
|
private $collections = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collection of footnotes
|
* Metadata
|
||||||
*
|
*
|
||||||
* @var \PhpOffice\PhpWord\Collection\Footnotes
|
* @var array
|
||||||
|
* @since 0.12.0
|
||||||
*/
|
*/
|
||||||
private $footnotes;
|
private $metadata = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collection of endnotes
|
* Create new instance
|
||||||
*
|
*
|
||||||
* @var \PhpOffice\PhpWord\Collection\Endnotes
|
* Collections are created dynamically
|
||||||
*/
|
|
||||||
private $endnotes;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create new
|
|
||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->documentProperties = new DocumentProperties();
|
// Collection
|
||||||
$this->titles = new Titles();
|
$collections = array('Bookmarks', 'Titles', 'Footnotes', 'Endnotes', 'Charts');
|
||||||
$this->footnotes = new Footnotes();
|
foreach ($collections as $collection) {
|
||||||
$this->endnotes = new Endnotes();
|
$class = 'PhpOffice\\PhpWord\\Collection\\' . $collection;
|
||||||
|
$this->collections[$collection] = new $class();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Metadata
|
||||||
|
$metadata = array('DocInfo', 'Protection', 'Compatibility');
|
||||||
|
foreach ($metadata as $meta) {
|
||||||
|
$class = 'PhpOffice\\PhpWord\\Metadata\\' . $meta;
|
||||||
|
$this->metadata[$meta] = new $class();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dynamic function call to reduce static dependency
|
||||||
|
*
|
||||||
|
* @param mixed $function
|
||||||
|
* @param mixed $args
|
||||||
|
* @throws \BadMethodCallException
|
||||||
|
* @return mixed
|
||||||
|
* @since 0.12.0
|
||||||
|
*/
|
||||||
|
public function __call($function, $args)
|
||||||
|
{
|
||||||
|
$function = strtolower($function);
|
||||||
|
|
||||||
|
$getCollection = array();
|
||||||
|
$addCollection = array();
|
||||||
|
$addStyle = array();
|
||||||
|
|
||||||
|
$collections = array('Bookmark', 'Title', 'Footnote', 'Endnote', 'Chart');
|
||||||
|
foreach ($collections as $collection) {
|
||||||
|
$getCollection[] = strtolower("get{$collection}s");
|
||||||
|
$addCollection[] = strtolower("add{$collection}");
|
||||||
|
}
|
||||||
|
|
||||||
|
$styles = array('Paragraph', 'Font', 'Table', 'Numbering', 'Link', 'Title');
|
||||||
|
foreach ($styles as $style) {
|
||||||
|
$addStyle[] = strtolower("add{$style}Style");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run get collection method
|
||||||
|
if (in_array($function, $getCollection)) {
|
||||||
|
$key = ucfirst(str_replace('get', '', $function));
|
||||||
|
|
||||||
|
return $this->collections[$key];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run add collection item method
|
||||||
|
if (in_array($function, $addCollection)) {
|
||||||
|
$key = ucfirst(str_replace('add', '', $function) . 's');
|
||||||
|
|
||||||
|
/** @var \PhpOffice\PhpWord\Collection\AbstractCollection $collectionObject */
|
||||||
|
$collectionObject = $this->collections[$key];
|
||||||
|
|
||||||
|
return $collectionObject->addItem(isset($args[0]) ? $args[0] : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run add style method
|
||||||
|
if (in_array($function, $addStyle)) {
|
||||||
|
return forward_static_call_array(array('PhpOffice\\PhpWord\\Style', $function), $args);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exception
|
||||||
|
throw new \BadMethodCallException("Method $function is not defined.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get document properties object
|
* Get document properties object
|
||||||
*
|
*
|
||||||
* @return DocumentProperties
|
* @return \PhpOffice\PhpWord\Metadata\DocInfo
|
||||||
*/
|
*/
|
||||||
public function getDocumentProperties()
|
public function getDocInfo()
|
||||||
{
|
{
|
||||||
return $this->documentProperties;
|
return $this->metadata['DocInfo'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set document properties object
|
* Get protection
|
||||||
*
|
*
|
||||||
* @param DocumentProperties $documentProperties
|
* @return \PhpOffice\PhpWord\Metadata\Protection
|
||||||
* @return self
|
* @since 0.12.0
|
||||||
*/
|
*/
|
||||||
public function setDocumentProperties(DocumentProperties $documentProperties)
|
public function getProtection()
|
||||||
{
|
{
|
||||||
$this->documentProperties = $documentProperties;
|
return $this->metadata['Protection'];
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
/**
|
||||||
|
* Get compatibility
|
||||||
|
*
|
||||||
|
* @return \PhpOffice\PhpWord\Metadata\Compatibility
|
||||||
|
* @since 0.12.0
|
||||||
|
*/
|
||||||
|
public function getCompatibility()
|
||||||
|
{
|
||||||
|
return $this->metadata['Compatibility'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -121,81 +196,18 @@ class PhpWord
|
|||||||
/**
|
/**
|
||||||
* Create new section
|
* Create new section
|
||||||
*
|
*
|
||||||
* @param array $settings
|
* @param array $style
|
||||||
* @return \PhpOffice\PhpWord\Element\Section
|
* @return \PhpOffice\PhpWord\Element\Section
|
||||||
*/
|
*/
|
||||||
public function addSection($settings = null)
|
public function addSection($style = null)
|
||||||
{
|
{
|
||||||
$section = new Section(count($this->sections) + 1, $settings);
|
$section = new Section(count($this->sections) + 1, $style);
|
||||||
$section->setPhpWord($this);
|
$section->setPhpWord($this);
|
||||||
$this->sections[] = $section;
|
$this->sections[] = $section;
|
||||||
|
|
||||||
return $section;
|
return $section;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get titles
|
|
||||||
*
|
|
||||||
* @return \PhpOffice\PhpWord\Collection\Titles
|
|
||||||
*/
|
|
||||||
public function getTitles()
|
|
||||||
{
|
|
||||||
return $this->titles;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add new title
|
|
||||||
*
|
|
||||||
* @param \PhpOffice\PhpWord\Element\Title $title
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function addTitle($title)
|
|
||||||
{
|
|
||||||
return $this->titles->addItem($title);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get footnotes
|
|
||||||
*
|
|
||||||
* @return \PhpOffice\PhpWord\Collection\Footnotes
|
|
||||||
*/
|
|
||||||
public function getFootnotes()
|
|
||||||
{
|
|
||||||
return $this->footnotes;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add new footnote
|
|
||||||
*
|
|
||||||
* @param \PhpOffice\PhpWord\Element\Footnote $footnote
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function addFootnote($footnote)
|
|
||||||
{
|
|
||||||
return $this->footnotes->addItem($footnote);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get endnotes
|
|
||||||
*
|
|
||||||
* @return \PhpOffice\PhpWord\Collection\Endnotes
|
|
||||||
*/
|
|
||||||
public function getEndnotes()
|
|
||||||
{
|
|
||||||
return $this->endnotes;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add new endnote
|
|
||||||
*
|
|
||||||
* @param \PhpOffice\PhpWord\Element\Endnote $endnote
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function addEndnote($endnote)
|
|
||||||
{
|
|
||||||
return $this->endnotes->addItem($endnote);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get default font name
|
* Get default font name
|
||||||
*
|
*
|
||||||
@ -207,9 +219,10 @@ class PhpWord
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set default font name
|
* Set default font name.
|
||||||
*
|
*
|
||||||
* @param string $fontName
|
* @param string $fontName
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setDefaultFontName($fontName)
|
public function setDefaultFontName($fontName)
|
||||||
{
|
{
|
||||||
@ -227,9 +240,10 @@ class PhpWord
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set default font size
|
* Set default font size.
|
||||||
*
|
*
|
||||||
* @param int $fontSize
|
* @param int $fontSize
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setDefaultFontSize($fontSize)
|
public function setDefaultFontSize($fontSize)
|
||||||
{
|
{
|
||||||
@ -247,97 +261,61 @@ class PhpWord
|
|||||||
return Style::setDefaultParagraphStyle($styles);
|
return Style::setDefaultParagraphStyle($styles);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a paragraph style definition to styles.xml
|
|
||||||
*
|
|
||||||
* @param string $styleName
|
|
||||||
* @param array $styles
|
|
||||||
* @return \PhpOffice\PhpWord\Style\Paragraph
|
|
||||||
*/
|
|
||||||
public function addParagraphStyle($styleName, $styles)
|
|
||||||
{
|
|
||||||
return Style::addParagraphStyle($styleName, $styles);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a font style definition to styles.xml
|
|
||||||
*
|
|
||||||
* @param string $styleName
|
|
||||||
* @param mixed $fontStyle
|
|
||||||
* @param mixed $paragraphStyle
|
|
||||||
* @return \PhpOffice\PhpWord\Style\Font
|
|
||||||
*/
|
|
||||||
public function addFontStyle($styleName, $fontStyle, $paragraphStyle = null)
|
|
||||||
{
|
|
||||||
return Style::addFontStyle($styleName, $fontStyle, $paragraphStyle);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a table style definition to styles.xml
|
|
||||||
*
|
|
||||||
* @param string $styleName
|
|
||||||
* @param mixed $styleTable
|
|
||||||
* @param mixed $styleFirstRow
|
|
||||||
* @return \PhpOffice\PhpWord\Style\Table
|
|
||||||
*/
|
|
||||||
public function addTableStyle($styleName, $styleTable, $styleFirstRow = null)
|
|
||||||
{
|
|
||||||
return Style::addTableStyle($styleName, $styleTable, $styleFirstRow);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a numbering style
|
|
||||||
*
|
|
||||||
* @param string $styleName
|
|
||||||
* @param mixed $styles
|
|
||||||
* @return \PhpOffice\PhpWord\Style\Numbering
|
|
||||||
*/
|
|
||||||
public function addNumberingStyle($styleName, $styles)
|
|
||||||
{
|
|
||||||
return Style::addNumberingStyle($styleName, $styles);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a hyperlink style to styles.xml
|
|
||||||
*
|
|
||||||
* @param string $styleName
|
|
||||||
* @param mixed $styles
|
|
||||||
* @return \PhpOffice\PhpWord\Style\Font
|
|
||||||
*/
|
|
||||||
public function addLinkStyle($styleName, $styles)
|
|
||||||
{
|
|
||||||
return Style::addLinkStyle($styleName, $styles);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a heading style definition to styles.xml
|
|
||||||
*
|
|
||||||
* @param int $depth
|
|
||||||
* @param mixed $fontStyle
|
|
||||||
* @param mixed $paragraphStyle
|
|
||||||
* @return \PhpOffice\PhpWord\Style\Font
|
|
||||||
*/
|
|
||||||
public function addTitleStyle($depth, $fontStyle, $paragraphStyle = null)
|
|
||||||
{
|
|
||||||
return Style::addTitleStyle($depth, $fontStyle, $paragraphStyle);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load template by filename
|
* Load template by filename
|
||||||
*
|
*
|
||||||
|
* @deprecated 0.12.0 Use `new TemplateProcessor($documentTemplate)` instead.
|
||||||
|
*
|
||||||
* @param string $filename Fully qualified filename.
|
* @param string $filename Fully qualified filename.
|
||||||
* @return Template
|
* @return TemplateProcessor
|
||||||
* @throws \PhpOffice\PhpWord\Exception\Exception
|
* @throws \PhpOffice\PhpWord\Exception\Exception
|
||||||
*/
|
*/
|
||||||
public function loadTemplate($filename)
|
public function loadTemplate($filename)
|
||||||
{
|
{
|
||||||
if (file_exists($filename)) {
|
if (file_exists($filename)) {
|
||||||
return new Template($filename);
|
return new TemplateProcessor($filename);
|
||||||
} else {
|
} else {
|
||||||
throw new Exception("Template file {$filename} not found.");
|
throw new Exception("Template file {$filename} not found.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save to file or download
|
||||||
|
*
|
||||||
|
* All exceptions should already been handled by the writers
|
||||||
|
*
|
||||||
|
* @param string $filename
|
||||||
|
* @param string $format
|
||||||
|
* @param bool $download
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function save($filename, $format = 'Word2007', $download = false)
|
||||||
|
{
|
||||||
|
$mime = array(
|
||||||
|
'Word2007' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||||
|
'ODText' => 'application/vnd.oasis.opendocument.text',
|
||||||
|
'RTF' => 'application/rtf',
|
||||||
|
'HTML' => 'text/html',
|
||||||
|
'PDF' => 'application/pdf',
|
||||||
|
);
|
||||||
|
|
||||||
|
$writer = IOFactory::createWriter($this, $format);
|
||||||
|
|
||||||
|
if ($download === true) {
|
||||||
|
header("Content-Description: File Transfer");
|
||||||
|
header('Content-Disposition: attachment; filename="' . $filename . '"');
|
||||||
|
header('Content-Type: ' . $mime[$format]);
|
||||||
|
header('Content-Transfer-Encoding: binary');
|
||||||
|
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
|
||||||
|
header('Expires: 0');
|
||||||
|
$filename = 'php://output'; // Change filename to force download
|
||||||
|
}
|
||||||
|
|
||||||
|
$writer->save($filename);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new section
|
* Create new section
|
||||||
*
|
*
|
||||||
@ -350,4 +328,31 @@ class PhpWord
|
|||||||
{
|
{
|
||||||
return $this->addSection($settings);
|
return $this->addSection($settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get document properties object
|
||||||
|
*
|
||||||
|
* @return \PhpOffice\PhpWord\Metadata\DocInfo
|
||||||
|
* @deprecated 0.12.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
public function getDocumentProperties()
|
||||||
|
{
|
||||||
|
return $this->getDocInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set document properties object
|
||||||
|
*
|
||||||
|
* @param \PhpOffice\PhpWord\Metadata\DocInfo $documentProperties
|
||||||
|
* @return self
|
||||||
|
* @deprecated 0.12.0
|
||||||
|
* @codeCoverageIgnore
|
||||||
|
*/
|
||||||
|
public function setDocumentProperties($documentProperties)
|
||||||
|
{
|
||||||
|
$this->metadata['Document'] = $documentProperties;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2341
src/PhpWord/Reader/MsDoc.php
Normal file
2341
src/PhpWord/Reader/MsDoc.php
Normal file
File diff suppressed because it is too large
Load Diff
@ -51,15 +51,16 @@ class ODText extends AbstractReader implements ReaderInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read document part
|
* Read document part.
|
||||||
*
|
*
|
||||||
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
* @param \PhpOffice\PhpWord\PhpWord $phpWord
|
||||||
* @param array $relationships
|
* @param array $relationships
|
||||||
* @param string $partName
|
* @param string $partName
|
||||||
* @param string $docFile
|
* @param string $docFile
|
||||||
* @param string $xmlFile
|
* @param string $xmlFile
|
||||||
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function readPart(PhpWord &$phpWord, $relationships, $partName, $docFile, $xmlFile)
|
private function readPart(PhpWord $phpWord, $relationships, $partName, $docFile, $xmlFile)
|
||||||
{
|
{
|
||||||
$partClass = "PhpOffice\\PhpWord\\Reader\\ODText\\{$partName}";
|
$partClass = "PhpOffice\\PhpWord\\Reader\\ODText\\{$partName}";
|
||||||
if (class_exists($partClass)) {
|
if (class_exists($partClass)) {
|
||||||
@ -68,7 +69,6 @@ class ODText extends AbstractReader implements ReaderInterface
|
|||||||
$part->setRels($relationships);
|
$part->setRels($relationships);
|
||||||
$part->read($phpWord);
|
$part->read($phpWord);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user