Merge pull request #177 from PHPOffice/develop

Version 0.9.0
This commit is contained in:
Progi1984 2014-03-26 10:41:15 +01:00
commit ac6f5a39a4
251 changed files with 10353 additions and 8758 deletions

7
.gitignore vendored
View File

@ -5,6 +5,7 @@
Thumbs.db
Desktop.ini
.idea
_build
phpunit.xml
composer.lock
composer.phar
@ -13,9 +14,3 @@ vendor
/.settings
/.buildpath
/.project
/docs
*.odt
*.docx
*.rtf
*.txt
*.xml

View File

@ -1,46 +1,49 @@
language: php
php:
- 5.3.3
- 5.3
- 5.4
- 5.5
## @reference https://github.com/travis-ci/travis-ci/issues/1749
- 5.6
- hhvm
matrix:
allow_failures:
- php: 5.3.3
- php: 5.6
- php: hhvm
before_script:
## Composer
- curl -s http://getcomposer.org/installer | php
- php composer.phar install --prefer-source
# - curl -s http://getcomposer.org/installer | php
# - php composer.phar install --prefer-source
- composer install --prefer-source
- composer selfupdate --quiet
## PHP_CodeSniffer
- pyrus install pear/PHP_CodeSniffer
- phpenv rehash
## PHP Copy/Paste Detector
- curl -o phpcpd.phar https://phar.phpunit.de/phpcpd.phar
#- curl -o phpcpd.phar https://phar.phpunit.de/phpcpd.phar
## PHP Mess Detector
- pear config-set preferred_state beta
- printf "\n" | pecl install imagick
#- pear config-set preferred_state beta
#- printf "\n" | pecl install imagick
#- pear channel-discover pear.phpmd.org
#- pear channel-discover pear.pdepend.org
#- pear install --alldeps phpmd/PHP_PMD
- phpenv rehash
#- phpenv rehash
## PHPLOC
- curl -o phploc.phar https://phar.phpunit.de/phploc.phar
#- curl -o phploc.phar https://phar.phpunit.de/phploc.phar
script:
## PHP_CodeSniffer
- phpcs --standard=PSR1 Classes/
- phpcs --standard=PSR2 Classes/
- phpcs --standard=PSR2 -n src/
- phpcs --standard=PSR2 -n tests/
## PHP Copy/Paste Detector
- php phpcpd.phar --verbose Classes/
#- php phpcpd.phar --verbose src/
## PHP Mess Detector
#- phpmd Classes/ text unusedcode,naming,design
#- phpmd src/ text unusedcode,naming,design
## PHPLOC
- php phploc.phar Classes/
#- php phploc.phar src/
## PHPUnit
- phpunit -c ./ --coverage-text
notifications:
email:
- progi1984@gmail.com

111
CHANGELOG.md Executable file
View File

@ -0,0 +1,111 @@
# Changelog
This is the changelog between releases of PHPWord. Releases are listed in reverse chronological order with the latest version listed on top, while additions/changes in each release are listed in chronological order. Changes in each release are divided into three parts: added or change features, bugfixes, and miscellaneous improvements. Each line contains short information about the change made, the person who made it, and the related issue number(s) in GitHub.
## 0.9.0 - Not yet released
This release marked the transformation to namespaces (PHP 5.3+).
### Features
- Image: Ability to use remote or GD images using `addImage()` on sections, headers, footer, cells, and textruns - @ivanlanin
- Header: Ability to use remote or GD images using `addWatermark()` - @ivanlanin
### Bugfixes
- Preserve text doesn't render correctly when the text is not the first word, e.g. 'Page {PAGE}' - @ivanlanin
### Miscellaneous
- Move documentation to [Read The Docs](http://phpword.readthedocs.org/en/develop/) - @Progi1984 @ivanlanin GH-82
- Reorganize and redesign samples folder - @ivanlanin GH-137
- Use `PhpOffice\PhpWord` namespace for PSR compliance - @RomanSyroeshko @gabrielbull GH-159 GH-58
- Restructure folders and change folder name `Classes` to `src` and `Tests` to `test` for PSR compliance - @RomanSyroeshko @gabrielbull
- Compliance to phpDocumentor - @ivanlanin
- Merge Style\TableFull into Style\Table. Style\TableFull is deprecated - @ivanlanin GH-160
- Merge Section\MemoryImage into Section\Image. Section\Image is deprecated - @ivanlanin GH-160
## 0.8.1 - 17 Mar 2014
This is a bugfix release for image detection functionality.
- Added fallback for computers that do not have exif_imagetype - @bskrtich, @gabrielbull
## 0.8.0 - 15 Mar 2014
This release merged a lot of improvements from the community. Unit tests introduced in this release and has reached 90% code coverage.
### Features
- Template: Permit to save a template generated as a file (PHPWord_Template::saveAs()) - @RomanSyroeshko GH-56 GH-57
- Word2007: Support sections page numbering - @gabrielbull
- Word2007: Added line height methods to mirror the line height settings in Word in the paragraph styling - @gabrielbull
- Word2007: Added support for page header & page footer height - @JillElaine GH-5
- General: Add ability to manage line breaks after image insertion - @bskrtich GH-6 GH-66 GH-84
- Template: Ability to limit number of replacements performed by setValue() method of Template class - @RomanSyroeshko GH-52 GH-53 GH-85
- Table row: Repeat as header row & allow row to break across pages - @ivanlanin GH-48 GH-86
- Table: Table width in percentage - @ivanlanin GH-48 GH-86
- Font: Superscript and subscript - @ivanlanin GH-48 GH-86
- Paragraph: Hanging paragraph - @ivanlanin GH-48 GH-86
- Section: Multicolumn and section break - @ivanlanin GH-48 GH-86
- Template: Ability to apply XSL style sheet to Template - @RomanSyroeshko GH-46 GH-47 GH-83
- General: PHPWord_Shared_Font::pointSizeToTwips() converter - @ivanlanin GH-87
- Paragraph: Ability to define normal paragraph style with PHPWord::setNormalStyle() - @ivanlanin GH-87
- Paragraph: Ability to define parent style (basedOn) and style for following paragraph (next) - @ivanlanin GH-87
- Clone table rows on the fly when using a template document - @jeroenmoors GH-44 GH-88
- Initial addition of basic footnote support - @deds GH-16
- Paragraph: Ability to define paragraph pagination: widow control, keep next, keep lines, and page break before - @ivanlanin GH-92
- General: PHPWord_Style_Font refactoring - @ivanlanin GH-93
- Font: Use points instead of halfpoints internally. Conversion to halfpoints done during XML Writing. - @ivanlanin GH-93
- Paragraph: setTabs() function - @ivanlanin GH-92
- General: Basic support for TextRun on ODT and RTF - @ivanlanin GH-99
- Reader: Basic Reader for Word2007 - @ivanlanin GH-104
- TextRun: Allow Text Break in Text Run - @bskrtich GH-109
- General: Support for East Asian fontstyle - @jhfangying GH-111 GH-118
- Image: Use exif_imagetype to check image format instead of extension name - @gabrielbull GH-114
- General: Setting for XMLWriter Compatibility option - @bskrtich GH-103
- MemoryImage: Allow remote image when allow_url_open = on - @ivanlanin GH-122
- TextBreak: Allow font and paragraph style for text break - @ivanlanin GH-18
### Bugfixes
- Fixed bug with cell styling - @gabrielbull
- Fixed bug list items inside of cells - @gabrielbull
- Adding a value that contains "&" in a template breaks it - @SiebelsTim GH-51
- Example in README.md is broken - @Progi1984 GH-89
- General: PHPWord_Shared_Drawing::centimetersToPixels() conversion - @ivanlanin GH-94
- Footnote: Corrupt DOCX reported by MS Word when sections > 1 and not every sections have footnote - @ivanlanin GH-125
### Miscellaneous
- UnitTests - @Progi1984
## 0.7.0 - 28 Jan 2014
This is the first release after a long development hiatus in [CodePlex](https://phpword.codeplex.com/). This release initialized ODT and RTF Writer, along with some other new features for the existing Word2007 Writer, e.g. tab, multiple header, rowspan and colspan. [Composer](https://packagist.org/packages/phpoffice/phpword) and [Travis](https://travis-ci.org/PHPOffice/PHPWord) were added.
### Features
- Implement RTF Writer - @Progi1984 GH-1
- Implement ODT Writer - @Progi1984 GH-2
- Word2007: Add rowspan and colspan to cells - @kaystrobach
- Word2007: Support for tab stops - @RLovelett
- Word2007: Support Multiple headers - @RLovelett
- Word2007: Wrapping Styles to Images - @gabrielbull
- Added support for image wrapping style - @gabrielbull
### Bugfixes
- "Warning: Invalid error type specified in ...\PHPWord.php on line 226" is thrown when the specified template file is not found - @RomanSyroeshko GH-32
- PHPWord_Shared_String.IsUTF8 returns FALSE for Cyrillic UTF-8 input - @RomanSyroeshko GH-34
- Temporary files naming logic in PHPWord_Template can lead to a collision - @RomanSyroeshko GH-38
### Miscellaneous
- Add superscript/subscript styling in Excel2007 Writer - @MarkBaker
- add indentation support to paragraphs - @deds
- Support for Composer - @Progi1984 GH-27
- Basic CI with Travis - @Progi1984
- Added PHPWord_Exception and exception when could not copy the template - @Progi1984
- IMPROVED: Moved examples out of Classes directory - @Progi1984
- IMPROVED: Advanced string replace in setValue for Template - @Esmeraldo CP-49

14
CONTRIBUTING.md Normal file
View File

@ -0,0 +1,14 @@
# Contributing to PHPWord
PHPWord is build by the crowd and for the crowd. Every contributions are welcomed; either by [submitting](https://github.com/PHPOffice/PHPWord/issues) bug issues or suggesting improvements, or in a more active form like [requesting](https://github.com/PHPOffice/PHPWord/pulls) a pull.
We want to create a high quality document writer and reader library that people can use with more confidence and less bugs. We want to collaborate happily, code joyfully, and get a life merrily. Thus, below are some guidelines that we expect to be followed by each contributor.
- **Be brief, but be bold**: State your issues briefly, but speak out your ideas loudly, even if you can't or don't know how to implement it right away. The world will be better with limitless innovations.
- **Code in PSR**: We use PHP Standards Recommendation (PSR) from as the PHP Framework Interoperability Group (PHP-FIG). If you're not familiar with this standard, please [familiarize yourself now](https://github.com/php-fig/fig-standards). Use [PHPCodeSniffer](http://pear.php.net/package/PHP_CodeSniffer/) to check your code against this standard.
- **Test your code**: Nobody else knows your code better than you. So, please, test your own code before submitting your pull request. PHPWord uses [PHPUnit](http://phpunit.de/) as our testing framework.
- **Request pull in separate branch**: Do not submit your request to the master branch, but create a separate branch named specifically for the issue that you addressed. Read [GitHub manual](https://help.github.com/articles/using-pull-requests) to find out more about this. If you are new to GitHub, read [this short manual](https://help.github.com/articles/fork-a-repo) to get you familiar with forks and how git works in general.
That's it. Thank you for your interest in PHPWord, and welcome!
May the Force be with you.

View File

@ -1,276 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/** PHPWORD_BASE_PATH */
// @codeCoverageIgnoreStart
if (!defined('PHPWORD_BASE_PATH')) {
define('PHPWORD_BASE_PATH', dirname(__FILE__) . '/');
require PHPWORD_BASE_PATH . 'PHPWord/Autoloader.php';
PHPWord_Autoloader::Register();
}
// @codeCoverageIgnoreEnd
/**
* PHPWord
*/
class PHPWord
{
/**
* Default font name (Arial)
*/
const DEFAULT_FONT_NAME = 'Arial';
/**
* Default Font Content Type(default)
* default|eastAsia|cs
*/
const DEFAULT_FONT_CONTENT_TYPE='default';
/**
* Default font size in points (10pt)
*
* OOXML defined font size values in halfpoints, i.e. twice of what PHPWord
* use, and the conversion will be conducted during XML writing.
*/
const DEFAULT_FONT_SIZE = 10;
/**
* Default font color (black)
*/
const DEFAULT_FONT_COLOR = '000000';
/**
* Document properties
*
* @var PHPWord_DocumentProperties
*/
private $_properties;
/**
* Default Font Name
*
* @var string
*/
private $_defaultFontName;
/**
* Default Font Size
*
* @var int
*/
private $_defaultFontSize;
/**
* Collection of section elements
*
* @var array
*/
private $_sectionCollection = array();
/**
* Create a new PHPWord Document
*/
public function __construct()
{
$this->_properties = new PHPWord_DocumentProperties();
$this->_defaultFontName = PHPWord::DEFAULT_FONT_NAME;
$this->_defaultFontSize = PHPWord::DEFAULT_FONT_SIZE;
}
/**
* Get properties
* @return PHPWord_DocumentProperties
*/
public function getProperties()
{
return $this->_properties;
}
/**
* Set properties
*
* @param PHPWord_DocumentProperties $value
* @return PHPWord
*/
public function setProperties(PHPWord_DocumentProperties $value)
{
$this->_properties = $value;
return $this;
}
/**
* Create a new Section
*
* @param PHPWord_Section_Settings $settings
* @return PHPWord_Section
*/
public function createSection($settings = null)
{
$sectionCount = $this->_countSections() + 1;
$section = new PHPWord_Section($sectionCount, $settings);
$this->_sectionCollection[] = $section;
return $section;
}
/**
* Get default Font name
* @return string
*/
public function getDefaultFontName()
{
return $this->_defaultFontName;
}
/**
* Set default Font name
* @param string $pValue
*/
public function setDefaultFontName($pValue)
{
$this->_defaultFontName = $pValue;
}
/**
* Get default Font size (in points)
* @return string
*/
public function getDefaultFontSize()
{
return $this->_defaultFontSize;
}
/**
* Set default Font size (in points)
* @param int $pValue
*/
public function setDefaultFontSize($pValue)
{
$this->_defaultFontSize = $pValue;
}
/**
* Set default paragraph style definition to styles.xml
*
* @param array $styles Paragraph style definition
*/
public function setDefaultParagraphStyle($styles)
{
PHPWord_Style::setDefaultParagraphStyle($styles);
}
/**
* Adds a paragraph style definition to styles.xml
*
* @param $styleName string
* @param $styles array
*/
public function addParagraphStyle($styleName, $styles)
{
PHPWord_Style::addParagraphStyle($styleName, $styles);
}
/**
* Adds a font style definition to styles.xml
*
* @param $styleName string
* @param $styles array
*/
public function addFontStyle($styleName, $styleFont, $styleParagraph = null)
{
PHPWord_Style::addFontStyle($styleName, $styleFont, $styleParagraph);
}
/**
* Adds a table style definition to styles.xml
*
* @param $styleName string
* @param $styles array
*/
public function addTableStyle($styleName, $styleTable, $styleFirstRow = null)
{
PHPWord_Style::addTableStyle($styleName, $styleTable, $styleFirstRow);
}
/**
* Adds a heading style definition to styles.xml
*
* @param $titleCount int
* @param $styles array
*/
public function addTitleStyle($titleCount, $styleFont, $styleParagraph = null)
{
PHPWord_Style::addTitleStyle($titleCount, $styleFont, $styleParagraph);
}
/**
* Adds a hyperlink style to styles.xml
*
* @param $styleName string
* @param $styles array
*/
public function addLinkStyle($styleName, $styles)
{
PHPWord_Style::addLinkStyle($styleName, $styles);
}
/**
* Get sections
* @return PHPWord_Section[]
*/
public function getSections()
{
return $this->_sectionCollection;
}
/**
* Load a Template File
*
* @param string $strFilename
* @return PHPWord_Template
*/
public function loadTemplate($strFilename)
{
if (file_exists($strFilename)) {
$template = new PHPWord_Template($strFilename);
return $template;
} else {
throw new PHPWord_Exception(
"Template file {$strFilename} not found."
);
}
}
/**
* Get section count
* @return int
*/
private function _countSections()
{
return count($this->_sectionCollection);
}
}

View File

@ -1,15 +0,0 @@
<?php
namespace PhpOffice\PhpWord\Exceptions;
use Exception;
/**
* InvalidImageException
*
* Exception used for when an image is not found
*
* @package PHPWord
*/
class InvalidImageException extends Exception
{
}

View File

@ -1,15 +0,0 @@
<?php
namespace PhpOffice\PhpWord\Exceptions;
use InvalidArgumentException;
/**
* InvalidStyleException
*
* Exception used for when a style value is invalid
*
* @package PHPWord
*/
class InvalidStyleException extends InvalidArgumentException
{
}

View File

@ -1,15 +0,0 @@
<?php
namespace PhpOffice\PhpWord\Exceptions;
use Exception;
/**
* UnsupportedImageTypeException
*
* Exception used for when an image type is unsupported
*
* @package PHPWord
*/
class UnsupportedImageTypeException extends Exception
{
}

View File

@ -1,158 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_IOFactory
*/
class PHPWord_IOFactory
{
/**
* Search locations
*
* @var array
*/
private static $_searchLocations = array(
array('type' => 'IWriter', 'path' => 'PHPWord/Writer/{0}.php', 'class' => 'PHPWord_Writer_{0}'),
array('type' => 'IReader', 'path' => 'PHPWord/Reader/{0}.php', 'class' => 'PHPWord_Reader_{0}' ),
);
/**
* Autoresolve classes
*
* @var array
*/
private static $_autoResolveClasses = array(
'Serialized'
);
/**
* Private constructor for PHPWord_IOFactory
*/
private function __construct()
{
}
/**
* Get search locations
*
* @return array
*/
public static function getSearchLocations()
{
return self::$_searchLocations;
}
/**
* Set search locations
*
* @param array $value
* @throws Exception
*/
public static function setSearchLocations($value)
{
if (is_array($value)) {
self::$_searchLocations = $value;
} else {
throw new Exception('Invalid parameter passed.');
}
}
/**
* Add search location
*
* @param string $type Example: IWriter
* @param string $location Example: PHPWord/Writer/{0}.php
* @param string $classname Example: PHPWord_Writer_{0}
*/
public static function addSearchLocation($type = '', $location = '', $classname = '')
{
self::$_searchLocations[] = array('type' => $type, 'path' => $location, 'class' => $classname);
}
/**
* Create PHPWord_Writer_IWriter
*
* @param PHPWord $PHPWord
* @param string $writerType Example: Word2007
* @return PHPWord_Writer_IWriter
*/
public static function createWriter(PHPWord $PHPWord, $writerType = '')
{
$searchType = 'IWriter';
foreach (self::$_searchLocations as $searchLocation) {
if ($searchLocation['type'] == $searchType) {
$className = str_replace('{0}', $writerType, $searchLocation['class']);
$classFile = str_replace('{0}', $writerType, $searchLocation['path']);
$instance = new $className($PHPWord);
if (!is_null($instance)) {
return $instance;
}
}
}
throw new Exception("No $searchType found for type $writerType");
}
/**
* Create PHPWord_Reader_IReader
*
* @param string $readerType Example: Word2007
* @return PHPWord_Reader_IReader
*/
public static function createReader($readerType = '')
{
$searchType = 'IReader';
foreach (self::$_searchLocations as $searchLocation) {
if ($searchLocation['type'] == $searchType) {
$className = str_replace('{0}', $readerType, $searchLocation['class']);
$instance = new $className();
if ($instance !== null) {
return $instance;
}
}
}
throw new PHPWord_Exception("No $searchType found for type $readerType");
}
/**
* Loads PHPWord from file
*
* @param string $pFilename The name of the file
* @return PHPWord
*/
public static function load($pFilename, $readerType = 'Word2007')
{
$reader = self::createReader($readerType);
return $reader->load($pFilename);
}
}

View File

@ -1,175 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
use PhpOffice\PhpWord\Exceptions\InvalidImageException;
use PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException;
/**
* Class PHPWord_Section_Image
*/
class PHPWord_Section_Image
{
/**
* Image Src
*
* @var string
*/
private $_src;
/**
* Image Style
*
* @var PHPWord_Style_Image
*/
private $_style;
/**
* Image Relation ID
*
* @var string
*/
private $_rId;
/**
* Is Watermark
*
* @var bool
*/
private $_isWatermark;
/**
* Create a new Image
*
* @param string $src
* @param mixed $style
* @param bool $isWatermark
* @throws InvalidImageException|UnsupportedImageTypeException
*/
public function __construct($src, $style = null, $isWatermark = false)
{
if (!file_exists($src)) {
throw new InvalidImageException;
}
if (!PHPWord_Shared_File::imagetype($src)) {
throw new UnsupportedImageTypeException;
}
$this->_src = $src;
$this->_isWatermark = $isWatermark;
$this->_style = new PHPWord_Style_Image();
if (!is_null($style) && is_array($style)) {
foreach ($style as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_style->setStyleValue($key, $value);
}
}
if (isset($style['wrappingStyle'])) {
$this->_style->setWrappingStyle($style['wrappingStyle']);
}
if ($this->_style->getWidth() == null && $this->_style->getHeight() == null) {
$imgData = getimagesize($this->_src);
$this->_style->setWidth($imgData[0]);
$this->_style->setHeight($imgData[1]);
}
}
/**
* Get Image style
*
* @return PHPWord_Style_Image
*/
public function getStyle()
{
return $this->_style;
}
/**
* Get Image Relation ID
*
* @return int
*/
public function getRelationId()
{
return $this->_rId;
}
/**
* Set Image Relation ID
*
* @param int $rId
*/
public function setRelationId($rId)
{
$this->_rId = $rId;
}
/**
* Get Image Source
*
* @return string
*/
public function getSource()
{
return $this->_src;
}
/**
* Get Image Media ID
*
* @return string
*/
public function getMediaId()
{
return md5($this->_src);
}
/**
* Get IsWatermark
*
* @return int
*/
public function getIsWatermark()
{
return $this->_isWatermark;
}
/**
* Set IsWatermark
*
* @param bool $pValue
*/
public function setIsWatermark($pValue)
{
$this->_isWatermark = $pValue;
}
}

View File

@ -1,232 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Section_MemoryImage
*/
class PHPWord_Section_MemoryImage
{
/**
* Image Src
*
* @var string
*/
private $_src;
/**
* Image Style
*
* @var PHPWord_Style_Image
*/
private $_style;
/**
* Image Relation ID
*
* @var string
*/
private $_rId;
/**
* Image Type
*
* @var string
*/
private $_imageType;
/**
* Image Create function
*
* @var string
*/
private $_imageCreateFunc;
/**
* Image function
*
* @var string
*/
private $_imageFunc;
/**
* Image function
*
* @var string
*/
private $_imageExtension;
/**
* Create a new Image
*
* @param string $src
* @param mixed $style
*/
public function __construct($src, $style = null)
{
$imgData = getimagesize($src);
$this->_imageType = $imgData['mime'];
$_supportedImageTypes = array('image/jpeg', 'image/gif', 'image/png');
if (in_array($this->_imageType, $_supportedImageTypes)) {
$this->_src = $src;
$this->_style = new PHPWord_Style_Image();
if (!is_null($style) && is_array($style)) {
foreach ($style as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_style->setStyleValue($key, $value);
}
}
if ($this->_style->getWidth() == null && $this->_style->getHeight() == null) {
$this->_style->setWidth($imgData[0]);
$this->_style->setHeight($imgData[1]);
}
$this->_setFunctions();
}
}
/**
* Set Functions
*/
private function _setFunctions()
{
switch ($this->_imageType) {
case 'image/png':
$this->_imageCreateFunc = 'imagecreatefrompng';
$this->_imageFunc = 'imagepng';
$this->_imageExtension = 'png';
break;
case 'image/gif':
$this->_imageCreateFunc = 'imagecreatefromgif';
$this->_imageFunc = 'imagegif';
$this->_imageExtension = 'gif';
break;
case 'image/jpeg':
case 'image/jpg':
$this->_imageCreateFunc = 'imagecreatefromjpeg';
$this->_imageFunc = 'imagejpeg';
$this->_imageExtension = 'jpg';
break;
}
}
/**
* Get Image style
*
* @return PHPWord_Style_Image
*/
public function getStyle()
{
return $this->_style;
}
/**
* Get Image Relation ID
*
* @return int
*/
public function getRelationId()
{
return $this->_rId;
}
/**
* Set Image Relation ID
*
* @param int $rId
*/
public function setRelationId($rId)
{
$this->_rId = $rId;
}
/**
* Get Image Source
*
* @return string
*/
public function getSource()
{
return $this->_src;
}
/**
* Get Image Media ID
*
* @return string
*/
public function getMediaId()
{
return md5($this->_src);
}
/**
* Get Image Type
*
* @return string
*/
public function getImageType()
{
return $this->_imageType;
}
/**
* Get Image Create Function
*
* @return string
*/
public function getImageCreateFunction()
{
return $this->_imageCreateFunc;
}
/**
* Get Image Function
*
* @return string
*/
public function getImageFunction()
{
return $this->_imageFunc;
}
/**
* Get Image Extension
*
* @return string
*/
public function getImageExtension()
{
return $this->_imageExtension;
}
}

View File

@ -1,128 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Shared_File
*/
class PHPWord_Shared_File
{
const IMAGETYPE_JPEG = 'jpg';
const IMAGETYPE_GIF = 'gif';
const IMAGETYPE_PNG = 'png';
const IMAGETYPE_BMP = 'bmp';
const IMAGETYPE_TIFF = 'tif';
/**
* Verify if a file exists
*
* @param string $pFilename Filename
* @return bool
*/
public static function file_exists($pFilename)
{
return file_exists($pFilename);
}
/**
* Returns canonicalized absolute pathname, also for ZIP archives
*
* @param string $pFilename
* @return string
*/
public static function realpath($pFilename)
{
$returnValue = realpath($pFilename);
if (!$returnValue) {
$pathArray = explode('/', $pFilename);
while (in_array('..', $pathArray) && $pathArray[0] !== '..') {
for ($i = 0; $i < count($pathArray); ++$i) {
if ($pathArray[$i] === '..' && $i > 0) {
unset($pathArray[$i]);
unset($pathArray[$i - 1]);
break;
}
}
}
$returnValue = implode('/', $pathArray);
}
return $returnValue;
}
/**
* PHP Words version of exif_imagetype to return the Image Type from a file
*
* @param string $filename
* @return int|bool
*/
private static function fallbackImagetype($filename)
{
if ((list($width, $height, $type, $attr) = getimagesize($filename)) !== false) {
if ($type === 2) {
return self::IMAGETYPE_JPEG;
} elseif ($type === 1) {
return self::IMAGETYPE_GIF;
} elseif ($type === 3) {
return self::IMAGETYPE_PNG;
} elseif ($type === 6) {
return self::IMAGETYPE_BMP;
} elseif ($type === 7 || $type === 8) {
return self::IMAGETYPE_TIFF;
}
}
return false;
}
/**
* Return the Image Type from a file
*
* @param string $filename
* @param bool $userFallbackFunction
* @return int|bool
*/
public static function imagetype($filename, $userFallbackFunction = false)
{
if ($userFallbackFunction || !function_exists('exif_imagetype')) {
return self::fallbackImagetype($filename);
}
$imagetype = exif_imagetype($filename);
if ($imagetype === IMAGETYPE_JPEG) {
return self::IMAGETYPE_JPEG;
} elseif ($imagetype === IMAGETYPE_GIF) {
return self::IMAGETYPE_GIF;
} elseif ($imagetype === IMAGETYPE_PNG) {
return self::IMAGETYPE_PNG;
} elseif ($imagetype === IMAGETYPE_BMP) {
return self::IMAGETYPE_BMP;
} elseif ($imagetype === IMAGETYPE_TIFF_II || $imagetype === IMAGETYPE_TIFF_MM) {
return self::IMAGETYPE_TIFF;
}
return false;
}
}

View File

@ -1,96 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Style_Table
*/
class PHPWord_Style_Table
{
private $_cellMarginTop;
private $_cellMarginLeft;
private $_cellMarginRight;
private $_cellMarginBottom;
public function __construct()
{
$this->_cellMarginTop = null;
$this->_cellMarginLeft = null;
$this->_cellMarginRight = null;
$this->_cellMarginBottom = null;
}
public function setStyleValue($key, $value)
{
$this->$key = $value;
}
public function setCellMarginTop($pValue = null)
{
$this->_cellMarginTop = $pValue;
}
public function getCellMarginTop()
{
return $this->_cellMarginTop;
}
public function setCellMarginLeft($pValue = null)
{
$this->_cellMarginLeft = $pValue;
}
public function getCellMarginLeft()
{
return $this->_cellMarginLeft;
}
public function setCellMarginRight($pValue = null)
{
$this->_cellMarginRight = $pValue;
}
public function getCellMarginRight()
{
return $this->_cellMarginRight;
}
public function setCellMarginBottom($pValue = null)
{
$this->_cellMarginBottom = $pValue;
}
public function getCellMarginBottom()
{
return $this->_cellMarginBottom;
}
public function getCellMargin()
{
return array($this->_cellMarginTop, $this->_cellMarginLeft, $this->_cellMarginRight, $this->_cellMarginBottom);
}
}

View File

@ -1,397 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Writer_ODText_Manifest
*/
class PHPWord_Writer_ODText_Content extends PHPWord_Writer_ODText_WriterPart
{
/**
* Write content file to XML format
*
* @param PHPWord $pPHPWord
* @return string XML Output
* @throws Exception
*/
public function writeContent(PHPWord $pPHPWord = null)
{
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8');
// office:document-content
$objWriter->startElement('office:document-content');
$objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
$objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
$objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
$objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
$objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
$objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
$objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
$objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
$objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
$objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
$objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
$objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
$objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
$objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
$objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
$objWriter->writeAttribute('xmlns:xforms', 'http://www.w3.org/2002/xforms');
$objWriter->writeAttribute('xmlns:xsd', 'http://www.w3.org/2001/XMLSchema');
$objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
$objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
$objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
$objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
$objWriter->writeAttribute('xmlns:field', 'urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0');
$objWriter->writeAttribute('xmlns:formx', 'urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0');
$objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
$objWriter->writeAttribute('office:version', '1.2');
// We firstly search all fonts used
$_sections = $pPHPWord->getSections();
$countSections = count($_sections);
if ($countSections > 0) {
$pSection = 0;
$numPStyles = 0;
$numFStyles = 0;
foreach ($_sections as $section) {
$pSection++;
$_elements = $section->getElements();
foreach ($_elements as $element) {
if ($element instanceof PHPWord_Section_Text) {
$fStyle = $element->getFontStyle();
$pStyle = $element->getParagraphStyle();
if ($fStyle instanceof PHPWord_Style_Font) {
$numFStyles++;
$arrStyle = array(
'color' => $fStyle->getColor(),
'name' => $fStyle->getName()
);
$pPHPWord->addFontStyle('T' . $numFStyles, $arrStyle);
$element->setFontStyle('T' . $numFStyles);
} elseif ($pStyle instanceof PHPWord_Style_Paragraph) {
$numPStyles++;
$pPHPWord->addParagraphStyle('P' . $numPStyles, array());
$element->setParagraphStyle('P' . $numPStyles);
}
}
}
}
}
// office:font-face-decls
$objWriter->startElement('office:font-face-decls');
$arrFonts = array();
$styles = PHPWord_Style::getStyles();
$numFonts = 0;
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
// PHPWord_Style_Font
if ($style instanceof PHPWord_Style_Font) {
$numFonts++;
$name = $style->getName();
if (!in_array($name, $arrFonts)) {
$arrFonts[] = $name;
// style:font-face
$objWriter->startElement('style:font-face');
$objWriter->writeAttribute('style:name', $name);
$objWriter->writeAttribute('svg:font-family', $name);
$objWriter->endElement();
}
}
}
if (!in_array(PHPWord::DEFAULT_FONT_NAME, $arrFonts)) {
$objWriter->startElement('style:font-face');
$objWriter->writeAttribute('style:name', PHPWord::DEFAULT_FONT_NAME);
$objWriter->writeAttribute('svg:font-family', PHPWord::DEFAULT_FONT_NAME);
$objWriter->endElement();
}
}
$objWriter->endElement();
$objWriter->startElement('office:automatic-styles');
$styles = PHPWord_Style::getStyles();
$numPStyles = 0;
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
if (preg_match('#^T[0-9]+$#', $styleName) != 0
|| preg_match('#^P[0-9]+$#', $styleName) != 0
) {
// PHPWord_Style_Font
if ($style instanceof PHPWord_Style_Font) {
$objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', $styleName);
$objWriter->writeAttribute('style:family', 'text');
// style:text-properties
$objWriter->startElement('style:text-properties');
$objWriter->writeAttribute('fo:color', '#' . $style->getColor());
$objWriter->writeAttribute('style:font-name', $style->getName());
$objWriter->writeAttribute('style:font-name-complex', $style->getName());
$objWriter->endElement();
$objWriter->endElement();
}
if ($style instanceof PHPWord_Style_Paragraph) {
$numPStyles++;
// style:style
$objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', $styleName);
$objWriter->writeAttribute('style:family', 'paragraph');
$objWriter->writeAttribute('style:parent-style-name', 'Standard');
$objWriter->writeAttribute('style:master-page-name', 'Standard');
// style:paragraph-properties
$objWriter->startElement('style:paragraph-properties');
$objWriter->writeAttribute('style:page-number', 'auto');
$objWriter->endElement();
$objWriter->endElement();
}
}
}
if ($numPStyles == 0) {
// style:style
$objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', 'P1');
$objWriter->writeAttribute('style:family', 'paragraph');
$objWriter->writeAttribute('style:parent-style-name', 'Standard');
$objWriter->writeAttribute('style:master-page-name', 'Standard');
// style:paragraph-properties
$objWriter->startElement('style:paragraph-properties');
$objWriter->writeAttribute('style:page-number', 'auto');
$objWriter->endElement();
$objWriter->endElement();
}
}
$objWriter->endElement();
// office:body
$objWriter->startElement('office:body');
// office:text
$objWriter->startElement('office:text');
// text:sequence-decls
$objWriter->startElement('text:sequence-decls');
// text:sequence-decl
$objWriter->startElement('text:sequence-decl');
$objWriter->writeAttribute('text:display-outline-level', 0);
$objWriter->writeAttribute('text:name', 'Illustration');
$objWriter->endElement();
// text:sequence-decl
$objWriter->startElement('text:sequence-decl');
$objWriter->writeAttribute('text:display-outline-level', 0);
$objWriter->writeAttribute('text:name', 'Table');
$objWriter->endElement();
// text:sequence-decl
$objWriter->startElement('text:sequence-decl');
$objWriter->writeAttribute('text:display-outline-level', 0);
$objWriter->writeAttribute('text:name', 'Text');
$objWriter->endElement();
// text:sequence-decl
$objWriter->startElement('text:sequence-decl');
$objWriter->writeAttribute('text:display-outline-level', 0);
$objWriter->writeAttribute('text:name', 'Drawing');
$objWriter->endElement();
$objWriter->endElement();
$_sections = $pPHPWord->getSections();
$countSections = count($_sections);
$pSection = 0;
if ($countSections > 0) {
foreach ($_sections as $section) {
$pSection++;
$_elements = $section->getElements();
foreach ($_elements as $element) {
if ($element instanceof PHPWord_Section_Text) {
$this->_writeText($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_TextRun) {
$this->_writeTextRun($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_TextBreak) {
$this->_writeTextBreak($objWriter);
} elseif ($element instanceof PHPWord_Section_Link) {
$this->writeUnsupportedElement($objWriter, 'Link');
} elseif ($element instanceof PHPWord_Section_Title) {
$this->writeUnsupportedElement($objWriter, 'Title');
} elseif ($element instanceof PHPWord_Section_PageBreak) {
$this->writeUnsupportedElement($objWriter, 'Page Break');
} elseif ($element instanceof PHPWord_Section_Table) {
$this->writeUnsupportedElement($objWriter, 'Table');
} elseif ($element instanceof PHPWord_Section_ListItem) {
$this->writeUnsupportedElement($objWriter, 'List Item');
} elseif ($element instanceof PHPWord_Section_Image ||
$element instanceof PHPWord_Section_MemoryImage) {
$this->writeUnsupportedElement($objWriter, 'Image');
} elseif ($element instanceof PHPWord_Section_Object) {
$this->writeUnsupportedElement($objWriter, 'Object');
} elseif ($element instanceof PHPWord_TOC) {
$this->writeUnsupportedElement($objWriter, 'TOC');
} else {
$this->writeUnsupportedElement($objWriter, 'Element');
}
}
if ($pSection == $countSections) {
$this->_writeEndSection($objWriter, $section);
} else {
$this->_writeSection($objWriter, $section);
}
}
}
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
// Return
return $objWriter->getData();
}
/**
* Write text
*
* @param PHPWord_Shared_XMLWriter $objWriter
* @param PHPWord_Section_Text $text
* @param bool $withoutP
*/
protected function _writeText(
PHPWord_Shared_XMLWriter $objWriter = null,
PHPWord_Section_Text $text,
$withoutP = false
) {
$styleFont = $text->getFontStyle();
$styleParagraph = $text->getParagraphStyle();
// @todo Commented for TextRun. Should really checkout this value
// $SfIsObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false;
$SfIsObject = false;
if ($SfIsObject) {
// Don't never be the case, because I browse all sections for cleaning all styles not declared
die('PHPWord : $SfIsObject wouldn\'t be an object');
} else {
if (!$withoutP) {
$objWriter->startElement('text:p'); // text:p
}
if (empty($styleFont)) {
if (empty($styleParagraph)) {
$objWriter->writeAttribute('text:style-name', 'P1');
} else {
$objWriter->writeAttribute('text:style-name', $text->getParagraphStyle());
}
$objWriter->writeRaw($text->getText());
} else {
if (empty($styleParagraph)) {
$objWriter->writeAttribute('text:style-name', 'Standard');
} else {
$objWriter->writeAttribute('text:style-name', $text->getParagraphStyle());
}
// text:span
$objWriter->startElement('text:span');
$objWriter->writeAttribute('text:style-name', $styleFont);
$objWriter->writeRaw($text->getText());
$objWriter->endElement();
}
if (!$withoutP) {
$objWriter->endElement(); // text:p
}
}
}
/**
* Write TextRun section
*
* @param PHPWord_Shared_XMLWriter $objWriter
* @param PHPWord_Section_TextRun $textrun
* @todo Enable all other section types
*/
protected function _writeTextRun(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_TextRun $textrun)
{
$elements = $textrun->getElements();
$objWriter->startElement('text:p');
if (count($elements) > 0) {
foreach ($elements as $element) {
if ($element instanceof PHPWord_Section_Text) {
$this->_writeText($objWriter, $element, true);
}
}
}
$objWriter->endElement();
}
/**
* Write TextBreak
*/
protected function _writeTextBreak(PHPWord_Shared_XMLWriter $objWriter = null)
{
$objWriter->startElement('text:p');
$objWriter->writeAttribute('text:style-name', 'Standard');
$objWriter->endElement();
}
// @codeCoverageIgnoreStart
private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section = null)
{
}
private function _writeSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section = null)
{
}
// @codeCoverageIgnoreEnd
/**
* Write unsupported element
*
* @param PHPWord_Shared_XMLWriter $objWriter
* @param string $element
*/
private function writeUnsupportedElement($objWriter, $element)
{
$objWriter->startElement('text:p');
$objWriter->writeRaw("{$element}");
$objWriter->endElement();
}
}

View File

@ -1,94 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Writer_ODText_Meta
*/
class PHPWord_Writer_ODText_Meta extends PHPWord_Writer_ODText_WriterPart
{
/**
* Write Meta file to XML format
*
* @param PHPWord $pPHPWord
* @return string XML Output
* @throws Exception
*/
public function writeMeta(PHPWord $pPHPWord = null)
{
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8');
// office:document-meta
$objWriter->startElement('office:document-meta');
$objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$objWriter->writeAttribute('office:version', '1.2');
// office:meta
$objWriter->startElement('office:meta');
// dc:creator
$objWriter->writeElement('dc:creator', $pPHPWord->getProperties()->getLastModifiedBy());
// dc:date
$objWriter->writeElement('dc:date', gmdate('Y-m-d\TH:i:s.000', $pPHPWord->getProperties()->getModified()));
// dc:description
$objWriter->writeElement('dc:description', $pPHPWord->getProperties()->getDescription());
// dc:subject
$objWriter->writeElement('dc:subject', $pPHPWord->getProperties()->getSubject());
// dc:title
$objWriter->writeElement('dc:title', $pPHPWord->getProperties()->getTitle());
// meta:creation-date
$objWriter->writeElement('meta:creation-date', gmdate('Y-m-d\TH:i:s.000', $pPHPWord->getProperties()->getCreated()));
// meta:initial-creator
$objWriter->writeElement('meta:initial-creator', $pPHPWord->getProperties()->getCreator());
// meta:keyword
$objWriter->writeElement('meta:keyword', $pPHPWord->getProperties()->getKeywords());
// @todo : Where these properties are written ?
// $pPHPWord->getProperties()->getCategory()
// $pPHPWord->getProperties()->getCompany()
$objWriter->endElement();
$objWriter->endElement();
// Return
return $objWriter->getData();
}
}

View File

@ -1,267 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Writer_ODText_Styles
*/
class PHPWord_Writer_ODText_Styles extends PHPWord_Writer_ODText_WriterPart
{
/**
* Write Styles file to XML format
*
* @param PHPWord $pPHPWord
* @return string XML Output
* @throws Exception
*/
public function writeStyles(PHPWord $pPHPWord = null)
{
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8');
// Styles:Styles
$objWriter->startElement('office:document-styles');
$objWriter->writeAttribute('xmlns:office', 'urn:oasis:names:tc:opendocument:xmlns:office:1.0');
$objWriter->writeAttribute('xmlns:style', 'urn:oasis:names:tc:opendocument:xmlns:style:1.0');
$objWriter->writeAttribute('xmlns:text', 'urn:oasis:names:tc:opendocument:xmlns:text:1.0');
$objWriter->writeAttribute('xmlns:table', 'urn:oasis:names:tc:opendocument:xmlns:table:1.0');
$objWriter->writeAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0');
$objWriter->writeAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0');
$objWriter->writeAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
$objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$objWriter->writeAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0');
$objWriter->writeAttribute('xmlns:number', 'urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0');
$objWriter->writeAttribute('xmlns:svg', 'urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0');
$objWriter->writeAttribute('xmlns:chart', 'urn:oasis:names:tc:opendocument:xmlns:chart:1.0');
$objWriter->writeAttribute('xmlns:dr3d', 'urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0');
$objWriter->writeAttribute('xmlns:math', 'http://www.w3.org/1998/Math/MathML');
$objWriter->writeAttribute('xmlns:form', 'urn:oasis:names:tc:opendocument:xmlns:form:1.0');
$objWriter->writeAttribute('xmlns:script', 'urn:oasis:names:tc:opendocument:xmlns:script:1.0');
$objWriter->writeAttribute('xmlns:ooo', 'http://openoffice.org/2004/office');
$objWriter->writeAttribute('xmlns:ooow', 'http://openoffice.org/2004/writer');
$objWriter->writeAttribute('xmlns:oooc', 'http://openoffice.org/2004/calc');
$objWriter->writeAttribute('xmlns:dom', 'http://www.w3.org/2001/xml-events');
$objWriter->writeAttribute('xmlns:rpt', 'http://openoffice.org/2005/report');
$objWriter->writeAttribute('xmlns:of', 'urn:oasis:names:tc:opendocument:xmlns:of:1.2');
$objWriter->writeAttribute('xmlns:xhtml', 'http://www.w3.org/1999/xhtml');
$objWriter->writeAttribute('xmlns:grddl', 'http://www.w3.org/2003/g/data-view#');
$objWriter->writeAttribute('xmlns:tableooo', 'http://openoffice.org/2009/table');
$objWriter->writeAttribute('xmlns:css3t', 'http://www.w3.org/TR/css3-text/');
$objWriter->writeAttribute('office:version', '1.2');
// office:font-face-decls
$objWriter->startElement('office:font-face-decls');
$arrFonts = array();
$styles = PHPWord_Style::getStyles();
$numFonts = 0;
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
// PHPWord_Style_Font
if ($style instanceof PHPWord_Style_Font) {
$numFonts++;
$name = $style->getName();
if (!in_array($name, $arrFonts)) {
$arrFonts[] = $name;
// style:font-face
$objWriter->startElement('style:font-face');
$objWriter->writeAttribute('style:name', $name);
$objWriter->writeAttribute('svg:font-family', $name);
$objWriter->endElement();
}
}
}
}
if (!in_array(PHPWord::DEFAULT_FONT_NAME, $arrFonts)) {
$objWriter->startElement('style:font-face');
$objWriter->writeAttribute('style:name', PHPWord::DEFAULT_FONT_NAME);
$objWriter->writeAttribute('svg:font-family', PHPWord::DEFAULT_FONT_NAME);
$objWriter->endElement();
}
$objWriter->endElement();
// office:styles
$objWriter->startElement('office:styles');
// style:default-style
$objWriter->startElement('style:default-style');
$objWriter->writeAttribute('style:family', 'paragraph');
// style:paragraph-properties
$objWriter->startElement('style:paragraph-properties');
$objWriter->writeAttribute('fo:hyphenation-ladder-count', 'no-limit');
$objWriter->writeAttribute('style:text-autospace', 'ideograph-alpha');
$objWriter->writeAttribute('style:punctuation-wrap', 'hanging');
$objWriter->writeAttribute('style:line-break', 'strict');
$objWriter->writeAttribute('style:tab-stop-distance', '1.249cm');
$objWriter->writeAttribute('style:writing-mode', 'page');
$objWriter->endElement();
// style:text-properties
$objWriter->startElement('style:text-properties');
$objWriter->writeAttribute('style:use-window-font-color', 'true');
$objWriter->writeAttribute('style:font-name', PHPWord::DEFAULT_FONT_NAME);
$objWriter->writeAttribute('fo:font-size', PHPWord::DEFAULT_FONT_SIZE . 'pt');
$objWriter->writeAttribute('fo:language', 'fr');
$objWriter->writeAttribute('fo:country', 'FR');
$objWriter->writeAttribute('style:letter-kerning', 'true');
$objWriter->writeAttribute('style:font-name-asian', PHPWord::DEFAULT_FONT_NAME . '2');
$objWriter->writeAttribute('style:font-size-asian', PHPWord::DEFAULT_FONT_SIZE . 'pt');
$objWriter->writeAttribute('style:language-asian', 'zh');
$objWriter->writeAttribute('style:country-asian', 'CN');
$objWriter->writeAttribute('style:font-name-complex', PHPWord::DEFAULT_FONT_NAME . '2');
$objWriter->writeAttribute('style:font-size-complex', PHPWord::DEFAULT_FONT_SIZE . 'pt');
$objWriter->writeAttribute('style:language-complex', 'hi');
$objWriter->writeAttribute('style:country-complex', 'IN');
$objWriter->writeAttribute('fo:hyphenate', 'false');
$objWriter->writeAttribute('fo:hyphenation-remain-char-count', '2');
$objWriter->writeAttribute('fo:hyphenation-push-char-count', '2');
$objWriter->endElement();
$objWriter->endElement();
// Write Style Definitions
$styles = PHPWord_Style::getStyles();
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
if (preg_match('#^T[0-9]+$#', $styleName) == 0
&& preg_match('#^P[0-9]+$#', $styleName) == 0
) {
// PHPWord_Style_Font
if ($style instanceof PHPWord_Style_Font) {
// style:style
$objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', $styleName);
$objWriter->writeAttribute('style:family', 'text');
// style:text-properties
$objWriter->startElement('style:text-properties');
$objWriter->writeAttribute('fo:font-size', ($style->getSize()) . 'pt');
$objWriter->writeAttribute('style:font-size-asian', ($style->getSize()) . 'pt');
$objWriter->writeAttribute('style:font-size-complex', ($style->getSize()) . 'pt');
if ($style->getItalic()) {
$objWriter->writeAttribute('fo:font-style', 'italic');
$objWriter->writeAttribute('style:font-style-asian', 'italic');
$objWriter->writeAttribute('style:font-style-complex', 'italic');
}
if ($style->getBold()) {
$objWriter->writeAttribute('fo:font-weight', 'bold');
$objWriter->writeAttribute('style:font-weight-asian', 'bold');
}
$objWriter->endElement();
$objWriter->endElement();
} elseif ($style instanceof PHPWord_Style_Paragraph) {
// PHPWord_Style_Paragraph
// style:style
$objWriter->startElement('style:style');
$objWriter->writeAttribute('style:name', $styleName);
$objWriter->writeAttribute('style:family', 'paragraph');
//style:paragraph-properties
$objWriter->startElement('style:paragraph-properties');
$objWriter->writeAttribute('fo:margin-top', ((is_null($style->getSpaceBefore())) ? '0' : round(17.6 / $style->getSpaceBefore(), 2)) . 'cm');
$objWriter->writeAttribute('fo:margin-bottom', ((is_null($style->getSpaceAfter())) ? '0' : round(17.6 / $style->getSpaceAfter(), 2)) . 'cm');
$objWriter->writeAttribute('fo:text-align', $style->getAlign());
$objWriter->endElement();
$objWriter->endElement();
} elseif ($style instanceof PHPWord_Style_TableFull) {
// PHPWord_Style_TableFull
}
}
}
}
$objWriter->endElement();
// office:automatic-styles
$objWriter->startElement('office:automatic-styles');
// style:page-layout
$objWriter->startElement('style:page-layout');
$objWriter->writeAttribute('style:name', 'Mpm1');
// style:page-layout-properties
$objWriter->startElement('style:page-layout-properties');
$objWriter->writeAttribute('fo:page-width', "21.001cm");
$objWriter->writeAttribute('fo:page-height', '29.7cm');
$objWriter->writeAttribute('style:num-format', '1');
$objWriter->writeAttribute('style:print-orientation', 'portrait');
$objWriter->writeAttribute('fo:margin-top', '2.501cm');
$objWriter->writeAttribute('fo:margin-bottom', '2cm');
$objWriter->writeAttribute('fo:margin-left', '2.501cm');
$objWriter->writeAttribute('fo:margin-right', '2.501cm');
$objWriter->writeAttribute('style:writing-mode', 'lr-tb');
$objWriter->writeAttribute('style:layout-grid-color', '#c0c0c0');
$objWriter->writeAttribute('style:layout-grid-lines', '25199');
$objWriter->writeAttribute('style:layout-grid-base-height', '0.423cm');
$objWriter->writeAttribute('style:layout-grid-ruby-height', '0cm');
$objWriter->writeAttribute('style:layout-grid-mode', 'none');
$objWriter->writeAttribute('style:layout-grid-ruby-below', 'false');
$objWriter->writeAttribute('style:layout-grid-print', 'false');
$objWriter->writeAttribute('style:layout-grid-display', 'false');
$objWriter->writeAttribute('style:layout-grid-base-width', '0.37cm');
$objWriter->writeAttribute('style:layout-grid-snap-to', 'true');
$objWriter->writeAttribute('style:footnote-max-height', '0cm');
//style:footnote-sep
$objWriter->startElement('style:footnote-sep');
$objWriter->writeAttribute('style:width', '0.018cm');
$objWriter->writeAttribute('style:line-style', 'solid');
$objWriter->writeAttribute('style:adjustment', 'left');
$objWriter->writeAttribute('style:rel-width', '25%');
$objWriter->writeAttribute('style:color', '#000000');
$objWriter->endElement();
$objWriter->endElement();
// style:header-style
$objWriter->startElement('style:header-style');
$objWriter->endElement();
// style:footer-style
$objWriter->startElement('style:footer-style');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
// office:master-styles
$objWriter->startElement('office:master-styles');
// style:master-page
$objWriter->startElement('style:master-page');
$objWriter->writeAttribute('style:name', 'Standard');
$objWriter->writeAttribute('style:page-layout-name', 'Mpm1');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
// Return
return $objWriter->getData();
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,185 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Writer_Word2007_DocProps
*/
class PHPWord_Writer_Word2007_DocProps extends PHPWord_Writer_Word2007_WriterPart
{
public function writeDocPropsApp(PHPWord $pPHPWord = null)
{
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes');
// Properties
$objWriter->startElement('Properties');
$objWriter->writeAttribute('xmlns', 'http://schemas.openxmlformats.org/officeDocument/2006/extended-properties');
$objWriter->writeAttribute('xmlns:vt', 'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');
// Application
$objWriter->writeElement('Application', 'Microsoft Office Word');
// ScaleCrop
$objWriter->writeElement('ScaleCrop', 'false');
// HeadingPairs
$objWriter->startElement('HeadingPairs');
// Vector
$objWriter->startElement('vt:vector');
$objWriter->writeAttribute('size', '4');
$objWriter->writeAttribute('baseType', 'variant');
// Variant
$objWriter->startElement('vt:variant');
$objWriter->writeElement('vt:lpstr', 'Theme');
$objWriter->endElement();
// Variant
$objWriter->startElement('vt:variant');
$objWriter->writeElement('vt:i4', '1');
$objWriter->endElement();
// Variant
$objWriter->startElement('vt:variant');
$objWriter->writeElement('vt:lpstr', 'Slide Titles');
$objWriter->endElement();
// Variant
$objWriter->startElement('vt:variant');
$objWriter->writeElement('vt:i4', '1');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
// TitlesOfParts
$objWriter->startElement('TitlesOfParts');
// Vector
$objWriter->startElement('vt:vector');
$objWriter->writeAttribute('size', '1');
$objWriter->writeAttribute('baseType', 'lpstr');
$objWriter->writeElement('vt:lpstr', 'Office Theme');
$objWriter->endElement();
$objWriter->endElement();
// Company
$objWriter->writeElement('Company', $pPHPWord->getProperties()->getCompany());
// LinksUpToDate
$objWriter->writeElement('LinksUpToDate', 'false');
// SharedDoc
$objWriter->writeElement('SharedDoc', 'false');
// HyperlinksChanged
$objWriter->writeElement('HyperlinksChanged', 'false');
// AppVersion
$objWriter->writeElement('AppVersion', '12.0000');
$objWriter->endElement();
// Return
return $objWriter->getData();
}
public function writeDocPropsCore(PHPWord $pPHPWord = null)
{
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes');
// cp:coreProperties
$objWriter->startElement('cp:coreProperties');
$objWriter->writeAttribute('xmlns:cp', 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties');
$objWriter->writeAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/');
$objWriter->writeAttribute('xmlns:dcterms', 'http://purl.org/dc/terms/');
$objWriter->writeAttribute('xmlns:dcmitype', 'http://purl.org/dc/dcmitype/');
$objWriter->writeAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
// dc:creator
$objWriter->writeElement('dc:creator', $pPHPWord->getProperties()->getCreator());
// cp:lastModifiedBy
$objWriter->writeElement('cp:lastModifiedBy', $pPHPWord->getProperties()->getLastModifiedBy());
// dcterms:created
$objWriter->startElement('dcterms:created');
$objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
$objWriter->writeRaw(date(DATE_W3C, $pPHPWord->getProperties()->getCreated()));
$objWriter->endElement();
// dcterms:modified
$objWriter->startElement('dcterms:modified');
$objWriter->writeAttribute('xsi:type', 'dcterms:W3CDTF');
$objWriter->writeRaw(date(DATE_W3C, $pPHPWord->getProperties()->getModified()));
$objWriter->endElement();
// dc:title
$objWriter->writeElement('dc:title', $pPHPWord->getProperties()->getTitle());
// dc:description
$objWriter->writeElement('dc:description', $pPHPWord->getProperties()->getDescription());
// dc:subject
$objWriter->writeElement('dc:subject', $pPHPWord->getProperties()->getSubject());
// cp:keywords
$objWriter->writeElement('cp:keywords', $pPHPWord->getProperties()->getKeywords());
// cp:category
$objWriter->writeElement('cp:category', $pPHPWord->getProperties()->getCategory());
$objWriter->endElement();
// Return
return $objWriter->getData();
}
}

View File

@ -1,491 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Writer_Word2007_Document
*/
class PHPWord_Writer_Word2007_Document extends PHPWord_Writer_Word2007_Base
{
public function writeDocument(PHPWord $pPHPWord = null)
{
// Create XML writer
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes');
// w:document
$objWriter->startElement('w:document');
$objWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
$objWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$objWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
$objWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
$objWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing');
$objWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word');
$objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
$objWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml');
$objWriter->startElement('w:body');
$_sections = $pPHPWord->getSections();
$countSections = count($_sections);
$pSection = 0;
if ($countSections > 0) {
foreach ($_sections as $section) {
$pSection++;
$_elements = $section->getElements();
foreach ($_elements as $element) {
if ($element instanceof PHPWord_Section_Text) {
$this->_writeText($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_TextRun) {
$this->_writeTextRun($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_Link) {
$this->_writeLink($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_Title) {
$this->_writeTitle($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_TextBreak) {
$this->_writeTextBreak($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_PageBreak) {
$this->_writePageBreak($objWriter);
} elseif ($element instanceof PHPWord_Section_Table) {
$this->_writeTable($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_ListItem) {
$this->_writeListItem($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_Image ||
$element instanceof PHPWord_Section_MemoryImage
) {
$this->_writeImage($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_Object) {
$this->_writeObject($objWriter, $element);
} elseif ($element instanceof PHPWord_TOC) {
$this->_writeTOC($objWriter);
} elseif ($element instanceof PHPWord_Section_Footnote) {
$this->_writeFootnoteReference($objWriter, $element);
}
}
if ($pSection == $countSections) {
$this->_writeEndSection($objWriter, $section);
} else {
$this->_writeSection($objWriter, $section);
}
}
}
$objWriter->endElement(); // End w:body
$objWriter->endElement(); // End w:document
// Return
return $objWriter->getData();
}
private function _writeSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section)
{
$objWriter->startElement('w:p');
$objWriter->startElement('w:pPr');
$this->_writeEndSection($objWriter, $section, 3);
$objWriter->endElement();
$objWriter->endElement();
}
private function _writeEndSection(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section $section)
{
$settings = $section->getSettings();
$_headers = $section->getHeaders();
$_footer = $section->getFooter();
$pgSzW = $settings->getPageSizeW();
$pgSzH = $settings->getPageSizeH();
$orientation = $settings->getOrientation();
$marginTop = $settings->getMarginTop();
$marginLeft = $settings->getMarginLeft();
$marginRight = $settings->getMarginRight();
$marginBottom = $settings->getMarginBottom();
$headerHeight = $settings->getHeaderHeight();
$footerHeight = $settings->getFooterHeight();
$borders = $settings->getBorderSize();
$colsNum = $settings->getColsNum();
$colsSpace = $settings->getColsSpace();
$breakType = $settings->getBreakType();
$objWriter->startElement('w:sectPr');
foreach ($_headers as &$_header) {
$rId = $_header->getRelationId();
$objWriter->startElement('w:headerReference');
$objWriter->writeAttribute('w:type', $_header->getType());
$objWriter->writeAttribute('r:id', 'rId' . $rId);
$objWriter->endElement();
}
if ($section->hasDifferentFirstPage()) {
$objWriter->startElement('w:titlePg');
$objWriter->endElement();
}
if (!is_null($breakType)) {
$objWriter->startElement('w:type');
$objWriter->writeAttribute('w:val', $breakType);
$objWriter->endElement();
}
if (!is_null($_footer)) {
$rId = $_footer->getRelationId();
$objWriter->startElement('w:footerReference');
$objWriter->writeAttribute('w:type', 'default');
$objWriter->writeAttribute('r:id', 'rId' . $rId);
$objWriter->endElement();
}
$objWriter->startElement('w:pgSz');
$objWriter->writeAttribute('w:w', $pgSzW);
$objWriter->writeAttribute('w:h', $pgSzH);
if (!is_null($orientation) && strtolower($orientation) != 'portrait') {
$objWriter->writeAttribute('w:orient', $orientation);
}
$objWriter->endElement();
$objWriter->startElement('w:pgMar');
$objWriter->writeAttribute('w:top', $marginTop);
$objWriter->writeAttribute('w:right', $marginRight);
$objWriter->writeAttribute('w:bottom', $marginBottom);
$objWriter->writeAttribute('w:left', $marginLeft);
$objWriter->writeAttribute('w:header', $headerHeight);
$objWriter->writeAttribute('w:footer', $footerHeight);
$objWriter->writeAttribute('w:gutter', '0');
$objWriter->endElement();
if (!is_null($borders[0]) || !is_null($borders[1]) || !is_null($borders[2]) || !is_null($borders[3])) {
$borderColor = $settings->getBorderColor();
$objWriter->startElement('w:pgBorders');
$objWriter->writeAttribute('w:offsetFrom', 'page');
if (!is_null($borders[0])) {
$objWriter->startElement('w:top');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $borders[0]);
$objWriter->writeAttribute('w:space', '24');
$objWriter->writeAttribute('w:color', $borderColor[0]);
$objWriter->endElement();
}
if (!is_null($borders[1])) {
$objWriter->startElement('w:left');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $borders[1]);
$objWriter->writeAttribute('w:space', '24');
$objWriter->writeAttribute('w:color', $borderColor[1]);
$objWriter->endElement();
}
if (!is_null($borders[2])) {
$objWriter->startElement('w:right');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $borders[2]);
$objWriter->writeAttribute('w:space', '24');
$objWriter->writeAttribute('w:color', $borderColor[2]);
$objWriter->endElement();
}
if (!is_null($borders[3])) {
$objWriter->startElement('w:bottom');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $borders[3]);
$objWriter->writeAttribute('w:space', '24');
$objWriter->writeAttribute('w:color', $borderColor[3]);
$objWriter->endElement();
}
$objWriter->endElement();
}
// Page numbering
if (null !== $settings->getPageNumberingStart()) {
$objWriter->startElement('w:pgNumType');
$objWriter->writeAttribute('w:start', $section->getSettings()->getPageNumberingStart());
$objWriter->endElement();
}
$objWriter->startElement('w:cols');
$objWriter->writeAttribute('w:num', $colsNum);
$objWriter->writeAttribute('w:space', $colsSpace);
$objWriter->endElement();
$objWriter->endElement();
}
private function _writePageBreak(PHPWord_Shared_XMLWriter $objWriter = null)
{
$objWriter->startElement('w:p');
$objWriter->startElement('w:r');
$objWriter->startElement('w:br');
$objWriter->writeAttribute('w:type', 'page');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
}
public function _writeListItem(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_ListItem $listItem)
{
$textObject = $listItem->getTextObject();
$text = $textObject->getText();
$styleParagraph = $textObject->getParagraphStyle();
$SpIsObject = ($styleParagraph instanceof PHPWord_Style_Paragraph) ? true : false;
$depth = $listItem->getDepth();
$listType = $listItem->getStyle()->getListType();
$objWriter->startElement('w:p');
$objWriter->startElement('w:pPr');
if ($SpIsObject) {
$this->_writeParagraphStyle($objWriter, $styleParagraph, true);
} elseif (!$SpIsObject && !is_null($styleParagraph)) {
$objWriter->startElement('w:pStyle');
$objWriter->writeAttribute('w:val', $styleParagraph);
$objWriter->endElement();
}
$objWriter->startElement('w:numPr');
$objWriter->startElement('w:ilvl');
$objWriter->writeAttribute('w:val', $depth);
$objWriter->endElement();
$objWriter->startElement('w:numId');
$objWriter->writeAttribute('w:val', $listType);
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
$this->_writeText($objWriter, $textObject, true);
$objWriter->endElement();
}
protected function _writeObject(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Section_Object $object)
{
$rIdObject = $object->getRelationId();
$rIdImage = $object->getImageRelationId();
$shapeId = md5($rIdObject . '_' . $rIdImage);
$objectId = $object->getObjectId();
$style = $object->getStyle();
$width = $style->getWidth();
$height = $style->getHeight();
$align = $style->getAlign();
$objWriter->startElement('w:p');
if (!is_null($align)) {
$objWriter->startElement('w:pPr');
$objWriter->startElement('w:jc');
$objWriter->writeAttribute('w:val', $align);
$objWriter->endElement();
$objWriter->endElement();
}
$objWriter->startElement('w:r');
$objWriter->startElement('w:object');
$objWriter->writeAttribute('w:dxaOrig', '249');
$objWriter->writeAttribute('w:dyaOrig', '160');
$objWriter->startElement('v:shape');
$objWriter->writeAttribute('id', $shapeId);
$objWriter->writeAttribute('type', '#_x0000_t75');
$objWriter->writeAttribute('style', 'width:104px;height:67px');
$objWriter->writeAttribute('o:ole', '');
$objWriter->startElement('v:imagedata');
$objWriter->writeAttribute('r:id', 'rId' . $rIdImage);
$objWriter->writeAttribute('o:title', '');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->startElement('o:OLEObject');
$objWriter->writeAttribute('Type', 'Embed');
$objWriter->writeAttribute('ProgID', 'Package');
$objWriter->writeAttribute('ShapeID', $shapeId);
$objWriter->writeAttribute('DrawAspect', 'Icon');
$objWriter->writeAttribute('ObjectID', '_' . $objectId);
$objWriter->writeAttribute('r:id', 'rId' . $rIdObject);
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement(); // w:r
$objWriter->endElement(); // w:p
}
private function _writeTOC(PHPWord_Shared_XMLWriter $objWriter = null)
{
$titles = PHPWord_TOC::getTitles();
$styleFont = PHPWord_TOC::getStyleFont();
$styleTOC = PHPWord_TOC::getStyleTOC();
$fIndent = $styleTOC->getIndent();
$tabLeader = $styleTOC->getTabLeader();
$tabPos = $styleTOC->getTabPos();
$isObject = ($styleFont instanceof PHPWord_Style_Font) ? true : false;
for ($i = 0; $i < count($titles); $i++) {
$title = $titles[$i];
$indent = ($title['depth'] - 1) * $fIndent;
$objWriter->startElement('w:p');
$objWriter->startElement('w:pPr');
if ($isObject && !is_null($styleFont->getParagraphStyle())) {
$this->_writeParagraphStyle($objWriter, $styleFont->getParagraphStyle());
}
if ($indent > 0) {
$objWriter->startElement('w:ind');
$objWriter->writeAttribute('w:left', $indent);
$objWriter->endElement();
}
if (!empty($styleFont) && !$isObject) {
$objWriter->startElement('w:pPr');
$objWriter->startElement('w:pStyle');
$objWriter->writeAttribute('w:val', $styleFont);
$objWriter->endElement();
$objWriter->endElement();
}
$objWriter->startElement('w:tabs');
$objWriter->startElement('w:tab');
$objWriter->writeAttribute('w:val', 'right');
if (!empty($tabLeader)) {
$objWriter->writeAttribute('w:leader', $tabLeader);
}
$objWriter->writeAttribute('w:pos', $tabPos);
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement(); // w:pPr
if ($i == 0) {
$objWriter->startElement('w:r');
$objWriter->startElement('w:fldChar');
$objWriter->writeAttribute('w:fldCharType', 'begin');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->startElement('w:r');
$objWriter->startElement('w:instrText');
$objWriter->writeAttribute('xml:space', 'preserve');
$objWriter->writeRaw('TOC \o "1-9" \h \z \u');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->startElement('w:r');
$objWriter->startElement('w:fldChar');
$objWriter->writeAttribute('w:fldCharType', 'separate');
$objWriter->endElement();
$objWriter->endElement();
}
$objWriter->startElement('w:hyperlink');
$objWriter->writeAttribute('w:anchor', $title['anchor']);
$objWriter->writeAttribute('w:history', '1');
$objWriter->startElement('w:r');
if ($isObject) {
$this->_writeTextStyle($objWriter, $styleFont);
}
$objWriter->startElement('w:t');
$objWriter->writeRaw($title['text']);
$objWriter->endElement();
$objWriter->endElement();
$objWriter->startElement('w:r');
$objWriter->writeElement('w:tab', null);
$objWriter->endElement();
$objWriter->startElement('w:r');
$objWriter->startElement('w:fldChar');
$objWriter->writeAttribute('w:fldCharType', 'begin');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->startElement('w:r');
$objWriter->startElement('w:instrText');
$objWriter->writeAttribute('xml:space', 'preserve');
$objWriter->writeRaw('PAGEREF ' . $title['anchor'] . ' \h');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->startElement('w:r');
$objWriter->startElement('w:fldChar');
$objWriter->writeAttribute('w:fldCharType', 'end');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement(); // w:hyperlink
$objWriter->endElement(); // w:p
}
$objWriter->startElement('w:p');
$objWriter->startElement('w:r');
$objWriter->startElement('w:fldChar');
$objWriter->writeAttribute('w:fldCharType', 'end');
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
}
}

View File

@ -1,83 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Writer_Word2007_Footer
*/
class PHPWord_Writer_Word2007_Footer extends PHPWord_Writer_Word2007_Base
{
public function writeFooter(PHPWord_Section_Footer $footer)
{
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes');
$objWriter->startElement('w:ftr');
$objWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
$objWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$objWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
$objWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
$objWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing');
$objWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word');
$objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
$objWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml');
$_elements = $footer->getElements();
foreach ($_elements as $element) {
if ($element instanceof PHPWord_Section_Text) {
$this->_writeText($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_TextRun) {
$this->_writeTextRun($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_TextBreak) {
$this->_writeTextBreak($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_Table) {
$this->_writeTable($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_Image ||
$element instanceof PHPWord_Section_MemoryImage
) {
$this->_writeImage($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_Footer_PreserveText) {
$this->_writePreserveText($objWriter, $element);
}
}
$objWriter->endElement();
// Return
return $objWriter->getData();
}
}

View File

@ -1,83 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
class PHPWord_Writer_Word2007_Footnotes extends PHPWord_Writer_Word2007_Base
{
public function writeFootnotes($allFootnotesCollection)
{
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes');
$objWriter->startElement('w:footnotes');
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
// write separator and continuation separator
$objWriter->startElement('w:footnote');
$objWriter->writeAttribute('w:id', 0);
$objWriter->writeAttribute('w:type', 'separator');
$objWriter->startElement('w:p');
$objWriter->startElement('w:r');
$objWriter->startElement('w:separator');
$objWriter->endElement(); // w:separator
$objWriter->endElement(); // w:r
$objWriter->endElement(); // w:p
$objWriter->endElement(); // w:footnote
$objWriter->startElement('w:footnote');
$objWriter->writeAttribute('w:id', 1);
$objWriter->writeAttribute('w:type', 'continuationSeparator');
$objWriter->startElement('w:p');
$objWriter->startElement('w:r');
$objWriter->startElement('w:continuationSeparator');
$objWriter->endElement(); // w:continuationSeparator
$objWriter->endElement(); // w:r
$objWriter->endElement(); // w:p
$objWriter->endElement(); // w:footnote
foreach ($allFootnotesCollection as $footnote) {
if ($footnote instanceof PHPWord_Section_Footnote) {
$this->_writeFootnote($objWriter, $footnote);
}
}
$objWriter->endElement();
// Return
return $objWriter->getData();
}
}

View File

@ -1,87 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Writer_Word2007_Header
*/
class PHPWord_Writer_Word2007_Header extends PHPWord_Writer_Word2007_Base
{
public function writeHeader(PHPWord_Section_Header $header)
{
// Create XML writer
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
// XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes');
$objWriter->startElement('w:hdr');
$objWriter->writeAttribute('xmlns:ve', 'http://schemas.openxmlformats.org/markup-compatibility/2006');
$objWriter->writeAttribute('xmlns:o', 'urn:schemas-microsoft-com:office:office');
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$objWriter->writeAttribute('xmlns:m', 'http://schemas.openxmlformats.org/officeDocument/2006/math');
$objWriter->writeAttribute('xmlns:v', 'urn:schemas-microsoft-com:vml');
$objWriter->writeAttribute('xmlns:wp', 'http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing');
$objWriter->writeAttribute('xmlns:w10', 'urn:schemas-microsoft-com:office:word');
$objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
$objWriter->writeAttribute('xmlns:wne', 'http://schemas.microsoft.com/office/word/2006/wordml');
$_elements = $header->getElements();
foreach ($_elements as $element) {
if ($element instanceof PHPWord_Section_Text) {
$this->_writeText($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_TextRun) {
$this->_writeTextRun($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_TextBreak) {
$this->_writeTextBreak($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_Table) {
$this->_writeTable($objWriter, $element);
} elseif ($element instanceof PHPWord_Section_Image ||
$element instanceof PHPWord_Section_MemoryImage
) {
if (!$element->getIsWatermark()) {
$this->_writeImage($objWriter, $element);
} else {
$this->_writeWatermark($objWriter, $element);
}
} elseif ($element instanceof PHPWord_Section_Footer_PreserveText) {
$this->_writePreserveText($objWriter, $element);
}
}
$objWriter->endElement();
// Return
return $objWriter->getData();
}
}

View File

@ -1,394 +0,0 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
/**
* Class PHPWord_Writer_Word2007_Styles
*/
class PHPWord_Writer_Word2007_Styles extends PHPWord_Writer_Word2007_Base
{
private $_document;
public function writeStyles(PHPWord $pPHPWord = null)
{
// Create XML writer
$objWriter = null;
if ($this->getParentWriter()->getUseDiskCaching()) {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_DISK, $this->getParentWriter()->getDiskCachingDirectory());
} else {
$objWriter = new PHPWord_Shared_XMLWriter(PHPWord_Shared_XMLWriter::STORAGE_MEMORY);
}
$this->_document = $pPHPWord;
// XML header
$objWriter->startDocument('1.0', 'UTF-8', 'yes');
$objWriter->startElement('w:styles');
$objWriter->writeAttribute('xmlns:r', 'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
$objWriter->writeAttribute('xmlns:w', 'http://schemas.openxmlformats.org/wordprocessingml/2006/main');
// Write DocDefaults
$this->_writeDocDefaults($objWriter);
// Write Style Definitions
$styles = PHPWord_Style::getStyles();
// Write normal paragraph style
$normalStyle = null;
if (array_key_exists('Normal', $styles)) {
$normalStyle = $styles['Normal'];
}
$objWriter->startElement('w:style');
$objWriter->writeAttribute('w:type', 'paragraph');
$objWriter->writeAttribute('w:default', '1');
$objWriter->writeAttribute('w:styleId', 'Normal');
$objWriter->startElement('w:name');
$objWriter->writeAttribute('w:val', 'Normal');
$objWriter->endElement();
if (!is_null($normalStyle)) {
$this->_writeParagraphStyle($objWriter, $normalStyle);
}
$objWriter->endElement();
// Write other styles
if (count($styles) > 0) {
foreach ($styles as $styleName => $style) {
if ($styleName == 'Normal') {
continue;
}
if ($style instanceof PHPWord_Style_Font) {
$paragraphStyle = $style->getParagraphStyle();
$styleType = $style->getStyleType();
$type = ($styleType == 'title') ? 'paragraph' : 'character';
if (!is_null($paragraphStyle)) {
$type = 'paragraph';
}
$objWriter->startElement('w:style');
$objWriter->writeAttribute('w:type', $type);
if ($styleType == 'title') {
$arrStyle = explode('_', $styleName);
$styleId = 'Heading' . $arrStyle[1];
$styleName = 'heading ' . $arrStyle[1];
$styleLink = 'Heading' . $arrStyle[1] . 'Char';
$objWriter->writeAttribute('w:styleId', $styleId);
$objWriter->startElement('w:link');
$objWriter->writeAttribute('w:val', $styleLink);
$objWriter->endElement();
}
$objWriter->startElement('w:name');
$objWriter->writeAttribute('w:val', $styleName);
$objWriter->endElement();
if (!is_null($paragraphStyle)) {
// Point parent style to Normal
$objWriter->startElement('w:basedOn');
$objWriter->writeAttribute('w:val', 'Normal');
$objWriter->endElement();
$this->_writeParagraphStyle($objWriter, $paragraphStyle);
}
$this->_writeTextStyle($objWriter, $style);
$objWriter->endElement();
} elseif ($style instanceof PHPWord_Style_Paragraph) {
$objWriter->startElement('w:style');
$objWriter->writeAttribute('w:type', 'paragraph');
$objWriter->writeAttribute('w:customStyle', '1');
$objWriter->writeAttribute('w:styleId', $styleName);
$objWriter->startElement('w:name');
$objWriter->writeAttribute('w:val', $styleName);
$objWriter->endElement();
// Parent style
$basedOn = $style->getBasedOn();
if (!is_null($basedOn)) {
$objWriter->startElement('w:basedOn');
$objWriter->writeAttribute('w:val', $basedOn);
$objWriter->endElement();
}
// Next paragraph style
$next = $style->getNext();
if (!is_null($next)) {
$objWriter->startElement('w:next');
$objWriter->writeAttribute('w:val', $next);
$objWriter->endElement();
}
$this->_writeParagraphStyle($objWriter, $style);
$objWriter->endElement();
} elseif ($style instanceof PHPWord_Style_TableFull) {
$objWriter->startElement('w:style');
$objWriter->writeAttribute('w:type', 'table');
$objWriter->writeAttribute('w:customStyle', '1');
$objWriter->writeAttribute('w:styleId', $styleName);
$objWriter->startElement('w:name');
$objWriter->writeAttribute('w:val', $styleName);
$objWriter->endElement();
$objWriter->startElement('w:uiPriority');
$objWriter->writeAttribute('w:val', '99');
$objWriter->endElement();
$this->_writeFullTableStyle($objWriter, $style);
$objWriter->endElement();
}
}
}
$objWriter->endElement(); // w:styles
// Return
return $objWriter->getData();
}
private function _writeFullTableStyle(PHPWord_Shared_XMLWriter $objWriter = null, PHPWord_Style_TableFull $style)
{
$brdSz = $style->getBorderSize();
$brdCol = $style->getBorderColor();
$bgColor = $style->getBgColor();
$cellMargin = $style->getCellMargin();
$bTop = (!is_null($brdSz[0])) ? true : false;
$bLeft = (!is_null($brdSz[1])) ? true : false;
$bRight = (!is_null($brdSz[2])) ? true : false;
$bBottom = (!is_null($brdSz[3])) ? true : false;
$bInsH = (!is_null($brdSz[4])) ? true : false;
$bInsV = (!is_null($brdSz[5])) ? true : false;
$borders = ($bTop || $bLeft || $bRight || $bBottom || $bInsH || $bInsV) ? true : false;
$mTop = (!is_null($cellMargin[0])) ? true : false;
$mLeft = (!is_null($cellMargin[1])) ? true : false;
$mRight = (!is_null($cellMargin[2])) ? true : false;
$mBottom = (!is_null($cellMargin[3])) ? true : false;
$margins = ($mTop || $mLeft || $mRight || $mBottom) ? true : false;
$objWriter->startElement('w:tblPr');
if ($margins) {
$objWriter->startElement('w:tblCellMar');
if ($mTop) {
echo $margins[0];
$objWriter->startElement('w:top');
$objWriter->writeAttribute('w:w', $cellMargin[0]);
$objWriter->writeAttribute('w:type', 'dxa');
$objWriter->endElement();
}
if ($mLeft) {
$objWriter->startElement('w:left');
$objWriter->writeAttribute('w:w', $cellMargin[1]);
$objWriter->writeAttribute('w:type', 'dxa');
$objWriter->endElement();
}
if ($mRight) {
$objWriter->startElement('w:right');
$objWriter->writeAttribute('w:w', $cellMargin[2]);
$objWriter->writeAttribute('w:type', 'dxa');
$objWriter->endElement();
}
if ($mBottom) {
$objWriter->startElement('w:bottom');
$objWriter->writeAttribute('w:w', $cellMargin[3]);
$objWriter->writeAttribute('w:type', 'dxa');
$objWriter->endElement();
}
$objWriter->endElement();
}
if ($borders) {
$objWriter->startElement('w:tblBorders');
if ($bTop) {
$objWriter->startElement('w:top');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[0]);
$objWriter->writeAttribute('w:color', $brdCol[0]);
$objWriter->endElement();
}
if ($bLeft) {
$objWriter->startElement('w:left');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[1]);
$objWriter->writeAttribute('w:color', $brdCol[1]);
$objWriter->endElement();
}
if ($bRight) {
$objWriter->startElement('w:right');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[2]);
$objWriter->writeAttribute('w:color', $brdCol[2]);
$objWriter->endElement();
}
if ($bBottom) {
$objWriter->startElement('w:bottom');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[3]);
$objWriter->writeAttribute('w:color', $brdCol[3]);
$objWriter->endElement();
}
if ($bInsH) {
$objWriter->startElement('w:insideH');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[4]);
$objWriter->writeAttribute('w:color', $brdCol[4]);
$objWriter->endElement();
}
if ($bInsV) {
$objWriter->startElement('w:insideV');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[5]);
$objWriter->writeAttribute('w:color', $brdCol[5]);
$objWriter->endElement();
}
$objWriter->endElement();
}
$objWriter->endElement();
if (!is_null($bgColor)) {
$objWriter->startElement('w:tcPr');
$objWriter->startElement('w:shd');
$objWriter->writeAttribute('w:val', 'clear');
$objWriter->writeAttribute('w:color', 'auto');
$objWriter->writeAttribute('w:fill', $bgColor);
$objWriter->endElement();
$objWriter->endElement();
}
// First Row
$firstRow = $style->getFirstRow();
if (!is_null($firstRow)) {
$this->_writeRowStyle($objWriter, 'firstRow', $firstRow);
}
}
private function _writeRowStyle(PHPWord_Shared_XMLWriter $objWriter = null, $type, PHPWord_Style_TableFull $style)
{
$brdSz = $style->getBorderSize();
$brdCol = $style->getBorderColor();
$bgColor = $style->getBgColor();
$bTop = (!is_null($brdSz[0])) ? true : false;
$bLeft = (!is_null($brdSz[1])) ? true : false;
$bRight = (!is_null($brdSz[2])) ? true : false;
$bBottom = (!is_null($brdSz[3])) ? true : false;
$borders = ($bTop || $bLeft || $bRight || $bBottom) ? true : false;
$objWriter->startElement('w:tblStylePr');
$objWriter->writeAttribute('w:type', $type);
$objWriter->startElement('w:tcPr');
if (!is_null($bgColor)) {
$objWriter->startElement('w:shd');
$objWriter->writeAttribute('w:val', 'clear');
$objWriter->writeAttribute('w:color', 'auto');
$objWriter->writeAttribute('w:fill', $bgColor);
$objWriter->endElement();
}
$objWriter->startElement('w:tcBorders');
if ($bTop) {
$objWriter->startElement('w:top');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[0]);
$objWriter->writeAttribute('w:color', $brdCol[0]);
$objWriter->endElement();
}
if ($bLeft) {
$objWriter->startElement('w:left');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[1]);
$objWriter->writeAttribute('w:color', $brdCol[1]);
$objWriter->endElement();
}
if ($bRight) {
$objWriter->startElement('w:right');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[2]);
$objWriter->writeAttribute('w:color', $brdCol[2]);
$objWriter->endElement();
}
if ($bBottom) {
$objWriter->startElement('w:bottom');
$objWriter->writeAttribute('w:val', 'single');
$objWriter->writeAttribute('w:sz', $brdSz[3]);
$objWriter->writeAttribute('w:color', $brdCol[3]);
$objWriter->endElement();
}
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
}
private function _writeDocDefaults(PHPWord_Shared_XMLWriter $objWriter = null)
{
$fontName = $this->_document->getDefaultFontName();
$fontSize = $this->_document->getDefaultFontSize();
$objWriter->startElement('w:docDefaults');
$objWriter->startElement('w:rPrDefault');
$objWriter->startElement('w:rPr');
$objWriter->startElement('w:rFonts');
$objWriter->writeAttribute('w:ascii', $fontName);
$objWriter->writeAttribute('w:hAnsi', $fontName);
$objWriter->writeAttribute('w:eastAsia', $fontName);
$objWriter->writeAttribute('w:cs', $fontName);
$objWriter->endElement();
$objWriter->startElement('w:sz');
$objWriter->writeAttribute('w:val', $fontSize * 2);
$objWriter->endElement();
$objWriter->startElement('w:szCs');
$objWriter->writeAttribute('w:val', $fontSize * 2);
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
$objWriter->endElement();
}
}

255
README.md
View File

@ -1,19 +1,15 @@
# PHPWord
# ![PHPWord](https://raw.githubusercontent.com/PHPOffice/PHPWord/develop/docs/images/phpword.svg "PHPWord")
[![Build Status](https://travis-ci.org/PHPOffice/PHPWord.png?branch=master)](https://travis-ci.org/PHPOffice/PHPWord)
[![Latest Stable Version](https://poser.pugx.org/phpoffice/phpword/v/stable.png)](https://packagist.org/packages/phpoffice/phpword) [![Total Downloads](https://poser.pugx.org/phpoffice/phpword/downloads.png)](https://packagist.org/packages/phpoffice/phpword) [![Latest Unstable Version](https://poser.pugx.org/phpoffice/phpword/v/unstable.png)](https://packagist.org/packages/phpoffice/phpword) [![License](https://poser.pugx.org/phpoffice/phpword/license.png)](https://packagist.org/packages/phpoffice/phpword)
[![Build Status](https://travis-ci.org/PHPOffice/PHPWord.svg?branch=master)](https://travis-ci.org/PHPOffice/PHPWord)
[![Latest Stable Version](https://poser.pugx.org/phpoffice/phpword/v/stable.png)](https://packagist.org/packages/phpoffice/phpword)
[![Total Downloads](https://poser.pugx.org/phpoffice/phpword/downloads.png)](https://packagist.org/packages/phpoffice/phpword)
[![Latest Unstable Version](https://poser.pugx.org/phpoffice/phpword/v/unstable.png)](https://packagist.org/packages/phpoffice/phpword)
[![License](https://poser.pugx.org/phpoffice/phpword/license.png)](https://packagist.org/packages/phpoffice/phpword)
__OpenXML - Read, Write and Create Word documents in PHP.__
PHPWord is a library written in pure PHP and providing a set of classes that allow you to write to and read from different document file formats, like Word (.docx), WordPad (.rtf), Libre/OpenOffice Writer (.odt).
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), and [Rich Text Format](http://en.wikipedia.org/wiki/Rich_Text_Format) (RTF).
No Windows operating system is needed for usage because the resulting DOCX, ODT, or RTF files can be opened by all major [word processing softwares](http://en.wikipedia.org/wiki/List_of_word_processors).
PHPWord is an open source project licensed under [LGPL](license.md). PHPWord is unit tested to make sure that the released versions are stable.
__Want to contribute?__ Fork us!
## Features
With PHPWord, you can create DOCX, ODT, or RTF documents dynamically using your PHP 5.3+ scripts. Below are some of the things that you can do with PHPWord library:
* Set document properties, e.g. title, subject, and creator.
* Create document sections with different settings, e.g. portrait/landscape, page size, and page numbering
@ -38,10 +34,10 @@ __Want to contribute?__ Fork us!
* PHP [Zip](http://php.net/manual/en/book.zip.php) extension
* PHP [XML Parser](http://www.php.net/manual/en/xml.installation.php) extension
## Optional PHP extensions
* [GD](http://php.net/manual/en/book.image.php)
* [XMLWriter](http://php.net/manual/en/book.xmlwriter.php)
* [XSL](http://php.net/manual/en/book.xsl.php)
### Optional PHP extensions
* PHP [GD](http://php.net/manual/en/book.image.php) extension
* PHP [XMLWriter](http://php.net/manual/en/book.xmlwriter.php) extension
* PHP [XSL](http://php.net/manual/en/book.xsl.php) extension
## Installation
@ -56,37 +52,19 @@ the following lines to your ``composer.json``.
}
```
## Documentation
We're reorganizing our documentation. Below are some of the most important things that you needed to get PHPWord creates document for you in no time.
### Table of contents
1. [Basic usage](#basic-usage)
* [Measurement units](#measurement-units)
2. [Sections](#sections)
* [Section settings](#section-settings)
* [Section page numbering](#section-page-numbering)
3. [Texts](#texts)
* [Attributes](#text-attributes)
4. [Paragraph Style](#paragraph-style)
* [Attributes](#paragraph-style-attributes)
5. [Tables](#tables)
* [Cell Style](#tables-cell-style)
6. [Images](#images)
* [Attributes](#images-attributes)
<a name="basic-usage"></a>
#### Basic usage
## Basic usage
The following is a basic example of the PHPWord library. More examples are provided in the [samples folder](samples/).
```php
$PHPWord = new PHPWord();
require_once 'src/PhpWord/Autoloader.php';
PhpOffice\PhpWord\Autoloader::register();
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Every element you want to append to the word document is placed in a section.
// To create a basic section:
$section = $PHPWord->createSection();
$section = $phpWord->createSection();
// After creating a section, you can append elements:
$section->addText('Hello world!');
@ -97,13 +75,13 @@ $section->addText('Hello world! I am formatted.',
// If you often need the same style again you can create a user defined style
// to the word document and give the addText function the name of the style:
$PHPWord->addFontStyle('myOwnStyle',
$phpWord->addFontStyle('myOwnStyle',
array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232'));
$section->addText('Hello world! I am formatted by a user defined style',
'myOwnStyle');
// You can also put the appended element to local object like this:
$fontStyle = new PHPWord_Style_Font();
$fontStyle = new \PhpOffice\PhpWord\Style\Font();
$fontStyle->setBold(true);
$fontStyle->setName('Verdana');
$fontStyle->setSize(22);
@ -111,191 +89,16 @@ $myTextElement = $section->addText('Hello World!');
$myTextElement->setFontStyle($fontStyle);
// Finally, write the document:
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('helloWorld.docx');
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText');
$objWriter->save('helloWorld.odt');
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'RTF');
$objWriter->save('helloWorld.rtf');
```
<a name="measurement-units"></a>
##### Measurement units
__Want to contribute?__ [Fork us](https://github.com/PHPOffice/PHPWord/fork) or [submit](https://github.com/PHPOffice/PHPWord/issues) your bug reports or feature requests to us.
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.
```php
// Paragraph with 6 points space after
$PHPWord->addParagraphStyle('My Style', array(
'spaceAfter' => PHPWord_Shared_Font::pointSizeToTwips(6))
);
$section = $PHPWord->createSection();
$sectionStyle = $section->getSettings();
// half inch left margin
$sectionStyle->setMarginLeft(PHPWord_Shared_Font::inchSizeToTwips(.5));
// 2 cm right margin
$sectionStyle->setMarginRight(PHPWord_Shared_Font::centimeterSizeToTwips(2));
```
<a name="sections"></a>
#### Sections
Every visible element in word is placed inside of a section. To create a section, use the following code:
```php
$section = $PHPWord->createSection($sectionSettings);
```
The `$sectionSettings` is an optional associative array that sets the section. Example:
```php
$sectionSettings = array(
'orientation' => 'landscape',
'marginTop' => 600,
'colsNum' => 2,
);
```
<a name="section-settings"></a>
##### Section settings
Below are the available settings for section:
* `orientation` Page orientation, i.e. 'portrait' (default) or 'landscape'
* `marginTop` Page margin top in twips
* `marginLeft` Page margin left in twips
* `marginRight` Page margin right in twips
* `marginBottom` Page margin bottom in twips
* `borderTopSize` Border top size in twips
* `borderTopColor` Border top color
* `borderLeftSize` Border left size in twips
* `borderLeftColor` Border left color
* `borderRightSize` Border right size in twips
* `borderRightColor` Border right color
* `borderBottomSize` Border bottom size in twips
* `borderBottomColor` Border bottom color
* `headerHeight` Spacing to top of header
* `footerHeight` Spacing to bottom of footer
* `colsNum` Number of columns
* `colsSpace` Spacing between columns
* `breakType` Section break type (nextPage, nextColumn, continuous, evenPage, oddPage)
The following two settings are automatically set by the use of the `orientation` setting. You can alter them but that's not recommended.
* `pageSizeW` Page width in twips
* `pageSizeH` Page height in twips
<a name="section-page-numbering"></a>
##### Section page numbering
You can change a section page numbering.
```php
$section = $PHPWord->createSection();
$section->getSettings()->setPageNumberingStart(1);
```
<a name="texts"></a>
#### Texts
Text can be added by using `addText` and `createTextRun` method. `addText` is used for creating simple paragraphs that only contain texts with the same style. `createTextRun` is used for creating complex paragraphs that contain text with different style (some bold, other italics, etc) or other elements, e.g. images or links.
`addText` sample:
```php
$fontStyle = array('name' => 'Times New Roman', 'size' => 9);
$paragraphStyle = array('align' => 'both');
$section->addText('I am simple paragraph', $fontStyle, $paragraphStyle);
```
`createTextRun` sample:
```php
$textrun = $section->createTextRun();
$textrun->addText('I am bold', array('bold' => true));
$textrun->addText('I am italic', array('italic' => true));
$textrun->addText('I am colored', array('color' => 'AACC00'));
```
<a name="text-attributes"></a>
##### Attributes
* ``size`` text size, e.g. _20_, _22_,
* ``name`` font name, e.g. _Arial_
* ``bold`` text is bold, _true_ or _false_
* ``italic`` text is italic, _true_ or _false_
* ``superScript`` text is super script, _true_ or _false_
* ``subScript`` text is sub script, _true_ or _false_
* ``underline`` text is underline, _true_ or _false_
* ``strikethrough`` text is strikethrough, _true_ or _false_
* ``color`` text color, e.g. _FF0000_
* ``fgColor`` fgColor
* ``line-height`` text line height, e.g. _1.0_, _1.5_, ect...
<a name="paragraph-style"></a>
#### Paragraph Style
<a name="paragraph-style-attributes"></a>
##### Attributes
* ``line-height`` text line height, e.g. _1.0_, _1.5_, ect...
* ``align`` paragraph alignment, _left_, _right_ or _center_
* ``spaceBefore`` space before Paragraph
* ``spaceAfter`` space after Paragraph
* ``tabs`` set of Custom Tab Stops
* ``indent`` indent by how much
<a name="tables"></a>
#### Tables
The following illustrates how to create a table.
```php
$table = $section->addTable();
$table->addRow();
$table->addCell();
```
<a name="tables-cell-style"></a>
##### Cell Style
###### Cell Span
You can span a cell on multiple columms.
```php
$cell = $table->addCell(200);
$cell->getStyle()->setGridSpan(5);
```
<a name="images"></a>
#### Images
You can add images easily using the following example.
```php
$section = $PHPWord->createSection();
$section->addImage('mars.jpg');
```
<a name="images-attributes"></a>
##### Attributes
* ``width`` width in pixels
* ``height`` height in pixels
* ``align`` image alignment, _left_, _right_ or _center_
* ``marginTop`` top margin in inches, can be negative
* ``marginLeft`` left margin in inches, can be negative
* ``wrappingStyle`` can be _inline_, _square_, _tight_, _behind_, _infront_
To add an image with attributes, consider the following example.
```php
$section->addImage(
'mars.jpg',
array(
'width' => 100,
'height' => 100,
'marginTop' => -1,
'marginLeft' => -1,
'wrappingStyle' => 'behind'
)
);
```
__Want to know more?__ Read the full documentation of PHPWord on [Read The Docs](http://phpword.readthedocs.org/en/develop/).

View File

@ -1,49 +0,0 @@
<?php
namespace PHPWord\Tests;
use PHPWord_Autoloader;
use PHPWord_Autoloader as Autoloader;
class AutoloaderTest extends \PHPUnit_Framework_TestCase
{
public function testRegister()
{
PHPWord_Autoloader::register();
$this->assertContains(array('PHPWord_Autoloader', 'load'), spl_autoload_functions());
$this->assertContains(array('PHPWord_Autoloader', 'autoload'), spl_autoload_functions());
}
public function testAutoloadLegacy()
{
$this->assertNull(
PHPWord_Autoloader::load('Foo'),
'PHPWord_Autoloader::load() is trying to load classes outside of the PHPWord namespace'
);
$this->assertTrue(
PHPWord_Autoloader::load('PHPWord'),
'PHPWord_Autoloader::load() failed to autoload the PHPWord class'
);
}
public function testAutoload()
{
$declared = get_declared_classes();
$declaredCount = count($declared);
Autoloader::autoload('Foo');
$this->assertEquals(
$declaredCount,
count(get_declared_classes()),
'PhpOffice\\PhpWord\\Autoloader::autoload() is trying to load classes ' .
'outside of the PhpOffice\\PhpWord namespace'
);
// TODO change this class to the main PHPWord class when it is namespaced
Autoloader::autoload(
'PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException'
);
$this->assertTrue(
in_array('PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException', get_declared_classes()),
'PhpOffice\\PhpWord\\Autoloader::autoload() failed to autoload the ' .
'PhpOffice\\PhpWord\\Exceptions\\InvalidStyleException class'
);
}
}

View File

@ -1,72 +0,0 @@
<?php
namespace PHPWord\Tests;
use PHPWord;
use PHPWord_IOFactory;
use PHPWord_Writer_Word2007;
use Exception;
/**
* Class IOFactoryTest
* @package PHPWord\Tests
* @runTestsInSeparateProcesses
*/
class IOFactoryTest extends \PHPUnit_Framework_TestCase
{
public function testGetSearchLocations()
{
$this->assertAttributeEquals(
PHPWord_IOFactory::getSearchLocations(),
'_searchLocations',
'PHPWord_IOFactory'
);
}
public function testSetSearchLocationsWithArray()
{
PHPWord_IOFactory::setSearchLocations(array());
$this->assertAttributeEquals(array(), '_searchLocations', 'PHPWord_IOFactory');
}
/**
* @expectedException Exception
* @expectedExceptionMessage Invalid parameter passed.
*/
public function testSetSearchLocationsWithNotArray()
{
PHPWord_IOFactory::setSearchLocations('String');
}
public function testAddSearchLocation()
{
PHPWord_IOFactory::setSearchLocations(array());
PHPWord_IOFactory::addSearchLocation('type', 'location', 'classname');
$this->assertAttributeEquals(
array(array('type' => 'type', 'path' => 'location', 'class' => 'classname')),
'_searchLocations',
'PHPWord_IOFactory'
);
}
/**
* @expectedException Exception
* @expectedExceptionMessage No IWriter found for type
*/
public function testCreateWriterException()
{
$oPHPWord = new PHPWord();
PHPWord_IOFactory::setSearchLocations(array());
PHPWord_IOFactory::createWriter($oPHPWord);
}
public function testCreateWriter()
{
$oPHPWord = new PHPWord();
$this->assertEquals(
PHPWord_IOFactory::createWriter($oPHPWord, 'Word2007'),
new PHPWord_Writer_Word2007($oPHPWord)
);
}
}

View File

@ -1,50 +0,0 @@
<?php
namespace PHPWord\Tests;
use PHPWord_Media;
use PHPWord_Section;
class MediaTest extends \PHPUnit_Framework_TestCase
{
public function testGetSectionMediaElementsWithNull()
{
$this->assertEquals(PHPWord_Media::getSectionMediaElements(), array());
}
public function testCountSectionMediaElementsWithNull()
{
$this->assertEquals(PHPWord_Media::countSectionMediaElements(), 0);
}
public function testGetHeaderMediaElements()
{
$this->assertAttributeEquals(PHPWord_Media::getHeaderMediaElements(), '_headerMedia', 'PHPWord_Media');
}
public function testGetFooterMediaElements()
{
$this->assertAttributeEquals(PHPWord_Media::getFooterMediaElements(), '_footerMedia', 'PHPWord_Media');
}
/**
* Todo: add memory image to this test
*
* @covers PHPWord_Media::addSectionMediaElement
*/
public function testAddSectionMediaElement()
{
$section = new PHPWord_Section(0);
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars_noext_jpg");
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars.jpg");
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mario.gif");
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/firefox.png");
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/duke_nukem.bmp");
$section->addImage(PHPWORD_TESTS_DIR_ROOT . "/_files/images/angela_merkel.tif");
$elements = $section->getElements();
$this->assertEquals(6, count($elements));
foreach ($elements as $element) {
$this->assertInstanceOf('PHPWord_Section_Image', $element);
}
}
}

View File

@ -1,68 +0,0 @@
<?php
namespace PHPWord\Tests\Reader;
use PHPWord_Reader_Word2007;
use PHPWord_IOFactory;
/**
* Class Word2007Test
*
* @package PHPWord\Tests
*/
class Word2007Test extends \PHPUnit_Framework_TestCase
{
/** @var Test file directory */
private $dir;
/**
* Init
*/
public function tearDown()
{
}
/**
* Test canRead() method
*/
public function testCanRead()
{
$dir = join(
DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents')
);
$object = new PHPWord_Reader_Word2007;
$file = $dir . DIRECTORY_SEPARATOR . 'reader.docx';
$this->assertTrue($object->canRead($file));
}
/**
* Test canRead() failure
*
* @expectedException Exception
*/
public function testCanReadFailed()
{
$dir = join(
DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents')
);
$object = new PHPWord_Reader_Word2007;
$file = $dir . DIRECTORY_SEPARATOR . 'foo.docx';
$this->assertFalse($object->canRead($file));
$object = PHPWord_IOFactory::load($file);
}
/**
* Test load document
*/
public function testLoad()
{
$dir = join(
DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents')
);
$file = $dir . DIRECTORY_SEPARATOR . 'reader.docx';
$object = PHPWord_IOFactory::load($file);
$this->assertInstanceOf('PHPWord', $object);
}
}

View File

@ -1,102 +0,0 @@
<?php
namespace PHPWord\Tests\Section;
use PHPWord_Section_Image;
use PHPWord_Style_Image;
class ImageTest extends \PHPUnit_Framework_TestCase
{
public function testConstruct()
{
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png')
);
$oImage = new PHPWord_Section_Image($src);
$this->assertInstanceOf('PHPWord_Section_Image', $oImage);
$this->assertEquals($oImage->getSource(), $src);
$this->assertEquals($oImage->getMediaId(), md5($src));
$this->assertEquals($oImage->getIsWatermark(), false);
$this->assertInstanceOf('PHPWord_Style_Image', $oImage->getStyle());
}
public function testConstructWithStyle()
{
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png')
);
$oImage = new PHPWord_Section_Image(
$src,
array('width' => 210, 'height' => 210, 'align' => 'center',
'wrappingStyle' => \PHPWord_Style_Image::WRAPPING_STYLE_BEHIND)
);
$this->assertInstanceOf('PHPWord_Style_Image', $oImage->getStyle());
}
/**
* @covers PHPWord_Section_Image::__construct
*/
public function testValidImageTypes()
{
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars_noext_jpg");
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars.jpg");
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/mario.gif");
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/firefox.png");
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/duke_nukem.bmp");
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/angela_merkel.tif");
}
/**
* @expectedException \PhpOffice\PhpWord\Exceptions\InvalidImageException
* @covers PHPWord_Section_Image::__construct
*/
public function testImageNotFound()
{
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/thisisnotarealimage");
}
/**
* @expectedException \PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException
* @covers PHPWord_Section_Image::__construct
*/
public function testInvalidImageTypes()
{
new PHPWord_Section_Image(PHPWORD_TESTS_DIR_ROOT . "/_files/images/alexz-johnson.pcx");
}
public function testStyle()
{
$oImage = new PHPWord_Section_Image(\join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
), array('width' => 210, 'height' => 210, 'align' => 'center'));
$this->assertInstanceOf('PHPWord_Style_Image', $oImage->getStyle());
}
public function testRelationID()
{
$oImage = new PHPWord_Section_Image(\join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
));
$iVal = rand(1, 1000);
$oImage->setRelationId($iVal);
$this->assertEquals($oImage->getRelationId(), $iVal);
}
public function testWatermark()
{
$oImage = new PHPWord_Section_Image(\join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
));
$oImage->setIsWatermark(true);
$this->assertEquals($oImage->getIsWatermark(), true);
}
}

View File

@ -1,36 +0,0 @@
<?php
namespace PHPWord\Tests\Section;
use PHPWord_Section_ListItem;
use PHPWord_Style_ListItem;
class ListItemTest extends \PHPUnit_Framework_TestCase
{
public function testText()
{
$oListItem = new PHPWord_Section_ListItem('text');
$this->assertInstanceOf('PHPWord_Section_Text', $oListItem->getTextObject());
}
public function testStyle()
{
$oListItem = new PHPWord_Section_ListItem(
'text',
1,
null,
array('listType' => PHPWord_Style_ListItem::TYPE_NUMBER)
);
$this->assertInstanceOf('PHPWord_Style_ListItem', $oListItem->getStyle());
$this->assertEquals($oListItem->getStyle()->getListType(), PHPWord_Style_ListItem::TYPE_NUMBER);
}
public function testDepth()
{
$iVal = rand(1, 1000);
$oListItem = new PHPWord_Section_ListItem('text', $iVal);
$this->assertEquals($oListItem->getDepth(), $iVal);
}
}

View File

@ -1,94 +0,0 @@
<?php
namespace PHPWord\Tests\Section;
use PHPWord_Section_MemoryImage;
class MemoryImageTest extends \PHPUnit_Framework_TestCase
{
public function testPNG()
{
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'firefox.png')
);
$oMemoryImage = new PHPWord_Section_MemoryImage($src);
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $oMemoryImage);
$this->assertEquals($oMemoryImage->getSource(), $src);
$this->assertEquals($oMemoryImage->getMediaId(), md5($src));
$this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefrompng');
$this->assertEquals($oMemoryImage->getImageFunction(), 'imagepng');
$this->assertEquals($oMemoryImage->getImageExtension(), 'png');
$this->assertEquals($oMemoryImage->getImageType(), 'image/png');
}
public function testGIF()
{
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'mario.gif')
);
$oMemoryImage = new PHPWord_Section_MemoryImage($src);
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $oMemoryImage);
$this->assertEquals($oMemoryImage->getSource(), $src);
$this->assertEquals($oMemoryImage->getMediaId(), md5($src));
$this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefromgif');
$this->assertEquals($oMemoryImage->getImageFunction(), 'imagegif');
$this->assertEquals($oMemoryImage->getImageExtension(), 'gif');
$this->assertEquals($oMemoryImage->getImageType(), 'image/gif');
}
public function testJPG()
{
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
);
$oMemoryImage = new PHPWord_Section_MemoryImage($src);
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $oMemoryImage);
$this->assertEquals($oMemoryImage->getSource(), $src);
$this->assertEquals($oMemoryImage->getMediaId(), md5($src));
$this->assertEquals($oMemoryImage->getImageCreateFunction(), 'imagecreatefromjpeg');
$this->assertEquals($oMemoryImage->getImageFunction(), 'imagejpeg');
$this->assertEquals($oMemoryImage->getImageExtension(), 'jpg');
$this->assertEquals($oMemoryImage->getImageType(), 'image/jpeg');
}
public function testBMP()
{
$oMemoryImage = new PHPWord_Section_MemoryImage(\join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'duke_nukem.bmp')
));
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $oMemoryImage);
$this->assertEquals($oMemoryImage->getImageCreateFunction(), null);
$this->assertEquals($oMemoryImage->getImageFunction(), null);
$this->assertEquals($oMemoryImage->getImageExtension(), null);
$this->assertEquals($oMemoryImage->getImageType(), 'image/x-ms-bmp');
}
public function testStyle()
{
$oMemoryImage = new PHPWord_Section_MemoryImage(\join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
), array('width' => 210, 'height' => 210, 'align' => 'center'));
$this->assertInstanceOf('PHPWord_Style_Image', $oMemoryImage->getStyle());
}
public function testRelationID()
{
$oMemoryImage = new PHPWord_Section_MemoryImage(\join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
));
$iVal = rand(1, 1000);
$oMemoryImage->setRelationId($iVal);
$this->assertEquals($oMemoryImage->getRelationId(), $iVal);
}
}

View File

@ -1,85 +0,0 @@
<?php
namespace PHPWord\Tests\Section;
use PHPWord_Section_Object;
class ObjectTest extends \PHPUnit_Framework_TestCase
{
public function testConstructWithSupportedFiles()
{
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
);
$oObject = new PHPWord_Section_Object($src);
$this->assertInstanceOf('PHPWord_Section_Object', $oObject);
$this->assertInstanceOf('PHPWord_Style_Image', $oObject->getStyle());
$this->assertEquals($oObject->getSource(), $src);
}
public function testConstructWithNotSupportedFiles()
{
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'xsl', 'passthrough.xsl')
);
$oObject = new PHPWord_Section_Object($src);
$this->assertInstanceOf('PHPWord_Section_Object', $oObject);
$this->assertEquals($oObject->getSource(), null);
$this->assertEquals($oObject->getStyle(), null);
}
public function testConstructWithSupportedFilesAndStyle()
{
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
);
$oObject = new PHPWord_Section_Object($src, array('width' => '230px'));
$this->assertInstanceOf('PHPWord_Section_Object', $oObject);
$this->assertInstanceOf('PHPWord_Style_Image', $oObject->getStyle());
$this->assertEquals($oObject->getSource(), $src);
}
public function testRelationId()
{
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
);
$oObject = new PHPWord_Section_Object($src);
$iVal = rand(1, 1000);
$oObject->setRelationId($iVal);
$this->assertEquals($oObject->getRelationId(), $iVal);
}
public function testImageRelationId()
{
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
);
$oObject = new PHPWord_Section_Object($src);
$iVal = rand(1, 1000);
$oObject->setImageRelationId($iVal);
$this->assertEquals($oObject->getImageRelationId(), $iVal);
}
public function testObjectId()
{
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
);
$oObject = new PHPWord_Section_Object($src);
$iVal = rand(1, 1000);
$oObject->setObjectId($iVal);
$this->assertEquals($oObject->getObjectId(), $iVal);
}
}

View File

@ -1,18 +0,0 @@
<?php
namespace PHPWord\Tests\Section;
use PHPWord_Section_PageBreak;
class PageBreakTest extends \PHPUnit_Framework_TestCase
{
/**
* Executed before each method of the class
*/
public function testConstruct()
{
// Section Settings
$oPageBreak = new PHPWord_Section_PageBreak();
$this->assertInstanceOf('PHPWord_Section_PageBreak', $oPageBreak);
}
}

View File

@ -1,209 +0,0 @@
<?php
namespace PHPWord\Tests\Section\Table;
use PHPWord_Section_Table_Cell;
class CellTest extends \PHPUnit_Framework_TestCase
{
public function testConstruct()
{
$iVal = rand(1, 1000);
$oCell = new PHPWord_Section_Table_Cell('section', $iVal);
$this->assertInstanceOf('PHPWord_Section_Table_Cell', $oCell);
$this->assertEquals($oCell->getWidth(), null);
}
public function testConstructWithStyleArray()
{
$iVal = rand(1, 1000);
$oCell = new PHPWord_Section_Table_Cell('section', $iVal, null, array('valign' => 'center'));
$this->assertInstanceOf('PHPWord_Style_Cell', $oCell->getStyle());
$this->assertEquals($oCell->getWidth(), null);
}
public function testConstructWithStyleString()
{
$iVal = rand(1, 1000);
$oCell = new PHPWord_Section_Table_Cell('section', $iVal, null, 'cellStyle');
$this->assertEquals($oCell->getStyle(), 'cellStyle');
}
public function testAddText()
{
$oCell = new PHPWord_Section_Table_Cell('section', 1);
$element = $oCell->addText('text');
$this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Text', $element);
}
public function testAddTextNotUTF8()
{
$oCell = new PHPWord_Section_Table_Cell('section', 1);
$element = $oCell->addText(utf8_decode('ééé'));
$this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Text', $element);
$this->assertEquals($element->getText(), 'ééé');
}
public function testAddLink()
{
$oCell = new PHPWord_Section_Table_Cell('section', 1);
$element = $oCell->addLink('http://www.google.fr', 'Nom');
$this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Link', $element);
}
public function testAddTextBreak()
{
$oCell = new PHPWord_Section_Table_Cell('section', 1);
$oCell->addTextBreak();
$this->assertCount(1, $oCell->getElements());
}
public function testAddListItem()
{
$oCell = new PHPWord_Section_Table_Cell('section', 1);
$element = $oCell->addListItem('text');
$this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_ListItem', $element);
$this->assertEquals($element->getTextObject()->getText(), 'text');
}
public function testAddListItemNotUTF8()
{
$oCell = new PHPWord_Section_Table_Cell('section', 1);
$element = $oCell->addListItem(utf8_decode('ééé'));
$this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_ListItem', $element);
$this->assertEquals($element->getTextObject()->getText(), 'ééé');
}
public function testAddImageSection()
{
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
);
$oCell = new PHPWord_Section_Table_Cell('section', 1);
$element = $oCell->addImage($src);
$this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Image', $element);
}
public function testAddImageHeader()
{
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
);
$oCell = new PHPWord_Section_Table_Cell('header', 1);
$element = $oCell->addImage($src);
$this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Image', $element);
}
public function testAddImageFooter()
{
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'earth.jpg')
);
$oCell = new PHPWord_Section_Table_Cell('footer', 1);
$element = $oCell->addImage($src);
$this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Image', $element);
}
public function testAddMemoryImageSection()
{
$oCell = new PHPWord_Section_Table_Cell('section', 1);
$element = $oCell->addMemoryImage(
'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'
);
$this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $element);
}
public function testAddMemoryImageHeader()
{
$oCell = new PHPWord_Section_Table_Cell('header', 1);
$element = $oCell->addMemoryImage(
'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'
);
$this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $element);
}
public function testAddMemoryImageFooter()
{
$oCell = new PHPWord_Section_Table_Cell('footer', 1);
$element = $oCell->addMemoryImage(
'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'
);
$this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_MemoryImage', $element);
}
public function testAddObjectXLS()
{
$src = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
);
$oCell = new PHPWord_Section_Table_Cell('section', 1);
$element = $oCell->addObject($src);
$this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Object', $element);
}
public function testAddPreserveText()
{
$oCell = new PHPWord_Section_Table_Cell('header', 1);
$element = $oCell->addPreserveText('text');
$this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element);
}
public function testAddPreserveTextNotUTF8()
{
$oCell = new PHPWord_Section_Table_Cell('header', 1);
$element = $oCell->addPreserveText(utf8_decode('ééé'));
$this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_Footer_PreserveText', $element);
$this->assertEquals($element->getText(), 'ééé');
}
public function testCreateTextRun()
{
$oCell = new PHPWord_Section_Table_Cell('section', 1);
$element = $oCell->createTextRun();
$this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PHPWord_Section_TextRun', $element);
}
public function testGetElements()
{
$oCell = new PHPWord_Section_Table_Cell('section', 1);
$this->assertInternalType('array', $oCell->getElements());
}
}

View File

@ -1,42 +0,0 @@
<?php
namespace PHPWord\Tests\Section;
use PHPWord_Section_Text;
class TextTest extends \PHPUnit_Framework_TestCase
{
public function testConstruct()
{
$oText = new PHPWord_Section_Text();
$this->assertInstanceOf('PHPWord_Section_Text', $oText);
$this->assertEquals(null, $oText->getText());
$this->assertInstanceOf('PHPWord_Style_Font', $oText->getFontStyle());
$this->assertInstanceOf('PHPWord_Style_Paragraph', $oText->getParagraphStyle());
}
public function testText()
{
$oText = new PHPWord_Section_Text('text');
$this->assertEquals($oText->getText(), 'text');
}
public function testFont()
{
$oText = new PHPWord_Section_Text('text', 'fontStyle');
$this->assertEquals($oText->getFontStyle(), 'fontStyle');
$oText->setFontStyle(array('bold' => true, 'italic' => true, 'size' => 16));
$this->assertInstanceOf('PHPWord_Style_Font', $oText->getFontStyle());
}
public function testParagraph()
{
$oText = new PHPWord_Section_Text('text', 'fontStyle', 'paragraphStyle');
$this->assertEquals($oText->getParagraphStyle(), 'paragraphStyle');
$oText->setParagraphStyle(array('align' => 'center', 'spaceAfter' => 100));
$this->assertInstanceOf('PHPWord_Style_Paragraph', $oText->getParagraphStyle());
}
}

View File

@ -1,133 +0,0 @@
<?php
namespace PHPWord\Tests;
use PHPWord_Section;
/**
* Class TOCTest
*
* @package PHPWord\Tests
* @covers PHPWord_Section
* @runTestsInSeparateProcesses
*/
class SectionTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers PHPWord_Section::getSettings
*/
public function testGetSettings()
{
$oSection = new PHPWord_Section(0);
$this->assertAttributeEquals($oSection->getSettings(), '_settings', new PHPWord_Section(0));
}
/**
* @covers PHPWord_Section::getElements
*/
public function testGetElements()
{
$oSection = new PHPWord_Section(0);
$this->assertAttributeEquals($oSection->getElements(), '_elementCollection', new PHPWord_Section(0));
}
/**
* @covers PHPWord_Section::getFooter
*/
public function testGetFooter()
{
$oSection = new PHPWord_Section(0);
$this->assertAttributeEquals($oSection->getFooter(), '_footer', new PHPWord_Section(0));
}
/**
* @covers PHPWord_Section::getHeaders
*/
public function testGetHeaders()
{
$oSection = new PHPWord_Section(0);
$this->assertAttributeEquals($oSection->getHeaders(), '_headers', new PHPWord_Section(0));
}
/**
* @covers PHPWord_Section::setSettings
*/
public function testSetSettings()
{
$expected = 'landscape';
$object = new PHPWord_Section(0);
$object->setSettings(array('orientation' => $expected));
$this->assertEquals($expected, $object->getSettings()->getOrientation());
}
/**
* @covers PHPWord_Section::addText
* @covers PHPWord_Section::addLink
* @covers PHPWord_Section::addTextBreak
* @covers PHPWord_Section::addPageBreak
* @covers PHPWord_Section::addTable
* @covers PHPWord_Section::addListItem
* @covers PHPWord_Section::addObject
* @covers PHPWord_Section::addImage
* @covers PHPWord_Section::addMemoryImage
* @covers PHPWord_Section::addTOC
* @covers PHPWord_Section::addTitle
* @covers PHPWord_Section::createTextRun
* @covers PHPWord_Section::createFootnote
*/
public function testAddElements()
{
$objectSource = join(
DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
);
$imageSource = join(
DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'PHPWord.png')
);
$imageUrl = 'http://php.net//images/logos/php-med-trans-light.gif';
$section = new PHPWord_Section(0);
$section->addText(utf8_decode('ä'));
$section->addLink(utf8_decode('http://äää.com'), utf8_decode('ä'));
$section->addTextBreak();
$section->addPageBreak();
$section->addTable();
$section->addListItem(utf8_decode('ä'));
$section->addObject($objectSource);
$section->addImage($imageSource);
$section->addMemoryImage($imageUrl);
$section->addTOC();
$section->addTitle(utf8_decode('ä'), 1);
$section->createTextRun();
$section->createFootnote();
$elementCollection = $section->getElements();
$elementType = 'Link';
$objectType = "PHPWord_Section_{$elementType}";
$this->assertInstanceOf($objectType, $elementCollection[1]);
// $elementTypes = array('Text', 'Link', 'TextBreak', 'PageBreak',
// 'Table', 'ListItem', 'Object', 'Image', 'MemoryImage', 'TOC',
// 'Title', 'TextRun');
// $i = 0;
// foreach ($elementTypes as $elementType) {
// $objectType = "PHPWord_Section_{$elementType}";
// $this->assertInstanceOf($objectType, $elementCollection[$i]);
// $i++;
// }
}
/**
* @covers PHPWord_Section::createHeader
* @covers PHPWord_Section::createFooter
*/
public function testCreateHeaderFooter()
{
$object = new PHPWord_Section(0);
$elements = array('Header', 'Footer');
foreach ($elements as $element) {
$objectType = "PHPWord_Section_{$element}";
$method = "create{$element}";
$this->assertInstanceOf($objectType, $object->$method());
}
}
}

View File

@ -1,26 +0,0 @@
<?php
namespace PHPWord\Tests;
use PHPWord_Settings;
/**
* Class TOCTest
*
* @package PHPWord\Tests
* @covers PHPWord_Settings
* @runTestsInSeparateProcesses
*/
class SettingsTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers PHPWord_Settings::setCompatibility
* @covers PHPWord_Settings::getCompatibility
*/
public function testGetSetCompatibility()
{
$this->assertTrue(PHPWord_Settings::getCompatibility());
$this->assertTrue(PHPWord_Settings::setCompatibility(false));
$this->assertFalse(PHPWord_Settings::getCompatibility());
$this->assertFalse(PHPWord_Settings::setCompatibility('Non boolean'));
}
}

View File

@ -1,92 +0,0 @@
<?php
namespace PHPWord\Tests\Shared;
use PHPWord_Shared_File;
/**
* Class FileTest
*
* @package PHPWord\Tests
* @coversDefaultClass PHPWord_Shared_File
* @runTestsInSeparateProcesses
*/
class FileTest extends \PHPUnit_Framework_TestCase
{
/**
* Test file_exists()
*/
public function testFileExists()
{
$dir = join(DIRECTORY_SEPARATOR, array(
PHPWORD_TESTS_DIR_ROOT,
'_files',
'templates'
));
chdir($dir);
$this->assertTrue(PHPWord_Shared_File::file_exists('blank.docx'));
}
/**
* Test file_exists()
*/
public function testNoFileExists()
{
$dir = join(DIRECTORY_SEPARATOR, array(
PHPWORD_TESTS_DIR_ROOT,
'_files',
'templates'
));
chdir($dir);
$this->assertFalse(PHPWord_Shared_File::file_exists('404.docx'));
}
/**
* Test realpath()
*/
public function testRealpath()
{
$dir = join(DIRECTORY_SEPARATOR, array(
PHPWORD_TESTS_DIR_ROOT,
'_files',
'templates'
));
chdir($dir);
$file = 'blank.docx';
$expected = $dir . DIRECTORY_SEPARATOR . $file;
$this->assertEquals($expected, PHPWord_Shared_File::realpath($file));
}
/**
* @covers PHPWord_Shared_File::imagetype
* @covers PHPWord_Shared_File::fallbackImagetype
*/
public function testImagetype()
{
$filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars_noext_jpg";
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_JPEG, PHPWord_Shared_File::imagetype($filename, true));
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_JPEG, PHPWord_Shared_File::imagetype($filename));
$filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/mars.jpg";
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_JPEG, PHPWord_Shared_File::imagetype($filename, true));
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_JPEG, PHPWord_Shared_File::imagetype($filename));
$filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/mario.gif";
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_GIF, PHPWord_Shared_File::imagetype($filename, true));
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_GIF, PHPWord_Shared_File::imagetype($filename));
$filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/firefox.png";
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_PNG, PHPWord_Shared_File::imagetype($filename, true));
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_PNG, PHPWord_Shared_File::imagetype($filename));
$filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/duke_nukem.bmp";
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_BMP, PHPWord_Shared_File::imagetype($filename, true));
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_BMP, PHPWord_Shared_File::imagetype($filename));
$filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/angela_merkel.tif";
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_TIFF, PHPWord_Shared_File::imagetype($filename, true));
$this->assertEquals(PHPWord_Shared_File::IMAGETYPE_TIFF, PHPWord_Shared_File::imagetype($filename));
$filename = PHPWORD_TESTS_DIR_ROOT . "/_files/images/alexz-johnson.pcx";
$this->assertFalse(PHPWord_Shared_File::imagetype($filename, true));
$this->assertFalse(PHPWord_Shared_File::imagetype($filename));
}
}

View File

@ -1,33 +0,0 @@
<?php
namespace PHPWord\Tests\Shared;
use PHPWord_Shared_String;
/**
* Class StringTest
*
* @package PHPWord\Tests
* @coversDefaultClass PHPWord_Shared_String
* @runTestsInSeparateProcesses
*/
class StringTest extends \PHPUnit_Framework_TestCase
{
public function testIsUTF8()
{
$this->assertTrue(PHPWord_Shared_String::IsUTF8(''));
$this->assertTrue(PHPWord_Shared_String::IsUTF8('éééé'));
$this->assertFalse(PHPWord_Shared_String::IsUTF8(utf8_decode('éééé')));
}
public function testControlCharacterOOXML2PHP()
{
$this->assertEquals('', PHPWord_Shared_String::ControlCharacterOOXML2PHP(''));
$this->assertEquals(chr(0x08), PHPWord_Shared_String::ControlCharacterOOXML2PHP('_x0008_'));
}
public function testControlCharacterPHP2OOXML()
{
$this->assertEquals('', PHPWord_Shared_String::ControlCharacterPHP2OOXML(''));
$this->assertEquals('_x0008_', PHPWord_Shared_String::ControlCharacterPHP2OOXML(chr(0x08)));
}
}

View File

@ -1,51 +0,0 @@
<?php
namespace PHPWord\Tests\Style;
use PHPWord_Style_Table;
/**
* Class TableTest
*
* @package PHPWord\Tests
* @runTestsInSeparateProcesses
*/
class TableTest extends \PHPUnit_Framework_TestCase
{
/**
* Test set style value
*/
public function testSetStyleValue()
{
$object = new PHPWord_Style_Table();
$parts = array('Top', 'Left', 'Right', 'Bottom');
$value = 240; // In twips
foreach ($parts as $part) {
$property = "_cellMargin{$part}";
$get = "getCellMargin{$part}";
$object->setStyleValue($property, $value);
$this->assertEquals($value, $object->$get());
}
}
/**
* Test cell margin
*/
public function testCellMargin()
{
$object = new PHPWord_Style_Table();
$parts = array('Top', 'Left', 'Right', 'Bottom');
// Set cell margin and test if each part has the same margin
// While looping, push values array to be asserted with getCellMargin
$value = 240; // In twips
foreach ($parts as $part) {
$set = "setCellMargin{$part}";
$get = "getCellMargin{$part}";
$values[] = $value;
$object->$set($value);
$this->assertEquals($value, $object->$get());
}
$this->assertEquals($values, $object->getCellMargin());
}
}

View File

@ -1,44 +0,0 @@
<?php
namespace PHPWord\Tests;
use PHPWord_Style;
/**
* Class StyleTest
*
* @package PHPWord\Tests
* @covers PHPWord_Style
* @runTestsInSeparateProcesses
*/
class StyleTest extends \PHPUnit_Framework_TestCase
{
/**
* @covers PHPWord_Style::addParagraphStyle
* @covers PHPWord_Style::addFontStyle
* @covers PHPWord_Style::addLinkStyle
* @covers PHPWord_Style::addTitleStyle
*/
public function testStyles()
{
$paragraph = array('align' => 'center');
$font = array('italic' => true);
$table = array('bgColor' => 'CCCCCC');
$styles = array('Paragraph' => 'Paragraph', 'Font' => 'Font',
'Link' => 'Font', 'Table' => 'TableFull',
'Heading_1' => 'Font', 'Normal' => 'Paragraph');
$elementCount = 6;
PHPWord_Style::addParagraphStyle('Paragraph', $paragraph);
PHPWord_Style::addFontStyle('Font', $font);
PHPWord_Style::addLinkStyle('Link', $font);
PHPWord_Style::addTableStyle('Table', $table);
PHPWord_Style::addTitleStyle(1, $font);
PHPWord_Style::setDefaultParagraphStyle($paragraph);
$this->assertEquals($elementCount, count(PHPWord_Style::getStyles()));
foreach ($styles as $name => $style) {
$expected = "PHPWord_Style_{$style}";
$this->assertInstanceOf($expected, PHPWord_Style::getStyle($name));
}
$this->assertNull(PHPWord_Style::getStyle('Unknown'));
}
}

View File

@ -1,154 +0,0 @@
<?php
namespace PHPWord\Tests\Writer;
use PHPWord_Writer_ODText;
use PHPWord;
/**
* Class ODTextTest
*
* @package PHPWord\Tests
* @coversDefaultClass PHPWord_Writer_ODText
* @runTestsInSeparateProcesses
*/
class ODTextTest extends \PHPUnit_Framework_TestCase
{
/**
* Test construct
*/
public function testConstruct()
{
$object = new PHPWord_Writer_ODText(new PHPWord());
$this->assertInstanceOf('PHPWord', $object->getPHPWord());
$this->assertInstanceOf("PHPWord_HashTable", $object->getDrawingHashTable());
$this->assertEquals('./', $object->getDiskCachingDirectory());
$writerParts = array('Content', 'Manifest', 'Meta', 'Mimetype', 'Styles');
foreach ($writerParts as $part) {
$this->assertInstanceOf(
"PHPWord_Writer_ODText_{$part}",
$object->getWriterPart($part)
);
$this->assertInstanceOf(
"PHPWord_Writer_ODText",
$object->getWriterPart($part)->getParentWriter()
);
}
}
/**
* @covers ::getPHPWord
* @expectedException Exception
* @expectedExceptionMessage No PHPWord assigned.
*/
public function testConstructWithNull()
{
$object = new PHPWord_Writer_ODText();
$object->getPHPWord();
}
/**
* @covers ::save
*/
public function testSave()
{
$imageSrc = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'PHPWord.png')
);
$objectSrc = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
);
$file = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.odt')
);
$phpWord = new PHPWord();
$phpWord->addFontStyle('Font', array('size' => 11));
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
$section = $phpWord->createSection();
$section->addText('Test 1', 'Font');
$section->addTextBreak();
$section->addText('Test 2', null, 'Paragraph');
$section->addLink('http://test.com');
$section->addTitle('Test', 1);
$section->addPageBreak();
$section->addTable();
$section->addListItem('Test');
$section->addImage($imageSrc);
$section->addObject($objectSrc);
$section->addTOC();
$section = $phpWord->createSection();
$textrun = $section->createTextRun();
$textrun->addText('Test 3');
$writer = new PHPWord_Writer_ODText($phpWord);
$writer->save($file);
$this->assertTrue(file_exists($file));
unlink($file);
}
/**
* @covers ::save
* @todo Haven't got any method to test this
*/
public function testSavePhpOutput()
{
$phpWord = new PHPWord();
$section = $phpWord->createSection();
$section->addText('Test');
$writer = new PHPWord_Writer_ODText($phpWord);
$writer->save('php://output');
}
/**
* @covers ::save
* @expectedException Exception
* @expectedExceptionMessage PHPWord object unassigned.
*/
public function testSaveException()
{
$writer = new PHPWord_Writer_ODText();
$writer->save();
}
/**
* @covers ::getWriterPart
*/
public function testGetWriterPartNull()
{
$object = new PHPWord_Writer_ODText();
$this->assertNull($object->getWriterPart('foo'));
}
/**
* @covers ::setUseDiskCaching
* @covers ::getUseDiskCaching
*/
public function testSetGetUseDiskCaching()
{
$object = new PHPWord_Writer_ODText();
$object->setUseDiskCaching(true, PHPWORD_TESTS_DIR_ROOT);
$this->assertTrue($object->getUseDiskCaching());
$this->assertEquals(PHPWORD_TESTS_DIR_ROOT, $object->getDiskCachingDirectory());
}
/**
* @covers ::setUseDiskCaching
* @expectedException Exception
*/
public function testSetUseDiskCachingException()
{
$dir = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, 'foo')
);
$object = new PHPWord_Writer_ODText($phpWord);
$object->setUseDiskCaching(true, $dir);
}
}

View File

@ -1,107 +0,0 @@
<?php
namespace PHPWord\Tests\Writer;
use PHPWord_Writer_RTF;
use PHPWord;
/**
* Class RTFTest
*
* @package PHPWord\Tests
* @coversDefaultClass PHPWord_Writer_RTF
* @runTestsInSeparateProcesses
*/
class RTFTest extends \PHPUnit_Framework_TestCase
{
/**
* covers ::construct
*/
public function testConstruct()
{
$object = new PHPWord_Writer_RTF(new PHPWord);
$this->assertInstanceOf('PHPWord', $object->getPHPWord());
$this->assertInstanceOf("PHPWord_HashTable", $object->getDrawingHashTable());
}
/**
* covers ::__construct
* @expectedException Exception
* @expectedExceptionMessage No PHPWord assigned.
*/
public function testConstructWithNull()
{
$object = new PHPWord_Writer_RTF();
$object->getPHPWord();
}
/**
* @covers ::save
* @todo Haven't got any method to test this
*/
public function testSavePhpOutput()
{
$phpWord = new PHPWord();
$section = $phpWord->createSection();
$section->addText('Test');
$writer = new PHPWord_Writer_RTF($phpWord);
$writer->save('php://output');
}
/**
* @covers ::save
* @expectedException Exception
* @expectedExceptionMessage PHPWord object unassigned.
*/
public function testSaveException()
{
$writer = new PHPWord_Writer_RTF();
$writer->save();
}
/**
* @covers ::save
* @covers ::<private>
*/
public function testSave()
{
$imageSrc = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'images', 'PHPWord.png')
);
$objectSrc = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'documents', 'sheet.xls')
);
$file = \join(
\DIRECTORY_SEPARATOR,
array(\PHPWORD_TESTS_DIR_ROOT, '_files', 'temp.rtf')
);
$phpWord = new PHPWord();
$phpWord->addFontStyle('Font', array('size' => 11));
$phpWord->addParagraphStyle('Paragraph', array('align' => 'center'));
$section = $phpWord->createSection();
$section->addText('Test 1', 'Font');
$section->addTextBreak();
$section->addText('Test 2', null, 'Paragraph');
$section->addLink('http://test.com');
$section->addTitle('Test', 1);
$section->addPageBreak();
$section->addTable();
$section->addListItem('Test');
$section->addImage($imageSrc);
$section->addObject($objectSrc);
$section->addTOC();
$section = $phpWord->createSection();
$textrun = $section->createTextRun();
$textrun->addText('Test 3');
$textrun->addTextBreak();
$writer = new PHPWord_Writer_RTF($phpWord);
$writer->save($file);
$this->assertTrue(file_exists($file));
unlink($file);
}
}

View File

@ -1,186 +0,0 @@
<?php
namespace PHPWord\Tests;
use PHPWord;
use PHPWord_DocumentProperties;
use PHPWord_Section;
use PHPWord_Style;
/**
* Class PHPWordTest
*
* @package PHPWord\Tests
* @covers PHPWord
* @runTestsInSeparateProcesses
*/
class PHPWordTest extends \PHPUnit_Framework_TestCase
{
/**
* @var PHPWord
*/
protected $object;
/**
* @covers PHPWord::__construct
* @covers PHPWord::getProperties
* @covers PHPWord::getDefaultFontName
* @covers PHPWord::getDefaultFontSize
*/
public function testConstruct()
{
$object = new PHPWord();
$this->assertEquals(
new PHPWord_DocumentProperties(),
$object->getProperties()
);
$this->assertEquals(
PHPWord::DEFAULT_FONT_NAME,
$object->getDefaultFontName()
);
$this->assertEquals(
PHPWord::DEFAULT_FONT_SIZE,
$object->getDefaultFontSize()
);
}
/**
* @covers PHPWord::setProperties
* @covers PHPWord::getProperties
*/
public function testSetGetProperties()
{
$object = new PHPWord();
$creator = 'PHPWord';
$properties = $object->getProperties();
$properties->setCreator($creator);
$object->setProperties($properties);
$this->assertEquals($creator, $object->getProperties()->getCreator());
}
/**
* @covers PHPWord::createSection
* @covers PHPWord::getSections
*/
public function testCreateGetSections()
{
$object = new PHPWord();
$this->assertEquals(new PHPWord_Section(1), $object->createSection());
$object->createSection();
$this->assertEquals(2, count($object->getSections()));
}
/**
* @covers PHPWord::setDefaultFontName
* @covers PHPWord::getDefaultFontName
*/
public function testSetGetDefaultFontName()
{
$object = new PHPWord();
$fontName = 'Times New Roman';
$this->assertEquals(
PHPWord::DEFAULT_FONT_NAME,
$object->getDefaultFontName()
);
$object->setDefaultFontName($fontName);
$this->assertEquals($fontName, $object->getDefaultFontName());
}
/**
* @covers PHPWord::setDefaultFontSize
* @covers PHPWord::getDefaultFontSize
*/
public function testSetGetDefaultFontSize()
{
$object = new PHPWord();
$fontSize = 16;
$this->assertEquals(
PHPWord::DEFAULT_FONT_SIZE,
$object->getDefaultFontSize()
);
$object->setDefaultFontSize($fontSize);
$this->assertEquals($fontSize, $object->getDefaultFontSize());
}
/**
* @covers PHPWord::setDefaultParagraphStyle
* @covers PHPWord::loadTemplate
*/
public function testSetDefaultParagraphStyle()
{
$object = new PHPWord();
$object->setDefaultParagraphStyle(array());
$this->assertInstanceOf(
'PHPWord_Style_Paragraph',
PHPWord_Style::getStyle('Normal')
);
}
/**
* @covers PHPWord::addParagraphStyle
* @covers PHPWord::addFontStyle
* @covers PHPWord::addTableStyle
* @covers PHPWord::addLinkStyle
*/
public function testAddStyles()
{
$object = new PHPWord();
$styles = array('Paragraph' => 'Paragraph', 'Font' => 'Font',
'Table' => 'TableFull', 'Link' => 'Font');
foreach ($styles as $key => $value) {
$method = "add{$key}Style";
$styleId = "{$key} Style";
$styleType = "PHPWord_Style_{$value}";
$object->$method($styleId, array());
$this->assertInstanceOf(
$styleType,
PHPWord_Style::getStyle($styleId)
);
}
}
/**
* @covers PHPWord::addTitleStyle
*/
public function testAddTitleStyle()
{
$object = new PHPWord();
$titleLevel = 1;
$titleName = "Heading_{$titleLevel}";
$object->addTitleStyle($titleLevel, array());
$this->assertInstanceOf(
'PHPWord_Style_Font',
PHPWord_Style::getStyle($titleName)
);
}
/**
* @covers PHPWord::loadTemplate
*/
public function testLoadTemplate()
{
$file = join(
DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'blank.docx')
);
$object = new PHPWord();
$this->assertInstanceOf(
'PHPWord_Template',
$object->loadTemplate($file)
);
}
/**
* @covers PHPWord::loadTemplate
* @expectedException PHPWord_Exception
*/
public function testLoadTemplateException()
{
$file = join(
DIRECTORY_SEPARATOR,
array(PHPWORD_TESTS_DIR_ROOT, '_files', 'templates', 'blanks.docx')
);
$object = new PHPWord();
$object->loadTemplate($file);
}
}

View File

@ -1,73 +0,0 @@
<?php
namespace PHPWord\Tests;
use PHPWord;
class TestHelperDOCX
{
/**
* @var string
*/
protected static $file;
/**
* @param \PHPWord $PHPWord
* @param string $writer
* @return \PHPWord\Tests\XmlDocument
*/
public static function getDocument(PHPWord $PHPWord, $writer = 'Word2007')
{
self::$file = tempnam(sys_get_temp_dir(), 'PHPWord');
if (!is_dir(sys_get_temp_dir() . '/PHPWord_Unit_Test/')) {
mkdir(sys_get_temp_dir() . '/PHPWord_Unit_Test/');
}
$objWriter = \PHPWord_IOFactory::createWriter($PHPWord, $writer);
$objWriter->save(self::$file);
$zip = new \ZipArchive;
$res = $zip->open(self::$file);
if ($res === true) {
$zip->extractTo(sys_get_temp_dir() . '/PHPWord_Unit_Test/');
$zip->close();
}
return new XmlDocument(sys_get_temp_dir() . '/PHPWord_Unit_Test/');
}
public static function clear()
{
if (file_exists(self::$file)) {
unlink(self::$file);
}
if (is_dir(sys_get_temp_dir() . '/PHPWord_Unit_Test/')) {
self::deleteDir(sys_get_temp_dir() . '/PHPWord_Unit_Test/');
}
}
/**
* @param string $dir
*/
public static function deleteDir($dir)
{
foreach (scandir($dir) as $file) {
if ($file === '.' || $file === '..') {
continue;
} elseif (is_file($dir . "/" . $file)) {
unlink($dir . "/" . $file);
} elseif (is_dir($dir . "/" . $file)) {
self::deleteDir($dir . "/" . $file);
}
}
rmdir($dir);
}
/**
* @return string
*/
public static function getFile()
{
return self::$file;
}
}

View File

@ -1,15 +0,0 @@
<?php
date_default_timezone_set('UTC');
// Constantes
if (!defined('PHPWORD_TESTS_DIR_ROOT')) {
define('PHPWORD_TESTS_DIR_ROOT', __DIR__);
}
// Includes
require_once __DIR__ . '/../Classes/PHPWord/Autoloader.php';
PHPWord_Autoloader::Register();
require_once __DIR__ . '/_inc/TestHelperDOCX.php';
require_once __DIR__ . '/_inc/XmlDocument.php';

View File

@ -1,83 +0,0 @@
**************************************************************************************
* PHPWord
*
* Copyright (c) 2011 - 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @copyright Copyright (c) 2011 - 2014 PHPWord (https://github.com/PHPOffice/PHPWord/)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE##
**************************************************************************************
Changes in branch for release 0.8.1 :
- Feature: (bskrtich, gabrielbull) - Added fallback for computers that do not have exif_imagetype
Changes in branch for release 0.8.0 :
- Bugfix: (gabrielbull) - Fixed bug with cell styling
- Bugfix: (gabrielbull) - Fixed bug list items inside of cells
- Bugfix: (SiebelsTim) GH-51 - Adding a value that contains "&" in a template breaks it
- Bugfix: (Progi1984) GH-89 - Example in README.md is broken
- Feature: (RomanSyroeshko) GH-56 GH-57 - Template : Permit to save a template generated as a file (PHPWord_Template::saveAs())
- Feature: (gabrielbull) - Word2007 : Support sections page numbering
- Feature: (gabrielbull) - Word2007 : Added line height methods to mirror the line height settings in Word in the paragraph styling
- Feature: (JillElaine) GH-5 - Word2007 : Added support for page header & page footer height
- Feature: (bskrtich) GH-6 GH-66 GH-84 - General : Add ability to manage line breaks after image insertion
- Feature: (RomanSyroeshko) GH-52 GH-53 GH-85 - Template : Ability to limit number of replacements performed by setValue() method of Template class
- Feature: (ivanlanin) GH-48 GH-86 - Table row: Repeat as header row & allow row to break across pages
- Feature: (ivanlanin) GH-48 GH-86 - Table: Table width in percentage
- Feature: (ivanlanin) GH-48 GH-86 - Font: Superscript and subscript
- Feature: (ivanlanin) GH-48 GH-86 - Paragraph: Hanging paragraph
- Feature: (ivanlanin) GH-48 GH-86 - Section: Multicolumn and section break
- Feature: (RomanSyroeshko) GH-46 GH-47 GH-83 - Template : Ability to apply XSL style sheet to Template
- Feature: (ivanlanin) GH-87 - General: PHPWord_Shared_Font::pointSizeToTwips() converter
- Feature: (ivanlanin) GH-87 - Paragraph: Ability to define normal paragraph style with PHPWord::setNormalStyle()
- Feature: (ivanlanin) GH-87 - Paragraph: Ability to define parent style (basedOn) and style for following paragraph (next)
- Feature: (jeroenmoors) GH-44 GH-88 - Clone table rows on the fly when using a template document
- Feature: (deds) GH-16 - Initial addition of basic footnote support
- Feature: (ivanlanin) GH-92 - Paragraph: Ability to define paragraph pagination: widow control, keep next, keep lines, and page break before
- General: (ivanlanin) GH-93 - General: PHPWord_Style_Font refactoring
- General: (ivanlanin) GH-93 - Font: Use points instead of halfpoints internally. Conversion to halfpoints done during XML Writing.
- Bugfix: (ivanlanin) GH-94 - General: PHPWord_Shared_Drawing::centimetersToPixels() conversion
- Feature: (ivanlanin) GH-92 - Paragraph: setTabs() function
- Feature: (ivanlanin) GH-99 - General: Basic support for TextRun on ODT and RTF
- Feature: (ivanlanin) GH-104 - Reader: Basic Reader for Word2007
- Feature: (bskrtich ) GH-109 - TextRun: Allow Text Break in Text Run
- Feature: (jhfangying) GH-111 GH-118 - General: Support for East Asian fontstyle
- Feature: (gabrielbull) GH-114 - Image: Use exif_imagetype to check image format instead of extension name
- Feature: (bskrtich ) GH-103 - General: Setting for XMLWriter Compatibility option
- Feature: (ivanlanin) GH-122 - MemoryImage: Allow remote image when allow_url_open = on
- Bugfix: (ivanlanin) GH-125 - Footnote: Corrupt DOCX reported by MS Word when sections > 1 and not every sections have footnote
- Feature: (ivanlanin) GH-18 - TextBreak: Allow font and paragraph style for text break
- QA: (Progi1984) - UnitTests
Changes in branch for release 0.7.0 :
- Bugfix: (RomanSyroeshko) GH-32 - "Warning: Invalid error type specified in ...\PHPWord.php on line 226" is thrown when the specified template file is not found
- Bugfix: (RomanSyroeshko) GH-34 - PHPWord_Shared_String.IsUTF8 returns FALSE for Cyrillic UTF-8 input
- Bugfix: (RomanSyroeshko) GH-38 - Temporary files naming logic in PHPWord_Template can lead to a collision
- Feature: (Progi1984) GH-1 - Implement RTF Writer
- Feature: (Progi1984) GH-2 - Implement ODT Writer
- Feature: (kaystrobach) - Word2007 : Add rowspan and colspan to cells
- Feature: (RLovelett) - Word2007 : Support for tab stops
- Feature: (RLovelett) - Word2007 : Support Multiple headers
- Feature: (gabrielbull) - Word2007 : Wrapping Styles to Images
- General: (MarkBaker) - Add superscript/subscript styling in Excel2007 Writer
- General: (deds) - add indentation support to paragraphs
- General: (Progi1984) GH-27 - Support for Composer
- General: (Progi1984) - Basic CI with Travis
- General: (Progi1984) - Added PHPWord_Exception and exception when could not copy the template
- General: (Progi1984) - IMPROVED : Moved examples out of Classes directory
- General: (Esmeraldo) CP-49 - IMPROVED : Advanced string replace in setValue for Template
- Feature: (gabrielbull) - Added support for image wrapping style

View File

@ -1,10 +1,14 @@
{
"name": "phpoffice/phpword",
"description": "PHPWord - Read, Create and Write Word documents in PHP",
"keywords": ["PHP", "Word", "Writer", "docx", "doc", "rtf"],
"description": "PHPWord - Read, Create, and Write DOCX, ODT, and RTF documents in PHP",
"keywords": [
"PHP", "PhpOffice", "office", "PhpWord", "word", "template", "reader", "writer",
"docx", "OOXML", "OpenXML", "Office Open XML", "ISO IEC 29500", "WordprocessingML",
"RTF", "Rich Text Format", "doc", "odt", "OpenDocument"
],
"homepage": "http://phpoffice.github.io",
"type": "library",
"license": "LGPL",
"license": "LGPL-3.0+",
"authors": [
{
"name": "Mark Baker"
@ -17,26 +21,28 @@
{
"name": "Franck Lefevre",
"homepage": "http://blog.rootslabs.net"
},
{
"name": "Ivan Lanin",
"homepage": "http://ivan.lanin.org"
}
],
"require": {
"php": ">=5.3.0",
"php": ">=5.3.3",
"ext-xml": "*",
"ext-zip": "*"
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
},
"recommend": {
"ext-gd2": "*"
},
"suggest": {
"ext-gd2": "*",
"ext-xmlwriter": "*",
"ext-xsl": "*"
},
"autoload": {
"psr-0": {
"PHPWord": "Classes/"
"psr-4": {
"PhpOffice\\PhpWord\\": "src/"
}
}
}

153
docs/Makefile Normal file
View File

@ -0,0 +1,153 @@
# Makefile for Sphinx documentation
#
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = _build
# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
# the i18n builder cannot share the environment and doctrees with the others
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " singlehtml to make a single large HTML file"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " devhelp to make HTML files and a Devhelp project"
@echo " epub to make an epub"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " text to make text files"
@echo " man to make manual pages"
@echo " texinfo to make Texinfo files"
@echo " info to make Texinfo files and run them through makeinfo"
@echo " gettext to make PO message catalogs"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
clean:
-rm -rf $(BUILDDIR)/*
html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
singlehtml:
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."
json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."
htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."
qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/PhpWord.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/PhpWord.qhc"
devhelp:
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo
@echo "Build finished."
@echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/PhpWord"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/PhpWord"
@echo "# devhelp"
epub:
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make' in that directory to run these through (pdf)latex" \
"(use \`make latexpdf' here to do that automatically)."
latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
text:
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
@echo
@echo "Build finished. The text files are in $(BUILDDIR)/text."
man:
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
@echo
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
texinfo:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
@echo "Run \`make' in that directory to run these through makeinfo" \
"(use \`make info' here to do that automatically)."
info:
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo "Running Texinfo files through makeinfo..."
make -C $(BUILDDIR)/texinfo info
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
gettext:
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
@echo
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."
linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."
doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."

290
docs/conf.py Normal file
View File

@ -0,0 +1,290 @@
# -*- coding: utf-8 -*-
#
# PhpWord documentation build configuration file, created by
# sphinx-quickstart on Fri Mar 14 23:09:26 2014.
#
# This file is execfile()d with the current directory set to its containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.
import sys, os
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
# -- General configuration -----------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = []
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8-sig'
# The master toctree document.
master_doc = 'index'
# General information about the project.
project = u'PhpWord'
copyright = u'2014, Progi1984'
# 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.9.0'
# The full version, including alpha/beta/rc tags.
release = version
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#language = None
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
#today = ''
# Else, today_fmt is used as the format for a strftime call.
#today_fmt = '%B %d, %Y'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
exclude_patterns = ['_build']
# The reST default role (used for this markup: `text`) to use for all documents.
#default_role = None
# If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True
# If true, the current module name will be prepended to all description
# unit titles (such as .. function::).
#add_module_names = True
# If true, sectionauthor and moduleauthor directives will be shown in the
# output. They are ignored by default.
#show_authors = False
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
# A list of ignored prefixes for module index sorting.
#modindex_common_prefix = []
# -- Options for HTML output ---------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'default'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#html_theme_options = {}
# Add any paths that contain custom themes here, relative to this directory.
#html_theme_path = []
# The name for this set of Sphinx documents. If None, it defaults to
# "<project> v<release> documentation".
#html_title = None
# A shorter title for the navigation bar. Default is the same as html_title.
#html_short_title = None
# The name of an image file (relative to this directory) to place at the top
# of the sidebar.
#html_logo = None
# The name of an image file (within the static path) to use as favicon of the
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
#html_favicon = None
# 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']
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
# using the given strftime format.
#html_last_updated_fmt = '%b %d, %Y'
# If true, SmartyPants will be used to convert quotes and dashes to
# typographically correct entities.
#html_use_smartypants = True
# Custom sidebar templates, maps document names to template names.
#html_sidebars = {}
# Additional templates that should be rendered to pages, maps page names to
# template names.
#html_additional_pages = {}
# If false, no module index is generated.
#html_domain_indices = True
# If false, no index is generated.
#html_use_index = True
# If true, the index is split into individual pages for each letter.
#html_split_index = False
# If true, links to the reST sources are added to the pages.
#html_show_sourcelink = True
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
#html_show_sphinx = True
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
#html_show_copyright = True
# If true, an OpenSearch description file will be output, and all pages will
# contain a <link> tag referring to it. The value of this option must be the
# base URL from which the finished HTML is served.
#html_use_opensearch = ''
# This is the file name suffix for HTML files (e.g. ".xhtml").
#html_file_suffix = None
# Output file base name for HTML help builder.
htmlhelp_basename = 'PhpWorddoc'
# -- Options for LaTeX output --------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'PhpWord.tex', u'PhpWord Documentation',
u'The PhpWord Team', 'manual'),
]
# The name of an image file (relative to this directory) to place at the top of
# the title page.
#latex_logo = None
# For "manual" documents, if this is true, then toplevel headings are parts,
# not chapters.
#latex_use_parts = False
# If true, show page references after internal links.
#latex_show_pagerefs = False
# If true, show URL addresses after external links.
#latex_show_urls = False
# Documents to append as an appendix to all manuals.
#latex_appendices = []
# If false, no module index is generated.
#latex_domain_indices = True
# -- Options for manual page output --------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'PhpWord', u'PhpWord Documentation',
[u'The PhpWord Team'], 1)
]
# If true, show URL addresses after external links.
#man_show_urls = False
# -- Options for Texinfo output ------------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'PhpWord', u'PhpWord Documentation',
u'The PhpWord Team', 'PhpWord', 'One line description of project.',
'Miscellaneous'),
]
# Documents to append as an appendix to all manuals.
#texinfo_appendices = []
# If false, no module index is generated.
#texinfo_domain_indices = True
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
# -- Options for Epub output ---------------------------------------------------
# Bibliographic Dublin Core info.
epub_title = u'PhpWord'
epub_author = u'The PhpWord Team'
epub_publisher = u'The PhpWord Team'
epub_copyright = copyright
# The language of the text. It defaults to the language option
# or en if the language is not set.
#epub_language = ''
# The scheme of the identifier. Typical schemes are ISBN or URL.
#epub_scheme = ''
# The unique identifier of the text. This can be a ISBN number
# or the project homepage.
#epub_identifier = ''
# A unique identification for the text.
#epub_uid = ''
# A tuple containing the cover image and cover page html template filenames.
#epub_cover = ()
# HTML files that should be inserted before the pages created by sphinx.
# The format is a list of tuples containing the path and title.
#epub_pre_files = []
# HTML files shat should be inserted after the pages created by sphinx.
# The format is a list of tuples containing the path and title.
#epub_post_files = []
# A list of files that should not be packed into the epub file.
#epub_exclude_files = []
# The depth of the table of contents in toc.ncx.
#epub_tocdepth = 3
# Allow duplicate toc entries.
#epub_tocdup = True
# Highlight PHP without starting <?php tag
from sphinx.highlighting import lexers
from pygments.lexers.web import PhpLexer
lexers['php'] = PhpLexer(startinline=True)

136
docs/containers.rst Normal file
View File

@ -0,0 +1,136 @@
.. _containers:
Containers
==========
Containers are objects where you can put elements (texts, lists, tables,
etc). There are 3 main containers, i.e. sections, headers, and footers.
There are 3 elements that can also act as containers, i.e. textruns,
table cells, and footnotes.
Sections
--------
Every visible element in word is placed inside of a section. To create a
section, use the following code:
.. code-block:: php
$section = $phpWord->createSection($sectionSettings);
The ``$sectionSettings`` is an optional associative array that sets the
section. Example:
.. code-block:: php
$sectionSettings = array(
'orientation' => 'landscape',
'marginTop' => 600,
'colsNum' => 2,
);
Section settings
~~~~~~~~~~~~~~~~
Below are the available settings for section:
- ``orientation`` Page orientation, i.e. 'portrait' (default) or
'landscape'
- ``marginTop`` Page margin top in twips
- ``marginLeft`` Page margin left in twips
- ``marginRight`` Page margin right in twips
- ``marginBottom`` Page margin bottom in twips
- ``borderTopSize`` Border top size in twips
- ``borderTopColor`` Border top color
- ``borderLeftSize`` Border left size in twips
- ``borderLeftColor`` Border left color
- ``borderRightSize`` Border right size in twips
- ``borderRightColor`` Border right color
- ``borderBottomSize`` Border bottom size in twips
- ``borderBottomColor`` Border bottom color
- ``headerHeight`` Spacing to top of header
- ``footerHeight`` Spacing to bottom of footer
- ``colsNum`` Number of columns
- ``colsSpace`` Spacing between columns
- ``breakType`` Section break type (nextPage, nextColumn, continuous,
evenPage, oddPage)
The following two settings are automatically set by the use of the
``orientation`` setting. You can alter them but that's not recommended.
- ``pageSizeW`` Page width in twips
- ``pageSizeH`` Page height in twips
Page number
~~~~~~~~~~~
You can change a section page number by using the ``pageNumberingStart``
property of the section.
.. code-block:: php
// Method 1
$section = $phpWord->createSection(array('pageNumberingStart' => 1));
// Method 2
$section = $phpWord->createSection();
$section->getSettings()->setPageNumberingStart(1);
Multicolumn
~~~~~~~~~~~
You can change a section layout to multicolumn (like in a newspaper) by
using the ``breakType`` and ``colsNum`` property of the section.
.. code-block:: php
// Method 1
$section = $phpWord->createSection(array('breakType' => 'continuous', 'colsNum' => 2));
// Method 2
$section = $phpWord->createSection();
$section->getSettings()->setBreakType('continuous');
$section->getSettings()->setColsNum(2);
Headers
-------
Each section can have its own header reference. To create a header use
the ``createHeader`` method:
.. code-block:: php
$header = $section->createHeader();
Be sure to save the result in a local object. You can use all elements
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.
Footers
-------
Each section can have its own footer reference. To create a footer, use
the ``createFooter`` method:
.. code-block:: php
$footer = $section->createFooter();
Be sure to save the result in a local object to add elements to a
footer. You can add the following elements to footers:
- Texts ``addText`` and ``createTextrun``
- Text breaks
- Images
- Tables
- Preserve text
See the "Elements" section for the detail of each elements.
Other containers
----------------
Textruns, table cells, and footnotes are elements that can also act as
containers. See the corresponding "Elements" section for the detail of
each elements.

4
docs/credits.rst Normal file
View File

@ -0,0 +1,4 @@
.. _credits:
Credits
=======

347
docs/elements.rst Normal file
View File

@ -0,0 +1,347 @@
.. _elements:
Elements
========
Texts
-----
Text can be added by using ``addText`` and ``createTextRun`` method.
``addText`` is used for creating simple paragraphs that only contain
texts with the same style. ``createTextRun`` is used for creating
complex paragraphs that contain text with different style (some bold,
other italics, etc) or other elements, e.g. images or links. The
syntaxes are as follow:
.. code-block:: php
$section->addText($text, [$fontStyle], [$paragraphStyle]);
$textrun = $section->createTextRun([$paragraphStyle]);
Text styles
~~~~~~~~~~~
You can use the ``$fontStyle`` and ``$paragraphStyle`` variable to
define text formatting. There are 2 options to style the inserted text
elements, i.e. inline style by using array or defined style by adding
style definition.
Inline style examples:
.. code-block:: php
$fontStyle = array('name' => 'Times New Roman', 'size' => 9);
$paragraphStyle = array('align' => 'both');
$section->addText('I am simple paragraph', $fontStyle, $paragraphStyle);
$textrun = $section->createTextRun();
$textrun->addText('I am bold', array('bold' => true));
$textrun->addText('I am italic', array('italic' => true));
$textrun->addText('I am colored, array('color' => 'AACC00'));
Defined style examples:
.. code-block:: php
$fontStyle = array('color' => '006699', 'size' => 18, 'bold' => true);
$phpWord->addFontStyle('fStyle', $fontStyle);
$text = $section->addText('Hello world!', 'fStyle');
$paragraphStyle = array('align' => 'center');
$phpWord->addParagraphStyle('pStyle', $paragraphStyle);
$text = $section->addText('Hello world!', 'pStyle');
Font style
^^^^^^^^^^
Available font styles:
- ``name`` Font name, e.g. *Arial*
- ``size`` Font size, e.g. *20*, *22*,
- ``hint`` Font content type, *default*, *eastAsia*, or *cs*
- ``bold`` Bold, *true* or *false*
- ``italic`` Italic, *true* or *false*
- ``superScript`` Superscript, *true* or *false*
- ``subScript`` Subscript, *true* or *false*
- ``underline`` Underline, *dash*, *dotted*, etc.
- ``strikethrough`` Strikethrough, *true* or *false*
- ``color`` Font color, e.g. *FF0000*
- ``fgColor`` Font highlight color, e.g. *yellow*, *green*, *blue*
Paragraph style
^^^^^^^^^^^^^^^
Available paragraph styles:
- ``align`` Paragraph alignment, *left*, *right* or *center*
- ``spaceBefore`` Space before paragraph
- ``spaceAfter`` Space after paragraph
- ``indent`` Indent by how much
- ``hanging`` Hanging by how much
- ``basedOn`` Parent style
- ``next`` Style for next paragraph
- ``widowControl`` Allow first/last line to display on a separate page,
*true* or *false*
- ``keepNext`` Keep paragraph with next paragraph, *true* or *false*
- ``keepLines`` Keep all lines on one page, *true* or *false*
- ``pageBreakBefore`` Start paragraph on next page, *true* or *false*
- ``lineHeight`` text line height, e.g. *1.0*, *1.5*, ect...
- ``tabs`` Set of custom tab stops
Titles
~~~~~~
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.
.. code-block:: php
$phpWord->addTitleStyle($depth, [$fontStyle], [$paragraphStyle]);
$section->addTitle($text, [$depth]);
Its necessary to add a title style to your document because otherwise
the title won't be detected as a real title.
Links
~~~~~
You can add Hyperlinks to the document by using the function addLink:
.. code-block:: php
$section->addLink($linkSrc, [$linkName], [$fontStyle], [$paragraphStyle]);
- ``$linkSrc`` The URL of the link.
- ``$linkName`` Placeholder of the URL that appears in the document.
- ``$fontStyle`` See "Font style" section.
- ``$paragraphStyle`` See "Paragraph style" section.
Preserve texts
~~~~~~~~~~~~~~
The ``addPreserveText`` method is used to add a page number or page
count to headers or footers.
.. code-block:: php
$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.');
Breaks
------
Text breaks
~~~~~~~~~~~
Text breaks are empty new lines. To add text breaks, use the following
syntax. All paramaters are optional.
.. code-block:: php
$section->addTextBreak([$breakCount], [$fontStyle], [$paragraphStyle]);
- ``$breakCount`` How many lines
- ``$fontStyle`` See "Font style" section.
- ``$paragraphStyle`` See "Paragraph style" section.
Page breaks
~~~~~~~~~~~
There are two ways to insert a page breaks, using the ``addPageBreak``
method or using the ``pageBreakBefore`` style of paragraph.
:: code-block:: php
$section->addPageBreak();
Lists
-----
To add a list item use the function ``addListItem``.
.. code-block:: php
$section->addListItem($text, [$depth], [$fontStyle], [$listStyle], [$paragraphStyle]);
- ``$text`` Text that appears in the document.
- ``$depth`` Depth of list item.
- ``$fontStyle`` See "Font style" section.
- ``$listStyle`` List style of the current element TYPE\_NUMBER,
TYPE\_ALPHANUM, TYPE\_BULLET\_FILLED, etc. See list of constants in
PHPWord\_Style\_ListItem.
- ``$paragraphStyle`` See "Paragraph style" section.
Tables
------
To add tables, rows, and cells, use the ``addTable``, ``addRow``, and
``addCell`` methods:
.. code-block:: php
$table = $section->addTable([$tableStyle]);
$table->addRow([$height], [$rowStyle]);
$cell = $table->addCell($width, [$cellStyle]);
Table style can be defined with ``addTableStyle``:
.. code-block:: php
$tableStyle = array(
'borderColor' => '006699',
'borderSize' => 6,
'cellMargin' => 50
);
$firstRowStyle = array('bgColor' => '66BBFF');
$phpWord->addTableStyle('myTable', $tableStyle, $firstRowStyle);
$table = $section->addTable('myTable');
Table, row, and cell styles
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Table styles:
- ``$width`` Table width in percent
- ``$bgColor`` Background color, e.g. '9966CC'
- ``$border(Top|Right|Bottom|Left)Size`` Border size in twips
- ``$border(Top|Right|Bottom|Left)Color`` Border color, e.g. '9966CC'
- ``$cellMargin(Top|Right|Bottom|Left)`` Cell margin in twips
Row styles:
- ``tblHeader`` Repeat table row on every new page, *true* or *false*
- ``cantSplit`` Table row cannot break across pages, *true* or *false*
Cell styles:
- ``$width`` Cell width in twips
- ``$valign`` Vertical alignment, *top*, *center*, *both*, *bottom*
- ``$textDirection`` Direction of text
- ``$bgColor`` Background color, e.g. '9966CC'
- ``$border(Top|Right|Bottom|Left)Size`` Border size in twips
- ``$border(Top|Right|Bottom|Left)Color`` Border color, e.g. '9966CC'
- ``$gridSpan`` Number of columns spanned
- ``$vMerge`` *restart* or *continue*
Cell span
~~~~~~~~~
You can span a cell on multiple columns by using ``gridSpan`` or
multiple rows by using ``vMerge``.
.. code-block:: php
$cell = $table->addCell(200);
$cell->getStyle()->setGridSpan(5);
See ``Sample_09_Tables.php`` for more code sample.
Images
------
To add an image, use the ``addImage`` method to sections, headers, footers,
textruns, or table cells.
.. code-block:: php
$section->addImage($src, [$style]);
- `source` String path to a local image or URL of a remote image
- `styles` Array fo styles for the image. See below.
Examples:
.. code-block:: php
$section = $phpWord->createSection();
$section->addImage(
'mars.jpg',
array(
'width' => 100,
'height' => 100,
'marginTop' => -1,
'marginLeft' => -1,
'wrappingStyle' => 'behind'
)
);
$footer = $section->createFooter();
$footer->addImage('http://example.com/image.php');
$textrun = $section->createTextRun();
$textrun->addImage('http://php.net/logo.jpg');
Image styles
~~~~~~~~~~~~
Available image styles:
- ``width`` Width in pixels
- ``height`` Height in pixels
- ``align`` Image alignment, *left*, *right*, or *center*
- ``marginTop`` Top margin in inches, can be negative
- ``marginLeft`` Left margin in inches, can be negative
- ``wrappingStyle`` Wrapping style, *inline*, *square*, *tight*,
*behind*, or *infront*
Watermarks
~~~~~~~~~~
To add a watermark (or page background image), your section needs a
header reference. After creating a header, you can use the
``addWatermark`` method to add a watermark.
.. code-block:: php
$section = $phpWord->createSection();
$header = $section->createHeader();
$header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55));
Objects
-------
You can add OLE embeddings, such as Excel spreadsheets or PowerPoint
presentations to the document by using ``addObject`` method.
.. code-block:: php
$section->addObject($src, [$style]);
Table of contents
-----------------
To add a table of contents (TOC), you can use the ``addTOC`` method.
Your TOC can only be generated if you have add at least one title (See
"Titles").
.. code-block:: php
$section->addTOC([$fontStyle], [$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.
Footnotes
---------
You can create footnotes in texts or textruns, but it's recommended to
use textrun to have better layout.
On textrun:
.. code-block:: php
$textrun = $section->createTextRun();
$textrun->addText('Lead text.');
$footnote = $textrun->createFootnote();
$footnote->addText('Footnote text.');
$textrun->addText('Trailing text.');
On text:
.. code-block:: php
$section->addText('Lead text.');
$footnote = $section->createFootnote();
$footnote->addText('Footnote text.');

20
docs/faq.rst Normal file
View File

@ -0,0 +1,20 @@
.. _faq:
Frequently asked questions
==========================
Is this the same with PHPWord that I found in CodePlex?
-------------------------------------------------------
No. This one is much better with tons of new features that you cant
find in PHPWord 0.6.3. The development in CodePlex is halted and
switched to GitHub to allow more participation from the crowd. The more
the merrier, right?
Ive been running PHPWord from CodePlex flawlessly, but I cant use the latest PHPWord from GitHub. Why?
--------------------------------------------------------------------------------------------------------
PHPWord requires PHP 5.3+ since 0.8, while PHPWord 0.6.3 from CodePlex
can run with PHP 5.2. Theres a lot of new features that we can get from
PHP 5.3 and its been around since 2009! You should upgrade your PHP
version to use PHPWord 0.8+.

107
docs/general.rst Normal file
View File

@ -0,0 +1,107 @@
.. _general:
General usage
=============
Basic example
-------------
The following is a basic example of the PHPWord library. More examples
are provided in the `samples folder <https://github.com/PHPOffice/PHPWord/tree/master/samples/>`__.
.. code-block:: php
require_once 'src/PhpWord/Autoloader.php';
PhpOffice\PhpWord\Autoloader::register();
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Every element you want to append to the word document is placed in a section.
// To create a basic section:
$section = $phpWord->createSection();
// After creating a section, you can append elements:
$section->addText('Hello world!');
// You can directly style your text by giving the addText function an array:
$section->addText('Hello world! I am formatted.',
array('name'=>'Tahoma', 'size'=>16, 'bold'=>true));
// If you often need the same style again you can create a user defined style
// to the word document and give the addText function the name of the style:
$phpWord->addFontStyle('myOwnStyle',
array('name'=>'Verdana', 'size'=>14, 'color'=>'1B2232'));
$section->addText('Hello world! I am formatted by a user defined style',
'myOwnStyle');
// You can also put the appended element to local object like this:
$fontStyle = new \PhpOffice\PhpWord\Style\Font();
$fontStyle->setBold(true);
$fontStyle->setName('Verdana');
$fontStyle->setSize(22);
$myTextElement = $section->addText('Hello World!');
$myTextElement->setFontStyle($fontStyle);
// Finally, write the document:
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('helloWorld.docx');
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'ODText');
$objWriter->save('helloWorld.odt');
$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'RTF');
$objWriter->save('helloWorld.rtf');
Default font
------------
By default, every text appears in Arial 10 point. You can alter the
default font by using the following two functions:
.. code-block:: php
$phpWord->setDefaultFontName('Times New Roman');
$phpWord->setDefaultFontSize(12);
Document properties
-------------------
You can set the document properties such as title, creator, and company
name. Use the following functions:
.. code-block:: php
$properties = $phpWord->getProperties();
$properties->setCreator('My name');
$properties->setCompany('My factory');
$properties->setTitle('My title');
$properties->setDescription('My description');
$properties->setCategory('My category');
$properties->setLastModifiedBy('My name');
$properties->setCreated(mktime(0, 0, 0, 3, 12, 2014));
$properties->setModified(mktime(0, 0, 0, 3, 14, 2014));
$properties->setSubject('My subject');
$properties->setKeywords('my, key, word');
Measurement units
-----------------
The base length unit in Open Office XML is twip. Twip means "TWentieth
of an Inch Point", i.e. 1 twip = 1/1440 inch.
You can use PHPWord helper functions to convert inches, centimeters, or
points to twips.
.. code-block:: php
// Paragraph with 6 points space after
$phpWord->addParagraphStyle('My Style', array(
'spaceAfter' => \PhpOffice\PhpWord\Shared\Font::pointSizeToTwips(6))
);
$section = $phpWord->createSection();
$sectionStyle = $section->getSettings();
// half inch left margin
$sectionStyle->setMarginLeft(\PhpOffice\PhpWord\Shared\Font::inchSizeToTwips(.5));
// 2 cm right margin
$sectionStyle->setMarginRight(\PhpOffice\PhpWord\Shared\Font::centimeterSizeToTwips(2));

BIN
docs/images/phpword.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

50
docs/images/phpword.svg Normal file
View File

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 17.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.2" baseProfile="tiny" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px"
y="0px" viewBox="0 0 280.016 60" xml:space="preserve" width="280" height="60">
<g id="Calque_1">
<g>
<path fill="#333333" d="M92.934,34.02h-2.996v12.265h-4.4V14.452c3.23-0.141,6.507-0.234,8.895-0.234
c6.835,0,11.188,3.417,11.188,8.941C105.62,30.181,100.002,34.02,92.934,34.02z M93.729,17.869h-3.792v12.593h3.417
c4.167,0,7.724-2.341,7.724-6.647C101.079,20.397,98.458,17.869,93.729,17.869z"/>
<path fill="#333333" d="M133.102,46.285V31.726h-17.228v14.559h-4.4V14.452h4.4V27.84h17.228V14.452h4.354v31.833H133.102z"/>
<path fill="#333333" d="M154.265,34.02h-2.996v12.265h-4.4V14.452c3.23-0.141,6.507-0.234,8.895-0.234
c6.835,0,11.188,3.417,11.188,8.941C166.951,30.181,161.333,34.02,154.265,34.02z M155.061,17.869h-3.792v12.593h3.417
c4.167,0,7.725-2.341,7.725-6.647C162.41,20.397,159.789,17.869,155.061,17.869z"/>
<path fill="#333333" d="M203.14,46.566h-3.558l-7.35-20.505c-0.608-1.732-1.311-5.243-1.311-5.243s-0.655,3.417-1.312,5.243
l-7.303,20.505h-3.511l-10.159-32.115h4.916l6.46,21.628c0.469,1.592,1.077,5.103,1.077,5.103s0.608-3.558,1.123-5.103
l7.304-21.628h3.37l7.443,21.535c0.562,1.638,1.218,5.103,1.218,5.103s0.468-3.417,0.936-5.056l6.414-21.581h4.4L203.14,46.566z"
/>
<path fill="#333333" d="M225.661,46.753c-6.46,0-10.673-5.196-10.673-11.891c0-7.115,4.588-12.452,11.609-12.452
c6.461,0,10.674,5.243,10.674,11.891C237.271,41.417,232.684,46.753,225.661,46.753z M226.083,25.874
c-4.214,0-6.882,3.839-6.882,8.474c0,4.775,2.668,8.988,6.976,8.988c4.166,0,6.882-3.839,6.882-8.52
C233.059,30.087,230.483,25.874,226.083,25.874z"/>
<path fill="#333333" d="M254.501,27.606c-1.171-0.608-2.622-1.03-4.026-1.03c-1.498,0-2.949,0.702-3.745,1.685v18.023h-4.166
V23.159l3.979-0.421l-0.14,3.371h0.14c1.171-2.153,3.23-3.698,5.618-3.698c1.17,0,2.153,0.281,3.043,0.749L254.501,27.606z"/>
<path fill="#333333" d="M279.782,46.238c-0.655,0.188-1.686,0.375-2.669,0.375c-1.919,0-3.137-1.171-3.558-2.95h-0.234
c-1.731,1.919-3.886,3.089-6.741,3.089c-5.945,0-9.784-4.962-9.784-11.656c0-7.35,4.635-12.546,11.798-12.546
c1.498,0,3.511,0.468,4.541,0.937V9.724h4.166V40.34c0,1.826,0.796,2.809,2.715,2.949L279.782,46.238z M273.135,27.513
c-1.171-0.936-3.23-1.545-5.197-1.545c-4.072,0-6.928,3.651-6.928,8.38c0,5.43,2.668,8.941,6.788,8.941
c2.247,0,3.792-0.796,5.337-2.106V27.513z"/>
</g>
</g>
<g id="Calque_2">
<rect fill="#00188F" width="59.875" height="60"/>
</g>
<g id="Calque_3">
<polygon fill="#FFFFFF" points="42.546,19.5 38.804,34.058 34.211,19.5 32.75,19.5 29.547,19.5 28.085,19.5 23.493,34.058
19.75,19.5 12.797,19.5 19.456,40.862 26.659,40.862 31.148,27.016 35.638,40.862 42.841,40.862 49.5,19.5 "/>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
<g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.9 KiB

38
docs/index.rst Normal file
View File

@ -0,0 +1,38 @@
.. PHPWord documentation master file, created by
sphinx-quickstart on Fri Mar 14 23:09:26 2014.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to PHPWord's documentation
==================================
|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 (OOXML or OpenXML), OASIS Open
Document Format for Office Applications (OpenDocument or ODF), and Rich Text
Format (RTF).
.. toctree::
:maxdepth: 2
intro
setup
general
containers
elements
templates
recipes
faq
credits
references
Indices and tables
==================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
.. |PHPWord| image:: images/phpword.png

182
docs/intro.rst Normal file
View File

@ -0,0 +1,182 @@
.. _intro:
Introduction
============
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), and `Rich Text
Format <http://en.wikipedia.org/wiki/Rich_Text_Format>`__ (RTF).
No Windows operating system is needed for usage because the resulting
DOCX, ODT, or RTF files can be opened by all major `word processing
softwares <http://en.wikipedia.org/wiki/List_of_word_processors>`__.
PHPWord is an open source project licensed under LGPL.
PHPWord is `unit tested <https://travis-ci.org/PHPOffice/PHPWord>`__ to
make sure that the released versions are stable.
**Want to contribute?** `Fork
us <https://github.com/PHPOffice/PHPWord/fork>`__ or
`submit <https://github.com/PHPOffice/PHPWord/issues>`__ your bug
reports or feature requests to us.
Features
--------
- Set document properties, e.g. title, subject, and creator.
- Create document sections with different settings, e.g.
portrait/landscape, page size, and page numbering
- Create header and footer for each sections
- Set default font type, font size, and paragraph style
- Use UTF-8 and East Asia fonts/characters
- Define custom font styles (e.g. bold, italic, color) and paragraph
styles (e.g. centered, multicolumns, spacing) either as named style
or inline in text
- Insert paragraphs, either as a simple text or complex one (a text
run) that contains other elements
- Insert titles (headers) and table of contents
- Insert text breaks and page breaks
- Insert and format images, either local, remote, or as page watermarks
- Insert binary OLE Objects such as Excel or Visio
- Insert and format table with customized properties for each rows
(e.g. repeat as header row) and cells (e.g. background color,
rowspan, colspan)
- Insert list items as bulleted, numbered, or multilevel
- Insert hyperlinks
- Create document from templates
- Use XSL 1.0 style sheets to transform main document part of OOXML
template
- ... and many more features on progress
File formats
------------
Below are the supported features for each file formats.
Writers
~~~~~~~
+-------------------------------------------------+--------+-------+-------+
| Features | DOCX | ODT | RTF |
+=========================+=======================+========+=======+=======+
| **Document Properties** | Standard | | | |
+ +-----------------------+--------+-------+-------+
| | Extended | | | |
+ +-----------------------+--------+-------+-------+
| | UserDefined | | | |
+-------------------------+-----------------------+--------+-------+-------+
| **Element Type** | Text | ✓ | ✓ | ✓ |
+ +-----------------------+--------+-------+-------+
| | Text Run | ✓ | ✓ | ✓ |
+ +-----------------------+--------+-------+-------+
| | Title | ✓ | | |
+ +-----------------------+--------+-------+-------+
| | Link | ✓ | | |
+ +-----------------------+--------+-------+-------+
| | Preserve Text | ✓ | | |
+ +-----------------------+--------+-------+-------+
| | Text Break | ✓ | ✓ | ✓ |
+ +-----------------------+--------+-------+-------+
| | Page Break | ✓ | | |
+ +-----------------------+--------+-------+-------+
| | List | ✓ | | |
+ +-----------------------+--------+-------+-------+
| | Table | ✓ | | |
+ +-----------------------+--------+-------+-------+
| | Image | ✓ | | |
+ +-----------------------+--------+-------+-------+
| | MemoryImage | ✓ | | |
+ +-----------------------+--------+-------+-------+
| | Object | ✓ | | |
+ +-----------------------+--------+-------+-------+
| | Watermark | ✓ | | |
+ +-----------------------+--------+-------+-------+
| | Table of Contents | ✓ | | |
+ +-----------------------+--------+-------+-------+
| | Header | ✓ | | |
+ +-----------------------+--------+-------+-------+
| | Footer | ✓ | | |
+ +-----------------------+--------+-------+-------+
| | Footnote | ✓ | | |
+-------------------------+-----------------------+--------+-------+-------+
| **Graphs** | 2D basic graphs | | | |
+ +-----------------------+--------+-------+-------+
| | 2D advanced graphs | | | |
+ +-----------------------+--------+-------+-------+
| | 3D graphs | | | |
+-------------------------+-----------------------+--------+-------+-------+
| **Math** | OMML support | | | |
+ +-----------------------+--------+-------+-------+
| | MathML support | | | |
+-------------------------+-----------------------+--------+-------+-------+
| **Bonus** | Encryption | | | |
+ +-----------------------+--------+-------+-------+
| | Protection | | | |
+-------------------------+-----------------------+--------+-------+-------+
Readers
~~~~~~~
+-------------------------------------------------+--------+-------+-------+
| Features | DOCX | ODT | RTF |
+=========================+=======================+========+=======+=======+
| **Document Properties** | Standard | | | |
+ +-----------------------+--------+-------+-------+
| | Extended | | | |
+ +-----------------------+--------+-------+-------+
| | UserDefined | | | |
+-------------------------+-----------------------+--------+-------+-------+
| **Element Type** | Text | ✓ | | |
+ +-----------------------+--------+-------+-------+
| | Text Run | ✓ | | |
+ +-----------------------+--------+-------+-------+
| | Title | | | |
+ +-----------------------+--------+-------+-------+
| | Link | | | |
+ +-----------------------+--------+-------+-------+
| | Preserve Text | | | |
+ +-----------------------+--------+-------+-------+
| | Text Break | ✓ | | |
+ +-----------------------+--------+-------+-------+
| | Page Break | | | |
+ +-----------------------+--------+-------+-------+
| | List | | | |
+ +-----------------------+--------+-------+-------+
| | Table | | | |
+ +-----------------------+--------+-------+-------+
| | Image | | | |
+ +-----------------------+--------+-------+-------+
| | MemoryImage | | | |
+ +-----------------------+--------+-------+-------+
| | Object | | | |
+ +-----------------------+--------+-------+-------+
| | Watermark | | | |
+ +-----------------------+--------+-------+-------+
| | Table of Contents | | | |
+ +-----------------------+--------+-------+-------+
| | Header | | | |
+ +-----------------------+--------+-------+-------+
| | Footer | | | |
+ +-----------------------+--------+-------+-------+
| | Footnote | | | |
+-------------------------+-----------------------+--------+-------+-------+
| **Graphs** | 2D basic graphs | | | |
+ +-----------------------+--------+-------+-------+
| | 2D advanced graphs | | | |
+ +-----------------------+--------+-------+-------+
| | 3D graphs | | | |
+-------------------------+-----------------------+--------+-------+-------+
| **Math** | OMML support | | | |
+ +-----------------------+--------+-------+-------+
| | MathML support | | | |
+-------------------------+-----------------------+--------+-------+-------+
| **Bonus** | Encryption | | | |
+ +-----------------------+--------+-------+-------+
| | Protection | | | |
+-------------------------+-----------------------+--------+-------+-------+

4
docs/recipes.rst Normal file
View File

@ -0,0 +1,4 @@
.. _recipes:
Recipes
=======

20
docs/references.rst Normal file
View File

@ -0,0 +1,20 @@
.. _references:
References
==========
Formal specifications
---------------------
- `Office Open XML (OOXML) (ECMA-376)
Schema <http://www.schemacentral.com/sc/ooxml/ss.html>`__
- `Oasis OpenDocument Standard Version
1.2 <http://docs.oasis-open.org/office/v1.2/os/OpenDocument-v1.2-os.html>`__
- `Rich Text Format (RTF) Specification, version
1.9.1 <http://www.microsoft.com/en-us/download/details.aspx?id=10725>`__
Other resources
---------------
- `DocumentFormat.OpenXml.Wordprocessing Namespace on
MSDN <http://msdn.microsoft.com/en-us/library/documentformat.openxml.wordprocessing%28v=office.14%29.aspx>`__

64
docs/setup.rst Normal file
View File

@ -0,0 +1,64 @@
.. _setup:
Installing/Configuring
======================
Requirements
------------
Mandatory:
- PHP 5.3+
- PHP `Zip <http://php.net/manual/en/book.zip.php>`__ extension
- PHP `XML
Parser <http://www.php.net/manual/en/xml.installation.php>`__
extension
Optional PHP extensions:
- `GD <http://php.net/manual/en/book.image.php>`__
- `XMLWriter <http://php.net/manual/en/book.xmlwriter.php>`__
- `XSL <http://php.net/manual/en/book.xsl.php>`__
Installation
------------
There are two ways to install PHPWord, i.e. via
`Composer <http://getcomposer.org/>`__ or manually by downloading the
library.
Using Composer
~~~~~~~~~~~~~~
To install via Composer, add the following lines to your
``composer.json``:
.. code-block:: json
{
"require": {
"phpoffice/phpword": "dev-master"
}
}
Manual install
~~~~~~~~~~~~~~
To install manually, `download PHPWord package from
github <https://github.com/PHPOffice/PHPWord/archive/master.zip>`__.
Extract the package and put the contents to your machine. To use the
library, include ``src/PhpWord/Autoloader.php`` in your script and
invoke ``Autoloader::register``.
.. code-block:: php
require_once '/path/to/src/PhpWord/Autoloader.php';
PhpOffice\PhpWord\Autoloader::register();
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/``.

24
docs/templates.rst Normal file
View File

@ -0,0 +1,24 @@
.. _templates:
Templates
=========
You can create a docx template with included search-patterns that can be
replaced by any value you wish. Only single-line values can be replaced.
To load a template file, use the ``loadTemplate`` method. After loading
the docx template, you can use the ``setValue`` method to change the
value of a search pattern. The search-pattern model is:
``${search-pattern}``. It is not possible to add new PHPWord elements to
a loaded template file.
Example:
.. code-block:: php
$template = $phpWord->loadTemplate('Template.docx');
$template->setValue('Name', 'Somebody someone');
$template->setValue('Street', 'Coming-Undone-Street 32');
See ``Sample_07_TemplateCloneRow.php`` for more code sample, including
how to create multirow from a single row in a template by using
``cloneRow``.

View File

@ -1,6 +1,6 @@
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="./Tests/bootstrap.php"
bootstrap="./tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
@ -9,13 +9,13 @@
stopOnFailure="false"
syntaxCheck="false">
<testsuites>
<testsuite name="PHPWord Unit Test Suite">
<directory>./Tests/PHPWord/</directory>
<testsuite name="PhpWord Test Suite">
<directory>./tests/PhpWord/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./Classes</directory>
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>

View File

@ -1,21 +1,18 @@
<?php
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
require_once '../Classes/PHPWord.php';
include_once 'Sample_Header.php';
// New Word Document
echo date('H:i:s') , " Create new PHPWord object" , EOL;
$PHPWord = new PHPWord();
$PHPWord->addFontStyle('rStyle', array('bold' => true, 'italic' => true, 'size' => 16));
$PHPWord->addParagraphStyle('pStyle', array('align' => 'center', 'spaceAfter' => 100));
$PHPWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240));
echo date('H:i:s') , " Create new PhpWord object" , \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->addFontStyle('rStyle', array('bold' => true, 'italic' => true, 'size' => 16));
$phpWord->addParagraphStyle('pStyle', array('align' => 'center', 'spaceAfter' => 100));
$phpWord->addTitleStyle(1, array('bold' => true), array('spaceAfter' => 240));
// New portrait section
$section = $PHPWord->createSection();
$section = $phpWord->createSection();
// Simple text
$section->addTitle('Welcome to PHPWord', 1);
$section->addTitle('Welcome to PhpWord', 1);
$section->addText('Hello World!');
// Two text break
@ -51,12 +48,10 @@ $section->addImage('resources/_earth.jpg', array('width'=>18, 'height'=>18));
$name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
$objWriter->save("{$name}.{$extension}");
echo date('H:i:s'), " Write to {$writer} format", \EOL;
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
}
// Done
echo date('H:i:s'), " Done writing file(s)", EOL;
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
include_once 'Sample_Footer.php';

View File

@ -1,34 +1,31 @@
<?php
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
require_once '../Classes/PHPWord.php';
include_once 'Sample_Header.php';
// New Word Document
echo date('H:i:s') , ' Create new PHPWord object' , EOL;
$PHPWord = new PHPWord();
echo date('H:i:s') , ' Create new PhpWord object' , \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Ads styles
$PHPWord->addParagraphStyle('multipleTab', array(
$phpWord->addParagraphStyle('multipleTab', array(
'tabs' => array(
new PHPWord_Style_Tab('left', 1550),
new PHPWord_Style_Tab('center', 3200),
new PHPWord_Style_Tab('right', 5300)
new \PhpOffice\PhpWord\Style\Tab('left', 1550),
new \PhpOffice\PhpWord\Style\Tab('center', 3200),
new \PhpOffice\PhpWord\Style\Tab('right', 5300)
)
));
$PHPWord->addParagraphStyle('rightTab', array(
$phpWord->addParagraphStyle('rightTab', array(
'tabs' => array(
new PHPWord_Style_Tab('right', 9090)
new \PhpOffice\PhpWord\Style\Tab('right', 9090)
)
));
$PHPWord->addParagraphStyle('centerTab', array(
$phpWord->addParagraphStyle('centerTab', array(
'tabs' => array(
new PHPWord_Style_Tab('center', 4680)
new \PhpOffice\PhpWord\Style\Tab('center', 4680)
)
));
// New portrait section
$section = $PHPWord->createSection();
$section = $phpWord->createSection();
// Add listitem elements
$section->addText("Multiple Tabs:\tOne\tTwo\tThree", NULL, 'multipleTab');
@ -39,12 +36,10 @@ $section->addText("\tCenter Aligned", NULL, 'centerTab');
$name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
$objWriter->save("{$name}.{$extension}");
echo date('H:i:s'), " Write to {$writer} format", \EOL;
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
}
// Done
echo date('H:i:s'), " Done writing file(s)", EOL;
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
include_once 'Sample_Footer.php';

View File

@ -1,29 +1,26 @@
<?php
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
require_once '../Classes/PHPWord.php';
include_once 'Sample_Header.php';
// New Word Document
echo date('H:i:s') , ' Create new PHPWord object' , EOL;
$PHPWord = new PHPWord();
echo date('H:i:s') , ' Create new PhpWord object' , \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// New portrait section
$section = $PHPWord->createSection(array('borderColor' => '00FF00', 'borderSize' => 12));
$section = $phpWord->createSection(array('borderColor' => '00FF00', 'borderSize' => 12));
$section->addText('I am placed on a default section.');
// New landscape section
$section = $PHPWord->createSection(array('orientation' => 'landscape'));
$section = $phpWord->createSection(array('orientation' => 'landscape'));
$section->addText('I am placed on a landscape section. Every page starting from this section will be landscape style.');
$section->addPageBreak();
$section->addPageBreak();
// New portrait section
$section = $PHPWord->createSection(array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600));
$section = $phpWord->createSection(array('marginLeft' => 600, 'marginRight' => 600, 'marginTop' => 600, 'marginBottom' => 600));
$section->addText('This section uses other margins.');
// New portrait section with Header & Footer
$section = $PHPWord->createSection(array('marginLeft' => 200, 'marginRight' => 200, 'marginTop' => 200, 'marginBottom' => 200, 'headerHeight' => 50, 'footerHeight' => 50,));
$section = $phpWord->createSection(array('marginLeft' => 200, 'marginRight' => 200, 'marginTop' => 200, 'marginBottom' => 200, 'headerHeight' => 50, 'footerHeight' => 50,));
$section->addText('This section and we play with header/footer height.');
$section->createHeader()->addText('Header');
$section->createFooter()->addText('Footer');
@ -32,12 +29,10 @@ $section->createFooter()->addText('Footer');
$name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
$objWriter->save("{$name}.{$extension}");
echo date('H:i:s'), " Write to {$writer} format", \EOL;
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
}
// Done
echo date('H:i:s'), " Done writing file(s)", EOL;
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
include_once 'Sample_Footer.php';

View File

@ -1,22 +1,18 @@
<?php
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
require_once '../Classes/PHPWord.php';
include_once 'Sample_Header.php';
// New Word Document
echo date('H:i:s') , ' Create new PHPWord object' , EOL;
$PHPWord = new PHPWord();
echo date('H:i:s') , ' Create new PhpWord object' , \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Ads styles
$PHPWord->addParagraphStyle('pStyle', array('spacing'=>100));
$PHPWord->addFontStyle('BoldText', array('bold'=>true));
$PHPWord->addFontStyle('ColoredText', array('color'=>'FF8080'));
$PHPWord->addLinkStyle('NLink', array('color'=>'0000FF', 'underline'=>PHPWord_Style_Font::UNDERLINE_SINGLE));
$phpWord->addParagraphStyle('pStyle', array('spacing'=>100));
$phpWord->addFontStyle('BoldText', array('bold'=>true));
$phpWord->addFontStyle('ColoredText', array('color'=>'FF8080'));
$phpWord->addLinkStyle('NLink', array('color'=>'0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
// New portrait section
$section = $PHPWord->createSection();
$section = $phpWord->createSection();
// Add text run
$textrun = $section->createTextRun('pStyle');
@ -39,12 +35,10 @@ $textrun->addText(' Here is some more text. ');
$name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
$objWriter->save("{$name}.{$extension}");
echo date('H:i:s'), " Write to {$writer} format", \EOL;
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
}
// Done
echo date('H:i:s'), " Done writing file(s)", EOL;
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
include_once 'Sample_Footer.php';

View File

@ -1,53 +1,48 @@
<?php
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
require_once '../Classes/PHPWord.php';
include_once 'Sample_Header.php';
// New Word Document
echo date('H:i:s') , " Create new PHPWord object" , EOL;
$PHPWord = new PHPWord();
echo date('H:i:s') , " Create new PhpWord object" , \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$filler = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' .
'Nulla fermentum, tortor id adipiscing adipiscing, tortor turpis commodo. ' .
'Donec vulputate iaculis metus, vel luctus dolor hendrerit ac. ' .
'Suspendisse congue congue leo sed pellentesque.';
// Normal
$section = $PHPWord->createSection();
$section = $phpWord->createSection();
$section->addText('Normal paragraph. ' . $filler);
// Two columns
$section = $PHPWord->createSection(array(
$section = $phpWord->createSection(array(
'colsNum' => 2,
'colsSpace' => 1440,
'breakType' => 'continuous'));
$section->addText('Three columns, one inch (1440 twips) spacing. ' . $filler);
// Normal
$section = $PHPWord->createSection(array('breakType' => 'continuous'));
$section = $phpWord->createSection(array('breakType' => 'continuous'));
$section->addText('Normal paragraph again. ' . $filler);
// Three columns
$section = $PHPWord->createSection(array(
$section = $phpWord->createSection(array(
'colsNum' => 3,
'colsSpace' => 720,
'breakType' => 'continuous'));
$section->addText('Three columns, half inch (720 twips) spacing. ' . $filler);
// Normal
$section = $PHPWord->createSection(array('breakType' => 'continuous'));
$section = $phpWord->createSection(array('breakType' => 'continuous'));
$section->addText('Normal paragraph again.');
// Save file
$name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
$objWriter->save("{$name}.{$extension}");
echo date('H:i:s'), " Write to {$writer} format", \EOL;
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
}
// Done
echo date('H:i:s'), " Done writing file(s)", EOL;
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
include_once 'Sample_Footer.php';

View File

@ -1,21 +1,18 @@
<?php
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
require_once '../Classes/PHPWord.php';
include_once 'Sample_Header.php';
// New Word Document
echo date('H:i:s') , " Create new PHPWord object" , EOL;
$PHPWord = new PHPWord();
echo date('H:i:s') , " Create new PhpWord object" , \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// New portrait section
$section = $PHPWord->createSection();
$section = $phpWord->createSection();
// Add style definitions
$PHPWord->addParagraphStyle('pStyle', array('spacing'=>100));
$PHPWord->addFontStyle('BoldText', array('bold'=>true));
$PHPWord->addFontStyle('ColoredText', array('color'=>'FF8080'));
$PHPWord->addLinkStyle('NLink', array('color'=>'0000FF', 'underline'=>PHPWord_Style_Font::UNDERLINE_SINGLE));
$phpWord->addParagraphStyle('pStyle', array('spacing'=>100));
$phpWord->addFontStyle('BoldText', array('bold'=>true));
$phpWord->addFontStyle('ColoredText', array('color'=>'FF8080'));
$phpWord->addLinkStyle('NLink', array('color'=>'0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
// Add text elements
$textrun = $section->createTextRun('pStyle');
@ -40,12 +37,10 @@ $footnote->addText('The reference for this is wrapped in its own line');
$name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
$objWriter->save("{$name}.{$extension}");
echo date('H:i:s'), " Write to {$writer} format", \EOL;
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
}
// Done
echo date('H:i:s'), " Done writing file(s)", EOL;
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
include_once 'Sample_Footer.php';

View File

@ -1,14 +1,11 @@
<?php
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
require_once '../Classes/PHPWord.php';
include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s') , " Create new PHPWord object" , EOL;
$PHPWord = new PHPWord();
echo date('H:i:s') , " Create new PhpWord object" , \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$document = $PHPWord->loadTemplate('resources/Sample_07_TemplateCloneRow.docx');
$document = $phpWord->loadTemplate('resources/Sample_07_TemplateCloneRow.docx');
// Simple table
$document->cloneRow('rowValue', 10);
@ -56,11 +53,9 @@ $document->setValue('userFirstName#3', 'Michael');
$document->setValue('userName#3', 'Ray');
$document->setValue('userPhone#3', '+1 428 889 775');
$name = 'Sample_07_TemplateCloneRow_result.docx';
echo date('H:i:s'), " Write to Word2007 format", EOL;
$name = 'Sample_07_TemplateCloneRow.docx';
echo date('H:i:s'), " Write to Word2007 format", \EOL;
$document->saveAs($name);
rename($name, "results/{$name}");
// Done
echo date('H:i:s'), " Done writing file(s)", EOL;
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
include_once 'Sample_Footer.php';

View File

@ -1,20 +1,17 @@
<?php
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
require_once '../Classes/PHPWord.php';
include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s') , " Create new PHPWord object" , EOL;
$PHPWord = new PHPWord();
$PHPWord->setDefaultParagraphStyle(array(
echo date('H:i:s') , " Create new PhpWord object" , \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$phpWord->setDefaultParagraphStyle(array(
'align' => 'both',
'spaceAfter' => PHPWord_Shared_Font::pointSizeToTwips(12),
'spaceAfter' => \PhpOffice\PhpWord\Shared\Font::pointSizeToTwips(12),
'spacing' => 120,
));
// Sample
$section = $PHPWord->createSection();
$section = $phpWord->createSection();
$section->addText('Below are the samples on how to control your paragraph ' .
'pagination. See "Line and Page Break" tab on paragraph properties ' .
@ -52,12 +49,10 @@ $section->addText('Paragraph with pageBreakBefore = true (default: false). ' .
$name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
$objWriter->save("{$name}.{$extension}");
echo date('H:i:s'), " Write to {$writer} format", \EOL;
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
}
// Done
echo date('H:i:s'), " Done writing file(s)", EOL;
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
include_once 'Sample_Footer.php';

View File

@ -1,13 +1,10 @@
<?php
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
require_once '../Classes/PHPWord.php';
include_once 'Sample_Header.php';
// New Word Document
echo date('H:i:s') , ' Create new PHPWord object' , EOL;
$PHPWord = new PHPWord();
$section = $PHPWord->createSection();
echo date('H:i:s') , ' Create new PhpWord object' , \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->createSection();
$header = array('size' => 16, 'bold' => true);
// 1. Basic table
@ -32,9 +29,9 @@ $section->addText("Fancy table", $header);
$styleTable = array('borderSize' => 6, 'borderColor' => '006699', 'cellMargin' => 80);
$styleFirstRow = array('borderBottomSize' => 18, 'borderBottomColor' => '0000FF', 'bgColor' => '66BBFF');
$styleCell = array('valign' => 'center');
$styleCellBTLR = array('valign' => 'center', 'textDirection' => PHPWord_Style_Cell::TEXT_DIR_BTLR);
$styleCellBTLR = array('valign' => 'center', 'textDirection' => \PhpOffice\PhpWord\Style\Cell::TEXT_DIR_BTLR);
$fontStyle = array('bold' => true, 'align' => 'center');
$PHPWord->addTableStyle('Fancy Table', $styleTable, $styleFirstRow);
$phpWord->addTableStyle('Fancy Table', $styleTable, $styleFirstRow);
$table = $section->addTable('Fancy Table');
$table->addRow(900);
$table->addCell(2000, $styleCell)->addText('Row 1', $fontStyle);
@ -64,7 +61,7 @@ $cellColSpan = array('gridSpan' => 2, 'valign' => 'center');
$cellHCentered = array('align' => 'center');
$cellVCentered = array('valign' => 'center');
$PHPWord->addTableStyle('Colspan Rowspan', $styleTable);
$phpWord->addTableStyle('Colspan Rowspan', $styleTable);
$table = $section->addTable('Colspan Rowspan');
$table->addRow();
$table->addCell(2000, $cellRowSpan)->addText('A', null, $cellHCentered);
@ -80,12 +77,10 @@ $table->addCell(null, $cellRowContinue);
$name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
$objWriter->save("{$name}.{$extension}");
echo date('H:i:s'), " Write to {$writer} format", \EOL;
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
}
// Done
echo date('H:i:s'), " Done writing file(s)", EOL;
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
include_once 'Sample_Footer.php';

View File

@ -1,13 +1,10 @@
<?php
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
require_once '../Classes/PHPWord.php';
include_once 'Sample_Header.php';
// New Word Document
echo date('H:i:s') , ' Create new PHPWord object' , EOL;
$PHPWord = new PHPWord();
$section = $PHPWord->createSection();
echo date('H:i:s') , ' Create new PhpWord object' , \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->createSection();
$header = array('size' => 16, 'bold' => true);
//1.Use EastAisa FontStyle
$section->addText('中文楷体样式测试',array('name' => '楷体', 'size' => 16, 'color' => '1B2232'));
@ -16,12 +13,10 @@ $section->addText('中文楷体样式测试',array('name' => '楷体', 'size' =>
$name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
$objWriter->save("{$name}.{$extension}");
echo date('H:i:s'), " Write to {$writer} format", \EOL;
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
}
// Done
echo date('H:i:s'), " Done writing file(s)", EOL;
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
include_once 'Sample_Footer.php';

View File

@ -1,24 +1,19 @@
<?php
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
require_once '../Classes/PHPWord.php';
include_once 'Sample_Header.php';
// Read contents
$name = basename(__FILE__, '.php');
$source = "resources/{$name}.docx";
echo date('H:i:s'), " Reading contents from `{$source}`", EOL;
$PHPWord = PHPWord_IOFactory::load($source);
echo date('H:i:s'), " Reading contents from `{$source}`", \EOL;
$phpWord = \PhpOffice\PhpWord\IOFactory::load($source);
// (Re)write contents
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
$objWriter->save("{$name}.{$extension}");
echo date('H:i:s'), " Write to {$writer} format", \EOL;
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
}
// Done
echo date('H:i:s'), " Done writing file(s)", EOL;
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
include_once 'Sample_Footer.php';

View File

@ -1,15 +1,12 @@
<?php
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
require_once '../Classes/PHPWord.php';
include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s') , " Create new PHPWord object" , EOL;
$PHPWord = new PHPWord();
echo date('H:i:s') , " Create new PhpWord object" , \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// New portrait section
$section = $PHPWord->createSection();
$section = $phpWord->createSection();
// Add first page header
$header = $section->createHeader();
@ -18,7 +15,7 @@ $table = $header->addTable();
$table->addRow();
$table->addCell(4500)->addText('This is the header.');
$table->addCell(4500)->addImage(
'resources/PHPWord.png',
'resources/PhpWord.png',
array('width' => 80, 'height' => 80, 'align' => 'right')
);
@ -49,7 +46,7 @@ $section->addTextBreak();
$section->addText('Some text...');
// New portrait section
$section2 = $PHPWord->createSection();
$section2 = $phpWord->createSection();
$sec2Header = $section2->createHeader();
$sec2Header->addText("All pages in Section 2 will Have this!");
@ -63,12 +60,10 @@ $section2->addText('Some text...');
$name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
$objWriter->save("{$name}.{$extension}");
echo date('H:i:s'), " Write to {$writer} format", \EOL;
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
}
// Done
echo date('H:i:s'), " Done writing file(s)", EOL;
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
include_once 'Sample_Footer.php';

View File

@ -1,19 +1,12 @@
<?php
/**
* Image creation
*/
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
require_once '../Classes/PHPWord.php';
include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s'), " Create new PHPWord object", EOL;
$PHPWord = new PHPWord();
echo date('H:i:s'), " Create new PhpWord object", \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
$section = $PHPWord->createSection();
$section = $phpWord->createSection();
$section->addText('Local image without any styles:');
$section->addImage('resources/_mars.jpg');
$section->addTextBreak(2);
@ -31,12 +24,10 @@ $section->addMemoryImage($source);
$name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
$objWriter->save("{$name}.{$extension}");
echo date('H:i:s'), " Write to {$writer} format", \EOL;
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
}
// Done
echo date('H:i:s'), " Done writing file(s)", EOL;
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
include_once 'Sample_Footer.php';

View File

@ -1,19 +1,12 @@
<?php
/**
* List item sample
*/
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
require_once '../Classes/PHPWord.php';
include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s'), " Create new PHPWord object", EOL;
$PHPWord = new PHPWord();
echo date('H:i:s'), " Create new PhpWord object", \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
$section = $PHPWord->createSection();
$section = $phpWord->createSection();
// Add listitem elements
$section->addListItem('List Item 1', 0);
@ -31,16 +24,16 @@ $section->addListItem('List Item 1.3.2', 2);
$section->addTextBreak(2);
// Add listitem elements
$listStyle = array('listType'=>PHPWord_Style_ListItem::TYPE_NUMBER);
$listStyle = array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER);
$section->addListItem('List Item 1', 0, null, $listStyle);
$section->addListItem('List Item 2', 0, null, $listStyle);
$section->addListItem('List Item 3', 0, null, $listStyle);
$section->addTextBreak(2);
// Add listitem elements
$PHPWord->addFontStyle('myOwnStyle', array('color'=>'FF0000'));
$PHPWord->addParagraphStyle('P-Style', array('spaceAfter'=>95));
$listStyle = array('listType'=>PHPWord_Style_ListItem::TYPE_NUMBER_NESTED);
$phpWord->addFontStyle('myOwnStyle', array('color'=>'FF0000'));
$phpWord->addParagraphStyle('P-Style', array('spaceAfter'=>95));
$listStyle = array('listType' => \PhpOffice\PhpWord\Style\ListItem::TYPE_NUMBER_NESTED);
$section->addListItem('List Item 1', 0, 'myOwnStyle', $listStyle, 'P-Style');
$section->addListItem('List Item 2', 0, 'myOwnStyle', $listStyle, 'P-Style');
$section->addListItem('List Item 3', 1, 'myOwnStyle', $listStyle, 'P-Style');
@ -55,12 +48,10 @@ $section->addListItem('List Item 7', 0, 'myOwnStyle', $listStyle, 'P-Style');
$name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
$objWriter->save("{$name}.{$extension}");
echo date('H:i:s'), " Write to {$writer} format", \EOL;
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
}
// Done
echo date('H:i:s'), " Done writing file(s)", EOL;
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
include_once 'Sample_Footer.php';

View File

@ -1,25 +1,18 @@
<?php
/**
* Link sample
*/
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
require_once '../Classes/PHPWord.php';
include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s'), " Create new PHPWord object", EOL;
$PHPWord = new PHPWord();
echo date('H:i:s'), " Create new PhpWord object", \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
$section = $PHPWord->createSection();
$section = $phpWord->createSection();
// Add hyperlink elements
$section->addLink('http://www.google.com', 'Best search engine', array('color'=>'0000FF', 'underline'=>PHPWord_Style_Font::UNDERLINE_SINGLE));
$section->addLink('http://www.google.com', 'Best search engine', array('color'=>'0000FF', 'underline' => \PhpOffice\PhpWord\Style\Font::UNDERLINE_SINGLE));
$section->addTextBreak(2);
$PHPWord->addLinkStyle('myOwnLinkStyle', array('bold'=>true, 'color'=>'808000'));
$phpWord->addLinkStyle('myOwnLinkStyle', array('bold'=>true, 'color'=>'808000'));
$section->addLink('http://www.bing.com', null, 'myOwnLinkStyle');
$section->addLink('http://www.yahoo.com', null, 'myOwnLinkStyle');
@ -29,12 +22,10 @@ $section->addLink('http://www.yahoo.com', null, 'myOwnLinkStyle');
$name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
$objWriter->save("{$name}.{$extension}");
echo date('H:i:s'), " Write to {$writer} format", \EOL;
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
}
// Done
echo date('H:i:s'), " Done writing file(s)", EOL;
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
include_once 'Sample_Footer.php';

View File

@ -1,19 +1,12 @@
<?php
/**
* Object sample
*/
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
require_once '../Classes/PHPWord.php';
include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s'), " Create new PHPWord object", EOL;
$PHPWord = new PHPWord();
echo date('H:i:s'), " Create new PhpWord object", \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
$section = $PHPWord->createSection();
$section = $phpWord->createSection();
$section->addText('You can open this OLE object by double clicking on the icon:');
$section->addTextBreak(2);
$section->addObject('resources/_sheet.xls');
@ -24,12 +17,10 @@ $section->addObject('resources/_sheet.xls');
$name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
$objWriter->save("{$name}.{$extension}");
echo date('H:i:s'), " Write to {$writer} format", \EOL;
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
}
// Done
echo date('H:i:s'), " Done writing file(s)", EOL;
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
include_once 'Sample_Footer.php';

View File

@ -1,26 +1,19 @@
<?php
/**
* Generic template for creating PHPWord samples
*/
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
require_once '../Classes/PHPWord.php';
include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s'), " Create new PHPWord object", EOL;
$PHPWord = new PHPWord();
echo date('H:i:s'), " Create new PhpWord object", \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
$section = $PHPWord->createSection();
$section = $phpWord->createSection();
// Define the TOC font style
$fontStyle = array('spaceAfter'=>60, 'size'=>12);
// Add title styles
$PHPWord->addTitleStyle(1, array('size'=>20, 'color'=>'333333', 'bold'=>true));
$PHPWord->addTitleStyle(2, array('size'=>16, 'color'=>'666666'));
$phpWord->addTitleStyle(1, array('size'=>20, 'color'=>'333333', 'bold'=>true));
$phpWord->addTitleStyle(2, array('size'=>16, 'color'=>'666666'));
// Add text elements
$section->addText('Table of contents:');
@ -49,19 +42,17 @@ $section->addTextBreak(2);
$section->addTitle('I am a Subtitle of Title 3', 2);
$section->addText('Again and again, more text...');
echo date('H:i:s'), " Note: Please refresh TOC manually.", EOL;
echo date('H:i:s'), " Note: Please refresh TOC manually.", \EOL;
// End code
// Save file
$name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
$objWriter->save("{$name}.{$extension}");
echo date('H:i:s'), " Write to {$writer} format", \EOL;
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
}
// Done
echo date('H:i:s'), " Done writing file(s)", EOL;
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
include_once 'Sample_Footer.php';

View File

@ -1,20 +1,13 @@
<?php
/**
* Generic template for creating PHPWord samples
*/
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
require_once '../Classes/PHPWord.php';
include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s'), " Create new PHPWord object", EOL;
$PHPWord = new PHPWord();
echo date('H:i:s'), " Create new PhpWord object", \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
$section = $PHPWord->createSection();
$section = $phpWord->createSection();
$header = $section->createHeader();
$header->addWatermark('resources/_earth.jpg', array('marginTop' => 200, 'marginLeft' => 55));
$section->addText('The header reference to the current section includes a watermark image.');
@ -25,12 +18,10 @@ $section->addText('The header reference to the current section includes a waterm
$name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
$objWriter->save("{$name}.{$extension}");
echo date('H:i:s'), " Write to {$writer} format", \EOL;
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
}
// Done
echo date('H:i:s'), " Done writing file(s)", EOL;
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
include_once 'Sample_Footer.php';

View File

@ -1,25 +1,18 @@
<?php
/**
* Generic template for creating PHPWord samples
*/
// Init
error_reporting(E_ALL);
define('EOL', (PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
require_once '../Classes/PHPWord.php';
include_once 'Sample_Header.php';
// New Word document
echo date('H:i:s'), " Create new PHPWord object", EOL;
$PHPWord = new PHPWord();
echo date('H:i:s'), " Create new PhpWord object", \EOL;
$phpWord = new \PhpOffice\PhpWord\PhpWord();
// Begin code
$fontStyle = array('size' => 24);
$paragraphStyle = array('spacing' => 240, 'size' => 24);
$PHPWord->addFontStyle('fontStyle', array('size' => 9));
$PHPWord->addParagraphStyle('paragraphStyle', array('spacing' => 480));
$phpWord->addFontStyle('fontStyle', array('size' => 9));
$phpWord->addParagraphStyle('paragraphStyle', array('spacing' => 480));
$fontStyle = array('size' => 24);
$section = $PHPWord->createSection();
$section = $phpWord->createSection();
$section->addText('Text break with no style:');
$section->addTextBreak();
$section->addText('Text break with defined font style:');
@ -38,12 +31,10 @@ $section->addText('Done.');
$name = basename(__FILE__, '.php');
$writers = array('Word2007' => 'docx', 'ODText' => 'odt', 'RTF' => 'rtf');
foreach ($writers as $writer => $extension) {
echo date('H:i:s'), " Write to {$writer} format", EOL;
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, $writer);
$objWriter->save("{$name}.{$extension}");
echo date('H:i:s'), " Write to {$writer} format", \EOL;
$xmlWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, $writer);
$xmlWriter->save("{$name}.{$extension}");
rename("{$name}.{$extension}", "results/{$name}.{$extension}");
}
// Done
echo date('H:i:s'), " Done writing file(s)", EOL;
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
include_once 'Sample_Footer.php';

34
samples/Sample_Footer.php Normal file
View File

@ -0,0 +1,34 @@
<?php
/**
* Footer file
*/
// Do not show execution time for index
if (!$isIndexFile) {
echo date('H:i:s'), " Done writing file(s)", EOL;
echo date('H:i:s'), " Peak memory usage: ", (memory_get_peak_usage(true) / 1024 / 1024), " MB", EOL;
}
// Show message when executed with CLI, show links when using browsers
if (CLI) {
echo 'The results are stored in the "results" subdirectory.', EOL;
} else {
if (!$isIndexFile) {
$types = array('docx', 'odt', 'rtf');
echo '<p>&nbsp;</p>';
echo '<p>Results: ';
foreach ($types as $type) {
$result = "results/{$sampleFile}.{$type}";
if (file_exists($result)) {
echo "<a href='{$result}' class='btn btn-primary'>{$type}</a> ";
}
}
echo '</p>';
}
?>
</div>
<script src="bootstrap/js/jquery.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
</body>
</html>
<?php
} // if (CLI)

71
samples/Sample_Header.php Normal file
View File

@ -0,0 +1,71 @@
<?php
/**
* Header file
*/
error_reporting(E_ALL);
define('CLI', (PHP_SAPI == 'cli') ? true : false);
define('EOL', CLI ? PHP_EOL : '<br />');
require_once '../src/PhpWord/Autoloader.php';
PhpOffice\PhpWord\Autoloader::register();
// Return to the caller script when runs by CLI
if (CLI) {
return;
}
// Set titles and names
$sampleFile = basename($_SERVER['SCRIPT_FILENAME'], '.php');
$isIndexFile = ($sampleFile == 'index');
$pageHeading = str_replace('_', ' ', $sampleFile);
$pageTitle = $isIndexFile ? 'Welcome to ' : "{$pageHeading} - ";
$pageTitle .= 'PHPWord';
$pageHeading = $isIndexFile ? '' : "<h1>{$pageHeading}</h1>";
// Populate samples
$files = '';
if ($handle = opendir('.')) {
while (false !== ($file = readdir($handle))) {
if (preg_match('/^Sample_\d+_/', $file)) {
$name = str_replace('_', ' ', preg_replace('/(Sample_|\.php)/', '', $file));
$files .= "<li><a href='{$file}'>{$name}</a></li>";
}
}
closedir($handle);
}
?>
<title><?php echo $pageTitle; ?></title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" href="bootstrap/css/phpword.css" />
</head>
<body>
<div class="container">
<div class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="./">PHPWord</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="dropdown active">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Samples
<strong class="caret"></strong></a>
<ul class="dropdown-menu"><?php echo $files; ?></ul>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="https://github.com/PHPOffice/PHPWord">Github</a></li>
<li><a href="http://phpword.readthedocs.org/en/develop/">Docs</a></li>
</ul>
</div>
</div>
</div>
<?php echo $pageHeading; ?>

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,13 @@
body {
padding-top: 20px;
padding-bottom: 20px;
}
.navbar {
margin-bottom: 20px;
}
.passed {
color: #339900;
}
.failed {
color: #ff0000;
}

9
samples/bootstrap/js/bootstrap.min.js vendored Normal file

File diff suppressed because one or more lines are too long

6
samples/bootstrap/js/jquery.min.js vendored Normal file

File diff suppressed because one or more lines are too long

28
samples/index.php Normal file
View File

@ -0,0 +1,28 @@
<?php
include_once 'Sample_Header.php';
if (!CLI) {
?>
<div class="jumbotron">
<p>Welcome to PHPWord, a library written in pure PHP that provides a set of classes to write to and read from different document file formats, i.e. Word (.docx), WordPad (.rtf), and Libre/OpenOffice Writer (.odt).</p>
<p>Please use the menu above to browse PHPWord samples.</p>
<p>
<a class="btn btn-lg btn-primary" href="https://github.com/PHPOffice/PHPWord" role="button">Fork us on Github!</a>
<a class="btn btn-lg btn-primary" href="http://phpword.readthedocs.org/en/develop/" role="button">Read the Docs</a>
</p>
</div>
<?
$requirements = array(
'php' => array('PHP 5.3.0', version_compare(phpversion(), '5.3.0', '>=')),
'zip' => array('PHP extension ZipArchive', extension_loaded('zip')),
'xml' => array('PHP extension XML', extension_loaded('xml')),
'gd' => array('PHP extension GD (optional)', extension_loaded('gd')),
);
echo "<h3>Requirements</h3>";
echo "<ul>";
foreach ($requirements as $key => $value) {
$status = $value[1] ? 'passed' : 'failed';
echo "<li>{$value[0]} ... <span class='{$status}'>{$status}</span></li>";
}
echo "</ul>";
} // if (!CLI)
include_once 'Sample_Footer.php';

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -18,63 +18,39 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
* @version 0.9.0
*/
if (!defined('PHPWORD_BASE_PATH')) {
define('PHPWORD_BASE_PATH', realpath(__DIR__ . '/../') . '/');
}
namespace PhpOffice\PhpWord;
/**
* Class PHPWord_Autoloader
*
* TODO: remove legacy autoloader once everything is moved to namespaces
* Autoloader
*/
class PHPWord_Autoloader
class Autoloader
{
const PREFIX = 'PhpOffice\PhpWord';
const NAMESPACE_PREFIX = 'PhpOffice\\PhpWord\\';
/**
* Register the autoloader
* Register
*
* @return void
*/
public static function register()
{
spl_autoload_register(array('PHPWord_Autoloader', 'load')); // Legacy
spl_autoload_register(array(new self, 'autoload')); // PSR-4
spl_autoload_register(array(new self, 'autoload'));
}
/**
* Autoloader
* Autoload
*
* @param string $strObjectName
* @return mixed
*/
public static function load($strObjectName)
{
$strObjectFilePath = __DIR__ . '/../' . str_replace('_', '/', $strObjectName) . '.php';
if (file_exists($strObjectFilePath) && is_readable($strObjectFilePath)) {
require_once $strObjectFilePath;
return true;
}
return null;
}
/**
* Autoloader
*
* @param string
* @param string $class
*/
public static function autoload($class)
{
$prefixLength = strlen(self::PREFIX);
if (0 === strncmp(self::PREFIX, $class, $prefixLength)) {
$prefixLength = strlen(self::NAMESPACE_PREFIX);
if (0 === strncmp(self::NAMESPACE_PREFIX, $class, $prefixLength)) {
$file = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, $prefixLength));
$file = realpath(__DIR__ . (empty($file) ? '' : DIRECTORY_SEPARATOR) . $file . '.php');
if (file_exists($file)) {

View File

@ -18,17 +18,17 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
* @version 0.9.0
*/
namespace PhpOffice\PhpWord;
/**
* Class PHPWord_DocumentProperties
* Document properties
*/
class PHPWord_DocumentProperties
class DocumentProperties
{
/** Constants */
const PROPERTY_TYPE_BOOLEAN = 'b';
@ -123,7 +123,7 @@ class PHPWord_DocumentProperties
private $_customProperties = array();
/**
* Create new PHPWord_DocumentProperties
* Create new DocumentProperties
*/
public function __construct()
{
@ -153,8 +153,8 @@ class PHPWord_DocumentProperties
/**
* Set Creator
*
* @param string $pValue
* @return PHPWord_DocumentProperties
* @param string $pValue
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setCreator($pValue = '')
{
@ -175,8 +175,8 @@ class PHPWord_DocumentProperties
/**
* Set Last Modified By
*
* @param string $pValue
* @return PHPWord_DocumentProperties
* @param string $pValue
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setLastModifiedBy($pValue = '')
{
@ -197,8 +197,8 @@ class PHPWord_DocumentProperties
/**
* Set Created
*
* @param datetime $pValue
* @return PHPWord_DocumentProperties
* @param datetime $pValue
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setCreated($pValue = null)
{
@ -222,8 +222,8 @@ class PHPWord_DocumentProperties
/**
* Set Modified
*
* @param datetime $pValue
* @return PHPWord_DocumentProperties
* @param datetime $pValue
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setModified($pValue = null)
{
@ -247,8 +247,8 @@ class PHPWord_DocumentProperties
/**
* Set Title
*
* @param string $pValue
* @return PHPWord_DocumentProperties
* @param string $pValue
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setTitle($pValue = '')
{
@ -269,8 +269,8 @@ class PHPWord_DocumentProperties
/**
* Set Description
*
* @param string $pValue
* @return PHPWord_DocumentProperties
* @param string $pValue
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setDescription($pValue = '')
{
@ -291,8 +291,8 @@ class PHPWord_DocumentProperties
/**
* Set Subject
*
* @param string $pValue
* @return PHPWord_DocumentProperties
* @param string $pValue
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setSubject($pValue = '')
{
@ -314,7 +314,7 @@ class PHPWord_DocumentProperties
* Set Keywords
*
* @param string $pValue
* @return PHPWord_DocumentProperties
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setKeywords($pValue = '')
{
@ -336,7 +336,7 @@ class PHPWord_DocumentProperties
* Set Category
*
* @param string $pValue
* @return PHPWord_DocumentProperties
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setCategory($pValue = '')
{
@ -358,7 +358,7 @@ class PHPWord_DocumentProperties
* Set Company
*
* @param string $pValue
* @return PHPWord_DocumentProperties
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setCompany($pValue = '')
{
@ -380,7 +380,7 @@ class PHPWord_DocumentProperties
* Set Manager
*
* @param string $pValue
* @return PHPExcel_DocumentProperties
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setManager($pValue = '')
{
@ -448,7 +448,7 @@ class PHPWord_DocumentProperties
* 's': String
* 'd': Date/Time
* 'b': Boolean
* @return PHPExcel_DocumentProperties
* @return \PhpOffice\PhpWord\DocumentProperties
*/
public function setCustomProperty($propertyName, $propertyValue = '', $propertyType = null)
{

View File

@ -2,7 +2,7 @@
/**
* PHPWord
*
* Copyright (c) 2009 - 2010 PHPWord
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -18,32 +18,16 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
* @version 0.9.0
*/
namespace PhpOffice\PhpWord\Exceptions;
/**
* Class PHPWord_Exception
* General exception
*/
class PHPWord_Exception extends Exception
class Exception extends \Exception
{
/**
* Error handler callback
*
* @param mixed $code
* @param mixed $string
* @param mixed $file
* @param mixed $line
* @param mixed $context
*/
public static function errorHandlerCallback($code, $string, $file, $line, $context)
{
$e = new self($string, $code);
$e->line = $line;
$e->file = $file;
throw $e;
}
}

View File

@ -0,0 +1,33 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.9.0
*/
namespace PhpOffice\PhpWord\Exceptions;
/**
* Exception used for when an image is not found
*/
class InvalidImageException extends Exception
{
}

View File

@ -0,0 +1,33 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.9.0
*/
namespace PhpOffice\PhpWord\Exceptions;
/**
* Exception used for when an image is not found
*/
class InvalidObjectException extends Exception
{
}

View File

@ -0,0 +1,35 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.9.0
*/
namespace PhpOffice\PhpWord\Exceptions;
use InvalidArgumentException;
/**
* Exception used for when a style value is invalid
*/
class InvalidStyleException extends InvalidArgumentException
{
}

View File

@ -0,0 +1,33 @@
<?php
/**
* PHPWord
*
* Copyright (c) 2014 PHPWord
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.9.0
*/
namespace PhpOffice\PhpWord\Exceptions;
/**
* Exception used for when an image type is unsupported
*/
class UnsupportedImageTypeException extends Exception
{
}

View File

@ -18,20 +18,18 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
* @version 0.9.0
*/
namespace PhpOffice\PhpWord;
/**
* PHPWord_Footnote
* Footnote
*/
class PHPWord_Footnote
class Footnote
{
/**
* Footnote Elements
*
@ -54,7 +52,7 @@ class PHPWord_Footnote
*
* @return mixed
*/
public static function addFootnoteElement(PHPWord_Section_Footnote $footnote)
public static function addFootnoteElement(\PhpOffice\PhpWord\Section\Footnote $footnote)
{
$refID = self::countFootnoteElements() + 2;
@ -86,8 +84,7 @@ class PHPWord_Footnote
/**
* Add new Footnote Link Element
*
* @param string $src
* @param string $type
* @param string $linkSrc
*
* @return mixed
*/

View File

@ -18,19 +18,21 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPWord
* @package PHPWord
* @copyright Copyright (c) 2014 PHPWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
* @version 0.9.0
*/
namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Exceptions\Exception;
/**
* PHPWord_HashTable
* Hash table
*
* @codeCoverageIgnore Legacy from PHPExcel
* @codeCoverageIgnore Legacy from PHPExcel
*/
class PHPWord_HashTable
class HashTable
{
/**
* HashTable elements
@ -47,15 +49,13 @@ class PHPWord_HashTable
public $_keyMap = array();
/**
* Create a new PHPWord_HashTable
* Create new
*
* @param PHPWord_IComparable[] $pSource Optional source array to create HashTable from
* @throws Exception
* @param \PhpOffice\PhpWord\IComparable[] $pSource Optional source array to create HashTable from
*/
public function __construct($pSource = null)
{
if (!is_null($pSource)) {
// Create HashTable
$this->addFromSource($pSource);
}
}
@ -63,8 +63,8 @@ class PHPWord_HashTable
/**
* Add HashTable items from source
*
* @param PHPWord_IComparable[] $pSource Source array to create HashTable from
* @throws Exception
* @param \PhpOffice\PhpWord\IComparable[] $pSource Source array to create HashTable from
* @throws \PhpOffice\PhpWord\Exceptions\Exception
*/
public function addFromSource($pSource = null)
{
@ -83,10 +83,9 @@ class PHPWord_HashTable
/**
* Add HashTable item
*
* @param PHPWord_IComparable $pSource Item to add
* @throws Exception
* @param \PhpOffice\PhpWord\IComparable $pSource Item to add
*/
public function add(PHPWord_IComparable $pSource = null)
public function add(IComparable $pSource = null)
{
// Determine hashcode
$hashCode = null;
@ -113,10 +112,9 @@ class PHPWord_HashTable
/**
* Remove HashTable item
*
* @param PHPWord_IComparable $pSource Item to remove
* @throws Exception
* @param \PhpOffice\PhpWord\IComparable $pSource Item to remove
*/
public function remove(PHPWord_IComparable $pSource = null)
public function remove(IComparable $pSource = null)
{
if (isset($this->_items[$pSource->getHashCode()])) {
unset($this->_items[$pSource->getHashCode()]);
@ -146,7 +144,7 @@ class PHPWord_HashTable
}
/**
* Count
* Get item count
*
* @return int
*/
@ -156,10 +154,10 @@ class PHPWord_HashTable
}
/**
* Get index for hash code
* Get hash code index
*
* @param string $pHashCode
* @return int Index
* @param string $pHashCode
* @return int Index
*/
public function getIndexForHashCode($pHashCode = '')
{
@ -169,9 +167,8 @@ class PHPWord_HashTable
/**
* Get by index
*
* @param int $pIndex
* @return PHPWord_IComparable
*
* @param int $pIndex
* @return \PhpOffice\PhpWord\IComparable
*/
public function getByIndex($pIndex = 0)
{
@ -184,9 +181,8 @@ class PHPWord_HashTable
/**
* Get by hashcode
*
* @param string $pHashCode
* @return PHPWord_IComparable
* @param string $pHashCode
* @return \PhpOffice\PhpWord\IComparable
*
*/
public function getByHashCode($pHashCode = '')
@ -199,9 +195,9 @@ class PHPWord_HashTable
}
/**
* HashTable to array
* Convert to array
*
* @return PHPWord_IComparable[]
* @return \PhpOffice\PhpWord\IComparable[]
*/
public function toArray()
{

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