diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 00000000..f3d033a7
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,21 @@
+# build config
+/.scrutinizer.yml export-ignore
+/.travis.yml export-ignore
+/php_cs.dist export-ignore
+/phpmd.xml.dist export-ignore
+/phpstan.neon export-ignore
+
+/composer.lock export-ignore
+
+# git files
+/.gitignore export-ignore
+/.gitattributes export-ignore
+
+# project directories
+/build export-ignore
+/docs export-ignore
+/samples export-ignore
+
+# tests
+/phpunit.xml.dist export-ignore
+/tests export-ignore
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index 2ac6e2b5..dd858cea 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,11 +13,11 @@ composer.phar
vendor
/report
/build
-/samples/resources
/samples/results
/.settings
phpword.ini
/.buildpath
+/.scannerwork
/.project
/nbproject
/.php_cs.cache
diff --git a/.travis.yml b/.travis.yml
index bd85b2d7..1d32cfda 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -10,11 +10,20 @@ php:
- 7.0
- 7.1
- 7.2
+ - 7.3
matrix:
include:
- - php: 5.6
+ - php: 7.0
env: COVERAGE=1
+ - php: 5.3
+ env: COMPOSER_MEMORY_LIMIT=2G
+ - php: 7.3
+ env: DEPENDENCIES="--ignore-platform-reqs"
+ exclude:
+ - php: 5.3
+ - php: 7.0
+ - php: 7.3
cache:
directories:
@@ -32,12 +41,12 @@ before_install:
before_script:
## Deactivate xdebug if we don't do code coverage
- - if [ -z "$COVERAGE" ]; then phpenv config-rm xdebug.ini ; fi
+ - if [ -z "$COVERAGE" ]; then phpenv config-rm xdebug.ini || echo "xdebug not available" ; fi
## Composer
- composer self-update
- - travis_wait composer install --prefer-source
+ - travis_wait composer install --prefer-source $(if [ -n "$DEPENDENCIES" ]; then echo $DEPENDENCIES; fi)
## PHPDocumentor
- - mkdir -p build/docs
+ ##- mkdir -p build/docs
- mkdir -p build/coverage
script:
@@ -52,7 +61,7 @@ script:
## PHPLOC
- if [ -z "$COVERAGE" ]; then ./vendor/bin/phploc src/ ; fi
## PHPDocumentor
- - if [ -z "$COVERAGE" ]; then ./vendor/bin/phpdoc -q -d ./src -t ./build/docs --ignore "*/src/PhpWord/Shared/*/*" --template="responsive-twig" ; fi
+ ##- if [ -z "$COVERAGE" ]; then ./vendor/bin/phpdoc -q -d ./src -t ./build/docs --ignore "*/src/PhpWord/Shared/*/*" --template="responsive-twig" ; fi
after_success:
## Coveralls
diff --git a/CHANGELOG.md b/CHANGELOG.md
index dfcce5a4..9ec1deef 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,7 +3,47 @@ Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
-v0.15.0 (?? ??? 2018)
+v0.17.0 (?? ??? 2019)
+----------------------
+### Added
+- Add RightToLeft table presentation. @troosan #1550
+- Set complex type in template @troosan #1565
+- Add support for page vertical alignment. @troosan #672 #1569
+
+### Fixed
+- Fix HTML border-color parsing. @troosan #1551 #1570
+
+### Miscelaneous
+- Use embedded http server to test loading of remote images @troosan #
+
+v0.16.0 (30 dec 2018)
+----------------------
+### Added
+- Add getVariableCount method in TemplateProcessor. @nicoder #1272
+- Add setting Chart Title and Legend visibility @Tom-Magill #1433
+- Add ability to pass a Style object in Section constructor @ndench #1416
+- Add support for hidden text @Alexmg86 #1527
+- Add support for setting images in TemplateProcessor @SailorMax #1170
+- Add "Plain Text" type to SDT (Structured Document Tags) @morrisdj #1541
+- Added possibility to index variables inside cloned block in TemplateProcessor @JPBetley #817
+- Added possibility to replace variables inside cloned block with values in TemplateProcessor @DIDoS #1392
+
+### Fixed
+- Fix regex in `cloneBlock` function @nicoder #1269
+- HTML Title Writer loses text when Title contains a TextRun instead a string. @begnini #1436
+- Fix regex in fixBrokenMacros, make it less greedy @MuriloSo @brainwood @yurii-sio2 #1502 #1345
+- 240 twips are being added to line spacing, should not happen when using lineRule fixed @troosan #1509 #1505
+- Adding table layout to the generated HTML @aarangara #1441
+- Fix loading of Sharepoint document @Garrcomm #1498
+- RTF writer: Round getPageSizeW and getPageSizeH to avoid decimals @Patrick64 #1493
+- Fix parsing of Office 365 documents @Timanx #1485
+- For RTF writers, sizes should should never have decimals @Samuel-BF #1536
+- Style Name Parsing fails if document generated by a non-english word version @begnini #1434
+
+### Miscelaneous
+- Get rid of duplicated code in TemplateProcessor @abcdmitry #1161
+
+v0.15.0 (14 Jul 2018)
----------------------
### Added
- Parsing of `align` HTML attribute - @troosan #1231
@@ -23,6 +63,9 @@ v0.15.0 (?? ??? 2018)
- Add support for table indent (tblInd) @Trainmaster #1343
- Added parsing of internal links in HTML reader @lalop #1336
- Several improvements to charts @JAEK-S #1332
+- Add parsing of html image in base64 format @jgpATs2w #1382
+- Added Support for Indentation & Tabs on RTF Writer. @smaug1985 #1405
+- Allows decimal numbers in HTML line-height style @jgpATs2w #1413
### Fixed
- Fix reading of docx default style - @troosan #1238
@@ -35,6 +78,9 @@ v0.15.0 (?? ??? 2018)
- Fix colspan and rowspan for tables in HTML Writer @mattbolt #1292
- Fix parsing of Heading and Title formating @troosan @gthomas2 #465
- Fix Dateformat typo, fix hours casing, add Month-Day-Year formats @ComputerTinker #591
+- Support reading of w:drawing for documents produced by word 2011+ @gthomas2 #464 #1324
+- Fix missing column width in ODText writer @potofcoffee #413
+- Disable entity loader before parsing XML to avoid XXE injection @Tom4t0 #1427
### Changed
- Remove zend-stdlib dependency @Trainmaster #1284
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index e62f2e6f..43ee0636 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -6,7 +6,7 @@ We want to create a high quality document writer and reader library that people
- **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.
- **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, it's completely your 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.
+- **Test your code**. Nobody else knows your code better than you. So, it's completely your 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.readthedocs.io) you can find documentation on how to write tests with PHPUnit, 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 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!
diff --git a/README.md b/README.md
index 7531a6bc..f1d1d6ee 100644
--- a/README.md
+++ b/README.md
@@ -1,13 +1,20 @@
# 
+Master:
[](https://packagist.org/packages/phpoffice/phpword)
[](https://travis-ci.org/PHPOffice/PHPWord)
-[](https://scrutinizer-ci.com/g/PHPOffice/PHPWord/)
-[](https://coveralls.io/github/PHPOffice/PHPWord?branch=develop)
+[](https://scrutinizer-ci.com/g/PHPOffice/PHPWord/)
+[](https://coveralls.io/github/PHPOffice/PHPWord?branch=master)
[](https://packagist.org/packages/phpoffice/phpword)
[](https://packagist.org/packages/phpoffice/phpword)
[](https://gitter.im/PHPOffice/PHPWord)
+Develop:
+[](https://packagist.org/packages/phpoffice/phpword#dev-develop)
+[](https://travis-ci.org/PHPOffice/PHPWord/branches)
+[](https://scrutinizer-ci.com/g/PHPOffice/PHPWord/?branch=develop)
+[](https://coveralls.io/github/PHPOffice/PHPWord?branch=develop)
+
PHPWord is a library written in pure PHP that provides a set of classes to write to and read from different document file formats. The current version of PHPWord supports Microsoft [Office Open XML](http://en.wikipedia.org/wiki/Office_Open_XML) (OOXML or OpenXML), OASIS [Open Document Format for Office Applications](http://en.wikipedia.org/wiki/OpenDocument) (OpenDocument or ODF), [Rich Text Format](http://en.wikipedia.org/wiki/Rich_Text_Format) (RTF), HTML, and PDF.
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/).
@@ -81,7 +88,7 @@ You can of course also manually edit your composer.json file
```json
{
"require": {
- "phpoffice/phpword": "v0.14.*"
+ "phpoffice/phpword": "v0.16.*"
}
}
```
@@ -161,7 +168,7 @@ $objWriter->save('helloWorld.html');
```
More examples are provided in the [samples folder](samples/). For an easy access to those samples launch `php -S localhost:8000` in the samples directory then browse to [http://localhost:8000](http://localhost:8000) to view the 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.
+You can also read the [Developers' Documentation](http://phpword.readthedocs.org/) for more detail.
## Contributing
diff --git a/composer.json b/composer.json
index c29e901a..bd57d6e3 100644
--- a/composer.json
+++ b/composer.json
@@ -45,7 +45,7 @@
"php-cs-fixer fix --ansi --dry-run --diff",
"phpcs --report-width=200 --report-summary --report-full samples/ src/ tests/ --ignore=src/PhpWord/Shared/PCLZip --standard=PSR2 -n",
"phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php",
- "@test"
+ "@test-no-coverage"
],
"fix": [
"php-cs-fixer fix --ansi"
@@ -61,18 +61,19 @@
"php": "^5.3.3 || ^7.0",
"ext-xml": "*",
"zendframework/zend-escaper": "^2.2",
- "phpoffice/common": "^0.2"
+ "phpoffice/common": "^0.2.9"
},
"require-dev": {
- "phpunit/phpunit": "^4.8.36 || ^5.0",
- "phpdocumentor/phpdocumentor":"2.*",
- "squizlabs/php_codesniffer": "^2.7",
- "friendsofphp/php-cs-fixer": "^2.0",
+ "ext-zip": "*",
+ "ext-gd": "*",
+ "phpunit/phpunit": "^4.8.36 || ^7.0",
+ "squizlabs/php_codesniffer": "^2.9",
+ "friendsofphp/php-cs-fixer": "^2.2",
"phpmd/phpmd": "2.*",
"phploc/phploc": "2.* || 3.* || 4.*",
"dompdf/dompdf":"0.8.*",
"tecnickcom/tcpdf": "6.*",
- "mpdf/mpdf": "5.* || 6.* || 7.*",
+ "mpdf/mpdf": "5.7.4 || 6.* || 7.*",
"php-coveralls/php-coveralls": "1.1.0 || ^2.0"
},
"suggest": {
@@ -89,7 +90,7 @@
},
"extra": {
"branch-alias": {
- "dev-develop": "0.15-dev"
+ "dev-develop": "0.17-dev"
}
}
}
diff --git a/docs/PULL_REQUEST_TEMPLATE.md b/docs/PULL_REQUEST_TEMPLATE.md
index 24ba001c..5430a996 100644
--- a/docs/PULL_REQUEST_TEMPLATE.md
+++ b/docs/PULL_REQUEST_TEMPLATE.md
@@ -8,4 +8,4 @@ Fixes # (issue)
- [ ] I have run `composer run-script check --timeout=0` and no errors were reported
- [ ] The new code is covered by unit tests (check build/coverage for coverage report)
-- [ ] I have update the documentation to describe the changes
+- [ ] I have updated the documentation to describe the changes
diff --git a/docs/conf.py b/docs/conf.py
index 6b7cf8e8..d83c43f5 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -48,7 +48,7 @@ copyright = u'2014-2017, PHPWord Contributors'
# built documents.
#
# The short X.Y version.
-version = '0.14.0'
+version = '0.16.0'
# The full version, including alpha/beta/rc tags.
release = version
diff --git a/docs/containers.rst b/docs/containers.rst
index dc194d59..9ee58efc 100644
--- a/docs/containers.rst
+++ b/docs/containers.rst
@@ -104,6 +104,12 @@ You can pass an optional parameter to specify where the header/footer should be
- ``Footer::FIRST`` each first page of the section
- ``Footer::EVEN`` each even page of the section. Will only be applied if the evenAndOddHeaders is set to true in phpWord->settings
+To change the evenAndOddHeaders use the ``getSettings`` method to return the Settings object, and then call the ``setEvenAndOddHeaders`` method:
+
+.. code-block:: php
+
+ $phpWord->getSettings()->setEvenAndOddHeaders(true);
+
Footers
-------
diff --git a/docs/elements.rst b/docs/elements.rst
index 74b1d56f..9d446b27 100644
--- a/docs/elements.rst
+++ b/docs/elements.rst
@@ -61,7 +61,7 @@ Legend:
Texts
-----
-Text can be added by using ``addText`` and ``addTextRun`` method.
+Text can be added by using ``addText`` and ``addTextRun`` methods.
``addText`` is used for creating simple paragraphs that only contain texts with the same style.
``addTextRun`` is used for creating complex paragraphs that contain text with different style (some bold, other
italics, etc) or other elements, e.g. images or links. The syntaxes are as follow:
@@ -155,13 +155,18 @@ method or using the ``pageBreakBefore`` style of paragraph.
Lists
-----
-To add a list item use the function ``addListItem``.
+Lists can be added by using ``addListItem`` and ``addListItemRun`` methods.
+``addListItem`` is used for creating lists that only contain plain text.
+``addListItemRun`` is used for creating complex list items that contains texts
+with different style (some bold, other italics, etc) or other elements, e.g.
+images or links. The syntaxes are as follow:
Basic usage:
.. code-block:: php
$section->addListItem($text, [$depth], [$fontStyle], [$listStyle], [$paragraphStyle]);
+ $listItemRun = $section->addListItemRun([$depth], [$listStyle], [$paragraphStyle])
Parameters:
@@ -172,6 +177,8 @@ Parameters:
TYPE\_ALPHANUM, TYPE\_BULLET\_FILLED, etc. See list of constants in PHPWord\\Style\\ListItem.
- ``$paragraphStyle``. See :ref:`paragraph-style`.
+See ``Sample_09_Tables.php`` for more code sample.
+
Advanced usage:
You can also create your own numbering style by changing the ``$listStyle`` parameter with the name of your numbering style.
diff --git a/docs/styles.rst b/docs/styles.rst
index 03366427..27f8ee66 100644
--- a/docs/styles.rst
+++ b/docs/styles.rst
@@ -29,8 +29,11 @@ Available Section style options:
- ``marginRight``. Page margin right in *twip*.
- ``marginBottom``. Page margin bottom in *twip*.
- ``orientation``. Page orientation (``portrait``, which is default, or ``landscape``).
+ See ``\PhpOffice\PhpWord\Style\Section::ORIENTATION_...`` class constants for possible values
- ``pageSizeH``. Page height in *twip*. Implicitly defined by ``orientation`` option. Any changes are discouraged.
- ``pageSizeW``. Page width in *twip*. Implicitly defined by ``orientation`` option. Any changes are discouraged.
+- ``vAlign``. Vertical Page Alignment
+ See ``\PhpOffice\PhpWord\SimpleType\VerticalJc`` for possible values
.. _font-style:
@@ -45,7 +48,7 @@ Available Font style options:
- ``color``. Font color, e.g. *FF0000*.
- ``doubleStrikethrough``. Double strikethrough, *true* or *false*.
- ``fgColor``. Font highlight color, e.g. *yellow*, *green*, *blue*.
- See ``\PhpOffice\PhpWord\Style\Font::FGCOLOR_...`` constants for more values
+ See ``\PhpOffice\PhpWord\Style\Font::FGCOLOR_...`` class constants for possible values
- ``hint``. Font content type, *default*, *eastAsia*, or *cs*.
- ``italic``. Italic, *true* or *false*.
- ``name``. Font name, e.g. *Arial*.
@@ -56,10 +59,11 @@ Available Font style options:
- ``subScript``. Subscript, *true* or *false*.
- ``superScript``. Superscript, *true* or *false*.
- ``underline``. Underline, *single*, *dash*, *dotted*, etc.
- See ``\PhpOffice\PhpWord\Style\Font::UNDERLINE_...`` constants for more values
+ See ``\PhpOffice\PhpWord\Style\Font::UNDERLINE_...`` class constants for possible values
- ``lang``. Language, either a language code like *en-US*, *fr-BE*, etc. or an object (or as an array) if you need to set eastAsian or bidirectional languages
See ``\PhpOffice\PhpWord\Style\Language`` class for some language codes.
- ``position``. The text position, raised or lowered, in half points
+- ``hidden``. Hidden text, *true* or *false*.
.. _paragraph-style:
@@ -69,7 +73,7 @@ Paragraph
Available Paragraph style options:
- ``alignment``. Supports all alignment modes since 1st Edition of ECMA-376 standard up till ISO/IEC 29500:2012.
- See ``\PhpOffice\PhpWord\SimpleType\Jc`` class for the details.
+ See ``\PhpOffice\PhpWord\SimpleType\Jc`` class constants for possible values.
- ``basedOn``. Parent style.
- ``hanging``. Hanging in *twip*.
- ``indent``. Indent in *twip*.
@@ -80,8 +84,9 @@ Available Paragraph style options:
- ``pageBreakBefore``. Start paragraph on next page, *true* or *false*.
- ``spaceBefore``. Space before paragraph in *twip*.
- ``spaceAfter``. Space after paragraph in *twip*.
-- ``spacing``. Space between lines.
+- ``spacing``. Space between lines in *twip*. If spacingLineRule is auto, 240 (height of 1 line) will be added, so if you want a double line height, set this to 240.
- ``spacingLineRule``. Line Spacing Rule. *auto*, *exact*, *atLeast*
+ See ``\PhpOffice\PhpWord\SimpleType\LineSpacingRule`` class constants for possible values.
- ``suppressAutoHyphens``. Hyphenation for paragraph, *true* or *false*.
- ``tabs``. Set of custom tab stops.
- ``widowControl``. Allow first/last line to display on a separate page, *true* or *false*.
@@ -89,7 +94,7 @@ Available Paragraph style options:
- ``bidi``. Right to Left Paragraph Layout, *true* or *false*.
- ``shading``. Paragraph Shading.
- ``textAlignment``. Vertical Character Alignment on Line.
- See ``\PhpOffice\PhpWord\SimpleType\TextAlignment`` class for possible values.
+ See ``\PhpOffice\PhpWord\SimpleType\TextAlignment`` class constants for possible values.
.. _table-style:
@@ -99,17 +104,18 @@ Table
Available Table style options:
- ``alignment``. Supports all alignment modes since 1st Edition of ECMA-376 standard up till ISO/IEC 29500:2012.
- See ``\PhpOffice\PhpWord\SimpleType\JcTable`` and ``\PhpOffice\PhpWord\SimpleType\Jc`` classes for the details.
+ See ``\PhpOffice\PhpWord\SimpleType\JcTable`` and ``\PhpOffice\PhpWord\SimpleType\Jc`` class constants for possible values.
- ``bgColor``. Background color, e.g. '9966CC'.
- ``border(Top|Right|Bottom|Left)Color``. Border color, e.g. '9966CC'.
- ``border(Top|Right|Bottom|Left)Size``. Border size in *twip*.
- ``cellMargin(Top|Right|Bottom|Left)``. Cell margin in *twip*.
- ``indent``. Table indent from leading margin. Must be an instance of ``\PhpOffice\PhpWord\ComplexType\TblWidth``.
-- ``width``. Table width in percent.
+- ``width``. Table width in Fiftieths of a Percent or Twentieths of a Point.
- ``unit``. The unit to use for the width. One of ``\PhpOffice\PhpWord\SimpleType\TblWidth``. Defaults to *auto*.
- ``layout``. Table layout, either *fixed* or *autofit* See ``\PhpOffice\PhpWord\Style\Table`` for constants.
- ``cellSpacing`` Cell spacing in *twip*
- ``position`` Floating Table Positioning, see below for options
+- ``bidiVisual`` Present table as Right-To-Left
Floating Table Positioning options:
@@ -168,7 +174,7 @@ Numbering level
Available NumberingLevel style options:
- ``alignment``. Supports all alignment modes since 1st Edition of ECMA-376 standard up till ISO/IEC 29500:2012.
- See ``\PhpOffice\PhpWord\SimpleType\Jc`` class for the details.
+ See ``\PhpOffice\PhpWord\SimpleType\Jc`` class constants for possible values.
- ``font``. Font name.
- ``format``. Numbering format bullet\|decimal\|upperRoman\|lowerRoman\|upperLetter\|lowerLetter.
- ``hanging``. See paragraph style.
@@ -190,6 +196,14 @@ Available Chart style options:
- ``width``. Width (in EMU).
- ``height``. Height (in EMU).
- ``3d``. Is 3D; applies to pie, bar, line, area, *true* or *false*.
+- ``colors``. A list of colors to use in the chart.
+- ``title``. The title for the chart.
+- ``showLegend``. Show legend, *true* or *false*.
+- ``categoryLabelPosition``. Label position for categories, *nextTo* (default), *low* or *high*.
+- ``valueLabelPosition``. Label position for values, *nextTo* (default), *low* or *high*.
+- ``categoryAxisTitle``. The title for the category axis.
+- ``valueAxisTitle``. The title for the values axis.
+- ``majorTickMarkPos``. The position for major tick marks, *in*, *out*, *cross*, *none* (default).
- ``showAxisLabels``. Show labels for axis, *true* or *false*.
- ``gridX``. Show Gridlines for X-Axis, *true* or *false*.
- ``gridY``. Show Gridlines for Y-Axis, *true* or *false*.
diff --git a/docs/templates-processing.rst b/docs/templates-processing.rst
index af03b245..5b32aa18 100644
--- a/docs/templates-processing.rst
+++ b/docs/templates-processing.rst
@@ -4,22 +4,243 @@ Templates processing
====================
You can create an OOXML document template with included search-patterns (macros) which can be replaced by any value you wish. Only single-line values can be replaced.
+Macros are defined like this: ``${search-pattern}``.
+To load a template file, create a new instance of the TemplateProcessor.
-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}``.
+.. code-block:: php
+
+ $templateProcessor = new TemplateProcessor('Template.docx');
+
+setValue
+""""""""
+Given a template containing
+
+.. code-block:: clean
+
+ Hello ${firstname} ${lastname}!
+
+The following will replace ``${firstname}`` with ``John``, and ``${lastname}`` with ``Doe`` .
+The resulting document will now contain ``Hello John Doe!``
+
+.. code-block:: php
+
+ $templateProcessor->setValue('firstname', 'John');
+ $templateProcessor->setValue('lastname', 'Doe');
+
+setValues
+"""""""""
+You can also set multiple values by passing all of them in an array.
+
+.. code-block:: php
+
+ $templateProcessor->setValues(array('firstname' => 'John', 'lastname' => 'Doe'));
+
+setImageValue
+"""""""""""""
+The search-pattern model for images can be like:
+ - ``${search-image-pattern}``
+ - ``${search-image-pattern:[width]:[height]:[ratio]}``
+ - ``${search-image-pattern:[width]x[height]}``
+ - ``${search-image-pattern:size=[width]x[height]}``
+ - ``${search-image-pattern:width=[width]:height=[height]:ratio=false}``
+
+Where:
+ - [width] and [height] can be just numbers or numbers with measure, which supported by Word (cm, mm, in, pt, pc, px, %, em, ex)
+ - [ratio] uses only for ``false``, ``-`` or ``f`` to turn off respect aspect ration of image. By default template image size uses as 'container' size.
Example:
+.. code-block:: clean
+
+ ${CompanyLogo}
+ ${UserLogo:50:50} ${Name} - ${City} - ${Street}
+
.. code-block:: php
$templateProcessor = new TemplateProcessor('Template.docx');
$templateProcessor->setValue('Name', 'John Doe');
$templateProcessor->setValue(array('City', 'Street'), array('Detroit', '12th Street'));
-It is not possible to directly add new OOXML elements to the template file being processed, but it is possible to transform headers, main document part, and footers of the template using XSLT (see ``TemplateProcessor::applyXslStyleSheet``).
+ $templateProcessor->setImageValue('CompanyLogo', 'path/to/company/logo.png');
+ $templateProcessor->setImageValue('UserLogo', array('path' => 'path/to/logo.png', 'width' => 100, 'height' => 100, 'ratio' => false));
-See ``Sample_07_TemplateCloneRow.php`` for example on how to create
-multirow from a single row in a template by using ``TemplateProcessor::cloneRow``.
+cloneBlock
+""""""""""
+Given a template containing
+See ``Sample_23_TemplateBlock.php`` for an example.
-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``.
+.. code-block:: clean
+
+ ${block_name}
+ Customer: ${customer_name}
+ Address: ${customer_address}
+ ${/block_name}
+
+The following will duplicate everything between ``${block_name}`` and ``${/block_name}`` 3 times.
+
+.. code-block:: php
+
+ $templateProcessor->cloneBlock('block_name', 3, true, true);
+
+The last parameter will rename any macro defined inside the block and add #1, #2, #3 ... to the macro name.
+The result will be
+
+.. code-block:: clean
+
+ Customer: ${customer_name#1}
+ Address: ${customer_address#1}
+
+ Customer: ${customer_name#2}
+ Address: ${customer_address#2}
+
+ Customer: ${customer_name#3}
+ Address: ${customer_address#3}
+
+It is also possible to pass an array with the values to replace the marcros with.
+If an array with replacements is passed, the ``count`` argument is ignored, it is the size of the array that counts.
+
+.. code-block:: php
+
+ $replacements = array(
+ array('customer_name' => 'Batman', 'customer_address' => 'Gotham City'),
+ array('customer_name' => 'Superman', 'customer_address' => 'Metropolis'),
+ );
+ $templateProcessor->cloneBlock('block_name', 0, true, false, $replacements);
+
+The result will then be
+
+.. code-block:: clean
+
+ Customer: Batman
+ Address: Gotham City
+
+ Customer: Superman
+ Address: Metropolis
+
+replaceBlock
+""""""""""""
+Given a template containing
+
+.. code-block:: clean
+
+ ${block_name}
+ This block content will be replaced
+ ${/block_name}
+
+The following will replace everything between``${block_name}`` and ``${/block_name}`` with the value passed.
+
+.. code-block:: php
+
+ $templateProcessor->replaceBlock('block_name', 'This is the replacement text.');
+
+deleteBlock
+"""""""""""
+Same as previous, but it deletes the block
+
+.. code-block:: php
+
+ $templateProcessor->deleteBlock('block_name');
+
+cloneRow
+""""""""
+Clones a table row in a template document.
+See ``Sample_07_TemplateCloneRow.php`` for an example.
+
+.. code-block:: clean
+
+ +-----------+----------------+
+ | ${userId} | ${userName} |
+ | |----------------+
+ | | ${userAddress} |
+ +-----------+----------------+
+
+.. code-block:: php
+
+ $templateProcessor->cloneRow('userId', 2);
+
+Will result in
+
+.. code-block:: clean
+
+ +-------------+------------------+
+ | ${userId#1} | ${userName#1} |
+ | |------------------+
+ | | ${userAddress#1} |
+ +-------------+------------------+
+ | ${userId#2} | ${userName#2} |
+ | |------------------+
+ | | ${userAddress#2} |
+ +-------------+------------------+
+
+cloneRowAndSetValues
+""""""""""""""""""""
+Finds a row in a table row identified by `$search` param and clones it as many times as there are entries in `$values`.
+
+.. code-block:: clean
+
+ +-----------+----------------+
+ | ${userId} | ${userName} |
+ | |----------------+
+ | | ${userAddress} |
+ +-----------+----------------+
+
+.. code-block:: php
+
+ $values = [
+ ['userId' => 1, 'userName' => 'Batman', 'userAddress' => 'Gotham City'],
+ ['userId' => 2, 'userName' => 'Superman', 'userAddress' => 'Metropolis'],
+ ];
+ $templateProcessor->cloneRowAndSetValues('userId', );
+
+Will result in
+
+.. code-block:: clean
+
+ +---+-------------+
+ | 1 | Batman |
+ | |-------------+
+ | | Gotham City |
+ +---+-------------+
+ | 2 | Superman |
+ | |-------------+
+ | | Metropolis |
+ +---+-------------+
+
+applyXslStyleSheet
+""""""""""""""""""
+Applies the XSL stylesheet passed to header part, footer part and main part
+
+.. code-block:: php
+
+ $xslDomDocument = new \DOMDocument();
+ $xslDomDocument->load('/path/to/my/stylesheet.xsl');
+ $templateProcessor->applyXslStyleSheet($xslDomDocument);
+
+setComplexValue
+"""""""""""""""
+Raplaces a ${macro} with the ComplexType passed.
+See ``Sample_40_TemplateSetComplexValue.php`` for examples.
+
+.. code-block:: php
+
+ $inline = new TextRun();
+ $inline->addText('by a red italic text', array('italic' => true, 'color' => 'red'));
+ $templateProcessor->setComplexValue('inline', $inline);
+
+setComplexBlock
+"""""""""""""""
+Raplaces a ${macro} with the ComplexType passed.
+See ``Sample_40_TemplateSetComplexValue.php`` for examples.
+
+.. code-block:: php
+
+ $table = new Table(array('borderSize' => 12, 'borderColor' => 'green', 'width' => 6000, 'unit' => TblWidth::TWIP));
+ $table->addRow();
+ $table->addCell(150)->addText('Cell A1');
+ $table->addCell(150)->addText('Cell A2');
+ $table->addCell(150)->addText('Cell A3');
+ $table->addRow();
+ $table->addCell(150)->addText('Cell B1');
+ $table->addCell(150)->addText('Cell B2');
+ $table->addCell(150)->addText('Cell B3');
+ $templateProcessor->setComplexBlock('table', $table);
diff --git a/phpstan.neon b/phpstan.neon
index 5ae6d0f2..666c63b9 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -1,7 +1,7 @@
includes:
- vendor/phpstan/phpstan/conf/config.level1.neon
parameters:
- memory-limit: 200000
+ memory-limit: 20000000
autoload_directories:
- tests
autoload_files:
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 015dd2ed..4a882446 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -6,8 +6,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
- stopOnFailure="false"
- syntaxCheck="false">
+ stopOnFailure="false">
The text below is not visible, click on show/hide to reveil it:
-
';
@@ -89,6 +89,9 @@ $html .= '
+ 1 2 1 2 This is bold text 6
';
+$html .= 'Cell in parent table
Ordered (numbered) list:
Double height
+ +
+
+
+
+