Merge branch 'develop' into patch-1

This commit is contained in:
troosan 2018-12-03 01:07:08 +01:00 committed by GitHub
commit b54200e5d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
450 changed files with 19440 additions and 8450 deletions

21
.gitattributes vendored Normal file
View File

@ -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

5
.gitignore vendored
View File

@ -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
/.scannerwork
/.project
/nbproject
/.php_cs.cache

146
.php_cs.dist Normal file
View File

@ -0,0 +1,146 @@
<?php
$finder = PhpCsFixer\Finder::create()
->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,
));

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 `<w:br/>` tag. @troosan #1274
- Bookmark are not writton as internal link in html writer @troosan #1263
- It should be possible to add a Footnote in a ListItemRun @troosan #1287 #1287
- 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
- The default unit for `\PhpOffice\PhpWord\Style\Image` changed from `px` to `pt`.
### Miscelaneous
- Drop GitHub pages, switch to coveralls for code coverage analysis @czosel #1360
v0.14.0 (29 Dec 2017)
----------------------
This release fixes several bugs and adds some new features.
This version brings compatibility with PHP 7.0 & 7.1
### Added
- Possibility to control the footnote numbering - @troosan #1068
- Image creation from string - @troosan #937
- Introduced the `\PhpOffice\PhpWord\SimpleType\NumberFormat` simple type. - @troosan
- Support for ContextualSpacing - @postHawk #1088
- Possiblity to hide spelling and/or grammatical errors - @troosan #542
- Possiblity to set default document language as well as changing the language for each text element - @troosan #1108
- Support for Comments - @troosan #1067
- Support for paragraph textAlignment - @troosan #1165
- Add support for HTML underline tag <u> in addHtml - @zNightFalLz #1186
- Add support for HTML <br> 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.

View File

@ -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!

View File

@ -1,18 +1,18 @@
# ![PHPWord](https://rawgit.com/PHPOffice/PHPWord/develop/docs/images/phpword.svg "PHPWord")
## :mag_right: PHPWord is looking for a new maintainer :crown: :pencil: ([#948](https://github.com/PHPOffice/PHPWord/issues/948))
[![Latest Stable Version](https://poser.pugx.org/phpoffice/phpword/v/stable.png)](https://packagist.org/packages/phpoffice/phpword)
[![Build Status](https://travis-ci.org/PHPOffice/PHPWord.svg?branch=master)](https://travis-ci.org/PHPOffice/PHPWord)
[![Code Quality](https://scrutinizer-ci.com/g/PHPOffice/PHPWord/badges/quality-score.png?s=b5997ce59ac2816b4514f3a38de9900f6d492c1d)](https://scrutinizer-ci.com/g/PHPOffice/PHPWord/)
[![Code Coverage](https://scrutinizer-ci.com/g/PHPOffice/PHPWord/badges/coverage.png?s=742a98745725c562955440edc8d2c39d7ff5ae25)](https://scrutinizer-ci.com/g/PHPOffice/PHPWord/)
[![Coverage Status](https://coveralls.io/repos/github/PHPOffice/PHPWord/badge.svg?branch=develop)](https://coveralls.io/github/PHPOffice/PHPWord?branch=develop)
[![Total Downloads](https://poser.pugx.org/phpoffice/phpword/downloads.png)](https://packagist.org/packages/phpoffice/phpword)
[![License](https://poser.pugx.org/phpoffice/phpword/license.png)](https://packagist.org/packages/phpoffice/phpword)
[![Join the chat at https://gitter.im/PHPOffice/PHPWord](https://img.shields.io/badge/GITTER-join%20chat-green.svg)](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

View File

@ -1 +0,0 @@
0.13.0

View File

@ -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
*/

View File

@ -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"
}
}
}

35
docs/ISSUE_TEMPLATE.md Normal file
View File

@ -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
<?php
require __DIR__ . '/vendor/autoload.php';
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section->...
```
### Context
* PHP version:
* PHPWord version: 0.14

View File

@ -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

View File

@ -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.

View File

@ -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
-------

View File

@ -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 <https://support.office.com/en-us/article/Field-codes-Index-field-adafcf4a-cb30-43f6-85c7-743da1635d9e?ui=en-US&rs=en-US&ad=US>`_ ):
.. code-block:: php
//the $fieldText can be either a simple string
$fieldText = 'The index value';
//or a 'TextRun', to be able to format the text you want in the index
$fieldText = new TextRun();
$fieldText->addText('My ');
$fieldText->addText('bold index', ['bold' => true]);
$fieldText->addText(' entry');
$section->addField('XE', array(), array(), $fieldText);
//this actually adds the index
$section->addField('INDEX', array(), array('\\e " " \\h "A" \\c "3"'), 'right click to update index');
Line
------
----
Line elements can be added to sections by using ``addLine``.
.. code-block:: php
$linestyle = array('weight' => 1, 'width' => 100, 'height' => 0, 'color' => 635552);
$section->addLine($lineStyle)
$lineStyle = array('weight' => 1, 'width' => 100, 'height' => 0, 'color' => 635552);
$section->addLine($lineStyle);
Available line style attributes:
- ``weight``. Line width in twips.
- ``weight``. Line width in *twip*.
- ``color``. Defines the color of stroke.
- ``dash``. Line types: dash, rounddot, squaredot, dashdot, longdash, longdashdot, longdashdotdot.
- ``beginArrow``. Start type of arrow: block, open, classic, diamond, oval.
- ``endArrow``. End type of arrow: block, open, classic, diamond, oval.
- ``width``. Line-object width in pt.
- ``height``. Line-object height in pt.
- ``width``. Line-object width in *pt*.
- ``height``. Line-object height in *pt*.
- ``flip``. Flip the line element: true, false.
Chart
-----
Charts can be added using
.. code-block:: php
$categories = array('A', 'B', 'C', 'D', 'E');
$series = array(1, 3, 2, 5, 4);
$chart = $section->addChart('line', $categories, $series, $style);
For available styling options see :ref:`chart-style`.
check out the Sample_32_Chart.php for more options and styling.
Comments
--------
Comments can be added to a document by using ``addComment``.
The comment can contain formatted text. Once the comment has been added, it can be linked to any element with ``setCommentStart``.
.. code-block:: php
// first create a comment
$comment= new \PhpOffice\PhpWord\Element\Comment('Authors name', new \DateTime(), 'my_initials');
$comment->addText('Test', array('bold' => true));
// add it to the document
$phpWord->addComment($comment);
$textrun = $section->addTextRun();
$textrun->addText('This ');
$text = $textrun->addText('is');
// link the comment to the text you just created
$text->setCommentStart($comment);
If no end is set for a comment using the ``setCommentEnd``, the comment will be ended automatically at the end of the element it is started on.
Track Changes
-------------
Track changes can be set on text elements. There are 2 ways to set the change information on an element.
Either by calling the `setChangeInfo()`, or by setting the `TrackChange` instance on the element with `setTrackChange()`.
.. code-block:: php
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// New portrait section
$section = $phpWord->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)));

View File

@ -80,8 +80,8 @@ folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
/* 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
--------
PHPWord Settings
----------------
The ``PhpOffice\PhpWord\Settings`` class provides some options that will
affect the behavior of PHPWord. Below are the options.
@ -109,8 +109,8 @@ Zip class
By default, PHPWord uses `Zip extension <http://php.net/manual/en/book.zip.php>`__
to deal with ZIP compressed archives and files inside them. If you can't have
Zip extension installed on your server, you can use pure PHP library
alternative, `PclZip <http://www.phpconcept.net/pclzip/>`__, which
included with PHPWord.
alternative, `PclZip <http://www.phpconcept.net/pclzip/>`__, which is
included in PHPWord.
.. code-block:: php
@ -141,6 +141,93 @@ default font by using the following two functions:
$phpWord->setDefaultFontName('Times New Roman');
$phpWord->setDefaultFontSize(12);
Document settings
-----------------
Settings for the generated document can be set using ``$phpWord->getSettings()``
Magnification Setting
~~~~~~~~~~~~~~~~~~~~~
The default zoom value is 100 percent. This can be changed either to another percentage
.. code-block:: php
$phpWord->getSettings()->setZoom(75);
Or to predefined values ``fullPage``, ``bestFit``, ``textFit``
.. code-block:: php
$phpWord->getSettings()->setZoom(Zoom::BEST_FIT);
Mirroring the Page Margins
~~~~~~~~~~~~~~~~~~~~~~~~~~
Use mirror margins to set up facing pages for double-sided documents, such as books or magazines.
.. code-block:: php
$phpWord->getSettings()->setMirrorMargins(true);
Spelling and grammatical checks
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
By default spelling and grammatical errors are shown as soon as you open a word document.
For big documents this can slow down the opening of the document. You can hide the spelling and/or grammatical errors with:
.. code-block:: php
$phpWord->getSettings()->setHideGrammaticalErrors(true);
$phpWord->getSettings()->setHideSpellingErrors(true);
You can also specify the status of the spell and grammar checks, marking spelling or grammar as dirty will force a re-check when opening the document.
.. code-block:: php
$proofState = new ProofState();
$proofState->setGrammar(ProofState::CLEAN);
$proofState->setSpelling(ProofState::DIRTY);
$phpWord->getSettings()->setProofState(proofState);
Track Revisions
~~~~~~~~~~~~~~~
Track changes can be activated using ``setTrackRevisions``, you can furture specify
- Not to use move syntax, instead moved items will be seen as deleted in one place and added in another
- Not track formatting revisions
.. code-block:: php
$phpWord->getSettings()->setTrackRevisions(true);
$phpWord->getSettings()->setDoNotTrackMoves(true);
$phpWord->getSettings()->setDoNotTrackFormatting(true);
Decimal Symbol
~~~~~~~~~~~~~~
The default symbol to represent a decimal figure is the ``.`` in english. In french you might want to change it to ``,`` for instance.
.. code-block:: php
$phpWord->getSettings()->setDecimalSymbol(',');
Document Language
~~~~~~~~~~~~~~~~~
The default language of the document can be change with the following.
.. code-block:: php
$phpWord->getSettings()->setThemeFontLang(new Language(Language::FR_BE));
``Language`` has 3 parameters, one for Latin languages, one for East Asian languages and one for Complex (Bi-Directional) languages.
A couple of language codes are provided in the ``PhpOffice\PhpWord\ComplexType\Language`` class but any valid code/ID can be used.
In case you are generating an RTF document the language need to be set differently.
.. code-block:: php
$lang = new Language();
$lang->setLangId(Language::EN_GB_ID);
$phpWord->getSettings()->setThemeFontLang($lang);
Document information
--------------------
@ -168,7 +255,7 @@ The base length unit in Open Office XML is twip. Twip means "TWentieth
of an Inch Point", i.e. 1 twip = 1/1440 inch.
You can use PHPWord helper functions to convert inches, centimeters, or
points to twips.
points to twip.
.. code-block:: php
@ -183,3 +270,65 @@ points to twips.
$sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Converter::inchToTwip(.5));
// 2 cm right margin
$sectionStyle->setMarginRight(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(2));
Document protection
-------------------
The document (or parts of it) can be password protected.
.. code-block:: php
$documentProtection = $phpWord->getSettings()->getDocumentProtection();
$documentProtection->setEditing(DocProtect::READ_ONLY);
$documentProtection->setPassword('myPassword');
Automatically Recalculate Fields on Open
----------------------------------------
To force an update of the fields present in the document, set updateFields to true
.. code-block:: php
$phpWord->getSettings()->setUpdateFields(true);
Hyphenation
-----------
Hyphenation describes the process of breaking words with hyphens. There are several options to control hyphenation.
Auto hyphenation
~~~~~~~~~~~~~~~~
To automatically hyphenate text set ``autoHyphenation`` to ``true``.
.. code-block:: php
$phpWord->getSettings()->setAutoHyphenation(true);
Consecutive Hyphen Limit
~~~~~~~~~~~~~~~~~~~~~~~~
The maximum number of consecutive lines of text ending with a hyphen can be controlled by the ``consecutiveHyphenLimit`` option.
There is no limit if the option is not set or the provided value is ``0``.
.. code-block:: php
$phpWord->getSettings()->setConsecutiveHyphenLimit(2);
Hyphenation Zone
~~~~~~~~~~~~~~~~
The hyphenation zone (in *twip*) is the allowed amount of whitespace before hyphenation is applied.
The smaller the hyphenation zone the more words are hyphenated. Or in other words, the wider the hyphenation zone the less words are hyphenated.
.. code-block:: php
$phpWord->getSettings()->setHyphenationZone(\PhpOffice\PhpWord\Shared\Converter::cmToTwip(1));
Hyphenate Caps
~~~~~~~~~~~~~~
To control whether or not words in all capital letters shall be hyphenated use the `doNotHyphenateCaps` option.
.. code-block:: php
$phpWord->getSettings()->setDoNotHyphenateCaps(true);

View File

@ -34,7 +34,7 @@ Example:
{
"require": {
"phpoffice/phpword": "v0.13.*"
"phpoffice/phpword": "v0.14.*"
}
}
@ -51,11 +51,8 @@ Example:
}
}
Using samples
-------------
After installation, you can browse and use the samples that we've
provided, either by command line or using browser. If you can access
your PHPWord library folder using browser, point your browser to the
``samples`` folder, e.g. ``http://localhost/PhpWord/samples/``.
More examples are provided in the ``samples`` directory.
For an easy access to those samples launch ``php -S localhost:8000`` in the samples directory then browse to http://localhost:8000 to view the samples.

View File

@ -49,6 +49,7 @@ Features
- 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)
- Insert comments
- Create document from templates
- Use XSL 1.0 style sheets to transform headers, main document part, and footers of an OOXML template
- ... and many more features on progress
@ -102,6 +103,8 @@ Writers
+---------------------------+----------------------+--------+-------+-------+--------+-------+
| | Endnote | ✓ | | | ✓ | |
+---------------------------+----------------------+--------+-------+-------+--------+-------+
| | Comments | ✓ | | | | |
+---------------------------+----------------------+--------+-------+-------+--------+-------+
| **Graphs** | 2D basic graphs | ✓ | | | | |
+---------------------------+----------------------+--------+-------+-------+--------+-------+
| | 2D advanced graphs | | | | | |
@ -161,6 +164,8 @@ Readers
+---------------------------+----------------------+--------+-------+-------+-------+-------+
| | Endnote | ✓ | | | | |
+---------------------------+----------------------+--------+-------+-------+-------+-------+
| | Comments | | | | | |
+---------------------------+----------------------+--------+-------+-------+-------+-------+
| **Graphs** | 2D basic graphs | | | | | |
+---------------------------+----------------------+--------+-------+-------+-------+-------+
| | 2D advanced graphs | | | | | |

View File

@ -4,7 +4,7 @@ References
==========
ISO/IEC 29500, Third edition, 2012-09-01
---------------------
----------------------------------------
- `Part 1: Fundamentals and Markup Language Reference
<http://standards.iso.org/ittf/PubliclyAvailableStandards/c061750_ISO_IEC_29500-1_2012.zip>`__

View File

@ -11,26 +11,27 @@ Section
Available Section style options:
- ``borderBottomColor``. Border bottom color.
- ``borderBottomSize``. Border bottom size (in twips).
- ``borderBottomSize``. Border bottom size in *twip*.
- ``borderLeftColor``. Border left color.
- ``borderLeftSize``. Border left size (in twips).
- ``borderLeftSize``. Border left size in *twip*.
- ``borderRightColor``. Border right color.
- ``borderRightSize``. Border right size (in twips).
- ``borderRightSize``. Border right size in *twip*.
- ``borderTopColor``. Border top color.
- ``borderTopSize``. Border top size (in twips).
- ``borderTopSize``. Border top size in *twip*.
- ``breakType``. Section break type (nextPage, nextColumn, continuous, evenPage, oddPage).
- ``colsNum``. Number of columns.
- ``colsSpace``. Spacing between columns.
- ``footerHeight``. Spacing to bottom of footer.
- ``gutter``. Page gutter spacing.
- ``headerHeight``. Spacing to top of header.
- ``marginTop``. Page margin top (in twips).
- ``marginLeft``. Page margin left (in twips).
- ``marginRight``. Page margin right (in twips).
- ``marginBottom``. Page margin bottom (in twips).
- ``marginTop``. Page margin top in *twip*.
- ``marginLeft``. Page margin left in *twip*.
- ``marginRight``. Page margin right in *twip*.
- ``marginBottom``. Page margin bottom in *twip*.
- ``orientation``. Page orientation (``portrait``, which is default, or ``landscape``).
- ``pageSizeH``. Page height (in twips). Implicitly defined by ``orientation`` option. Any changes are discouraged.
- ``pageSizeW``. Page width (in twips). Implicitly defined by ``orientation`` option. Any changes are discouraged.
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.
.. _font-style:
@ -45,6 +46,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_...`` class constants for possible values
- ``hint``. Font content type, *default*, *eastAsia*, or *cs*.
- ``italic``. Italic, *true* or *false*.
- ``name``. Font name, e.g. *Arial*.
@ -54,7 +56,11 @@ Available Font style options:
- ``strikethrough``. Strikethrough, *true* or *false*.
- ``subScript``. Subscript, *true* or *false*.
- ``superScript``. Superscript, *true* or *false*.
- ``underline``. Underline, *dash*, *dotted*, etc.
- ``underline``. Underline, *single*, *dash*, *dotted*, etc.
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
.. _paragraph-style:
@ -64,19 +70,28 @@ 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 by how much.
- ``indent``. Indent by how much.
- ``hanging``. Hanging in *twip*.
- ``indent``. Indent in *twip*.
- ``keepLines``. Keep all lines on one page, *true* or *false*.
- ``keepNext``. Keep paragraph with next paragraph, *true* or *false*.
- ``lineHeight``. Text line height, e.g. *1.0*, *1.5*, etc.
- ``next``. Style for next paragraph.
- ``pageBreakBefore``. Start paragraph on next page, *true* or *false*.
- ``spaceBefore``. Space before paragraph.
- ``spaceAfter``. Space after paragraph.
- ``spaceBefore``. Space before paragraph in *twip*.
- ``spaceAfter``. Space after paragraph in *twip*.
- ``spacing``. Space between lines.
- ``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*.
- ``contextualSpacing``. Ignore Spacing Above and Below When Using Identical Styles, *true* or *false*.
- ``bidi``. Right to Left Paragraph Layout, *true* or *false*.
- ``shading``. Paragraph Shading.
- ``textAlignment``. Vertical Character Alignment on Line.
See ``\PhpOffice\PhpWord\SimpleType\TextAlignment`` class constants for possible values.
.. _table-style:
@ -86,12 +101,30 @@ 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 twips.
- ``cellMargin(Top|Right|Bottom|Left)``. Cell margin in twips.
- ``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.
- ``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
Floating Table Positioning options:
- ``leftFromText`` Distance From Left of Table to Text in *twip*
- ``rightFromText`` Distance From Right of Table to Text in *twip*
- ``topFromText`` Distance From Top of Table to Text in *twip*
- ``bottomFromText`` Distance From Top of Table to Text in *twip*
- ``vertAnchor`` Table Vertical Anchor, one of ``\PhpOffice\PhpWord\Style\TablePosition::VANCHOR_*``
- ``horzAnchor`` Table Horizontal Anchor, one of ``\PhpOffice\PhpWord\Style\TablePosition::HANCHOR_*``
- ``tblpXSpec`` Relative Horizontal Alignment From Anchor, one of ``\PhpOffice\PhpWord\Style\TablePosition::XALIGN_*``
- ``tblpX`` Absolute Horizontal Distance From Anchorin *twip*
- ``tblpYSpec`` Relative Vertical Alignment From Anchor, one of ``\PhpOffice\PhpWord\Style\TablePosition::YALIGN_*``
- ``tblpY`` Absolute Vertical Distance From Anchorin *twip*
Available Row style options:
@ -103,12 +136,13 @@ Available Cell style options:
- ``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 twips.
- ``border(Top|Right|Bottom|Left)Size``. Border size in *twip*.
- ``gridSpan``. Number of columns spanned.
- ``textDirection(btLr|tbRl)``. Direction of text. You can use constants ``\PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR`` and ``\PhpOffice\PhpWord\Style\Cell::TEXT_DIR_TBRL``
- ``textDirection(btLr|tbRl)``. Direction of text.
You can use constants ``\PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR`` and ``\PhpOffice\PhpWord\Style\Cell::TEXT_DIR_TBRL``
- ``valign``. Vertical alignment, *top*, *center*, *both*, *bottom*.
- ``vMerge``. *restart* or *continue*.
- ``width``. Cell width in twips.
- ``width``. Cell width in *twip*.
.. _image-style:
@ -118,11 +152,15 @@ Image
Available Image style options:
- ``alignment``. See ``\PhpOffice\PhpWord\SimpleType\Jc`` class for the details.
- ``height``. Height in pixels.
- ``height``. Height in *pt*.
- ``marginLeft``. Left margin in inches, can be negative.
- ``marginTop``. Top margin in inches, can be negative.
- ``width``. Width in pixels.
- ``width``. Width in *pt*.
- ``wrappingStyle``. Wrapping style, *inline*, *square*, *tight*, *behind*, or *infront*.
- ``wrapDistanceTop``. Top text wrapping in pixels.
- ``wrapDistanceBottom``. Bottom text wrapping in pixels.
- ``wrapDistanceLeft``. Left text wrapping in pixels.
- ``wrapDistanceRight``. Right text wrapping in pixels.
.. _numbering-level-style:
@ -132,7 +170,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.
@ -143,3 +181,25 @@ See ``\PhpOffice\PhpWord\SimpleType\Jc`` class for the details.
- ``suffix``. Content between numbering symbol and paragraph text tab\|space\|nothing.
- ``tabPos``. See paragraph style.
- ``text``. Numbering level text e.g. %1 for nonbullet or bullet character.
.. _chart-style:
Chart
-----
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*.

13
phpstan.neon Normal file
View File

@ -0,0 +1,13 @@
includes:
- vendor/phpstan/phpstan/conf/config.level1.neon
parameters:
memory-limit: 20000000
autoload_directories:
- tests
autoload_files:
- tests/bootstrap.php
excludes_analyse:
- */pclzip.lib.php
- src/PhpWord/Shared/OLERead.php
- src/PhpWord/Reader/MsDoc.php
- src/PhpWord/Writer/PDF/MPDF.php

View File

@ -6,8 +6,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false">
stopOnFailure="false">
<testsuites>
<testsuite name="PhpWord Test Suite">
<directory>./tests/PhpWord</directory>
@ -22,7 +21,8 @@
</whitelist>
</filter>
<logging>
<log type="coverage-html" target="./build/coverage" charset="UTF-8" highlight="true" />
<log type="coverage-html" target="./build/coverage" />
<log type="coverage-clover" target="./build/logs/clover.xml" />
<log type="junit" target="./build/logs/logfile.xml"/>
</logging>
</phpunit>

View File

@ -1,9 +1,15 @@
<?php
use PhpOffice\PhpWord\Style\Font;
include_once 'Sample_Header.php';
// New Word Document
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
$languageEnGb = new \PhpOffice\PhpWord\Style\Language(\PhpOffice\PhpWord\Style\Language::EN_GB);
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->getSettings()->setThemeFontLang($languageEnGb);
$fontStyleName = 'rStyle';
$phpWord->addFontStyle($fontStyleName, array('bold' => true, 'italic' => true, 'size' => 16, 'allCaps' => true, 'doubleStrikethrough' => true));
@ -20,6 +26,10 @@ $section = $phpWord->addSection();
$section->addTitle('Welcome to PhpWord', 1);
$section->addText('Hello World!');
// $pStyle = new Font();
// $pStyle->setLang()
$section->addText('Ce texte-ci est en français.', array('lang' => \PhpOffice\PhpWord\Style\Language::FR_BE));
// Two text break
$section->addTextBreak(2);

View File

@ -14,7 +14,7 @@ $phpWord->addParagraphStyle(
new \PhpOffice\PhpWord\Style\Tab('left', 1550),
new \PhpOffice\PhpWord\Style\Tab('center', 3200),
new \PhpOffice\PhpWord\Style\Tab('right', 5300),
)
),
)
);

View File

@ -1,4 +1,7 @@
<?php
use PhpOffice\PhpWord\ComplexType\FootnoteProperties;
use PhpOffice\PhpWord\SimpleType\NumberFormat;
include_once 'Sample_Header.php';
// New Word Document
@ -42,11 +45,15 @@ $footnote->addText('But you can only put footnote in section, not in header or f
$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.'
. 'like the footnote below this paragraph. But is best used from within a textrun.'
);
$footnote = $section->addFootnote();
$footnote->addText('The reference for this is wrapped in its own line');
$footnoteProperties = new FootnoteProperties();
$footnoteProperties->setNumFmt(NumberFormat::DECIMAL_ENCLOSED_CIRCLE);
$section->setFootnoteProperties($footnoteProperties);
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {

View File

@ -56,7 +56,7 @@ $templateProcessor->setValue('userPhone#3', '+1 428 889 775');
echo date('H:i:s'), ' Saving the result document...', EOL;
$templateProcessor->saveAs('results/Sample_07_TemplateCloneRow.docx');
echo getEndingNotes(array('Word2007' => 'docx'));
echo getEndingNotes(array('Word2007' => 'docx'), 'results/Sample_07_TemplateCloneRow.docx');
if (!CLI) {
include_once 'Sample_Footer.php';
}

View File

@ -1,4 +1,7 @@
<?php
use PhpOffice\PhpWord\Shared\Converter;
use PhpOffice\PhpWord\Style\TablePosition;
include_once 'Sample_Header.php';
// New Word Document
@ -27,7 +30,7 @@ $section->addTextBreak(1);
$section->addText('Fancy table', $header);
$fancyTableStyleName = 'Fancy Table';
$fancyTableStyle = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER);
$fancyTableStyle = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80, 'alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER, 'cellSpacing' => 50);
$fancyTableFirstRowStyle = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF');
$fancyTableCellStyle = array('valign' => 'center');
$fancyTableCellBtlrStyle = array('valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR);
@ -50,7 +53,7 @@ for ($i = 1; $i <= 8; $i++) {
$table->addCell(500)->addText($text);
}
/**
/*
* 3. colspan (gridSpan) and rowspan (vMerge)
* ---------------------
* | | B | |
@ -93,7 +96,7 @@ $table->addCell(2000, $cellVCentered)->addText('C', null, $cellHCentered);
$table->addCell(2000, $cellVCentered)->addText('D', null, $cellHCentered);
$table->addCell(null, $cellRowContinue);
/**
/*
* 4. colspan (gridSpan) and rowspan (vMerge)
* ---------------------
* | | B | 1 |
@ -104,28 +107,29 @@ $table->addCell(null, $cellRowContinue);
* ---------------------
* @see https://github.com/PHPOffice/PHPWord/issues/806
*/
$section->addPageBreak();
$section->addText('Table with colspan and rowspan', $header);
$styleTable = ['borderSize' => 6, 'borderColor' => '999999'];
$styleTable = array('borderSize' => 6, 'borderColor' => '999999');
$phpWord->addTableStyle('Colspan Rowspan', $styleTable);
$table = $section->addTable('Colspan Rowspan');
$row = $table->addRow();
$row->addCell(null, ['vMerge' => 'restart'])->addText('A');
$row->addCell(null, ['gridSpan' => 2, 'vMerge' => 'restart',])->addText('B');
$row->addCell()->addText('1');
$row->addCell(1000, array('vMerge' => 'restart'))->addText('A');
$row->addCell(1000, array('gridSpan' => 2, 'vMerge' => 'restart'))->addText('B');
$row->addCell(1000)->addText('1');
$row = $table->addRow();
$row->addCell(null, ['vMerge' => 'continue']);
$row->addCell(null, ['vMerge' => 'continue','gridSpan' => 2,]);
$row->addCell()->addText('2');
$row->addCell(1000, array('vMerge' => 'continue'));
$row->addCell(1000, array('vMerge' => 'continue', 'gridSpan' => 2));
$row->addCell(1000)->addText('2');
$row = $table->addRow();
$row->addCell(null, ['vMerge' => 'continue']);
$row->addCell()->addText('C');
$row->addCell()->addText('D');
$row->addCell()->addText('3');
$row->addCell(1000, array('vMerge' => 'continue'));
$row->addCell(1000)->addText('C');
$row->addCell(1000)->addText('D');
$row->addCell(1000)->addText('3');
// 5. Nested table
@ -138,6 +142,15 @@ $cell->addText('This cell contains nested table.');
$innerCell = $cell->addTable(array('alignment' => \PhpOffice\PhpWord\SimpleType\JcTable::CENTER))->addRow()->addCell();
$innerCell->addText('Inside nested table');
// 6. Table with floating position
$section->addTextBreak(2);
$section->addText('Table with floating positioning.', $header);
$table = $section->addTable(array('borderSize' => 6, 'borderColor' => '999999', 'position' => array('vertAnchor' => TablePosition::VANCHOR_TEXT, 'bottomFromText' => Converter::cmToTwip(1))));
$cell = $table->addRow()->addCell();
$cell->addText('This is a single cell.');
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {

View File

@ -7,7 +7,7 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$header = array('size' => 16, 'bold' => true);
//1.Use EastAisa FontStyle
$section->addText('中文楷体样式测试', array('name' => '楷体', 'size' => 16, 'color' => '1B2232'));
$section->addText('中文楷体样式测试', array('name' => '楷体', 'size' => 16, 'color' => '1B2232', 'lang' => array('latin' => 'en-US', 'eastAsia' => 'zh-CN')));
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);

View File

@ -1,4 +1,7 @@
<?php
use PhpOffice\PhpWord\Element\Section;
use PhpOffice\PhpWord\Shared\Converter;
include_once 'Sample_Header.php';
// New Word document
@ -9,22 +12,29 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section->addText('Local image without any styles:');
$section->addImage('resources/_mars.jpg');
$section->addTextBreak(2);
printSeparator($section);
$section->addText('Local image with styles:');
$section->addImage('resources/_earth.jpg', array('width' => 210, 'height' => 210, 'alignment' => \PhpOffice\PhpWord\SimpleType\Jc::CENTER));
$section->addTextBreak(2);
// Remote image
printSeparator($section);
$source = 'http://php.net/images/logos/php-med-trans-light.gif';
$section->addText("Remote image from: {$source}");
$section->addImage($source);
// Image from string
printSeparator($section);
$source = 'resources/_mars.jpg';
$fileContent = file_get_contents($source);
$section->addText('Image from string');
$section->addImage($fileContent);
//Wrapping style
$text = str_repeat('Hello World! ', 15);
printSeparator($section);
$text = str_repeat('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. ', 2);
$wrappingStyles = array('inline', 'behind', 'infront', 'square', 'tight');
foreach ($wrappingStyles as $wrappingStyle) {
$section->addTextBreak(5);
$section->addText("Wrapping style {$wrappingStyle}");
$section->addImage(
'resources/_earth.jpg',
@ -35,13 +45,15 @@ foreach ($wrappingStyles as $wrappingStyle) {
'width' => 80,
'height' => 80,
'wrappingStyle' => $wrappingStyle,
'wrapDistanceRight' => Converter::cmToPoint(1),
'wrapDistanceBottom' => Converter::cmToPoint(1),
)
);
$section->addText($text);
printSeparator($section);
}
//Absolute positioning
$section->addTextBreak(3);
$section->addText('Absolute positioning: see top right corner of page');
$section->addImage(
'resources/_mars.jpg',
@ -58,7 +70,7 @@ $section->addImage(
);
//Relative positioning
$section->addTextBreak(3);
printSeparator($section);
$section->addText('Relative positioning: Horizontal position center relative to column,');
$section->addText('Vertical position top relative to line');
$section->addImage(
@ -74,6 +86,14 @@ $section->addImage(
)
);
function printSeparator(Section $section)
{
$section->addTextBreak();
$lineStyle = array('weight' => 0.2, 'width' => 150, 'height' => 0, 'align' => 'center');
$section->addLine($lineStyle);
$section->addTextBreak(2);
}
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);
if (!CLI) {

View File

@ -67,6 +67,8 @@ $listItemRun->addText(' in bold', array('bold' => true));
$listItemRun = $section->addListItemRun();
$listItemRun->addText('List item 2');
$listItemRun->addText(' in italic', array('italic' => true));
$footnote = $listItemRun->addFootnote();
$footnote->addText('this is a footnote on a list item');
$listItemRun = $section->addListItemRun();
$listItemRun->addText('List item 3');
$listItemRun->addText(' underlined', array('underline' => 'dash'));

View File

@ -9,7 +9,7 @@ $phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section->addText('You can open this OLE object by double clicking on the icon:');
$section->addTextBreak(2);
$section->addObject('resources/_sheet.xls');
$section->addOLEObject('resources/_sheet.xls');
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);

View File

@ -4,6 +4,7 @@ include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s'), ' Create new PhpWord object', EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->getSettings()->setUpdateFields(true);
// New section
$section = $phpWord->addSection();
@ -11,13 +12,14 @@ $section = $phpWord->addSection();
// Define styles
$fontStyle12 = array('spaceAfter' => 60, 'size' => 12);
$fontStyle10 = array('size' => 10);
$phpWord->addTitleStyle(null, array('size' => 22, 'bold' => true));
$phpWord->addTitleStyle(1, array('size' => 20, 'color' => '333333', 'bold' => true));
$phpWord->addTitleStyle(2, array('size' => 16, 'color' => '666666'));
$phpWord->addTitleStyle(3, array('size' => 14, 'italic' => true));
$phpWord->addTitleStyle(4, array('size' => 12));
// Add text elements
$section->addText('Table of contents 1');
$section->addTitle('Table of contents 1', 0);
$section->addTextBreak(2);
// Add TOC #1

View File

@ -14,7 +14,7 @@ $templateProcessor->deleteBlock('DELETEME');
echo date('H:i:s'), ' Saving the result document...', EOL;
$templateProcessor->saveAs('results/Sample_23_TemplateBlock.docx');
echo getEndingNotes(array('Word2007' => 'docx'));
echo getEndingNotes(array('Word2007' => 'docx'), 'results/Sample_23_TemplateBlock.docx');
if (!CLI) {
include_once 'Sample_Footer.php';
}

View File

@ -4,17 +4,92 @@ include_once 'Sample_Header.php';
// New Word Document
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->addParagraphStyle('Heading2', array('alignment' => 'center'));
$section = $phpWord->addSection();
$html = '<h1>Adding element via HTML</h1>';
$html .= '<p>Some well formed HTML snippet needs to be used</p>';
$html .= '<p>Some well-formed HTML snippet needs to be used</p>';
$html .= '<p>With for example <strong>some<sup>1</sup> <em>inline</em> formatting</strong><sub>1</sub></p>';
$html .= '<p>Unordered (bulleted) list:</p>';
$html .= '<ul><li>Item 1</li><li>Item 2</li><ul><li>Item 2.1</li><li>Item 2.1</li></ul></ul>';
$html .= '<p>Ordered (numbered) list:</p>';
$html .= '<ol><li>Item 1</li><li>Item 2</li></ol>';
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html);
$html .= '<p>A link to <a href="http://phpword.readthedocs.io/" style="text-decoration: underline">Read the docs</a></p>';
$html .= '<p lang="he-IL" style="text-align: right; direction: rtl">היי, זה פסקה מימין לשמאל</p>';
$html .= '<p style="margin-top: 240pt;">Unordered (bulleted) list:</p>';
$html .= '<ul><li>Item 1</li><li>Item 2</li><ul><li>Item 2.1</li><li>Item 2.1</li></ul></ul>';
$html .= '<p style="margin-top: 240pt;">1.5 line height with first line text indent:</p>';
$html .= '<p style="text-align: justify; text-indent: 70.9pt; line-height: 150%;">Lorem ipsum dolor sit amet, <strong>consectetur adipiscing elit</strong>, 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.</p>';
$html .= '<h2 style="align: center">centered title</h2>';
$html .= '<p style="margin-top: 240pt;">Ordered (numbered) list:</p>';
$html .= '<ol>
<li><p style="font-weight: bold;">List 1 item 1</p></li>
<li>List 1 item 2</li>
<ol>
<li>sub list 1</li>
<li>sub list 2</li>
</ol>
<li>List 1 item 3</li>
</ol>
<p style="margin-top: 15px;">A second list, numbering should restart</p>
<ol>
<li>List 2 item 1</li>
<li>List 2 item 2</li>
<li>
<ol>
<li>sub list 1</li>
<li>sub list 2</li>
</ol>
</li>
<li>List 2 item 3</li>
<ol>
<li>sub list 1, restarts with a</li>
<li>sub list 2</li>
</ol>
</ol>';
$html .= '<p style="margin-top: 240pt;">List with formatted content:</p>';
$html .= '<ul>
<li>
<span style="font-family: arial,helvetica,sans-serif;">
<span style="font-size: 16px;">big list item1</span>
</span>
</li>
<li>
<span style="font-family: arial,helvetica,sans-serif;">
<span style="font-size: 10px; font-weight: bold;">list item2 in bold</span>
</span>
</li>
</ul>';
$html .= '<p style="margin-top: 240pt;">A table with formatting:</p>';
$html .= '<table align="center" style="width: 50%; border: 6px #0000FF double;">
<thead>
<tr style="background-color: #FF0000; text-align: center; color: #FFFFFF; font-weight: bold; ">
<th style="width: 50pt">header a</th>
<th style="width: 50">header b</th>
<th style="background-color: #FFFF00; border-width: 12px"><span style="background-color: #00FF00;">header c</span></th>
</tr>
</thead>
<tbody>
<tr><td style="border-style: dotted;">1</td><td colspan="2">2</td></tr>
<tr><td>This is <b>bold</b> text</td><td></td><td>6</td></tr>
</tbody>
</table>';
$html .= '<p style="margin-top: 240pt;">Table inside another table:</p>';
$html .= '<table align="center" style="width: 80%; border: 6px #0000FF double;">
<tr><td>
<table style="width: 100%; border: 4px #FF0000 dotted;">
<tr><td>column 1</td><td>column 2</td></tr>
</table>
</td></tr>
<tr><td style="text-align: center;">Cell in parent table</td></tr>
</table>';
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html, false, false);
// Save file
echo write($phpWord, basename(__FILE__, '.php'), $writers);

View File

@ -1,28 +1,67 @@
<?php
use PhpOffice\PhpWord\Element\TextRun;
include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s'), ' Create new PhpWord object', EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
PhpOffice\PhpWord\Style::addTitleStyle(1, array('size' => 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);

View File

@ -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);

View File

@ -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);

View File

@ -0,0 +1,62 @@
<?php
include_once 'Sample_Header.php';
// New Word Document
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// A comment
$comment = new \PhpOffice\PhpWord\Element\Comment('Authors name', new \DateTime(), 'my_initials');
$comment->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';
}

View File

@ -0,0 +1,21 @@
<?php
use PhpOffice\PhpWord\SimpleType\DocProtect;
include_once 'Sample_Header.php';
// New Word Document
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$documentProtection = $phpWord->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';
}

View File

@ -0,0 +1,29 @@
<?php
use PhpOffice\PhpWord\Element\TrackChange;
include_once 'Sample_Header.php';
// New Word Document
echo date('H:i:s') , ' Create new PhpWord object' , EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// New portrait section
$section = $phpWord->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';
}

View File

@ -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 ? '' : "<h1>{$pageHeading}</h1>";
// 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 .= "<li><a href='{$file}'>{$name}</a></li>";
}
}
closedir($handle);
}
/**
@ -71,7 +83,7 @@ function write($phpWord, $filename, $writers)
$result .= EOL;
}
$result .= getEndingNotes($writers);
$result .= getEndingNotes($writers, $filename);
return $result;
}
@ -80,17 +92,17 @@ function write($phpWord, $filename, $writers)
* Get ending notes
*
* @param array $writers
*
* @param mixed $filename
* @return string
*/
function getEndingNotes($writers)
function getEndingNotes($writers, $filename)
{
$result = '';
// Do not show execution time for index
if (!IS_INDEX) {
$result .= date('H:i:s') . " Done writing file(s)" . EOL;
$result .= date('H:i:s') . " Peak memory usage: " . (memory_get_peak_usage(true) / 1024 / 1024) . " MB" . EOL;
$result .= date('H:i:s') . ' Done writing file(s)' . EOL;
$result .= date('H:i:s') . ' Peak memory usage: ' . (memory_get_peak_usage(true) / 1024 / 1024) . ' MB' . EOL;
}
// Return
@ -110,6 +122,12 @@ function getEndingNotes($writers)
}
}
$result .= '</p>';
$result .= '<pre>';
if (file_exists($filename . '.php')) {
$result .= highlight_file($filename . '.php', true);
}
$result .= '</pre>';
}
}

View File

@ -25,14 +25,14 @@ if (!CLI) {
<?php
}
if (!CLI) {
echo "<h3>Requirement check:</h3>";
echo "<ul>";
echo '<h3>Requirement check:</h3>';
echo '<ul>';
foreach ($requirements as $key => $value) {
list($label, $result) = $value;
$status = $result ? 'passed' : 'failed';
echo "<li>{$label} ... <span class='{$status}'>{$status}</span></li>";
}
echo "</ul>";
echo '</ul>';
include_once 'Sample_Footer.php';
} else {
echo 'Requirement check:' . PHP_EOL;

View File

@ -11,5 +11,15 @@
<ul><li>Item 1</li><li>Item 2</li><ul><li>Item 2.1</li><li>Item 2.1</li></ul></ul>
<p>Ordered (numbered) list:</p>
<ol><li>Item 1</li><li>Item 2</li></ol>
<p style="line-height:2">Double height</p>
<h2>Includes images</h2>
<img src="https://phpword.readthedocs.io/en/latest/_images/phpword.png" alt=""/>
<img src="https://localhost/gev/desarrollo/actividades/pruebas_14/5b064503587f7.jpeg" name="Imagen 12" align="bottom" width="208" height="183" border="0"/>
<img src="http://localhost/gev/desarrollo/actividades/pruebas_14/5b064503589db.png" name="Imagen 13" align="bottom" width="143" height="202" border="0"/>
<img src="http://localhost/gev/desarrollo/actividades/pruebas_14/5b0645035aac8.jpeg" name="Imagen 14" align="bottom" width="194" height="188" border="0"/>
</body>
</html>

0
samples/results/.gitignore vendored Normal file → Executable file
View File

17
sonar-project.properties Normal file
View File

@ -0,0 +1,17 @@
# must be unique in a given SonarQube instance
sonar.projectKey=phpoffice:phpword
# this is the name and version displayed in the SonarQube UI. Was mandatory prior to SonarQube 6.1.
sonar.projectName=PHPWord
sonar.projectVersion=0.16
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
# This property is optional if sonar.modules is set.
sonar.sources=src
sonar.tests=tests
sonar.php.coverage.reportPaths=build/logs/clover.xml
sonar.php.tests.reportPath=build/logs/logfile.xml
# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
sonar.host.url=http://localhost:9000

View File

@ -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.
*
* @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
*/
@ -27,14 +27,14 @@ abstract class AbstractCollection
/**
* Items
*
* @var array
* @var \PhpOffice\PhpWord\Element\AbstractContainer[]
*/
private $items = array();
/**
* Get items
*
* @return array
* @return \PhpOffice\PhpWord\Element\AbstractContainer[]
*/
public function getItems()
{
@ -45,23 +45,22 @@ abstract class AbstractCollection
* Get item by index
*
* @param int $index
* @return mixed
* @return \PhpOffice\PhpWord\Element\AbstractContainer
*/
public function getItem($index)
{
if (array_key_exists($index, $this->items)) {
return $this->items[$index];
} else {
return null;
}
return null;
}
/**
* Set item.
*
* @param int $index
* @param mixed $item
* @return void
* @param \PhpOffice\PhpWord\Element\AbstractContainer $item
*/
public function setItem($index, $item)
{
@ -73,7 +72,7 @@ abstract class AbstractCollection
/**
* Add new item
*
* @param mixed $item
* @param \PhpOffice\PhpWord\Element\AbstractContainer $item
* @return int
*/
public function addItem($item)

View File

@ -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.
*
* @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
*/

View File

@ -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.
*
* @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
*/

View 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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Collection;
/**
* Comments collection
*
* @since 0.12.0
*/
class Comments extends AbstractCollection
{
}

View File

@ -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.
*
* @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
*/

View File

@ -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.
*
* @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
*/

View File

@ -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.
*
* @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
*/

View File

@ -0,0 +1,181 @@
<?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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\ComplexType;
use PhpOffice\PhpWord\SimpleType\NumberFormat;
/**
* Footnote properties
*
* @see http://www.datypic.com/sc/ooxml/e-w_footnotePr-1.html
*/
final class FootnoteProperties
{
const RESTART_NUMBER_CONTINUOUS = 'continuous';
const RESTART_NUMBER_EACH_SECTION = 'eachSect';
const RESTART_NUMBER_EACH_PAGE = 'eachPage';
const POSITION_PAGE_BOTTOM = 'pageBottom';
const POSITION_BENEATH_TEXT = 'beneathText';
const POSITION_SECTION_END = 'sectEnd';
const POSITION_DOC_END = 'docEnd';
/**
* Footnote Positioning Location
*
* @var string
*/
private $pos;
/**
* Footnote Numbering Format w:numFmt, one of PhpOffice\PhpWord\SimpleType\NumberFormat
*
* @var string
*/
private $numFmt;
/**
* Footnote and Endnote Numbering Starting Value
*
* @var float
*/
private $numStart;
/**
* Footnote and Endnote Numbering Restart Location
*
* @var string
*/
private $numRestart;
/**
* Get the Footnote Positioning Location
*
* @return string
*/
public function getPos()
{
return $this->pos;
}
/**
* Set the Footnote Positioning Location (pageBottom, beneathText, sectEnd, docEnd)
*
* @param string $pos
* @throws \InvalidArgumentException
* @return self
*/
public function setPos($pos)
{
$position = array(
self::POSITION_PAGE_BOTTOM,
self::POSITION_BENEATH_TEXT,
self::POSITION_SECTION_END,
self::POSITION_DOC_END,
);
if (in_array($pos, $position)) {
$this->pos = $pos;
} else {
throw new \InvalidArgumentException('Invalid value, on of ' . implode(', ', $position) . ' possible');
}
return $this;
}
/**
* Get the Footnote Numbering Format
*
* @return string
*/
public function getNumFmt()
{
return $this->numFmt;
}
/**
* Set the Footnote Numbering Format
*
* @param string $numFmt One of NumberFormat
* @return self
*/
public function setNumFmt($numFmt)
{
NumberFormat::validate($numFmt);
$this->numFmt = $numFmt;
return $this;
}
/**
* Get the Footnote Numbering Format
*
* @return float
*/
public function getNumStart()
{
return $this->numStart;
}
/**
* Set the Footnote Numbering Format
*
* @param float $numStart
* @return self
*/
public function setNumStart($numStart)
{
$this->numStart = $numStart;
return $this;
}
/**
* Get the Footnote and Endnote Numbering Starting Value
*
* @return string
*/
public function getNumRestart()
{
return $this->numRestart;
}
/**
* Set the Footnote and Endnote Numbering Starting Value (continuous, eachSect, eachPage)
*
* @param string $numRestart
* @throws \InvalidArgumentException
* @return self
*/
public function setNumRestart($numRestart)
{
$restartNumbers = array(
self::RESTART_NUMBER_CONTINUOUS,
self::RESTART_NUMBER_EACH_SECTION,
self::RESTART_NUMBER_EACH_PAGE,
);
if (in_array($numRestart, $restartNumbers)) {
$this->numRestart = $numRestart;
} else {
throw new \InvalidArgumentException('Invalid value, on of ' . implode(', ', $restartNumbers) . ' possible');
}
return $this;
}
}

View File

@ -0,0 +1,106 @@
<?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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\ComplexType;
/**
* Spelling and Grammatical Checking State
*
* @see http://www.datypic.com/sc/ooxml/e-w_proofState-1.html
*/
final class ProofState
{
/**
* Check Completed
*/
const CLEAN = 'clean';
/**
* Check Not Completed
*/
const DIRTY = 'dirty';
/**
* Spell Checking State
*
* @var string
*/
private $spelling;
/**
* Grammatical Checking State
*
* @var string
*/
private $grammar;
/**
* Set the Spell Checking State (dirty or clean)
*
* @param string $spelling
* @throws \InvalidArgumentException
* @return self
*/
public function setSpelling($spelling)
{
if ($spelling == self::CLEAN || $spelling == self::DIRTY) {
$this->spelling = $spelling;
} else {
throw new \InvalidArgumentException('Invalid value, dirty or clean possible');
}
return $this;
}
/**
* Get the Spell Checking State
*
* @return string
*/
public function getSpelling()
{
return $this->spelling;
}
/**
* Set the Grammatical Checking State (dirty or clean)
*
* @param string $grammar
* @throws \InvalidArgumentException
* @return self
*/
public function setGrammar($grammar)
{
if ($grammar == self::CLEAN || $grammar == self::DIRTY) {
$this->grammar = $grammar;
} else {
throw new \InvalidArgumentException('Invalid value, dirty or clean possible');
}
return $this;
}
/**
* Get the Grammatical Checking State
*
* @return string
*/
public function getGrammar()
{
return $this->grammar;
}
}

View File

@ -0,0 +1,59 @@
<?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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\ComplexType;
use PhpOffice\PhpWord\SimpleType\TblWidth as TblWidthSimpleType;
/**
* @see http://www.datypic.com/sc/ooxml/t-w_CT_TblWidth.html
*/
final class TblWidth
{
/** @var string */
private $type;
/** @var int */
private $value;
/**
* @param int $value If omitted, then its value shall be assumed to be 0
* @param string $type If omitted, then its value shall be assumed to be dxa
*/
public function __construct($value = 0, $type = TblWidthSimpleType::TWIP)
{
$this->value = $value;
TblWidthSimpleType::validate($type);
$this->type = $type;
}
/**
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* @return int
*/
public function getValue()
{
return $this->value;
}
}

View File

@ -0,0 +1,166 @@
<?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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\ComplexType;
/**
* Visibility of Annotation Types
*
* @see http://www.datypic.com/sc/ooxml/e-w_revisionView-1.html
*/
final class TrackChangesView
{
/**
* Display Visual Indicator Of Markup Area
*
* @var bool
*/
private $markup;
/**
* Display Comments
*
* @var bool
*/
private $comments;
/**
* Display Content Revisions
*
* @var bool
*/
private $insDel;
/**
* Display Formatting Revisions
*
* @var bool
*/
private $formatting;
/**
* Display Ink Annotations
*
* @var bool
*/
private $inkAnnotations;
/**
* Get Display Visual Indicator Of Markup Area
*
* @return bool True if markup is shown
*/
public function hasMarkup()
{
return $this->markup;
}
/**
* Set Display Visual Indicator Of Markup Area
*
* @param bool $markup
* Set to true to show markup
*/
public function setMarkup($markup)
{
$this->markup = $markup === null ? true : $markup;
}
/**
* Get Display Comments
*
* @return bool True if comments are shown
*/
public function hasComments()
{
return $this->comments;
}
/**
* Set Display Comments
*
* @param bool $comments
* Set to true to show comments
*/
public function setComments($comments)
{
$this->comments = $comments === null ? true : $comments;
}
/**
* Get Display Content Revisions
*
* @return bool True if content revisions are shown
*/
public function hasInsDel()
{
return $this->insDel;
}
/**
* Set Display Content Revisions
*
* @param bool $insDel
* Set to true to show content revisions
*/
public function setInsDel($insDel)
{
$this->insDel = $insDel === null ? true : $insDel;
}
/**
* Get Display Formatting Revisions
*
* @return bool True if formatting revisions are shown
*/
public function hasFormatting()
{
return $this->formatting;
}
/**
* Set Display Formatting Revisions
*
* @param bool|null $formatting
* Set to true to show formatting revisions
*/
public function setFormatting($formatting = null)
{
$this->formatting = $formatting === null ? true : $formatting;
}
/**
* Get Display Ink Annotations
*
* @return bool True if ink annotations are shown
*/
public function hasInkAnnotations()
{
return $this->inkAnnotations;
}
/**
* Set Display Ink Annotations
*
* @param bool $inkAnnotations
* Set to true to show ink annotations
*/
public function setInkAnnotations($inkAnnotations)
{
$this->inkAnnotations = $inkAnnotations === null ? true : $inkAnnotations;
}
}

View File

@ -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.
*
* @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
*/
@ -23,7 +23,7 @@ namespace PhpOffice\PhpWord\Element;
* @method Text addText(string $text, mixed $fStyle = null, mixed $pStyle = null)
* @method TextRun addTextRun(mixed $pStyle = null)
* @method Bookmark addBookmark(string $name)
* @method Link addLink(string $target, string $text = null, mixed $fStyle = null, mixed $pStyle = null)
* @method Link addLink(string $target, string $text = null, mixed $fStyle = null, mixed $pStyle = null, boolean $internal = false)
* @method PreserveText addPreserveText(string $text, mixed $fStyle = null, mixed $pStyle = null)
* @method void addTextBreak(int $count = 1, mixed $fStyle = null, mixed $pStyle = null)
* @method ListItem addListItem(string $txt, int $depth = 0, mixed $font = null, mixed $list = null, mixed $para = null)
@ -33,19 +33,20 @@ namespace PhpOffice\PhpWord\Element;
* @method CheckBox addCheckBox(string $name, $text, mixed $fStyle = null, mixed $pStyle = null)
* @method Title addTitle(string $text, int $depth = 1)
* @method TOC addTOC(mixed $fontStyle = null, mixed $tocStyle = null, int $minDepth = 1, int $maxDepth = 9)
*
* @method PageBreak addPageBreak()
* @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 Image addImage(string $source, mixed $style = null, bool $isWatermark = false, $name = null)
* @method OLEObject addOLEObject(string $source, mixed $style = null)
* @method TextBox addTextBox(mixed $style = null)
* @method Field addField(string $type = null, array $properties = array(), array $options = array())
* @method Field addField(string $type = null, array $properties = array(), array $options = array(), mixed $text = null)
* @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)
*
* @method \PhpOffice\PhpWord\Element\OLEObject addObject(string $source, mixed $style = null) deprecated, use addOLEObject instead
*
* @since 0.10.0
*/
abstract class AbstractContainer extends AbstractElement
@ -53,12 +54,12 @@ abstract class AbstractContainer extends AbstractElement
/**
* Elements collection
*
* @var array
* @var \PhpOffice\PhpWord\Element\AbstractElement[]
*/
protected $elements = array();
/**
* Container type Section|Header|Footer|Footnote|Endnote|Cell|TextRun|TextBox|ListItemRun
* Container type Section|Header|Footer|Footnote|Endnote|Cell|TextRun|TextBox|ListItemRun|TrackChange
*
* @var string
*/
@ -80,14 +81,14 @@ abstract class AbstractContainer extends AbstractElement
{
$elements = array(
'Text', 'TextRun', 'Bookmark', 'Link', 'PreserveText', 'TextBreak',
'ListItem', 'ListItemRun', 'Table', 'Image', 'Object',
'ListItem', 'ListItemRun', 'Table', 'Image', 'Object', 'OLEObject',
'Footnote', 'Endnote', 'CheckBox', 'TextBox', 'Field',
'Line', 'Shape', 'Title', 'TOC', 'PageBreak',
'Chart', 'FormField', 'SDT'
'Chart', 'FormField', 'SDT', 'Comment',
);
$functions = array();
foreach ($elements as $element) {
$functions['add' . strtolower($element)] = $element;
$functions['add' . strtolower($element)] = $element == 'Object' ? 'OLEObject' : $element;
}
// Run valid `add` command
@ -98,16 +99,15 @@ abstract class AbstractContainer extends AbstractElement
// Special case for TextBreak
// @todo Remove the `$count` parameter in 1.0.0 to make this element similiar to other elements?
if ($element == 'TextBreak') {
@list($count, $fontStyle, $paragraphStyle) = $args; // Suppress error
list($count, $fontStyle, $paragraphStyle) = array_pad($args, 3, null);
if ($count === null) {
$count = 1;
}
for ($i = 1; $i <= $count; $i++) {
$this->addElement($element, $fontStyle, $paragraphStyle);
}
// All other elements
} else {
// All other elements
array_unshift($args, $element); // Prepend element name to the beginning of args array
return call_user_func_array(array($this, 'addElement'), $args);
}
@ -157,15 +157,48 @@ abstract class AbstractContainer extends AbstractElement
/**
* Get all elements
*
* @return array
*
* @codeCoverageIgnore
* @return \PhpOffice\PhpWord\Element\AbstractElement[]
*/
public function getElements()
{
return $this->elements;
}
/**
* Returns the element at the requested position
*
* @param int $index
* @return \PhpOffice\PhpWord\Element\AbstractElement|null
*/
public function getElement($index)
{
if (array_key_exists($index, $this->elements)) {
return $this->elements[$index];
}
return null;
}
/**
* Removes the element at requested index
*
* @param int|\PhpOffice\PhpWord\Element\AbstractElement $toRemove
*/
public function removeElement($toRemove)
{
if (is_int($toRemove) && array_key_exists($toRemove, $this->elements)) {
unset($this->elements[$toRemove]);
} elseif ($toRemove instanceof \PhpOffice\PhpWord\Element\AbstractElement) {
foreach ($this->elements as $key => $element) {
if ($element->getElementId() === $toRemove->getElementId()) {
unset($this->elements[$key]);
return;
}
}
}
}
/**
* Count elements
*
@ -181,14 +214,13 @@ abstract class AbstractContainer extends AbstractElement
*
* @param string $method
*
* @return bool
*
* @throws \BadMethodCallException
* @return bool
*/
private function checkValidity($method)
{
$generalContainers = array(
'Section', 'Header', 'Footer', 'Footnote', 'Endnote', 'Cell', 'TextRun', 'TextBox', 'ListItemRun',
'Section', 'Header', 'Footer', 'Footnote', 'Endnote', 'Cell', 'TextRun', 'TextBox', 'ListItemRun', 'TrackChange',
);
$validContainers = array(
@ -197,25 +229,26 @@ abstract class AbstractContainer extends AbstractElement
'Link' => $generalContainers,
'TextBreak' => $generalContainers,
'Image' => $generalContainers,
'Object' => $generalContainers,
'OLEObject' => $generalContainers,
'Field' => $generalContainers,
'Line' => $generalContainers,
'Shape' => $generalContainers,
'FormField' => $generalContainers,
'SDT' => $generalContainers,
'TextRun' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
'TrackChange' => $generalContainers,
'TextRun' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox', 'TrackChange', 'ListItemRun'),
'ListItem' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
'ListItemRun' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
'Table' => array('Section', 'Header', 'Footer', 'Cell', 'TextBox'),
'CheckBox' => array('Section', 'Header', 'Footer', 'Cell'),
'CheckBox' => array('Section', 'Header', 'Footer', 'Cell', 'TextRun'),
'TextBox' => array('Section', 'Header', 'Footer', 'Cell'),
'Footnote' => array('Section', 'TextRun', 'Cell'),
'Footnote' => array('Section', 'TextRun', 'Cell', 'ListItemRun'),
'Endnote' => array('Section', 'TextRun', 'Cell'),
'PreserveText' => array('Header', 'Footer', 'Cell'),
'Title' => array('Section'),
'PreserveText' => array('Section', 'Header', 'Footer', 'Cell'),
'Title' => array('Section', 'Cell'),
'TOC' => array('Section'),
'PageBreak' => array('Section'),
'Chart' => array('Section'),
'Chart' => array('Section', 'Cell'),
);
// Special condition, e.g. preservetext can only exists in cell when

View File

@ -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.
*
* @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
*/
@ -73,7 +73,7 @@ abstract class AbstractElement
/**
* Unique Id for element
*
* @var int
* @var string
*/
protected $elementId;
@ -93,6 +93,20 @@ abstract class AbstractElement
*/
private $nestedLevel = 0;
/**
* A reference to the parent
*
* @var \PhpOffice\PhpWord\Element\AbstractElement
*/
private $parent;
/**
* changed element info
*
* @var TrackChange
*/
private $trackChange;
/**
* Parent container type
*
@ -108,12 +122,26 @@ abstract class AbstractElement
protected $mediaRelation = false;
/**
* Is part of collection; true for Title, Footnote, Endnote, and Chart
* Is part of collection; true for Title, Footnote, Endnote, Chart, and Comment
*
* @var bool
*/
protected $collectionRelation = false;
/**
* The start position for the linked comment
*
* @var Comment
*/
protected $commentRangeStart;
/**
* The end position for the linked comment
*
* @var Comment
*/
protected $commentRangeEnd;
/**
* Get PhpWord
*
@ -128,7 +156,6 @@ abstract class AbstractElement
* Set PhpWord as reference.
*
* @param \PhpOffice\PhpWord\PhpWord $phpWord
* @return void
*/
public function setPhpWord(PhpWord $phpWord = null)
{
@ -150,7 +177,6 @@ abstract class AbstractElement
*
* @param string $docPart
* @param int $docPartId
* @return void
*/
public function setDocPart($docPart, $docPartId = 1)
{
@ -207,7 +233,6 @@ abstract class AbstractElement
* Set element index.
*
* @param int $value
* @return void
*/
public function setElementIndex($value)
{
@ -226,8 +251,6 @@ abstract class AbstractElement
/**
* Set element unique ID from 6 first digit of md5.
*
* @return void
*/
public function setElementId()
{
@ -248,7 +271,6 @@ abstract class AbstractElement
* Set relation Id.
*
* @param int $value
* @return void
*/
public function setRelationId($value)
{
@ -265,17 +287,70 @@ abstract class AbstractElement
return $this->nestedLevel;
}
/**
* Get comment start
*
* @return Comment
*/
public function getCommentRangeStart()
{
return $this->commentRangeStart;
}
/**
* Set comment start
*
* @param Comment $value
*/
public function setCommentRangeStart(Comment $value)
{
if ($this instanceof Comment) {
throw new \InvalidArgumentException('Cannot set a Comment on a Comment');
}
$this->commentRangeStart = $value;
$this->commentRangeStart->setStartElement($this);
}
/**
* Get comment end
*
* @return Comment
*/
public function getCommentRangeEnd()
{
return $this->commentRangeEnd;
}
/**
* Set comment end
*
* @param Comment $value
*/
public function setCommentRangeEnd(Comment $value)
{
if ($this instanceof Comment) {
throw new \InvalidArgumentException('Cannot set a Comment on a Comment');
}
$this->commentRangeEnd = $value;
$this->commentRangeEnd->setEndElement($this);
}
public function getParent()
{
return $this->parent;
}
/**
* Set parent container
*
* 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 setParentContainer(AbstractElement $container)
public function setParentContainer(self $container)
{
$this->parentContainer = substr(get_class($container), strrpos(get_class($container), '\\') + 1);
$this->parent = $container;
// Set nested level
$this->nestedLevel = $container->getNestedLevel();
@ -300,16 +375,17 @@ abstract class AbstractElement
*
* - 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) {
if (!$this instanceof Link && !$this instanceof Image && !$this instanceof OLEObject) {
return;
}
$elementName = substr(get_class($this), strrpos(get_class($this), '\\') + 1);
if ($elementName == 'OLEObject') {
$elementName = 'Object';
}
$mediaPart = $this->getMediaPart();
$source = $this->getSource();
$image = null;
@ -319,7 +395,7 @@ abstract class AbstractElement
$rId = Media::addElement($mediaPart, strtolower($elementName), $source, $image);
$this->setRelationId($rId);
if ($this instanceof Object) {
if ($this instanceof OLEObject) {
$icon = $this->getIcon();
$rId = Media::addElement($mediaPart, 'image', $icon, new Image($icon));
$this->setImageRelationId($rId);
@ -328,8 +404,6 @@ abstract class AbstractElement
/**
* Set relation Id for elements that will be registered in the Collection subnamespaces.
*
* @return void
*/
private function setCollectionRelation()
{
@ -348,7 +422,7 @@ abstract class AbstractElement
*/
public function isInSection()
{
return ($this->docPart == 'Section');
return $this->docPart == 'Section';
}
/**
@ -371,22 +445,53 @@ abstract class AbstractElement
return $style;
}
/**
* Sets the trackChange information
*
* @param TrackChange $trackChange
*/
public function setTrackChange(TrackChange $trackChange)
{
$this->trackChange = $trackChange;
}
/**
* Gets the trackChange information
*
* @return TrackChange
*/
public function getTrackChange()
{
return $this->trackChange;
}
/**
* Set changed
*
* @param string $type INSERTED|DELETED
* @param string $author
* @param null|int|\DateTime $date allways in UTC
*/
public function setChangeInfo($type, $author, $date = null)
{
$this->trackChange = new TrackChange($type, $author, $date);
}
/**
* Set enum value
*
* @param mixed $value
* @param array $enum
* @param mixed $default
*
* @return mixed
* @param string|null $value
* @param string[] $enum
* @param string|null $default
*
* @throws \InvalidArgumentException
* @return string|null
*
* @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)) {
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;

View File

@ -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.
*
* @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
*/
@ -43,11 +43,9 @@ class Bookmark extends AbstractElement
*
* @param string $name
*/
public function __construct($name)
public function __construct($name = '')
{
$this->name = CommonText::toUTF8($name);
return $this;
}
/**

View File

@ -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.
*
* @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
*/

View File

@ -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.
*
* @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
*/
@ -61,11 +61,12 @@ class Chart extends AbstractElement
* @param array $categories
* @param array $values
* @param array $style
* @param null|mixed $seriesName
*/
public function __construct($type, $categories, $values, $style = null)
public function __construct($type, $categories, $values, $style = null, $seriesName = null)
{
$this->setType($type);
$this->addSeries($categories, $values);
$this->addSeries($categories, $values, $seriesName);
$this->style = $this->setNewStyle(new ChartStyle(), $style, true);
}
@ -83,11 +84,10 @@ class Chart extends AbstractElement
* Set type.
*
* @param string $value
* @return void
*/
public function setType($value)
{
$enum = array('pie', 'doughnut', 'line', 'bar', 'column', 'area', 'radar', 'scatter');
$enum = array('pie', 'doughnut', 'line', 'bar', 'stacked_bar', 'percent_stacked_bar', 'column', 'stacked_column', 'percent_stacked_column', 'area', 'radar', 'scatter');
$this->type = $this->setEnumVal($value, $enum, 'pie');
}
@ -96,11 +96,15 @@ class Chart extends AbstractElement
*
* @param array $categories
* @param array $values
* @return void
* @param null|mixed $name
*/
public function addSeries($categories, $values)
public function addSeries($categories, $values, $name = null)
{
$this->series[] = array('categories' => $categories, 'values' => $values);
$this->series[] = array(
'categories' => $categories,
'values' => $values,
'name' => $name,
);
}
/**

View File

@ -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.
*
* @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
*/
@ -40,7 +40,6 @@ class CheckBox extends Text
* @param string $text
* @param mixed $fontStyle
* @param mixed $paragraphStyle
* @return self
*/
public function __construct($name = null, $text = null, $fontStyle = null, $paragraphStyle = null)
{

View File

@ -0,0 +1,122 @@
<?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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
/**
* Comment element
* @see http://datypic.com/sc/ooxml/t-w_CT_Comment.html
*/
class Comment extends TrackChange
{
/**
* Initials
*
* @var string
*/
private $initials;
/**
* The Element where this comment starts
*
* @var AbstractElement
*/
private $startElement;
/**
* The Element where this comment ends
*
* @var AbstractElement
*/
private $endElement;
/**
* Is part of collection
*
* @var bool
*/
protected $collectionRelation = true;
/**
* Create a new Comment Element
*
* @param string $author
* @param null|\DateTime $date
* @param string $initials
*/
public function __construct($author, $date = null, $initials = null)
{
parent::__construct(null, $author, $date);
$this->initials = $initials;
}
/**
* Get Initials
*
* @return string
*/
public function getInitials()
{
return $this->initials;
}
/**
* Sets the element where this comment starts
*
* @param \PhpOffice\PhpWord\Element\AbstractElement $value
*/
public function setStartElement(AbstractElement $value)
{
$this->startElement = $value;
if ($value->getCommentRangeStart() == null) {
$value->setCommentRangeStart($this);
}
}
/**
* Get the element where this comment starts
*
* @return \PhpOffice\PhpWord\Element\AbstractElement
*/
public function getStartElement()
{
return $this->startElement;
}
/**
* Sets the element where this comment ends
*
* @param \PhpOffice\PhpWord\Element\AbstractElement $value
*/
public function setEndElement(AbstractElement $value)
{
$this->endElement = $value;
if ($value->getCommentRangeEnd() == null) {
$value->setCommentRangeEnd($this);
}
}
/**
* Get the element where this comment ends
*
* @return \PhpOffice\PhpWord\Element\AbstractElement
*/
public function getEndElement()
{
return $this->endElement;
}
}

View File

@ -10,15 +10,13 @@
* 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-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
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Paragraph;
/**
* Endnote element
*
@ -38,6 +36,6 @@ class Endnote extends Footnote
*/
public function __construct($paragraphStyle = null)
{
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
parent::__construct($paragraphStyle);
}
}

View File

@ -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.
*
* @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
*/
@ -21,7 +21,7 @@ namespace PhpOffice\PhpWord\Element;
* Field element
*
* @since 0.11.0
* @link http://www.schemacentral.com/sc/ooxml/t-w_CT_SimpleField.html
* @see http://www.schemacentral.com/sc/ooxml/t-w_CT_SimpleField.html
*/
class Field extends AbstractElement
{
@ -36,23 +36,52 @@ class Field extends AbstractElement
'properties' => array(
'format' => array('Arabic', 'ArabicDash', 'alphabetic', 'ALPHABETIC', 'roman', 'ROMAN'),
),
'options'=>array('PreserveFormat')
'options' => array('PreserveFormat'),
),
'NUMPAGES' => array(
'properties' => array(
'format' => array('Arabic', 'ArabicDash', 'alphabetic', 'ALPHABETIC', 'roman', 'ROMAN'),
'numformat' => array('0', '0,00', '#.##0', '#.##0,00', '€ #.##0,00(€ #.##0,00)', '0%', '0,00%')
'format' => array('Arabic', 'ArabicDash', 'CardText', 'DollarText', 'Ordinal', 'OrdText',
'alphabetic', 'ALPHABETIC', 'roman', 'ROMAN', 'Caps', 'FirstCap', 'Lower', 'Upper', ),
'numformat' => array('0', '0,00', '#.##0', '#.##0,00', '€ #.##0,00(€ #.##0,00)', '0%', '0,00%'),
),
'options'=>array('PreserveFormat')
'options' => array('PreserveFormat'),
),
'DATE' => array(
'properties' => array(
'dateformat' =>array('d-M-yyyy', 'dddd d MMMM yyyy', 'd MMMM yyyy', 'd-M-yy', 'yyyy-MM-dd',
'd-MMM-yy', 'd/M/yyyy', 'd MMM. yy', 'd/M/yy', 'MMM-yy', 'd-M-yyy H:mm', 'd-M-yyyy H:mm:ss',
'h:mm am/pm', 'h:mm:ss am/pm', 'HH:mm', 'HH:mm:ss')
'dateformat' => array(
/* Generic formats */
'yyyy-MM-dd', 'yyyy-MM', 'MMM-yy', 'MMM-yyyy', 'h:mm am/pm', 'h:mm:ss am/pm', 'HH:mm', 'HH:mm:ss',
/* Day-Month-Year formats */
'dddd d MMMM yyyy', 'd MMMM yyyy', 'd-MMM-yy', 'd MMM. yy',
'd-M-yy', 'd-M-yy h:mm', 'd-M-yy h:mm:ss', 'd-M-yy h:mm am/pm', 'd-M-yy h:mm:ss am/pm', 'd-M-yy HH:mm', 'd-M-yy HH:mm:ss',
'd/M/yy', 'd/M/yy h:mm', 'd/M/yy h:mm:ss', 'd/M/yy h:mm am/pm', 'd/M/yy h:mm:ss am/pm', 'd/M/yy HH:mm', 'd/M/yy HH:mm:ss',
'd-M-yyyy', 'd-M-yyyy h:mm', 'd-M-yyyy h:mm:ss', 'd-M-yyyy h:mm am/pm', 'd-M-yyyy h:mm:ss am/pm', 'd-M-yyyy HH:mm', 'd-M-yyyy HH:mm:ss',
'd/M/yyyy', 'd/M/yyyy h:mm', 'd/M/yyyy h:mm:ss', 'd/M/yyyy h:mm am/pm', 'd/M/yyyy h:mm:ss am/pm', 'd/M/yyyy HH:mm', 'd/M/yyyy HH:mm:ss',
/* Month-Day-Year formats */
'dddd, MMMM d yyyy', 'MMMM d yyyy', 'MMM-d-yy', 'MMM. d yy',
'M-d-yy', 'M-d-yy h:mm', 'M-d-yy h:mm:ss', 'M-d-yy h:mm am/pm', 'M-d-yy h:mm:ss am/pm', 'M-d-yy HH:mm', 'M-d-yy HH:mm:ss',
'M/d/yy', 'M/d/yy h:mm', 'M/d/yy h:mm:ss', 'M/d/yy h:mm am/pm', 'M/d/yy h:mm:ss am/pm', 'M/d/yy HH:mm', 'M/d/yy HH:mm:ss',
'M-d-yyyy', 'M-d-yyyy h:mm', 'M-d-yyyy h:mm:ss', 'M-d-yyyy h:mm am/pm', 'M-d-yyyy h:mm:ss am/pm', 'M-d-yyyy HH:mm', 'M-d-yyyy HH:mm:ss',
'M/d/yyyy', 'M/d/yyyy h:mm', 'M/d/yyyy h:mm:ss', 'M/d/yyyy h:mm am/pm', 'M/d/yyyy h:mm:ss am/pm', 'M/d/yyyy HH:mm', 'M/d/yyyy HH:mm:ss',
),
),
'options' => array('PreserveFormat', 'LunarCalendar', 'SakaEraCalendar', 'LastUsedFormat'),
),
'MACROBUTTON' => array(
'properties' => array('macroname' => ''),
),
'XE' => array(
'properties' => array(),
'options' => array('Bold', 'Italic'),
),
'INDEX' => array(
'properties' => array(),
'options' => array('PreserveFormat'),
),
'STYLEREF' => array(
'properties' => array('StyleIdentifier' => ''),
'options' => array('PreserveFormat'),
),
'options'=>array('PreserveFormat', 'LunarCalendar', 'SakaEraCalendar', 'LastUsedFormat')
)
);
/**
@ -62,6 +91,13 @@ class Field extends AbstractElement
*/
protected $type;
/**
* Field text
*
* @var TextRun|string
*/
protected $text;
/**
* Field properties
*
@ -76,18 +112,27 @@ class Field extends AbstractElement
*/
protected $options = array();
/**
* Font style
*
* @var \PhpOffice\PhpWord\Style\Font
*/
protected $fontStyle;
/**
* Create a new Field Element
*
* @param string $type
* @param array $properties
* @param array $options
* @param TextRun|string|null $text
*/
public function __construct($type = null, $properties = array(), $options = array())
public function __construct($type = null, $properties = array(), $options = array(), $text = null)
{
$this->setType($type);
$this->setProperties($properties);
$this->setOptions($options);
$this->setText($text);
}
/**
@ -95,9 +140,8 @@ class Field extends AbstractElement
*
* @param string $type
*
* @return string
*
* @throws \InvalidArgumentException
* @return string
*/
public function setType($type = null)
{
@ -105,9 +149,10 @@ class Field extends AbstractElement
if (isset($this->fieldsArray[$type])) {
$this->type = $type;
} else {
throw new \InvalidArgumentException("Invalid type");
throw new \InvalidArgumentException("Invalid type '$type'");
}
}
return $this->type;
}
@ -126,20 +171,20 @@ class Field extends AbstractElement
*
* @param array $properties
*
* @return self
*
* @throws \InvalidArgumentException
* @return self
*/
public function setProperties($properties = array())
{
if (is_array($properties)) {
foreach (array_keys($properties) as $propkey) {
if (!(isset($this->fieldsArray[$this->type]['properties'][$propkey]))) {
throw new \InvalidArgumentException("Invalid property");
throw new \InvalidArgumentException("Invalid property '$propkey'");
}
}
$this->properties = array_merge($this->properties, $properties);
}
return $this->properties;
}
@ -158,20 +203,20 @@ class Field extends AbstractElement
*
* @param array $options
*
* @return self
*
* @throws \InvalidArgumentException
* @return self
*/
public function setOptions($options = array())
{
if (is_array($options)) {
foreach (array_keys($options) as $optionkey) {
if (!(isset($this->fieldsArray[$this->type]['options'][$optionkey]))) {
throw new \InvalidArgumentException("Invalid option");
if (!(isset($this->fieldsArray[$this->type]['options'][$optionkey])) && substr($optionkey, 0, 1) !== '\\') {
throw new \InvalidArgumentException("Invalid option '$optionkey', possible values are " . implode(', ', $this->fieldsArray[$this->type]['options']));
}
}
$this->options = array_merge($this->options, $options);
}
return $this->options;
}
@ -184,4 +229,35 @@ class Field extends AbstractElement
{
return $this->options;
}
/**
* Set Field text
*
* @param string|TextRun $text
*
* @throws \InvalidArgumentException
* @return null|string|TextRun
*/
public function setText($text = null)
{
if (isset($text)) {
if (is_string($text) || $text instanceof TextRun) {
$this->text = $text;
} else {
throw new \InvalidArgumentException('Invalid text');
}
}
return $this->text;
}
/**
* Get Field text
*
* @return string|TextRun
*/
public function getText()
{
return $this->text;
}
}

View File

@ -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.
*
* @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
*/
@ -26,7 +26,7 @@ class Footer extends AbstractContainer
* Header/footer types constants
*
* @var string
* @link http://www.schemacentral.com/sc/ooxml/a-wtype-4.html Header or Footer Type
* @see http://www.datypic.com/sc/ooxml/t-w_ST_HdrFtr.html Header or Footer Type
*/
const AUTO = 'default'; // default and odd pages
const FIRST = 'first';
@ -64,7 +64,6 @@ class Footer extends AbstractContainer
* @since 0.10.0
*
* @param string $value
* @return void
*/
public function setType($value = self::AUTO)
{

View File

@ -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.
*
* @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
*/
@ -19,9 +19,6 @@ namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\Paragraph;
/**
* @codeCoverageIgnore
*/
class Footnote extends AbstractContainer
{
/**
@ -68,6 +65,7 @@ class Footnote extends AbstractContainer
* Get Footnote Reference ID
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*
* @return int
*/
@ -80,6 +78,7 @@ class Footnote extends AbstractContainer
* Set Footnote Reference ID
*
* @deprecated 0.10.0
* @codeCoverageIgnore
*
* @param int $rId
*/

View File

@ -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.
*
* @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
*/
@ -21,7 +21,7 @@ namespace PhpOffice\PhpWord\Element;
* Form field element
*
* @since 0.12.0
* @link http://www.datypic.com/sc/ooxml/t-w_CT_FFData.html
* @see http://www.datypic.com/sc/ooxml/t-w_CT_FFData.html
*/
class FormField extends Text
{
@ -35,7 +35,7 @@ class FormField extends Text
/**
* Form field name
*
* @var string
* @var string|bool|int
*/
private $name;
@ -70,10 +70,10 @@ class FormField extends Text
* @param string $type
* @param mixed $fontStyle
* @param mixed $paragraphStyle
* @return self
*/
public function __construct($type, $fontStyle = null, $paragraphStyle = null)
{
parent::__construct(null, $fontStyle, $paragraphStyle);
$this->setType($type);
}

View File

@ -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.
*
* @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
*/

View File

@ -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.
*
* @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
*/
@ -61,10 +61,17 @@ class Image extends AbstractElement
/**
* Is watermark
*
* @var boolean
* @var bool
*/
private $watermark;
/**
* Name of image
*
* @var string
*/
private $name;
/**
* Image type
*
@ -96,7 +103,7 @@ class Image extends AbstractElement
/**
* Is memory image
*
* @var boolean
* @var bool
*/
private $memoryImage;
@ -110,7 +117,7 @@ class Image extends AbstractElement
/**
* Image media index
*
* @var integer
* @var int
*/
private $mediaIndex;
@ -126,18 +133,20 @@ class Image extends AbstractElement
*
* @param string $source
* @param mixed $style
* @param boolean $watermark
* @param bool $watermark
* @param string $name
*
* @throws \PhpOffice\PhpWord\Exception\InvalidImageException
* @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
*/
public function __construct($source, $style = null, $watermark = false)
public function __construct($source, $style = null, $watermark = false, $name = null)
{
$this->source = $source;
$this->setIsWatermark($watermark);
$this->style = $this->setNewStyle(new ImageStyle(), $style, true);
$this->setIsWatermark($watermark);
$this->setName($name);
$this->checkImage($source);
$this->checkImage();
}
/**
@ -170,6 +179,26 @@ class Image extends AbstractElement
return $this->sourceType;
}
/**
* Sets the image name
*
* @param string $value
*/
public function setName($value)
{
$this->name = $value;
}
/**
* Get image name
*
* @return null|string
*/
public function getName()
{
return $this->name;
}
/**
* Get image media ID
*
@ -183,7 +212,7 @@ class Image extends AbstractElement
/**
* Get is watermark
*
* @return boolean
* @return bool
*/
public function isWatermark()
{
@ -193,7 +222,7 @@ class Image extends AbstractElement
/**
* Set is watermark
*
* @param boolean $value
* @param bool $value
*/
public function setIsWatermark($value)
{
@ -243,7 +272,7 @@ class Image extends AbstractElement
/**
* Get is memory image
*
* @return boolean
* @return bool
*/
public function isMemImage()
{
@ -264,7 +293,6 @@ class Image extends AbstractElement
* Set target file name.
*
* @param string $value
* @return void
*/
public function setTarget($value)
{
@ -274,7 +302,7 @@ class Image extends AbstractElement
/**
* Get media index
*
* @return integer
* @return int
*/
public function getMediaIndex()
{
@ -284,8 +312,7 @@ class Image extends AbstractElement
/**
* Set media index.
*
* @param integer $value
* @return void
* @param int $value
*/
public function setMediaIndex($value)
{
@ -315,7 +342,7 @@ class Image extends AbstractElement
$zip = new ZipArchive();
if ($zip->open($zipFilename) !== false) {
if ($zip->locateName($imageFilename)) {
if ($zip->locateName($imageFilename) !== false) {
$isTemp = true;
$zip->extractTo(Settings::getTempDir(), $imageFilename);
$actualSource = Settings::getTempDir() . DIRECTORY_SEPARATOR . $imageFilename;
@ -336,10 +363,16 @@ class Image extends AbstractElement
// Read image binary data and convert to hex/base64 string
if ($this->sourceType == self::SOURCE_GD) {
$imageResource = call_user_func($this->imageCreateFunc, $actualSource);
if ($this->imageType === 'image/png') {
// PNG images need to preserve alpha channel information
imagesavealpha($imageResource, true);
}
ob_start();
call_user_func($this->imageFunc, $imageResource);
$imageBinary = ob_get_contents();
ob_end_clean();
} elseif ($this->sourceType == self::SOURCE_STRING) {
$imageBinary = $this->source;
} else {
$fileHandle = fopen($actualSource, 'rb', false);
if ($fileHandle !== false) {
@ -366,33 +399,29 @@ class Image extends AbstractElement
/**
* Check memory image, supported type, image functions, and proportional width/height.
*
* @param string $source
*
* @return void
*
* @throws \PhpOffice\PhpWord\Exception\InvalidImageException
* @throws \PhpOffice\PhpWord\Exception\UnsupportedImageTypeException
*/
private function checkImage($source)
private function checkImage()
{
$this->setSourceType($source);
$this->setSourceType();
// Check image data
if ($this->sourceType == self::SOURCE_ARCHIVE) {
$imageData = $this->getArchiveImageSize($source);
$imageData = $this->getArchiveImageSize($this->source);
} elseif ($this->sourceType == self::SOURCE_STRING) {
$imageData = $this->getStringImageSize($source);
$imageData = $this->getStringImageSize($this->source);
} else {
$imageData = @getimagesize($source);
$imageData = @getimagesize($this->source);
}
if (!is_array($imageData)) {
throw new InvalidImageException(sprintf('Invalid image: %s', $source));
throw new InvalidImageException(sprintf('Invalid image: %s', $this->source));
}
list($actualWidth, $actualHeight, $imageType) = $imageData;
// Check image type support
$supportedTypes = array(IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_PNG);
if ($this->sourceType != self::SOURCE_GD) {
if ($this->sourceType != self::SOURCE_GD && $this->sourceType != self::SOURCE_STRING) {
$supportedTypes = array_merge($supportedTypes, array(IMAGETYPE_BMP, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM));
}
if (!in_array($imageType, $supportedTypes)) {
@ -407,22 +436,25 @@ class Image extends AbstractElement
/**
* Set source type.
*
* @param string $source
* @return void
*/
private function setSourceType($source)
private function setSourceType()
{
if (stripos(strrev($source), strrev('.php')) === 0) {
if (stripos(strrev($this->source), strrev('.php')) === 0) {
$this->memoryImage = true;
$this->sourceType = self::SOURCE_GD;
} elseif (strpos($source, 'zip://') !== false) {
} elseif (strpos($this->source, 'zip://') !== false) {
$this->memoryImage = false;
$this->sourceType = self::SOURCE_ARCHIVE;
} elseif (filter_var($source, FILTER_VALIDATE_URL) !== false) {
} elseif (filter_var($this->source, FILTER_VALIDATE_URL) !== false) {
$this->memoryImage = true;
if (strpos($this->source, 'https') === 0) {
$fileContent = file_get_contents($this->source);
$this->source = $fileContent;
$this->sourceType = self::SOURCE_STRING;
} else {
$this->sourceType = self::SOURCE_GD;
} elseif (@file_exists($source)) {
}
} elseif (@file_exists($this->source)) {
$this->memoryImage = false;
$this->sourceType = self::SOURCE_LOCAL;
} else {
@ -438,9 +470,9 @@ class Image extends AbstractElement
*
* @param string $source
*
* @return array|null
*
* @throws \PhpOffice\PhpWord\Exception\CreateTemporaryFileException
*
* @return array|null
*/
private function getArchiveImageSize($source)
{
@ -450,12 +482,12 @@ class Image extends AbstractElement
$tempFilename = tempnam(Settings::getTempDir(), 'PHPWordImage');
if (false === $tempFilename) {
throw new CreateTemporaryFileException();
throw new CreateTemporaryFileException(); // @codeCoverageIgnore
}
$zip = new ZipArchive();
if ($zip->open($zipFilename) !== false) {
if ($zip->locateName($imageFilename)) {
if ($zip->locateName($imageFilename) !== false) {
$imageContent = $zip->getFromName($imageFilename);
if ($imageContent !== false) {
file_put_contents($tempFilename, $imageContent);
@ -478,36 +510,36 @@ class Image extends AbstractElement
*/
private function getStringImageSize($source)
{
$result = false;
if (!function_exists('getimagesizefromstring')) {
$uri = 'data://application/octet-stream;base64,' . base64_encode($source);
return @getimagesize($uri);
$result = @getimagesize($uri);
} else {
return @getimagesizefromstring($source);
$result = @getimagesizefromstring($source);
}
return false;
return $result;
}
/**
* Set image functions and extensions.
*
* @return void
*/
private function setFunctions()
{
switch ($this->imageType) {
case 'image/png':
$this->imageCreateFunc = 'imagecreatefrompng';
$this->imageCreateFunc = $this->sourceType == self::SOURCE_STRING ? 'imagecreatefromstring' : 'imagecreatefrompng';
$this->imageFunc = 'imagepng';
$this->imageExtension = 'png';
break;
case 'image/gif':
$this->imageCreateFunc = 'imagecreatefromgif';
$this->imageCreateFunc = $this->sourceType == self::SOURCE_STRING ? 'imagecreatefromstring' : 'imagecreatefromgif';
$this->imageFunc = 'imagegif';
$this->imageExtension = 'gif';
break;
case 'image/jpeg':
case 'image/jpg':
$this->imageCreateFunc = 'imagecreatefromjpeg';
$this->imageCreateFunc = $this->sourceType == self::SOURCE_STRING ? 'imagecreatefromstring' : 'imagecreatefromjpeg';
$this->imageFunc = 'imagejpeg';
$this->imageExtension = 'jpg';
break;
@ -525,9 +557,8 @@ class Image extends AbstractElement
/**
* Set proportional width/height if one dimension not available.
*
* @param integer $actualWidth
* @param integer $actualHeight
* @return void
* @param int $actualWidth
* @param int $actualHeight
*/
private function setProportionalSize($actualWidth, $actualHeight)
{

View File

@ -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.
*
* @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
*/

View File

@ -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.
*
* @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
*/
@ -75,6 +75,7 @@ class Link extends AbstractElement
* @param string $text
* @param mixed $fontStyle
* @param mixed $paragraphStyle
* @param bool $internal
*/
public function __construct($source, $text = null, $fontStyle = null, $paragraphStyle = null, $internal = false)
{
@ -83,7 +84,6 @@ class Link extends AbstractElement
$this->fontStyle = $this->setNewStyle(new Font('text'), $fontStyle);
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
$this->internal = $internal;
return $this;
}
/**

View File

@ -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.
*
* @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
*/
@ -62,7 +62,7 @@ class ListItem extends AbstractElement
// Version >= 0.10.0 will pass numbering style name. Older version will use old method
if (!is_null($listStyle) && is_string($listStyle)) {
$this->style = new ListItemStyle($listStyle);
$this->style = new ListItemStyle($listStyle); // @codeCoverageIgnore
} else {
$this->style = $this->setNewStyle(new ListItemStyle(), $listStyle, true);
}

View File

@ -10,15 +10,14 @@
* 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-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
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\Style\ListItem as ListItemStyle;
use PhpOffice\PhpWord\Style\Paragraph;
/**
* List item element
@ -61,7 +60,7 @@ class ListItemRun extends TextRun
} else {
$this->style = $this->setNewStyle(new ListItemStyle(), $listStyle, true);
}
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
parent::__construct($paragraphStyle);
}
/**

View File

@ -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.
*
* @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
*/
@ -21,9 +21,9 @@ use PhpOffice\PhpWord\Exception\InvalidObjectException;
use PhpOffice\PhpWord\Style\Image as ImageStyle;
/**
* Object element
* OLEObject element
*/
class Object extends AbstractElement
class OLEObject extends AbstractElement
{
/**
* Ole-Object Src
@ -83,10 +83,10 @@ class Object extends AbstractElement
$this->style = $this->setNewStyle(new ImageStyle(), $style, true);
$this->icon = realpath(__DIR__ . "/../resources/{$ext}.png");
return $this;
} else {
throw new InvalidObjectException();
return;
}
throw new InvalidObjectException();
}
/**
@ -133,7 +133,6 @@ class Object extends AbstractElement
* Set Image Relation ID.
*
* @param int $rId
* @return void
*/
public function setImageRelationId($rId)
{

View File

@ -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.
*
* @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
*/

View File

@ -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.
*
* @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
*/
@ -29,7 +29,7 @@ class PreserveText extends AbstractElement
/**
* Text content
*
* @var string
* @var string|array
*/
private $text;
@ -47,14 +47,12 @@ class PreserveText extends AbstractElement
*/
private $paragraphStyle;
/**
* Create a new Preserve Text Element
*
* @param string $text
* @param mixed $fontStyle
* @param mixed $paragraphStyle
* @return self
*/
public function __construct($text = null, $fontStyle = null, $paragraphStyle = null)
{
@ -66,8 +64,6 @@ class PreserveText extends AbstractElement
if (isset($matches[0])) {
$this->text = $matches;
}
return $this;
}
/**
@ -93,7 +89,7 @@ class PreserveText extends AbstractElement
/**
* Get Text content
*
* @return string
* @return string|array
*/
public function getText()
{

View File

@ -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.
*
* @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
*/

View File

@ -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.
*
* @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
*/
@ -45,16 +45,30 @@ class SDT extends Text
*/
private $listItems = array();
/**
* Alias
*
* @var string
*/
private $alias;
/**
* Tag
*
* @var string
*/
private $tag;
/**
* Create new instance
*
* @param string $type
* @param mixed $fontStyle
* @param mixed $paragraphStyle
* @return self
*/
public function __construct($type, $fontStyle = null, $paragraphStyle = null)
{
parent::__construct(null, $fontStyle, $paragraphStyle);
$this->setType($type);
}
@ -127,4 +141,50 @@ class SDT extends Text
return $this;
}
/**
* Get tag
*
* @return string
*/
public function getTag()
{
return $this->tag;
}
/**
* Set tag
*
* @param string $tag
* @return self
*/
public function setTag($tag)
{
$this->tag = $tag;
return $this;
}
/**
* Get alias
*
* @return string
*/
public function getAlias()
{
return $this->alias;
}
/**
* Set alias
*
* @param string $alias
* @return self
*/
public function setAlias($alias)
{
$this->alias = $alias;
return $this;
}
}

View File

@ -10,13 +10,14 @@
* 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-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
*/
namespace PhpOffice\PhpWord\Element;
use PhpOffice\PhpWord\ComplexType\FootnoteProperties;
use PhpOffice\PhpWord\Style\Section as SectionStyle;
class Section extends AbstractContainer
@ -47,6 +48,13 @@ class Section extends AbstractContainer
*/
private $footers = array();
/**
* The properties for the footnote of this section
*
* @var FootnoteProperties
*/
private $footnoteProperties;
/**
* Create new instance
*
@ -65,7 +73,6 @@ class Section extends AbstractContainer
* Set section style.
*
* @param array $style
* @return void
*/
public function setStyle($style = null)
{
@ -78,8 +85,6 @@ class Section extends AbstractContainer
* Get section style
*
* @return \PhpOffice\PhpWord\Style\Section
*
* @codeCoverageIgnore
*/
public function getStyle()
{
@ -118,8 +123,6 @@ class Section extends AbstractContainer
* Get header elements
*
* @return Header[]
*
* @codeCoverageIgnore
*/
public function getHeaders()
{
@ -130,21 +133,39 @@ class Section extends AbstractContainer
* Get footer elements
*
* @return Footer[]
*
* @codeCoverageIgnore
*/
public function getFooters()
{
return $this->footers;
}
/**
* Get the footnote properties
*
* @return FootnoteProperties
*/
public function getFootnotePropoperties()
{
return $this->footnoteProperties;
}
/**
* Set the footnote properties
*
* @param FootnoteProperties $footnoteProperties
*/
public function setFootnoteProperties(FootnoteProperties $footnoteProperties = null)
{
$this->footnoteProperties = $footnoteProperties;
}
/**
* Is there a header for this section that is for the first page only?
*
* If any of the Header instances have a type of Header::FIRST then this method returns true.
* False otherwise.
*
* @return boolean
* @return bool
*/
public function hasDifferentFirstPage()
{
@ -153,6 +174,12 @@ class Section extends AbstractContainer
return true;
}
}
foreach ($this->footers as $footer) {
if ($footer->getType() == Header::FIRST) {
return true;
}
}
return false;
}
@ -162,11 +189,11 @@ class Section extends AbstractContainer
* @since 0.10.0
*
* @param string $type
* @param boolean $header
*
* @return Header|Footer
* @param bool $header
*
* @throws \Exception
*
* @return Header|Footer
*/
private function addHeaderFooter($type = Header::AUTO, $header = true)
{
@ -182,11 +209,10 @@ class Section extends AbstractContainer
$container->setPhpWord($this->phpWord);
$collection[$index] = $container;
return $container;
} else {
throw new \Exception('Invalid header/footer type.');
}
return $container;
}
throw new \Exception('Invalid header/footer type.');
}
/**
@ -258,8 +284,8 @@ class Section extends AbstractContainer
{
if (empty($this->footers)) {
return null;
} else {
}
return $this->footers[1];
}
}
}

View File

@ -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.
*
* @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
*/

View File

@ -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.
*
* @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
*/
@ -36,7 +36,7 @@ class TOC extends AbstractElement
/**
* Font style
*
* @var \PhpOffice\PhpWord\Style\Font|array|string
* @var \PhpOffice\PhpWord\Style\Font|string
*/
private $fontStyle;
@ -54,14 +54,13 @@ class TOC extends AbstractElement
*/
private $maxDepth = 9;
/**
* Create a new Table-of-Contents Element
*
* @param mixed $fontStyle
* @param array $tocStyle
* @param integer $minDepth
* @param integer $maxDepth
* @param int $minDepth
* @param int $maxDepth
*/
public function __construct($fontStyle = null, $tocStyle = null, $minDepth = 1, $maxDepth = 9)
{
@ -121,7 +120,7 @@ class TOC extends AbstractElement
/**
* Get Font Style
*
* @return \PhpOffice\PhpWord\Style\Font
* @return \PhpOffice\PhpWord\Style\Font|string
*/
public function getStyleFont()
{
@ -132,7 +131,6 @@ class TOC extends AbstractElement
* Set max depth.
*
* @param int $value
* @return void
*/
public function setMaxDepth($value)
{
@ -153,7 +151,6 @@ class TOC extends AbstractElement
* Set min depth.
*
* @param int $value
* @return void
*/
public function setMinDepth($value)
{

View File

@ -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.
*
* @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
*/
@ -121,7 +121,6 @@ class Table extends AbstractElement
* Set table width.
*
* @param int $width
* @return void
*/
public function setWidth($width)
{
@ -136,7 +135,7 @@ class Table extends AbstractElement
public function countColumns()
{
$columnCount = 0;
if (is_array($this->rows)) {
$rowCount = count($this->rows);
for ($i = 0; $i < $rowCount; $i++) {
/** @var \PhpOffice\PhpWord\Element\Row $row Type hint */
@ -146,8 +145,30 @@ class Table extends AbstractElement
$columnCount = $cellCount;
}
}
}
return $columnCount;
}
/**
* The first declared cell width for each column
*
* @return int[]
*/
public function findFirstDefinedCellWidths()
{
$cellWidths = array();
foreach ($this->rows as $row) {
$cells = $row->getCells();
if (count($cells) <= count($cellWidths)) {
continue;
}
$cellWidths = array();
foreach ($cells as $cell) {
$cellWidths[] = $cell->getWidth();
}
}
return $cellWidths;
}
}

View File

@ -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.
*
* @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
*/
@ -105,12 +105,12 @@ class Text extends AbstractElement
public function setParagraphStyle($style = null)
{
if (is_array($style)) {
$this->paragraphStyle = new Paragraph;
$this->paragraphStyle = new Paragraph();
$this->paragraphStyle->setStyleByArray($style);
} elseif ($style instanceof Paragraph) {
$this->paragraphStyle = $style;
} elseif (null === $style) {
$this->paragraphStyle = new Paragraph;
$this->paragraphStyle = new Paragraph();
} else {
$this->paragraphStyle = $style;
}

View File

@ -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.
*
* @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
*/

View File

@ -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.
*
* @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
*/
@ -74,6 +74,7 @@ class TextBreak extends AbstractElement
$this->fontStyle = $style;
$this->setParagraphStyle($paragraphStyle);
}
return $this->fontStyle;
}
@ -96,13 +97,14 @@ class TextBreak extends AbstractElement
public function setParagraphStyle($style = null)
{
if (is_array($style)) {
$this->paragraphStyle = new Paragraph;
$this->paragraphStyle = new Paragraph();
$this->paragraphStyle->setStyleByArray($style);
} elseif ($style instanceof Paragraph) {
$this->paragraphStyle = $style;
} else {
$this->paragraphStyle = $style;
}
return $this->paragraphStyle;
}

View File

@ -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.
*
* @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
*/
@ -43,7 +43,7 @@ class TextRun extends AbstractContainer
*/
public function __construct($paragraphStyle = null)
{
$this->paragraphStyle = $this->setNewStyle(new Paragraph(), $paragraphStyle);
$this->paragraphStyle = $this->setParagraphStyle($paragraphStyle);
}
/**
@ -55,4 +55,26 @@ class TextRun extends AbstractContainer
{
return $this->paragraphStyle;
}
/**
* Set Paragraph style
*
* @param string|array|\PhpOffice\PhpWord\Style\Paragraph $style
* @return string|\PhpOffice\PhpWord\Style\Paragraph
*/
public function setParagraphStyle($style = null)
{
if (is_array($style)) {
$this->paragraphStyle = new Paragraph();
$this->paragraphStyle->setStyleByArray($style);
} elseif ($style instanceof Paragraph) {
$this->paragraphStyle = $style;
} elseif (null === $style) {
$this->paragraphStyle = new Paragraph();
} else {
$this->paragraphStyle = $style;
}
return $this->paragraphStyle;
}
}

View File

@ -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.
*
* @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
*/
@ -28,7 +28,7 @@ class Title extends AbstractElement
/**
* Title Text content
*
* @var string
* @var string|TextRun
*/
private $text;
@ -56,18 +56,24 @@ class Title extends AbstractElement
/**
* Create a new Title Element
*
* @param string $text
* @param string|TextRun $text
* @param int $depth
*/
public function __construct($text, $depth = 1)
{
if (is_string($text)) {
$this->text = CommonText::toUTF8($text);
$this->depth = $depth;
if (array_key_exists("Heading_{$this->depth}", Style::getStyles())) {
$this->style = "Heading{$this->depth}";
} elseif ($text instanceof TextRun) {
$this->text = $text;
} else {
throw new \InvalidArgumentException('Invalid text, should be a string or a TextRun');
}
return $this;
$this->depth = $depth;
$styleName = $depth === 0 ? 'Title' : "Heading_{$this->depth}";
if (array_key_exists($styleName, Style::getStyles())) {
$this->style = str_replace('_', '', $styleName);
}
}
/**
@ -83,7 +89,7 @@ class Title extends AbstractElement
/**
* Get depth
*
* @return integer
* @return int
*/
public function getDepth()
{

View File

@ -0,0 +1,101 @@
<?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.
*
* @see https://github.com/PHPOffice/PHPWord
* @copyright 2010-2018 PHPWord contributors
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWord\Element;
/**
* TrackChange element
* @see http://datypic.com/sc/ooxml/t-w_CT_TrackChange.html
* @see http://datypic.com/sc/ooxml/t-w_CT_RunTrackChange.html
*/
class TrackChange extends AbstractContainer
{
const INSERTED = 'INSERTED';
const DELETED = 'DELETED';
/**
* @var string Container type
*/
protected $container = 'TrackChange';
/**
* The type of change, (insert or delete), not applicable for PhpOffice\PhpWord\Element\Comment
*
* @var string
*/
private $changeType;
/**
* Author
*
* @var string
*/
private $author;
/**
* Date
*
* @var \DateTime
*/
private $date;
/**
* Create a new TrackChange Element
*
* @param string $changeType
* @param string $author
* @param null|int|\DateTime $date
*/
public function __construct($changeType = null, $author = null, $date = null)
{
$this->changeType = $changeType;
$this->author = $author;
if ($date !== null) {
$this->date = ($date instanceof \DateTime) ? $date : new \DateTime('@' . $date);
}
}
/**
* Get TrackChange Author
*
* @return string
*/
public function getAuthor()
{
return $this->author;
}
/**
* Get TrackChange Date
*
* @return \DateTime
*/
public function getDate()
{
return $this->date;
}
/**
* Get the Change type
*
* @return string
*/
public function getChangeType()
{
return $this->changeType;
}
}

View File

@ -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.
*
* @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
*/

View File

@ -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.
*
* @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
*/

View File

@ -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.
*
* @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
*/

View File

@ -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.
*
* @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
*/
@ -28,9 +28,9 @@ class Rtf extends AbstractEscaper
{
if (20 > $code || $code >= 80) {
return '{\u' . $code . '}';
} else {
return chr($code);
}
return chr($code);
}
protected function escapeMultibyteCharacter($code)
@ -40,6 +40,7 @@ class Rtf extends AbstractEscaper
/**
* @see http://www.randomchaos.com/documents/?source=php_and_unicode
* @param string $input
*/
protected function escapeSingleValue($input)
{

View File

@ -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.
*
* @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
*/

View File

@ -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.
*
* @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
*/
@ -23,10 +23,10 @@ namespace PhpOffice\PhpWord\Exception;
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.
* @param string $source The fully qualified source file name
* @param string $destination The fully qualified destination file name
* @param int $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)
{

View File

@ -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.
*
* @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
*/
@ -23,8 +23,8 @@ namespace PhpOffice\PhpWord\Exception;
final class CreateTemporaryFileException extends Exception
{
/**
* @param integer $code The user defined exception code.
* @param \Exception $previous The previous exception used for the exception chaining.
* @param int $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)
{

Some files were not shown because too many files have changed in this diff Show More