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 e5deb643..b2ec7e23 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,14 +6,19 @@ Thumbs.db
Desktop.ini
.idea
_build
+/build
phpunit.xml
composer.lock
composer.phar
vendor
/report
+/build
/samples/resources
/samples/results
/.settings
phpword.ini
/.buildpath
-/.project
\ No newline at end of file
+/.scannerwork
+/.project
+/nbproject
+/.php_cs.cache
diff --git a/.php_cs.dist b/.php_cs.dist
new file mode 100644
index 00000000..895ed80f
--- /dev/null
+++ b/.php_cs.dist
@@ -0,0 +1,146 @@
+notName('pclzip.lib.php')
+ ->notName('OLERead.php')
+ ->in('samples')
+ ->in('src')
+ ->in('tests');
+
+return PhpCsFixer\Config::create()
+ ->setRiskyAllowed(true)
+ ->setFinder($finder)
+ ->setRules(array(
+ 'array_syntax' => array('syntax' => 'long'),
+ 'binary_operator_spaces' => array('align_double_arrow' => true),
+ 'blank_line_after_namespace' => true,
+ 'blank_line_after_opening_tag' => false,
+ 'blank_line_before_return' => true,
+ 'braces' => true,
+ 'cast_spaces' => true,
+ 'class_definition' => true,
+ 'class_keyword_remove' => false, // ::class keyword gives us beter support in IDE
+ 'combine_consecutive_unsets' => true,
+ 'concat_space' => array('spacing' => 'one'),
+ 'declare_equal_normalize' => true,
+ 'declare_strict_types' => false, // Too early to adopt strict types
+ 'dir_constant' => true,
+ 'elseif' => true,
+ 'encoding' => true,
+ 'ereg_to_preg' => true,
+ 'full_opening_tag' => true,
+ 'function_declaration' => true,
+ 'function_typehint_space' => true,
+ 'general_phpdoc_annotation_remove' => false, // No use for that
+ 'hash_to_slash_comment' => true,
+ 'header_comment' => false, // We don't use common header in all our files
+ 'heredoc_to_nowdoc' => false, // Not sure about this one
+ 'is_null' => false, // Risky
+ 'include' => true,
+ 'indentation_type' => true,
+ 'line_ending' => true,
+ 'linebreak_after_opening_tag' => true,
+ 'lowercase_cast' => true,
+ 'lowercase_constants' => true,
+ 'lowercase_keywords' => true,
+ 'mb_str_functions' => false, // No, too dangerous to change that
+ 'method_argument_space' => true,
+ 'method_separation' => true,
+ 'modernize_types_casting' => true,
+ 'native_function_casing' => true,
+ 'native_function_invocation'=> false, // This is risky and seems to be micro-optimization that make code uglier so not worth it, at least for now
+ 'new_with_braces' => true,
+ 'no_alias_functions' => true,
+ 'no_blank_lines_after_class_opening' => true,
+ 'no_blank_lines_after_phpdoc' => true,
+ 'no_blank_lines_before_namespace' => false, // we want 1 blank line before namespace
+ 'no_closing_tag' => true,
+ 'no_empty_comment' => true,
+ 'no_empty_phpdoc' => true,
+ 'no_empty_statement' => true,
+ 'no_extra_consecutive_blank_lines' => array('break', 'continue', 'extra', 'return', 'throw', 'use', 'useTrait', 'curly_brace_block', 'parenthesis_brace_block', 'square_brace_block'),
+ 'no_leading_import_slash' => true,
+ 'no_leading_namespace_whitespace' => true,
+ 'no_mixed_echo_print' => true,
+ 'no_multiline_whitespace_around_double_arrow' => true,
+ 'no_multiline_whitespace_before_semicolons' => true,
+ 'no_php4_constructor' => true,
+ 'no_short_bool_cast' => true,
+ 'no_short_echo_tag' => true,
+ 'no_singleline_whitespace_before_semicolons' => true,
+ 'no_spaces_after_function_name' => true,
+ 'no_spaces_around_offset' => true,
+ 'no_spaces_inside_parenthesis' => true,
+ 'no_trailing_comma_in_list_call' => true,
+ 'no_trailing_comma_in_singleline_array' => true,
+ 'no_trailing_whitespace' => true,
+ 'no_trailing_whitespace_in_comment' => true,
+ 'no_unneeded_control_parentheses' => true,
+ 'no_unreachable_default_argument_value' => true,
+ 'no_unused_imports' => true,
+ 'no_useless_else' => true,
+ 'no_useless_return' => true,
+ 'no_whitespace_before_comma_in_array' => true,
+ 'no_whitespace_in_blank_line' => true,
+ 'normalize_index_brace' => true,
+ 'not_operator_with_space' => false, // No we prefer to keep '!' without spaces
+ 'not_operator_with_successor_space' => false, // idem
+ 'object_operator_without_whitespace' => true,
+ 'ordered_class_elements' => false, // We prefer to keep some freedom
+ 'ordered_imports' => true,
+ 'php_unit_construct' => true,
+ 'php_unit_dedicate_assert' => true,
+ 'php_unit_fqcn_annotation' => true,
+ 'php_unit_strict' => false, // We sometime actually need assertEquals
+ 'phpdoc_add_missing_param_annotation' => true,
+ 'phpdoc_align' => false, // Waste of time
+ 'phpdoc_annotation_without_dot' => true,
+ 'phpdoc_indent' => true,
+ 'phpdoc_inline_tag' => true,
+ 'phpdoc_no_access' => true,
+ 'phpdoc_no_alias_tag' => true,
+ 'phpdoc_no_empty_return' => true,
+ 'phpdoc_no_package' => true,
+ 'phpdoc_no_useless_inheritdoc' => true,
+ 'phpdoc_order' => true,
+ 'phpdoc_return_self_reference' => true,
+ 'phpdoc_scalar' => true,
+ 'phpdoc_separation' => false,
+ 'phpdoc_single_line_var_spacing' => true,
+ 'phpdoc_summary' => false,
+ 'phpdoc_to_comment' => true,
+ 'phpdoc_trim' => true,
+ 'phpdoc_types' => true,
+ 'phpdoc_var_without_name' => true,
+ 'pow_to_exponentiation' => false,
+ 'pre_increment' => false,
+ 'protected_to_private' => true,
+ 'psr0' => true,
+ 'psr4' => true,
+ 'random_api_migration' => false, // This breaks our unit tests
+ 'return_type_declaration' => true,
+ 'self_accessor' => true,
+ 'semicolon_after_instruction' => false, // Buggy in `samples/index.php`
+ 'short_scalar_cast' => true,
+ 'silenced_deprecation_error' => true,
+ 'simplified_null_return' => false, // While technically correct we prefer to be explicit when returning null
+ 'single_blank_line_at_eof' => true,
+ 'single_blank_line_before_namespace' => true,
+ 'single_class_element_per_statement' => true,
+ 'single_import_per_statement' => true,
+ 'single_line_after_imports' => true,
+ 'single_quote' => true,
+ 'space_after_semicolon' => true,
+ 'standardize_not_equals' => true,
+ 'strict_comparison' => false, // No, too dangerous to change that
+ 'strict_param' => false, // No, too dangerous to change that
+ 'switch_case_semicolon_to_colon' => true,
+ 'switch_case_space' => true,
+ 'ternary_operator_spaces' => true,
+ 'ternary_to_null_coalescing' => false, // Cannot use that with PHP 5.6
+ 'trailing_comma_in_multiline_array' => true,
+ 'trim_array_spaces' => false,
+ 'unary_operator_spaces' => true,
+ 'visibility_required' => true,
+ 'whitespace_after_comma_in_array' => true,
+ ));
diff --git a/.scrutinizer.yml b/.scrutinizer.yml
index 6f982d8e..2b395afd 100644
--- a/.scrutinizer.yml
+++ b/.scrutinizer.yml
@@ -1,3 +1,8 @@
+build:
+ nodes:
+ analysis:
+ tests:
+ override: [php-scrutinizer-run]
filter:
excluded_paths: [ 'vendor/*', 'tests/*', 'samples/*', 'src/PhpWord/Shared/PCLZip/*' ]
@@ -14,8 +19,8 @@ tools:
config:
ruleset: phpmd.xml.dist
external_code_coverage:
- enabled: true
- timeout: 900
+ enabled: false
+ timeout: 1200
php_cpd: true
# php_sim: # Temporarily disabled to allow focus on things other than duplicates
# min_mass: 40
diff --git a/.travis.yml b/.travis.yml
index 0712f734..881decfe 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,17 +1,36 @@
language: php
+dist: precise
+
php:
- 5.3
- 5.4
- 5.5
- 5.6
- 7.0
- - hhvm
+ - 7.1
+ - 7.2
+ - 7.3
matrix:
- allow_failures:
+ include:
- php: 7.0
- - php: hhvm
+ 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
+ allow_failures:
+ - php: 7.3
+
+cache:
+ directories:
+ - $HOME/.composer/cache
+ - .php-cs.cache
env:
global:
@@ -23,28 +42,29 @@ before_install:
- sudo apt-get install -y graphviz
before_script:
+ ## Deactivate xdebug if we don't do code coverage
+ - if [ -z "$COVERAGE" ]; then phpenv config-rm xdebug.ini || echo "xdebug not available" ; fi
## Composer
- composer self-update
- - 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:
## PHP_CodeSniffer
- - ./vendor/bin/phpcs src/ tests/ --standard=PSR2 -n --ignore=src/PhpWord/Shared/PCLZip
+ - if [ -z "$COVERAGE" ]; then ./vendor/bin/phpcs src/ tests/ --standard=PSR2 -n --ignore=src/PhpWord/Shared/PCLZip ; fi
+ ## PHP-CS-Fixer
+ - if [ -n "$COVERAGE" ]; then ./vendor/bin/php-cs-fixer fix --diff --verbose --dry-run ; fi
## PHP Mess Detector
- - ./vendor/bin/phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php
+ - if [ -z "$COVERAGE" ]; then ./vendor/bin/phpmd src/,tests/ text ./phpmd.xml.dist --exclude pclzip.lib.php ; fi
## PHPUnit
- - ./vendor/bin/phpunit -c ./ --coverage-text --coverage-html ./build/coverage
+ - ./vendor/bin/phpunit -c ./ $(if [ -n "$COVERAGE" ]; then echo --coverage-text; else echo --no-coverage; fi)
## PHPLOC
- - ./vendor/bin/phploc src/
+ - if [ -z "$COVERAGE" ]; then ./vendor/bin/phploc src/ ; fi
## PHPDocumentor
- - ./vendor/bin/phpdoc -q -d ./src -t ./build/docs --ignore "*/src/PhpWord/Shared/*/*" --template="responsive-twig"
+ ##- if [ -z "$COVERAGE" ]; then ./vendor/bin/phpdoc -q -d ./src -t ./build/docs --ignore "*/src/PhpWord/Shared/*/*" --template="responsive-twig" ; fi
-after_script:
- ## PHPDocumentor
- - bash .travis_shell_after_success.sh
- ## Scrutinizer
- - wget https://scrutinizer-ci.com/ocular.phar
- - php ocular.phar code-coverage:upload --format=php-clover build/logs/clover.xml
+after_success:
+ ## Coveralls
+ - if [ -n "$COVERAGE" ]; then travis_retry php vendor/bin/php-coveralls -v ; fi
diff --git a/.travis_shell_after_success.sh b/.travis_shell_after_success.sh
deleted file mode 100644
index 35c7a338..00000000
--- a/.travis_shell_after_success.sh
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/bin/bash
-
-echo "--DEBUG--"
-echo "TRAVIS_REPO_SLUG: $TRAVIS_REPO_SLUG"
-echo "TRAVIS_PHP_VERSION: $TRAVIS_PHP_VERSION"
-echo "TRAVIS_PULL_REQUEST: $TRAVIS_PULL_REQUEST"
-
-if [ "$TRAVIS_REPO_SLUG" == "PHPOffice/PHPWord" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_PHP_VERSION" == "5.5" ]; then
-
- echo -e "Publishing PHPDoc...\n"
-
- cp -R build/docs $HOME/docs-latest
- cp -R build/coverage $HOME/coverage-latest
-
- cd $HOME
- git config --global user.email "travis@travis-ci.org"
- git config --global user.name "travis-ci"
- git clone --quiet --branch=gh-pages https://${GH_TOKEN}@github.com/PHPOffice/PHPWord gh-pages > /dev/null
-
- cd gh-pages
- echo "--DEBUG : Suppression"
- git rm -rf ./docs/$TRAVIS_BRANCH
-
- echo "--DEBUG : Dossier"
- mkdir -p docs/$TRAVIS_BRANCH
- mkdir -p coverage/$TRAVIS_BRANCH
-
- echo "--DEBUG : Copie"
- cp -Rf $HOME/docs-latest/* ./docs/$TRAVIS_BRANCH/
- cp -Rf $HOME/coverage-latest/* ./coverage/$TRAVIS_BRANCH/
-
- echo "--DEBUG : Git"
- git add -f .
- git commit -m "PHPDocumentor (Travis Build: $TRAVIS_BUILD_NUMBER - Branch: $TRAVIS_BRANCH)"
- git push -fq origin gh-pages > /dev/null
-
- echo -e "Published PHPDoc to gh-pages.\n"
-
-fi
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 66f38dda..79ae2511 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,115 @@ Change Log
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
+v0.16.0 (xx xxx 2018)
+----------------------
+### Added
+- Add setting Chart Title and Legend visibility @Tom-Magill #1433
+
+### Fixed
+- Fix regex in `cloneBlock` function @nicoder #1269
+- HTML Title Writer loses text when Title contains a TextRun instead a string. @begnini #1436
+- 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
+
+v0.15.0 (14 Jul 2018)
+----------------------
+### Added
+- Parsing of `align` HTML attribute - @troosan #1231
+- Parse formatting inside HTML lists - @troosan @samimussbach #1239 #945 #1215 #508
+- Parsing of CSS `direction` instruction, HTML `lang` attribute, formatting inside table cell - @troosan #1273 #1252 #1254
+- Add support for Track changes @Cip @troosan #354 #1262
+- Add support for fixed Table Layout @aoloe @ekopach @troosan #841 #1276
+- Add support for Cell Spacing @dox07 @troosan #1040
+- Add parsing of formatting inside lists @atomicalnet @troosan #594
+- Added support for Vertically Raised or Lowered Text (w:position) @anrikun @troosan #640
+- Add support for MACROBUTTON field @phryneas @troosan #1021
+- Add support for Hyphenation @Trainmaster #1282 (Document: `autoHyphenation`, `consecutiveHyphenLimit`, `hyphenationZone`, `doNotHyphenateCaps`, Paragraph: `suppressAutoHyphens`)
+- Added support for Floating Table Positioning (tblpPr) @anrikun #639
+- Added support for Image text wrapping distance @troosan #1310
+- Added parsing of CSS line-height and text-indent in HTML reader @troosan #1316
+- Added the ability to enable gridlines and axislabels on charts @FrankMeyer #576
+- 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
+- Fix the size unit of when parsing html images - @troosan #1254
+- Fixed HTML parsing of nested lists - @troosan #1265
+- Save PNG alpha information when using remote images. @samsullivan #779
+- Fix parsing of ` Some well formed HTML snippet needs to be used Some well-formed HTML snippet needs to be used With for example some1 inline formatting1 Unordered (bulleted) list: Ordered (numbered) list: A link to Read the docs היי, זה פסקה מימין לשמאל Unordered (bulleted) list: 1.5 line height with first line text indent: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Ordered (numbered) list: List 1 item 1 A second list, numbering should restart List with formatted content: A table with formatting: Table inside another table:
in addHtml - @anrikun @troosan #659
+- Allow to change cell width unit - guillaume-ro-fr #986
+- Allow to change the line height rule @troosan
+- Implement PageBreak for odt writer @cookiekiller #863 #824
+- Allow to force an update of all fields on opening a document - @troosan #951
+- Allow adding a CheckBox in a TextRun - @irond #727
+- Add support for HTML img tag - @srggroup #934
+- Add support for password protection for docx - @mariahaubner #1019
+
+### Fixed
+- Loosen dependency to Zend
+- Images are not being printed when generating PDF - @hubertinio #1074 #431
+- Fixed some PHP 7 warnings - @ likeuntomurphy #927
+- Fixed PHP 7.2 compatibility (renamed `Object` class names to `ObjectElement`) - @SailorMax #1185
+- Fixed Word 97 reader - @alsofronie @Benpxpx @mario-rivera #912 #920 #892
+- Fixed image loading over https - @troosan #988
+- Impossibility to set different even and odd page headers - @troosan #981
+- Fixed Word2007 reader where unnecessary paragraphs were being created - @donghaobo #1043 #620
+- Fixed Word2007 reader where margins were not being read correctly - @slowprog #885 #1008
+- Impossible to add element PreserveText in Section - @rvanlaak #452
+- Added missing options for numbering format - @troosan #1041
+- Fixed impossibility to set a different footer for first page - @ctrlaltca #1116, @aoloe #875
+- Fixed styles not being applied by HTML writer, better pdf output - @sarke #1047 #500 #1139
+- Fixed read docx error when document contains image from remote url - @FBnil #1173 #1176
+- Padded the $args array to remove error - @kaigoh #1150, @reformed #870
+- Fix incorrect image size between windows and mac - @bskrtich #874
+- Fix adding HTML table to document - @mogilvie @arivanbastos #324
+- Fix parsing on/off values (w:val="true|false|1|0|on|off") - @troosan #1221 #1219
+- Fix error on Empty Dropdown Entry - @ComputerTinker #592
+
+### Deprecated
+- PhpWord->getProtection(), get it from the settings instead PhpWord->getSettings()->getDocumentProtection();
+
+
+
v0.13.0 (31 July 2016)
-------------------
This release brings several improvements in `TemplateProcessor`, automatic output escaping feature for OOXML, ODF, HTML, and RTF (turned off, by default).
@@ -22,6 +131,7 @@ Manual installation feature has been dropped since the release. Please, use [Com
- Improved error message for the case when `autoload.php` is not found. - @RomanSyroeshko #371
- Renamed the `align` option of `NumberingLevel`, `Frame`, `Table`, and `Paragraph` styles into `alignment`. - @RomanSyroeshko
- Improved performance of `TemplateProcessor::setValue()`. - @kazitanvirahsan #614, #617
+- Fixed some HTML tags not rendering any output (p, header & table) - #257, #324 - @twmobius and @garethellis
### Deprecated
- `getAlign` and `setAlign` methods of `NumberingLevel`, `Frame`, `Table`, and `Paragraph` styles.
@@ -399,4 +509,4 @@ This is the first release after a long development hiatus in [CodePlex](https://
- Basic CI with Travis - @Progi1984
- Added PHPWord_Exception and exception when could not copy the template - @Progi1984
- IMPROVED: Moved examples out of Classes directory - @Progi1984
-- IMPROVED: Advanced string replace in setValue for Template - @Esmeraldo [#49](http://phpword.codeplex.com/workitem/49)
\ No newline at end of file
+- IMPROVED: Advanced string replace in setValue for Template - @Esmeraldo [#49](http://phpword.codeplex.com/workitem/49)
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 335ad2d5..e62f2e6f 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 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.
+- **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.
- **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 18f4c55f..7531a6bc 100644
--- a/README.md
+++ b/README.md
@@ -1,18 +1,18 @@
# 
-## :mag_right: PHPWord is looking for a new maintainer :crown: :pencil: ([#948](https://github.com/PHPOffice/PHPWord/issues/948))
-
[](https://packagist.org/packages/phpoffice/phpword)
[](https://travis-ci.org/PHPOffice/PHPWord)
[](https://scrutinizer-ci.com/g/PHPOffice/PHPWord/)
-[](https://scrutinizer-ci.com/g/PHPOffice/PHPWord/)
+[](https://coveralls.io/github/PHPOffice/PHPWord?branch=develop)
[](https://packagist.org/packages/phpoffice/phpword)
[](https://packagist.org/packages/phpoffice/phpword)
[](https://gitter.im/PHPOffice/PHPWord)
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/) 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/).
+
+If you have any questions, please ask on [StackOverFlow](https://stackoverflow.com/questions/tagged/phpword)
Read more about PHPWord:
@@ -22,7 +22,6 @@ Read more about PHPWord:
- [Getting started](#getting-started)
- [Contributing](#contributing)
- [Developers' Documentation](http://phpword.readthedocs.org/)
-- [API Documentation](http://phpoffice.github.io/PHPWord/docs/master/)
## Features
@@ -57,8 +56,7 @@ PHPWord requires the following:
- PHP 5.3.3+
- [XML Parser extension](http://www.php.net/manual/en/xml.installation.php)
- [Zend\Escaper component](http://framework.zend.com/manual/current/en/modules/zend.escaper.introduction.html)
-- Zend\Stdlib component
-- [Zend\Validator component](http://framework.zend.com/manual/current/en/modules/zend.validator.html)
+- [Zend\Stdlib component](http://framework.zend.com/manual/current/en/modules/zend.stdlib.hydrator.html)
- [Zip extension](http://php.net/manual/en/book.zip.php) (optional, used to write OOXML and ODF)
- [GD extension](http://php.net/manual/en/book.image.php) (optional, used to add images)
- [XMLWriter extension](http://php.net/manual/en/book.xmlwriter.php) (optional, used to write OOXML and ODF)
@@ -68,14 +66,22 @@ PHPWord requires the following:
## Installation
PHPWord is installed via [Composer](https://getcomposer.org/).
-You just need to [add dependency](https://getcomposer.org/doc/04-schema.md#package-links>) on PHPWord into your package.
+To [add a dependency](https://getcomposer.org/doc/04-schema.md#package-links>) to PHPWord in your project, either
-Example:
+Run the following to use the latest stable version
+```sh
+ composer require phpoffice/phpword
+```
+or if you want the latest master version
+```sh
+ composer require phpoffice/phpword:dev-master
+```
+You can of course also manually edit your composer.json file
```json
{
"require": {
- "phpoffice/phpword": "v0.13.*"
+ "phpoffice/phpword": "v0.14.*"
}
}
```
@@ -154,7 +160,8 @@ $objWriter->save('helloWorld.html');
/* Note: we skip PDF, because "HTML-to-PDF" approach is used to create PDF documents. */
```
-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.
+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.
## Contributing
diff --git a/VERSION b/VERSION
deleted file mode 100644
index 51de3305..00000000
--- a/VERSION
+++ /dev/null
@@ -1 +0,0 @@
-0.13.0
\ No newline at end of file
diff --git a/bootstrap.php b/bootstrap.php
index 11939fee..740e3d04 100644
--- a/bootstrap.php
+++ b/bootstrap.php
@@ -10,8 +10,8 @@
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors. test bootstrap
*
- * @link https://github.com/PHPOffice/PHPWord
- * @copyright 2010-2016 PHPWord contributors
+ * @see https://github.com/PHPOffice/PHPWord
+ * @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
diff --git a/composer.json b/composer.json
index c49eb9cd..5d8a855b 100644
--- a/composer.json
+++ b/composer.json
@@ -20,7 +20,7 @@
},
{
"name": "Franck Lefevre",
- "homepage": "http://blog.rootslabs.net"
+ "homepage": "https://rootslabs.net/blog/"
},
{
"name": "Ivan Lanin",
@@ -29,25 +29,52 @@
{
"name": "Roman Syroeshko",
"homepage": "http://ru.linkedin.com/pub/roman-syroeshko/34/a53/994/"
+ },
+ {
+ "name": "Antoine de Troostembergh"
}
],
+ "scripts": {
+ "test": [
+ "phpunit --color=always"
+ ],
+ "test-no-coverage": [
+ "phpunit --color=always --no-coverage"
+ ],
+ "check": [
+ "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"
+ ],
+ "fix": [
+ "php-cs-fixer fix --ansi"
+ ]
+ },
+ "scripts-descriptions": {
+ "test": "Runs all unit tests",
+ "test-no-coverage": "Runs all unit tests, without code coverage",
+ "check": "Runs PHP CheckStyle and PHP Mess detector",
+ "fix": "Fixes issues found by PHP-CS"
+ },
"require": {
- "php": ">=5.3.3",
+ "php": "^5.3.3 || ^7.0",
"ext-xml": "*",
- "zendframework/zend-escaper": "2.4.*",
- "zendframework/zend-stdlib": "2.4.*",
- "zendframework/zend-validator": "2.4.*",
- "phpoffice/common": "0.2.*"
+ "zendframework/zend-escaper": "^2.2",
+ "phpoffice/common": "^0.2.9"
},
"require-dev": {
- "phpunit/phpunit": "3.7.*",
- "phpdocumentor/phpdocumentor":"2.*",
- "squizlabs/php_codesniffer": "1.*",
+ "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.*",
- "dompdf/dompdf":"0.6.*",
+ "phploc/phploc": "2.* || 3.* || 4.*",
+ "dompdf/dompdf":"0.8.*",
"tecnickcom/tcpdf": "6.*",
- "mpdf/mpdf": "5.*"
+ "mpdf/mpdf": "5.7.4 || 6.* || 7.*",
+ "php-coveralls/php-coveralls": "1.1.0 || ^2.0"
},
"suggest": {
"ext-zip": "Allows writing OOXML and ODF",
@@ -60,5 +87,10 @@
"psr-4": {
"PhpOffice\\PhpWord\\": "src/PhpWord"
}
+ },
+ "extra": {
+ "branch-alias": {
+ "dev-develop": "0.16-dev"
+ }
}
}
diff --git a/docs/ISSUE_TEMPLATE.md b/docs/ISSUE_TEMPLATE.md
new file mode 100644
index 00000000..c7ed27d7
--- /dev/null
+++ b/docs/ISSUE_TEMPLATE.md
@@ -0,0 +1,35 @@
+This is:
+
+- [ ] a bug report
+- [ ] a feature request
+- [ ] **not** a usage question (ask them on https://stackoverflow.com/questions/tagged/phpword)
+
+### Expected Behavior
+
+Please describe the behavior you are expecting.
+
+### Current Behavior
+
+What is the current behavior?
+
+### Failure Information
+
+Please help provide information about the failure.
+
+### How to Reproduce
+
+Please provide a code sample that reproduces the issue.
+
+```php
+addSection();
+$section->...
+```
+
+### Context
+
+* PHP version:
+* PHPWord version: 0.14
diff --git a/docs/PULL_REQUEST_TEMPLATE.md b/docs/PULL_REQUEST_TEMPLATE.md
new file mode 100644
index 00000000..5430a996
--- /dev/null
+++ b/docs/PULL_REQUEST_TEMPLATE.md
@@ -0,0 +1,11 @@
+### Description
+
+Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context.
+
+Fixes # (issue)
+
+### Checklist:
+
+- [ ] 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 updated the documentation to describe the changes
diff --git a/docs/conf.py b/docs/conf.py
index e9b1c59e..6b7cf8e8 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -41,14 +41,14 @@ master_doc = 'index'
# General information about the project.
project = u'PHPWord'
-copyright = u'2014-2015, PHPWord Contributors'
+copyright = u'2014-2017, PHPWord Contributors'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
-version = '0.13.0'
+version = '0.14.0'
# The full version, including alpha/beta/rc tags.
release = version
@@ -120,7 +120,7 @@ html_theme = 'default'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
-html_static_path = ['_static']
+#html_static_path = ['_static']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
diff --git a/docs/containers.rst b/docs/containers.rst
index f165a589..dc194d59 100644
--- a/docs/containers.rst
+++ b/docs/containers.rst
@@ -79,7 +79,7 @@ Below are the properties of the line numbering style.
- ``start`` Line numbering starting value
- ``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
@@ -98,6 +98,12 @@ that are available for the footer. See "Footer" section for detail.
Additionally, only inside of the header reference you can add watermarks
or background pictures. See "Watermarks" section.
+You can pass an optional parameter to specify where the header/footer should be applied, it can be
+
+- ``Footer::AUTO`` default, all pages except if overridden by first or even
+- ``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
+
Footers
-------
diff --git a/docs/elements.rst b/docs/elements.rst
index 27fd76b8..74b1d56f 100644
--- a/docs/elements.rst
+++ b/docs/elements.rst
@@ -31,7 +31,7 @@ column shows the containers while the rows lists the elements.
+-------+-----------------+-----------+----------+----------+---------+------------+------------+
| 11 | Watermark | - | v | - | - | - | - |
+-------+-----------------+-----------+----------+----------+---------+------------+------------+
-| 12 | Object | v | v | v | v | v | v |
+| 12 | OLEObject | v | v | v | v | v | v |
+-------+-----------------+-----------+----------+----------+---------+------------+------------+
| 13 | TOC | v | - | - | - | - | - |
+-------+-----------------+-----------+----------+----------+---------+------------+------------+
@@ -39,7 +39,7 @@ column shows the containers while the rows lists the elements.
+-------+-----------------+-----------+----------+----------+---------+------------+------------+
| 15 | Endnote | v | - | - | v\*\* | v\*\* | - |
+-------+-----------------+-----------+----------+----------+---------+------------+------------+
-| 16 | CheckBox | v | v | v | v | - | - |
+| 16 | CheckBox | v | v | v | v | v | - |
+-------+-----------------+-----------+----------+----------+---------+------------+------------+
| 17 | TextBox | v | v | v | v | - | - |
+-------+-----------------+-----------+----------+----------+---------+------------+------------+
@@ -47,6 +47,8 @@ column shows the containers while the rows lists the elements.
+-------+-----------------+-----------+----------+----------+---------+------------+------------+
| 19 | Line | v | v | v | v | v | v |
+-------+-----------------+-----------+----------+----------+---------+------------+------------+
+| 20 | Chart | v | | | v | | |
++-------+-----------------+-----------+----------+----------+---------+------------+------------+
Legend:
@@ -75,11 +77,19 @@ italics, etc) or other elements, e.g. images or links. The syntaxes are as follo
For available styling options see :ref:`font-style` and :ref:`paragraph-style`.
+If you want to enable track changes on added text you can mark it as INSERTED or DELETED by a specific user at a given time:
+
+.. code-block:: php
+
+ $text = $section->addText('Hello World!');
+ $text->setChanged(\PhpOffice\PhpWord\Element\ChangedElement::TYPE_INSERTED, 'Fred', (new \DateTime()));
+
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 `depth` is 0, a Title will be inserted, otherwise a Heading1, Heading2, ...
.. code-block:: php
@@ -89,7 +99,7 @@ To add a title to the document, use the ``addTitleStyle`` and ``addTitle`` metho
- ``depth``.
- ``$fontStyle``. See :ref:`font-style`.
- ``$paragraphStyle``. See :ref:`paragraph-style`.
-- ``$text``. Text to be displayed in the document.
+- ``$text``. Text to be displayed in the document. This can be `string` or a `\PhpOffice\PhpWord\Element\TextRun`
It's necessary to add a title style to your document because otherwise the title won't be detected as a real title.
@@ -135,12 +145,12 @@ Text breaks are empty new lines. To add text breaks, use the following syntax. A
Page breaks
~~~~~~~~~~~
-There are two ways to insert a page breaks, using the ``addPageBreak``
+There are two ways to insert a page break, using the ``addPageBreak``
method or using the ``pageBreakBefore`` style of paragraph.
-:: code-block:: php
+.. code-block:: php
- \\$section->addPageBreak();
+ $section->addPageBreak();
Lists
-----
@@ -159,7 +169,7 @@ Parameters:
- ``$depth``. Depth of list item.
- ``$fontStyle``. See :ref:`font-style`.
- ``$listStyle``. List style of the current element TYPE\_NUMBER,
- TYPE\_ALPHANUM, TYPE\_BULLET\_FILLED, etc. See list of constants in PHPWord\_Style\_ListItem.
+ TYPE\_ALPHANUM, TYPE\_BULLET\_FILLED, etc. See list of constants in PHPWord\\Style\\ListItem.
- ``$paragraphStyle``. See :ref:`paragraph-style`.
Advanced usage:
@@ -232,7 +242,7 @@ To add an image, use the ``addImage`` method to sections, headers, footers, text
$section->addImage($src, [$style]);
-- ``$src``. String path to a local image, URL of a remote image or the image data, as a string.
+- ``$src``. String path to a local image, URL of a remote image or the image data, as a string. Warning: Do not pass user-generated strings here, as that would allow an attacker to read arbitrary files or perform server-side request forgery by passing file paths or URLs instead of image data.
- ``$style``. See :ref:`image-style`.
Examples:
@@ -274,11 +284,11 @@ Objects
-------
You can add OLE embeddings, such as Excel spreadsheets or PowerPoint
-presentations to the document by using ``addObject`` method.
+presentations to the document by using ``addOLEObject`` method.
.. code-block:: php
- $section->addObject($src, [$style]);
+ $section->addOLEObject($src, [$style]);
Table of contents
-----------------
@@ -297,9 +307,9 @@ Your TOC can only be generated if you have add at least one title (See "Titles")
Options for ``$tocStyle``:
-- ``tabLeader``. Fill type between the title text and the page number. Use the defined constants in PHPWord\_Style\_TOC.
-- ``tabPos``. The position of the tab where the page number appears in twips.
-- ``indent``. The indent factor of the titles in twips.
+- ``tabLeader``. Fill type between the title text and the page number. Use the defined constants in ``\PhpOffice\PhpWord\Style\TOC``.
+- ``tabPos``. The position of the tab where the page number appears in *twip*.
+- ``indent``. The indent factor of the titles in *twip*.
Footnotes & endnotes
--------------------
@@ -307,7 +317,7 @@ Footnotes & endnotes
You can create footnotes with ``addFootnote`` and endnotes with
``addEndnote`` in texts or textruns, but it's recommended to use textrun
to have better layout. You can use ``addText``, ``addLink``,
-``addTextBreak``, ``addImage``, ``addObject`` on footnotes and endnotes.
+``addTextBreak``, ``addImage``, ``addOLEObject`` on footnotes and endnotes.
On textrun:
@@ -333,11 +343,27 @@ On text:
$footnote = $section->addFootnote();
$footnote->addText('Footnote text.');
-The footnote reference number will be displayed with decimal number
-starting from 1. This number use ``FooterReference`` style which you can
-redefine by ``addFontStyle`` method. Default value for this style is
+By default the footnote reference number will be displayed with decimal number
+starting from 1. This number uses the ``FooterReference`` style which you can
+redefine with the ``addFontStyle`` method. Default value for this style is
``array('superScript' => true)``;
+The footnote numbering can be controlled by setting the FootnoteProperties on the Section.
+
+.. code-block:: php
+
+ $fp = new PhpWord\SimpleType\FootnoteProperties();
+ //sets the position of the footnote (pageBottom (default), beneathText, sectEnd, docEnd)
+ $fp->setPos(FootnoteProperties::POSITION_DOC_END);
+ //set the number format to use (decimal (default), upperRoman, upperLetter, ...)
+ $fp->setNumFmt(FootnoteProperties::NUMBER_FORMAT_LOWER_ROMAN);
+ //force starting at other than 1
+ $fp->setNumStart(2);
+ //when to restart counting (continuous (default), eachSect, eachPage)
+ $fp->setNumRestart(FootnoteProperties::RESTART_NUMBER_EACH_PAGE);
+ //And finaly, set it on the Section
+ $section->setFootnoteProperties($properties);
+
Checkboxes
----------
@@ -360,25 +386,118 @@ To be completed
Fields
------
-To be completed
+Currently the following fields are supported:
+
+- PAGE
+- NUMPAGES
+- DATE
+- XE
+- INDEX
+
+.. code-block:: php
+
+ $section->addField($fieldType, [$properties], [$options], [$fieldText])
+
+See ``\PhpOffice\PhpWord\Element\Field`` for list of properties and options available for each field type.
+Options which are not specifically defined can be added. Those must start with a ``\``.
+
+For instance for the INDEX field, you can do the following (See `Index Field for list of available options Adding element via HTML
';
-$html .= '
';
-$html .= '
';
-\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html);
+$html .= '
';
+
+$html .= 'centered title
';
+
+$html .= '
+
+
+
+
+
';
+
+$html .= '
+
+
+
+
+
';
+
+$html .= '
+
+
';
+
+$html .= '
+
+
+
+ header a
+ header b
+ header c
+
+ 1 2
+
+ This is bold text 6
+
';
+
+\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html, false, false);
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
diff --git a/samples/Sample_27_Field.php b/samples/Sample_27_Field.php
index 57747895..4e7a5b22 100644
--- a/samples/Sample_27_Field.php
+++ b/samples/Sample_27_Field.php
@@ -1,28 +1,67 @@
14));
// New section
$section = $phpWord->addSection();
+$section->addTitle('This page demos fields');
// Add Field elements
// See Element/Field.php for all options
$section->addText('Date field:');
$section->addField('DATE', array('dateformat' => 'dddd d MMMM yyyy H:mm:ss'), array('PreserveFormat'));
+$section->addText('Style Ref field:');
+$section->addField('STYLEREF', array('StyleIdentifier' => 'Heading 1'));
+
$section->addText('Page field:');
-$section->addField('PAGE', array('format' => 'ArabicDash'));
+$section->addField('PAGE', array('format' => 'Arabic'));
$section->addText('Number of pages field:');
-$section->addField('NUMPAGES', array('format' => 'Arabic', 'numformat' => '0,00'), array('PreserveFormat'));
+$section->addField('NUMPAGES', array('numformat' => '0,00', 'format' => 'Arabic'), array('PreserveFormat'));
+$section->addTextBreak();
+
+$textrun = $section->addTextRun();
+$textrun->addText('An index field is ');
+$textrun->addField('XE', array(), array('Italic'), 'My first index');
+$textrun->addText('here:');
+
+$indexEntryText = new TextRun();
+$indexEntryText->addText('My ');
+$indexEntryText->addText('bold index', array('bold' => true));
+$indexEntryText->addText(' entry');
+
+$textrun = $section->addTextRun();
+$textrun->addText('A complex index field is ');
+$textrun->addField('XE', array(), array('Bold'), $indexEntryText);
+$textrun->addText('here:');
+
+$section->addText('The actual index:');
+$section->addField('INDEX', array(), array('\\e " "'), 'right click to update the index');
$textrun = $section->addTextRun(array('alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
$textrun->addText('This is the date of lunar calendar ');
$textrun->addField('DATE', array('dateformat' => 'd-M-yyyy H:mm:ss'), array('PreserveFormat', 'LunarCalendar'));
$textrun->addText(' written in a textrun.');
+$section->addTextBreak();
+
+$macroText = new TextRun();
+$macroText->addText('Double click', array('bold' => true));
+$macroText->addText(' to ');
+$macroText->addText('zoom to 100%', array('italic' => true));
+
+$section->addText('A macro button with styled text:');
+$section->addField('MACROBUTTON', array('macroname' => 'Zoom100'), array(), $macroText);
+$section->addTextBreak();
+
+$section->addText('A macro button with simple text:');
+$section->addField('MACROBUTTON', array('macroname' => 'Zoom100'), array(), 'double click to zoom');
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
diff --git a/samples/Sample_32_Chart.php b/samples/Sample_32_Chart.php
index 2c6458ca..c24a6f8e 100644
--- a/samples/Sample_32_Chart.php
+++ b/samples/Sample_32_Chart.php
@@ -16,18 +16,23 @@ $section = $phpWord->addSection();
$section->addTitle('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');
+$chartTypes = array('pie', 'doughnut', 'bar', 'column', 'line', 'area', 'scatter', 'radar', 'stacked_bar', 'percent_stacked_bar', 'stacked_column', 'percent_stacked_column');
+$twoSeries = array('bar', 'column', 'line', 'area', 'scatter', 'radar', 'stacked_bar', 'percent_stacked_bar', 'stacked_column', 'percent_stacked_column');
$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);
+$showGridLines = false;
+$showAxisLabels = false;
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));
+ $chart->getStyle()->setShowGridX($showGridLines);
+ $chart->getStyle()->setShowGridY($showGridLines);
+ $chart->getStyle()->setShowAxisLabels($showAxisLabels);
if (in_array($chartType, $twoSeries)) {
$chart->addSeries($categories, $series2);
}
@@ -44,7 +49,14 @@ $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);
+$style = array(
+ 'width' => Converter::cmToEmu(5),
+ 'height' => Converter::cmToEmu(4),
+ '3d' => true,
+ 'showAxisLabels' => $showAxisLabels,
+ 'showGridX' => $showGridLines,
+ 'showGridY' => $showGridLines,
+);
foreach ($chartTypes as $chartType) {
$section->addTitle(ucfirst($chartType), 2);
$chart = $section->addChart($chartType, $categories, $series1, $style);
diff --git a/samples/Sample_34_SDT.php b/samples/Sample_34_SDT.php
index a5042279..f9077a1a 100644
--- a/samples/Sample_34_SDT.php
+++ b/samples/Sample_34_SDT.php
@@ -15,10 +15,16 @@ $textrun->addSDT('comboBox')->setListItems(array('1' => 'Choice 1', '2' => 'Choi
$textrun = $section->addTextRun();
$textrun->addText('Date: ');
$textrun->addSDT('date');
+$textrun->addTextBreak(1);
+$textrun->addText('Date with pre set value: ');
+$textrun->addSDT('date')->setValue('03/30/2017');
+$textrun->addTextBreak(1);
+$textrun->addText('Date with pre set value: ');
+$textrun->addSDT('date')->setValue('30.03.2017');
$textrun = $section->addTextRun();
$textrun->addText('Drop down list: ');
-$textrun->addSDT('dropDownList')->setListItems(array('1' => 'Choice 1', '2' => 'Choice 2'));
+$textrun->addSDT('dropDownList')->setListItems(array('1' => 'Choice 1', '2' => 'Choice 2'))->setValue('Choice 1');
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
diff --git a/samples/Sample_37_Comments.php b/samples/Sample_37_Comments.php
new file mode 100644
index 00000000..268739bc
--- /dev/null
+++ b/samples/Sample_37_Comments.php
@@ -0,0 +1,62 @@
+addText('Test', array('bold' => true));
+$phpWord->addComment($comment);
+
+$section = $phpWord->addSection();
+
+$textrun = $section->addTextRun();
+$textrun->addText('This ');
+$text = $textrun->addText('is');
+$text->setCommentRangeStart($comment);
+$textrun->addText(' a test');
+
+$section->addTextBreak(2);
+
+// Let's create a comment that we will link to a start element and an end element
+$commentWithStartAndEnd = new \PhpOffice\PhpWord\Element\Comment('Foo Bar', new \DateTime());
+$commentWithStartAndEnd->addText('A comment with a start and an end');
+$phpWord->addComment($commentWithStartAndEnd);
+
+$textrunWithEnd = $section->addTextRun();
+$textrunWithEnd->addText('This ');
+$textToStartOn = $textrunWithEnd->addText('is', array('bold' => true));
+$textToStartOn->setCommentRangeStart($commentWithStartAndEnd);
+$textrunWithEnd->addText(' another', array('italic' => true));
+$textToEndOn = $textrunWithEnd->addText(' test');
+$textToEndOn->setCommentRangeEnd($commentWithStartAndEnd);
+
+$section->addTextBreak(2);
+
+// Let's add a comment on an image
+$commentOnImage = new \PhpOffice\PhpWord\Element\Comment('Mr Smart', new \DateTime());
+$imageComment = $commentOnImage->addTextRun();
+$imageComment->addText('Hey, Mars does look ');
+$imageComment->addText('red', array('color' => 'FF0000'));
+$phpWord->addComment($commentOnImage);
+$image = $section->addImage('resources/_mars.jpg');
+$image->setCommentRangeStart($commentOnImage);
+
+$section->addTextBreak(2);
+
+// We can also do things the other way round, link the comment to the element
+$anotherText = $section->addText('another text');
+
+$comment1 = new \PhpOffice\PhpWord\Element\Comment('Authors name', new \DateTime(), 'my_initials');
+$comment1->addText('Test', array('bold' => true));
+$comment1->setStartElement($anotherText);
+$comment1->setEndElement($anotherText);
+$phpWord->addComment($comment1);
+
+// Save file
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
+}
diff --git a/samples/Sample_38_Protection.php b/samples/Sample_38_Protection.php
new file mode 100644
index 00000000..ee2b460b
--- /dev/null
+++ b/samples/Sample_38_Protection.php
@@ -0,0 +1,21 @@
+getSettings()->getDocumentProtection();
+$documentProtection->setEditing(DocProtect::READ_ONLY);
+$documentProtection->setPassword('myPassword');
+
+$section = $phpWord->addSection();
+$section->addText('this document is password protected');
+
+// Save file
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
+}
diff --git a/samples/Sample_39_TrackChanges.php b/samples/Sample_39_TrackChanges.php
new file mode 100644
index 00000000..e6a30668
--- /dev/null
+++ b/samples/Sample_39_TrackChanges.php
@@ -0,0 +1,29 @@
+addSection();
+$textRun = $section->addTextRun();
+
+$text = $textRun->addText('Hello World! Time to ');
+
+$text = $textRun->addText('wake ', array('bold' => true));
+$text->setChangeInfo(TrackChange::INSERTED, 'Fred', time() - 1800);
+
+$text = $textRun->addText('up');
+$text->setTrackChange(new TrackChange(TrackChange::INSERTED, 'Fred'));
+
+$text = $textRun->addText('go to sleep');
+$text->setChangeInfo(TrackChange::DELETED, 'Barney', new \DateTime('@' . (time() - 3600)));
+
+// Save file
+echo write($phpWord, basename(__FILE__, '.php'), $writers);
+if (!CLI) {
+ include_once 'Sample_Footer.php';
+}
diff --git a/samples/Sample_Header.php b/samples/Sample_Header.php
index 90bdf4fa..f0fc6266 100644
--- a/samples/Sample_Header.php
+++ b/samples/Sample_Header.php
@@ -12,6 +12,12 @@ define('IS_INDEX', SCRIPT_FILENAME == 'index');
Settings::loadConfig();
+$dompdfPath = $vendorDirPath . '/dompdf/dompdf';
+if (file_exists($dompdfPath)) {
+ define('DOMPDF_ENABLE_AUTOLOAD', false);
+ Settings::setPdfRenderer(Settings::PDF_RENDERER_DOMPDF, $vendorDirPath . '/dompdf/dompdf');
+}
+
// Set writers
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf', 'HTML' => 'html', 'PDF' => 'pdf');
@@ -37,13 +43,19 @@ $pageHeading = IS_INDEX ? '' : "
+
+
+
+
+ column 1 column 2
+Cell in parent table {$pageHeading}
";
// Populate samples
$files = '';
if ($handle = opendir('.')) {
- while (false !== ($file = readdir($handle))) {
+ $sampleFiles = array();
+ while (false !== ($sampleFile = readdir($handle))) {
+ $sampleFiles[] = $sampleFile;
+ }
+ sort($sampleFiles);
+ closedir($handle);
+
+ foreach ($sampleFiles as $file) {
if (preg_match('/^Sample_\d+_/', $file)) {
$name = str_replace('_', ' ', preg_replace('/(Sample_|\.php)/', '', $file));
$files .= "
';
+ if (file_exists($filename . '.php')) {
+ $result .= highlight_file($filename . '.php', true);
+ }
+ $result .= '';
}
}
diff --git a/samples/index.php b/samples/index.php
index a65d8fd9..3dbc09ff 100644
--- a/samples/index.php
+++ b/samples/index.php
@@ -13,7 +13,7 @@ $requirements = array(
'xsl' => array('PHP extension XSL (optional)', extension_loaded('xsl')),
);
if (!CLI) {
-?>
+ ?>
Welcome to PHPWord, a library written in pure PHP that provides a set of classes to write to and read from different document file formats, i.e. Office Open XML (.docx), Open Document Format (.odt), and Rich Text Format (.rtf).
@@ -25,14 +25,14 @@ if (!CLI) { Requirement check:"; - echo "
Ordered (numbered) list:
Double height
+ +
+
+
+
+
+