Merge pull request #169 from ivanlanin/#160-refactoring

#160 refactoring: Merge TableFull-Table Style + Merge MemoryImage-Image
This commit is contained in:
Ivan Lanin 2014-03-26 15:30:54 +07:00
commit 004edd5346
33 changed files with 1162 additions and 1638 deletions

View File

@ -8,7 +8,8 @@ This release marked the transformation to namespaces (PHP 5.3+).
### Features
None yet.
- 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
@ -21,6 +22,8 @@ None yet.
- 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

View File

@ -239,17 +239,15 @@ See ``Sample_09_Tables.php`` for more code sample.
Images
------
To add an image, use the ``addImage`` or ``addMemoryImage`` method. The
first one is used when your source is stored locally, the later is used
when your source is a remote URL, either another script that create
image or an image on the internet.
Syntax:
To add an image, use the ``addImage`` method to sections, headers, footers,
textruns, or table cells.
.. code-block:: php
$section->addImage($src, [$style]);
$section->addMemoryImage($link, [$style]);
- `source` String path to a local image or URL of a remote image
- `styles` Array fo styles for the image. See below.
Examples:
@ -266,9 +264,10 @@ Examples:
'wrappingStyle' => 'behind'
)
);
$section->addMemoryImage('http://example.com/image.php');
$section->addMemoryImage('http://php.net/logo.jpg');
$footer = $section->createFooter();
$footer->addImage('http://example.com/image.php');
$textrun = $section->createTextRun();
$textrun->addImage('http://php.net/logo.jpg');
Image styles
~~~~~~~~~~~~

View File

@ -0,0 +1,34 @@
<?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
*/
namespace PhpOffice\PhpWord\Exceptions;
/**
* Exception used for when an image is not found
*/
class InvalidObjectException extends Exception
{
}

View File

@ -25,7 +25,7 @@
namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Section\MemoryImage;
use PhpOffice\PhpWord\Section\Image;
/**
* Media
@ -69,54 +69,33 @@ class Media
*
* @param string $src
* @param string $type
* @param \PhpOffice\PhpWord\Section\MemoryImage|null $memoryImage
* @param \PhpOffice\PhpWord\Section\Image $image
* @return mixed
*/
public static function addSectionMediaElement($src, $type, MemoryImage $memoryImage = null)
public static function addSectionMediaElement($src, $type, Image $image = null)
{
$mediaId = md5($src);
$key = ($type === 'image') ? 'images' : 'embeddings';
if (!array_key_exists($mediaId, self::$_sectionMedia[$key])) {
$cImg = self::countSectionMediaElements('images');
$cObj = self::countSectionMediaElements('embeddings');
$rID = self::countSectionMediaElements() + 7;
$media = array();
$folder = null;
$file = null;
if ($type === 'image') {
$cImg++;
//Detect if it's a memory image first by php ext and second by regex
$isMemImage = false;
if (stripos(strrev($src), strrev('.php')) === 0) {
$isMemImage = true;
}
if (!$isMemImage) {
$isMemImage = (filter_var($src, \FILTER_VALIDATE_URL) !== false);
}
$extension = '';
if ($isMemImage) {
$extension = $memoryImage->getImageExtension();
$media['isMemImage'] = true;
$media['createfunction'] = $memoryImage->getImageCreateFunction();
$media['imagefunction'] = $memoryImage->getImageFunction();
if (!is_null($image)) {
$isMemImage = $image->getIsMemImage();
$extension = $image->getImageExtension();
} else {
$imageType = exif_imagetype($src);
if ($imageType === \IMAGETYPE_JPEG) {
$extension = 'jpg';
} elseif ($imageType === \IMAGETYPE_GIF) {
$extension = 'gif';
} elseif ($imageType === \IMAGETYPE_PNG) {
$extension = 'png';
} elseif ($imageType === \IMAGETYPE_BMP) {
$extension = 'bmp';
} elseif ($imageType === \IMAGETYPE_TIFF_II || $imageType === \IMAGETYPE_TIFF_MM) {
$extension = 'tif';
}
$isMemImage = false;
}
if ($isMemImage) {
$media['isMemImage'] = true;
$media['createfunction'] = $image->getImageCreateFunction();
$media['imagefunction'] = $image->getImageFunction();
}
$folder = 'media';
$file = $type . $cImg . '.' . strtolower($extension);
} elseif ($type === 'oleObject') {
@ -124,26 +103,22 @@ class Media
$folder = 'embedding';
$file = $type . $cObj . '.bin';
}
$media['source'] = $src;
$media['target'] = "$folder/section_$file";
$media['type'] = $type;
$media['rID'] = $rID;
self::$_sectionMedia[$key][$mediaId] = $media;
if ($type === 'oleObject') {
return array($rID, ++self::$_objectId);
}
return $rID;
} else {
if ($type === 'oleObject') {
$rID = self::$_sectionMedia[$key][$mediaId]['rID'];
return array($rID, ++self::$_objectId);
}
return self::$_sectionMedia[$key][$mediaId]['rID'];
}
if ($type === 'oleObject') {
$rID = self::$_sectionMedia[$key][$mediaId]['rID'];
return array($rID, ++self::$_objectId);
}
return self::$_sectionMedia[$key][$mediaId]['rID'];
}
/**
@ -207,50 +182,42 @@ class Media
*
* @param int $headerCount
* @param string $src
* @param \PhpOffice\PhpWord\Section\MemoryImage|null $memoryImage
* @param \PhpOffice\PhpWord\Section\Image $image
* @return int
*/
public static function addHeaderMediaElement($headerCount, $src, MemoryImage $memoryImage = null)
public static function addHeaderMediaElement($headerCount, $src, Image $image = null)
{
$mediaId = md5($src);
$key = 'header' . $headerCount;
if (!array_key_exists($key, self::$_headerMedia)) {
self::$_headerMedia[$key] = array();
}
if (!array_key_exists($mediaId, self::$_headerMedia[$key])) {
$cImg = self::countHeaderMediaElements($key);
$rID = $cImg + 1;
$cImg++;
$inf = pathinfo($src);
$isMemImage = (substr(strtolower($inf['extension']), 0, 3) == 'php') ? true : false;
$media = array();
if ($isMemImage) {
$ext = $memoryImage->getImageExtension();
$media['isMemImage'] = true;
$media['createfunction'] = $memoryImage->getImageCreateFunction();
$media['imagefunction'] = $memoryImage->getImageFunction();
if (!is_null($image)) {
$isMemImage = $image->getIsMemImage();
$extension = $image->getImageExtension();
} else {
$ext = $inf['extension'];
if ($ext == 'jpeg') { // Office crashes when adding a jpEg Image, so rename to jpg
$ext = 'jpg';
}
$isMemImage = false;
}
$file = 'image' . $cImg . '.' . strtolower($ext);
if ($isMemImage) {
$media['isMemImage'] = true;
$media['createfunction'] = $image->getImageCreateFunction();
$media['imagefunction'] = $image->getImageFunction();
}
$file = 'image' . $cImg . '.' . strtolower($extension);
$media['source'] = $src;
$media['target'] = 'media/' . $key . '_' . $file;
$media['type'] = 'image';
$media['rID'] = $rID;
self::$_headerMedia[$key][$mediaId] = $media;
return $rID;
} else {
return self::$_headerMedia[$key][$mediaId]['rID'];
}
return self::$_headerMedia[$key][$mediaId]['rID'];
}
/**
@ -279,50 +246,41 @@ class Media
*
* @param int $footerCount
* @param string $src
* @param \PhpOffice\PhpWord\Section\MemoryImage|null $memoryImage
* @param \PhpOffice\PhpWord\Section\Image $image
* @return int
*/
public static function addFooterMediaElement($footerCount, $src, MemoryImage $memoryImage = null)
public static function addFooterMediaElement($footerCount, $src, Image $image = null)
{
$mediaId = md5($src);
$key = 'footer' . $footerCount;
if (!array_key_exists($key, self::$_footerMedia)) {
self::$_footerMedia[$key] = array();
}
if (!array_key_exists($mediaId, self::$_footerMedia[$key])) {
$cImg = self::countFooterMediaElements($key);
$rID = $cImg + 1;
$cImg++;
$inf = pathinfo($src);
$isMemImage = (substr(strtolower($inf['extension']), 0, 3) == 'php') ? true : false;
$media = array();
if ($isMemImage) {
$ext = $memoryImage->getImageExtension();
$media['isMemImage'] = true;
$media['createfunction'] = $memoryImage->getImageCreateFunction();
$media['imagefunction'] = $memoryImage->getImageFunction();
if (!is_null($image)) {
$isMemImage = $image->getIsMemImage();
$extension = $image->getImageExtension();
} else {
$ext = $inf['extension'];
if ($ext == 'jpeg') { // Office crashes when adding a jpEg Image, so rename to jpg
$ext = 'jpg';
}
$isMemImage = false;
}
$file = 'image' . $cImg . '.' . strtolower($ext);
if ($isMemImage) {
$media['isMemImage'] = true;
$media['createfunction'] = $image->getImageCreateFunction();
$media['imagefunction'] = $image->getImageFunction();
}
$file = 'image' . $cImg . '.' . strtolower($extension);
$media['source'] = $src;
$media['target'] = 'media/' . $key . '_' . $file;
$media['type'] = 'image';
$media['rID'] = $rID;
self::$_footerMedia[$key][$mediaId] = $media;
return $rID;
} else {
return self::$_footerMedia[$key][$mediaId]['rID'];
}
return self::$_footerMedia[$key][$mediaId]['rID'];
}
/**

View File

@ -25,13 +25,13 @@
namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Exceptions\InvalidImageException;
use PhpOffice\PhpWord\Exceptions\InvalidObjectException;
use PhpOffice\PhpWord\Section\Footer;
use PhpOffice\PhpWord\Section\Image;
use PhpOffice\PhpWord\Section\Header;
use PhpOffice\PhpWord\Section\Link;
use PhpOffice\PhpWord\Section\ListItem;
use PhpOffice\PhpWord\Section\MemoryImage;
use PhpOffice\PhpWord\Section\Object;
use PhpOffice\PhpWord\Section\PageBreak;
use PhpOffice\PhpWord\Section\Settings;
@ -230,7 +230,7 @@ class Section
* @param string $src
* @param mixed $style
* @return \PhpOffice\PhpWord\Section\Object
* @throws \PhpOffice\PhpWord\Exceptions\Exception
* @throws \PhpOffice\PhpWord\Exceptions\InvalidObjectException
*/
public function addObject($src, $style = null)
{
@ -250,7 +250,7 @@ class Section
$iconSrc .= '_' . $ext . '.png';
}
$rIDimg = Media::addSectionMediaElement($iconSrc, 'image');
$rIDimg = Media::addSectionMediaElement($iconSrc, 'image', new Image($iconSrc));
$data = Media::addSectionMediaElement($src, 'oleObject');
$rID = $data[0];
$objectId = $data[1];
@ -261,8 +261,9 @@ class Section
$this->_elementCollection[] = $object;
return $object;
} else {
throw new InvalidObjectException;
}
throw new Exception('Source does not exist or unsupported object type.');
}
/**
@ -271,20 +272,19 @@ class Section
* @param string $src
* @param mixed $style
* @return \PhpOffice\PhpWord\Section\Image
* @throws \PhpOffice\PhpWord\Exceptions\Exception
* @throws \PhpOffice\PhpWord\Exceptions\InvalidImageException
*/
public function addImage($src, $style = null)
{
$image = new Image($src, $style);
if (!is_null($image->getSource())) {
$rID = Media::addSectionMediaElement($src, 'image');
$rID = Media::addSectionMediaElement($src, 'image', $image);
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
return $image;
} else {
throw new InvalidImageException;
}
throw new Exception('Source does not exist or unsupported image type.');
}
/**
@ -292,20 +292,11 @@ class Section
*
* @param string $link
* @param mixed $style
* @return \PhpOffice\PhpWord\Section\MemoryImage
* @throws \PhpOffice\PhpWord\Exceptions\Exception
* @deprecated
*/
public function addMemoryImage($link, $style = null)
public function addMemoryImage($src, $style = null)
{
$memoryImage = new MemoryImage($link, $style);
if (!is_null($memoryImage->getSource())) {
$rID = Media::addSectionMediaElement($link, 'image', $memoryImage);
$memoryImage->setRelationId($rID);
$this->_elementCollection[] = $memoryImage;
return $memoryImage;
}
throw new Exception('Unsupported image type.');
return $this->addImage($src, $style);
}
/**

View File

@ -25,7 +25,7 @@
namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Exceptions\InvalidImageException;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Section\Footer\PreserveText;
use PhpOffice\PhpWord\Shared\String;
@ -134,15 +134,13 @@ class Footer
public function addImage($src, $style = null)
{
$image = new Image($src, $style);
if (!is_null($image->getSource())) {
$rID = Media::addFooterMediaElement($this->_footerCount, $src);
$rID = Media::addFooterMediaElement($this->_footerCount, $src, $image);
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
return $image;
} else {
throw new Exception('Src does not exist or invalid image type.');
throw new InvalidImageException;
}
}
@ -151,20 +149,11 @@ class Footer
*
* @param string $link
* @param mixed $style
* @return \PhpOffice\PhpWord\Section\MemoryImage
* @deprecated
*/
public function addMemoryImage($link, $style = null)
public function addMemoryImage($src, $style = null)
{
$memoryImage = new MemoryImage($link, $style);
if (!is_null($memoryImage->getSource())) {
$rID = Media::addFooterMediaElement($this->_footerCount, $link, $memoryImage);
$memoryImage->setRelationId($rID);
$this->_elementCollection[] = $memoryImage;
return $memoryImage;
} else {
throw new Exception('Unsupported image type.');
}
return $this->addImage($src, $style);
}
/**

View File

@ -25,7 +25,7 @@
namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Exceptions\InvalidImageException;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Section\Footer\PreserveText;
use PhpOffice\PhpWord\Shared\String;
@ -163,15 +163,13 @@ class Header
public function addImage($src, $style = null)
{
$image = new Image($src, $style);
if (!is_null($image->getSource())) {
$rID = Media::addHeaderMediaElement($this->_headerCount, $src);
$rID = Media::addHeaderMediaElement($this->_headerCount, $src, $image);
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
return $image;
} else {
throw new Exception('Src does not exist or invalid image type.');
throw new InvalidImageException;
}
}
@ -180,20 +178,11 @@ class Header
*
* @param string $link
* @param mixed $style
* @return \PhpOffice\PhpWord\Section\MemoryImage
* @deprecated
*/
public function addMemoryImage($link, $style = null)
public function addMemoryImage($src, $style = null)
{
$memoryImage = new MemoryImage($link, $style);
if (!is_null($memoryImage->getSource())) {
$rID = Media::addHeaderMediaElement($this->_headerCount, $link, $memoryImage);
$memoryImage->setRelationId($rID);
$this->_elementCollection[] = $memoryImage;
return $memoryImage;
} else {
throw new Exception('Unsupported image type.');
}
return $this->addImage($src, $style);
}
/**
@ -224,15 +213,13 @@ class Header
public function addWatermark($src, $style = null)
{
$image = new Image($src, $style, true);
if (!is_null($image->getSource())) {
$rID = Media::addHeaderMediaElement($this->_headerCount, $src);
$rID = Media::addHeaderMediaElement($this->_headerCount, $src, $image);
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
return $image;
} else {
throw new Exception('Src does not exist or invalid image type.');
throw new InvalidImageException;
}
}

View File

@ -34,77 +34,131 @@ use PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException;
class Image
{
/**
* Image Src
* Image source
*
* @var string
*/
private $_src;
private $source;
/**
* Image Style
* Image style
*
* @var \PhpOffice\PhpWord\Style\Image
*/
private $_style;
private $style;
/**
* Image Relation ID
* Image relation ID specific only for DOCX
*
* @var string
*/
private $_rId;
private $rId;
/**
* Is Watermark
* Is watermark
*
* @var bool
*/
private $_isWatermark;
private $isWatermark;
/**
* Create a new Image
* Image type
*
* @param string $src
* @var string
*/
private $imageType;
/**
* Image create function
*
* @var string
*/
private $imageCreateFunc;
/**
* Image function
*
* @var string
*/
private $imageFunc;
/**
* Image extension
*
* @var string
*/
private $imageExtension;
/**
* Is memory image
*
* @var string
*/
private $isMemImage;
/**
* Create new image element
*
* @param string $source
* @param mixed $style
* @param bool $isWatermark
* @throws \PhpOffice\PhpWord\Exceptions\InvalidImageException
* @throws \PhpOffice\PhpWord\Exceptions\UnsupportedImageTypeException
*/
public function __construct($src, $style = null, $isWatermark = false)
public function __construct($source, $style = null, $isWatermark = false)
{
$supportedImageTypes = array(\IMAGETYPE_JPEG, \IMAGETYPE_GIF, \IMAGETYPE_PNG, \IMAGETYPE_BMP, \IMAGETYPE_TIFF_II, \IMAGETYPE_TIFF_MM);
if (!\file_exists($src)) {
throw new InvalidImageException;
// Detect if it's a memory image, by .php ext or by URL
if (stripos(strrev($source), strrev('.php')) === 0) {
$this->isMemImage = true;
} else {
$this->isMemImage = (filter_var($source, \FILTER_VALIDATE_URL) !== false);
}
if (!in_array(exif_imagetype($src), $supportedImageTypes)) {
throw new UnsupportedImageTypeException;
// Check supported types
if ($this->isMemImage) {
$supportedTypes = array('image/jpeg', 'image/gif', 'image/png');
$imgData = getimagesize($source);
$this->imageType = $imgData['mime']; // string
if (!in_array($this->imageType, $supportedTypes)) {
throw new UnsupportedImageTypeException;
}
} else {
$supportedTypes = array(
\IMAGETYPE_JPEG, \IMAGETYPE_GIF,
\IMAGETYPE_PNG, \IMAGETYPE_BMP,
\IMAGETYPE_TIFF_II, \IMAGETYPE_TIFF_MM
);
if (!\file_exists($source)) {
throw new InvalidImageException;
}
$imgData = getimagesize($source);
$this->imageType = exif_imagetype($source);
if (!in_array($this->imageType, $supportedTypes)) {
throw new UnsupportedImageTypeException;
}
$this->imageType = \image_type_to_mime_type($this->imageType);
}
$this->_src = $src;
$this->_isWatermark = $isWatermark;
$this->_style = new \PhpOffice\PhpWord\Style\Image();
// Set private properties
$this->source = $source;
$this->isWatermark = $isWatermark;
$this->style = new \PhpOffice\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);
$this->style->setStyleValue($key, $value);
}
}
if (isset($style['wrappingStyle'])) {
$this->_style->setWrappingStyle($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]);
if ($this->style->getWidth() == null && $this->style->getHeight() == null) {
$this->style->setWidth($imgData[0]);
$this->style->setHeight($imgData[1]);
}
$this->setImageFunctions();
}
/**
@ -114,66 +168,149 @@ class Image
*/
public function getStyle()
{
return $this->_style;
return $this->style;
}
/**
* Get Image Relation ID
* Get image relation ID
*
* @return int
*/
public function getRelationId()
{
return $this->_rId;
return $this->rId;
}
/**
* Set Image Relation ID
* Set image relation ID
*
* @param int $rId
*/
public function setRelationId($rId)
{
$this->_rId = $rId;
$this->rId = $rId;
}
/**
* Get Image Source
* Get image source
*
* @return string
*/
public function getSource()
{
return $this->_src;
return $this->source;
}
/**
* Get Image Media ID
* Get image media ID
*
* @return string
*/
public function getMediaId()
{
return md5($this->_src);
return md5($this->source);
}
/**
* Get IsWatermark
* Get is watermark
*
* @return int
*/
public function getIsWatermark()
{
return $this->_isWatermark;
return $this->isWatermark;
}
/**
* Set IsWatermark
* Set is watermark
*
* @param bool $pValue
*/
public function setIsWatermark($pValue)
{
$this->_isWatermark = $pValue;
$this->isWatermark = $pValue;
}
/**
* 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;
}
/**
* Get is memory image
*
* @return boolean
*/
public function getIsMemImage()
{
return $this->isMemImage;
}
/**
* Set image functions
*/
private function setImageFunctions()
{
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;
case 'image/x-ms-bmp':
case 'image/bmp':
$this->imageType = 'image/bmp';
$this->imageExtension = 'bmp';
break;
case 'image/tiff':
$this->imageExtension = 'tif';
break;
}
}
}

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
*
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Section;
/**
* Memory image element
*/
class MemoryImage
{
/**
* Image Src
*
* @var string
*/
private $_src;
/**
* Image Style
*
* @var \PhpOffice\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 \PhpOffice\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 \PhpOffice\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

@ -26,12 +26,13 @@
namespace PhpOffice\PhpWord\Section\Table;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Exceptions\InvalidObjectException;
use PhpOffice\PhpWord\Exceptions\InvalidImageException;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Section\Footer\PreserveText;
use PhpOffice\PhpWord\Section\Image;
use PhpOffice\PhpWord\Section\Link;
use PhpOffice\PhpWord\Section\ListItem;
use PhpOffice\PhpWord\Section\MemoryImage;
use PhpOffice\PhpWord\Section\Object;
use PhpOffice\PhpWord\Section\Text;
use PhpOffice\PhpWord\Section\TextBreak;
@ -201,21 +202,19 @@ class Cell
public function addImage($src, $style = null)
{
$image = new Image($src, $style);
if (!is_null($image->getSource())) {
if ($this->_insideOf == 'section') {
$rID = Media::addSectionMediaElement($src, 'image');
$rID = Media::addSectionMediaElement($src, 'image', $image);
} elseif ($this->_insideOf == 'header') {
$rID = Media::addHeaderMediaElement($this->_pCount, $src);
$rID = Media::addHeaderMediaElement($this->_pCount, $src, $image);
} elseif ($this->_insideOf == 'footer') {
$rID = Media::addFooterMediaElement($this->_pCount, $src);
$rID = Media::addFooterMediaElement($this->_pCount, $src, $image);
}
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
return $image;
} else {
throw new Exception('Source does not exist or unsupported image type.');
throw new InvalidImageException;
}
}
@ -224,26 +223,11 @@ class Cell
*
* @param string $link
* @param mixed $style
* @return \PhpOffice\PhpWord\Section\MemoryImage
* @deprecated
*/
public function addMemoryImage($link, $style = null)
public function addMemoryImage($src, $style = null)
{
$memoryImage = new MemoryImage($link, $style);
if (!is_null($memoryImage->getSource())) {
if ($this->_insideOf == 'section') {
$rID = Media::addSectionMediaElement($link, 'image', $memoryImage);
} elseif ($this->_insideOf == 'header') {
$rID = Media::addHeaderMediaElement($this->_pCount, $link, $memoryImage);
} elseif ($this->_insideOf == 'footer') {
$rID = Media::addFooterMediaElement($this->_pCount, $link, $memoryImage);
}
$memoryImage->setRelationId($rID);
$this->_elementCollection[] = $memoryImage;
return $memoryImage;
} else {
throw new Exception('Unsupported image type.');
}
return $this->addImage($src, $style);
}
/**
@ -271,7 +255,7 @@ class Cell
$iconSrc .= '_' . $ext . '.png';
}
$rIDimg = Media::addSectionMediaElement($iconSrc, 'image');
$rIDimg = Media::addSectionMediaElement($iconSrc, 'image', new Image($iconSrc));
$data = Media::addSectionMediaElement($src, 'oleObject');
$rID = $data[0];
$objectId = $data[1];
@ -283,7 +267,7 @@ class Cell
$this->_elementCollection[] = $object;
return $object;
} else {
throw new Exception('Source does not exist or unsupported object type.');
throw new InvalidObjectException;
}
}

View File

@ -25,7 +25,7 @@
namespace PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Exceptions\Exception;
use PhpOffice\PhpWord\Exceptions\InvalidImageException;
use PhpOffice\PhpWord\Media;
use PhpOffice\PhpWord\Shared\String;
use PhpOffice\PhpWord\Style\Paragraph;
@ -125,15 +125,13 @@ class TextRun
public function addImage($imageSrc, $style = null)
{
$image = new Image($imageSrc, $style);
if (!is_null($image->getSource())) {
$rID = Media::addSectionMediaElement($imageSrc, 'image');
$rID = Media::addSectionMediaElement($imageSrc, 'image', $image);
$image->setRelationId($rID);
$this->_elementCollection[] = $image;
return $image;
} else {
throw new Exception('Source does not exist or unsupported image type.');
throw new InvalidImageException;
}
}

View File

@ -27,7 +27,7 @@ namespace PhpOffice\PhpWord;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\Style\TableFull;
use PhpOffice\PhpWord\Style\Table;
/**
* Style
@ -114,7 +114,7 @@ class Style
public static function addTableStyle($styleName, $styleTable, $styleFirstRow = null)
{
if (!array_key_exists($styleName, self::$_styleElements)) {
$style = new TableFull($styleTable, $styleFirstRow);
$style = new Table($styleTable, $styleFirstRow);
self::$_styleElements[$styleName] = $style;
}

View File

@ -30,6 +30,13 @@ namespace PhpOffice\PhpWord\Style;
*/
class Table
{
/**
* Style for first row
*
* @var \PhpOffice\PhpWord\Style\Table
*/
private $_firstRow = null;
/**
* Cell margin top
*
@ -59,14 +66,133 @@ class Table
private $_cellMarginBottom = null;
/**
* Create new table style
* Background color
*
* @var string
*/
public function __construct()
private $_bgColor;
/**
* Border size top
*
* @var int
*/
private $_borderTopSize;
/**
* Border color
*
* @var string top
*/
private $_borderTopColor;
/**
* Border size left
*
* @var int
*/
private $_borderLeftSize;
/**
* Border color left
*
* @var string
*/
private $_borderLeftColor;
/**
* Border size right
*
* @var int
*/
private $_borderRightSize;
/**
* Border color right
*
* @var string
*/
private $_borderRightColor;
/**
* Border size bottom
*
* @var int
*/
private $_borderBottomSize;
/**
* Border color bottom
*
* @var string
*/
private $_borderBottomColor;
/**
* Border size inside horizontal
*
* @var int
*/
private $_borderInsideHSize;
/**
* Border color inside horizontal
*
* @var string
*/
private $_borderInsideHColor;
/**
* Border size inside vertical
*
* @var int
*/
private $_borderInsideVSize;
/**
* Border color inside vertical
*
* @var string
*/
private $_borderInsideVColor;
/**
* Create new table style
*
* @param mixed $styleTable
* @param mixed $styleFirstRow
*/
public function __construct($styleTable = null, $styleFirstRow = null)
{
$this->_cellMarginTop = null;
$this->_cellMarginLeft = null;
$this->_cellMarginRight = null;
$this->_cellMarginBottom = null;
if (!is_null($styleFirstRow) && is_array($styleFirstRow)) {
$this->_firstRow = clone $this;
unset($this->_firstRow->_firstRow);
unset($this->_firstRow->_cellMarginBottom);
unset($this->_firstRow->_cellMarginTop);
unset($this->_firstRow->_cellMarginLeft);
unset($this->_firstRow->_cellMarginRight);
unset($this->_firstRow->_borderInsideVColor);
unset($this->_firstRow->_borderInsideVSize);
unset($this->_firstRow->_borderInsideHColor);
unset($this->_firstRow->_borderInsideHSize);
foreach ($styleFirstRow as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_firstRow->setStyleValue($key, $value);
}
}
if (!is_null($styleTable) && is_array($styleTable)) {
foreach ($styleTable as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->setStyleValue($key, $value);
}
}
}
/**
@ -77,7 +203,359 @@ class Table
*/
public function setStyleValue($key, $value)
{
$this->$key = $value;
if ($key == '_borderSize') {
$this->setBorderSize($value);
} elseif ($key == '_borderColor') {
$this->setBorderColor($value);
} elseif ($key == '_cellMargin') {
$this->setCellMargin($value);
} else {
$this->$key = $value;
}
}
/**
* Get First Row Style
*
* @return \PhpOffice\PhpWord\Style\Table
*/
public function getFirstRow()
{
return $this->_firstRow;
}
/**
* Get Last Row Style
*
* @return \PhpOffice\PhpWord\Style\Table
*/
public function getLastRow()
{
return $this->_lastRow;
}
/**
* Get background
*
* @return \PhpOffice\PhpWord\Style\Table
*/
public function getBgColor()
{
return $this->_bgColor;
}
/**
* Set background
*
* @param string $pValue
* @return \PhpOffice\PhpWord\Style\Table
*/
public function setBgColor($pValue = null)
{
$this->_bgColor = $pValue;
}
/**
* Set TLRBVH Border Size
*
* @param int $pValue Border size in eighths of a point (1/8 point)
*/
public function setBorderSize($pValue = null)
{
$this->_borderTopSize = $pValue;
$this->_borderLeftSize = $pValue;
$this->_borderRightSize = $pValue;
$this->_borderBottomSize = $pValue;
$this->_borderInsideHSize = $pValue;
$this->_borderInsideVSize = $pValue;
}
/**
* Get TLRBVH Border Size
*
* @return array
*/
public function getBorderSize()
{
$t = $this->getBorderTopSize();
$l = $this->getBorderLeftSize();
$r = $this->getBorderRightSize();
$b = $this->getBorderBottomSize();
$h = $this->getBorderInsideHSize();
$v = $this->getBorderInsideVSize();
return array($t, $l, $r, $b, $h, $v);
}
/**
* Set TLRBVH Border Color
* @param string $pValue
*/
public function setBorderColor($pValue = null)
{
$this->_borderTopColor = $pValue;
$this->_borderLeftColor = $pValue;
$this->_borderRightColor = $pValue;
$this->_borderBottomColor = $pValue;
$this->_borderInsideHColor = $pValue;
$this->_borderInsideVColor = $pValue;
}
/**
* Get TLRB Border Color
*
* @return array
*/
public function getBorderColor()
{
$t = $this->getBorderTopColor();
$l = $this->getBorderLeftColor();
$r = $this->getBorderRightColor();
$b = $this->getBorderBottomColor();
$h = $this->getBorderInsideHColor();
$v = $this->getBorderInsideVColor();
return array($t, $l, $r, $b, $h, $v);
}
/**
* Set border size top
*
* @param $pValue
*/
public function setBorderTopSize($pValue = null)
{
$this->_borderTopSize = $pValue;
}
/**
* Get border size top
*
* @return
*/
public function getBorderTopSize()
{
return $this->_borderTopSize;
}
/**
* Set border color top
*
* @param $pValue
*/
public function setBorderTopColor($pValue = null)
{
$this->_borderTopColor = $pValue;
}
/**
* Get border color top
*
* @return
*/
public function getBorderTopColor()
{
return $this->_borderTopColor;
}
/**
* Set border size left
*
* @param $pValue
*/
public function setBorderLeftSize($pValue = null)
{
$this->_borderLeftSize = $pValue;
}
/**
* Get border size left
*
* @return
*/
public function getBorderLeftSize()
{
return $this->_borderLeftSize;
}
/**
* Set border color left
*
* @param $pValue
*/
public function setBorderLeftColor($pValue = null)
{
$this->_borderLeftColor = $pValue;
}
/**
* Get border color left
*
* @return
*/
public function getBorderLeftColor()
{
return $this->_borderLeftColor;
}
/**
* Set border size right
*
* @param $pValue
*/
public function setBorderRightSize($pValue = null)
{
$this->_borderRightSize = $pValue;
}
/**
* Get border size right
*
* @return
*/
public function getBorderRightSize()
{
return $this->_borderRightSize;
}
/**
* Set border color right
*
* @param $pValue
*/
public function setBorderRightColor($pValue = null)
{
$this->_borderRightColor = $pValue;
}
/**
* Get border color right
*
* @return
*/
public function getBorderRightColor()
{
return $this->_borderRightColor;
}
/**
* Set border size bottom
*
* @param $pValue
*/
public function setBorderBottomSize($pValue = null)
{
$this->_borderBottomSize = $pValue;
}
/**
* Get border size bottom
*
* @return
*/
public function getBorderBottomSize()
{
return $this->_borderBottomSize;
}
/**
* Set border color bottom
*
* @param $pValue
*/
public function setBorderBottomColor($pValue = null)
{
$this->_borderBottomColor = $pValue;
}
/**
* Get border color bottom
*
* @return
*/
public function getBorderBottomColor()
{
return $this->_borderBottomColor;
}
/**
* Set border color inside horizontal
*
* @param $pValue
*/
public function setBorderInsideHColor($pValue = null)
{
$this->_borderInsideHColor = $pValue;
}
/**
* Get border color inside horizontal
*
* @return
*/
public function getBorderInsideHColor()
{
return (isset($this->_borderInsideHColor)) ? $this->_borderInsideHColor : null;
}
/**
* Set border color inside vertical
*
* @param $pValue
*/
public function setBorderInsideVColor($pValue = null)
{
$this->_borderInsideVColor = $pValue;
}
/**
* Get border color inside vertical
*
* @return
*/
public function getBorderInsideVColor()
{
return (isset($this->_borderInsideVColor)) ? $this->_borderInsideVColor : null;
}
/**
* Set border size inside horizontal
*
* @param $pValue
*/
public function setBorderInsideHSize($pValue = null)
{
$this->_borderInsideHSize = $pValue;
}
/**
* Get border size inside horizontal
*
* @return
*/
public function getBorderInsideHSize()
{
return (isset($this->_borderInsideHSize)) ? $this->_borderInsideHSize : null;
}
/**
* Set border size inside vertical
*
* @param $pValue
*/
public function setBorderInsideVSize($pValue = null)
{
$this->_borderInsideVSize = $pValue;
}
/**
* Get border size inside vertical
*
* @return
*/
public function getBorderInsideVSize()
{
return (isset($this->_borderInsideVSize)) ? $this->_borderInsideVSize : null;
}
/**

View File

@ -1,663 +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
*
* @copyright Copyright (c) 2014 PhpWord
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 0.8.0
*/
namespace PhpOffice\PhpWord\Style;
/**
* Table (full) style
*/
class TableFull
{
/**
* Style for first row
*
* @var \PhpOffice\PhpWord\Style\TableFull
*/
private $_firstRow = null;
/**
* Cell margin top
*
* @var int
*/
private $_cellMarginTop = null;
/**
* Cell margin left
*
* @var int
*/
private $_cellMarginLeft = null;
/**
* Cell margin right
*
* @var int
*/
private $_cellMarginRight = null;
/**
* Cell margin bottom
*
* @var int
*/
private $_cellMarginBottom = null;
/**
* Background color
*
* @var string
*/
private $_bgColor;
/**
* Border size top
*
* @var int
*/
private $_borderTopSize;
/**
* Border color
*
* @var string top
*/
private $_borderTopColor;
/**
* Border size left
*
* @var int
*/
private $_borderLeftSize;
/**
* Border color left
*
* @var string
*/
private $_borderLeftColor;
/**
* Border size right
*
* @var int
*/
private $_borderRightSize;
/**
* Border color right
*
* @var string
*/
private $_borderRightColor;
/**
* Border size bottom
*
* @var int
*/
private $_borderBottomSize;
/**
* Border color bottom
*
* @var string
*/
private $_borderBottomColor;
/**
* Border size inside horizontal
*
* @var int
*/
private $_borderInsideHSize;
/**
* Border color inside horizontal
*
* @var string
*/
private $_borderInsideHColor;
/**
* Border size inside vertical
*
* @var int
*/
private $_borderInsideVSize;
/**
* Border color inside vertical
*
* @var string
*/
private $_borderInsideVColor;
/**
* Create new table style
*
* @param mixed $styleTable
* @param mixed $styleFirstRow
*/
public function __construct($styleTable = null, $styleFirstRow = null)
{
if (!is_null($styleFirstRow) && is_array($styleFirstRow)) {
$this->_firstRow = clone $this;
unset($this->_firstRow->_firstRow);
unset($this->_firstRow->_cellMarginBottom);
unset($this->_firstRow->_cellMarginTop);
unset($this->_firstRow->_cellMarginLeft);
unset($this->_firstRow->_cellMarginRight);
unset($this->_firstRow->_borderInsideVColor);
unset($this->_firstRow->_borderInsideVSize);
unset($this->_firstRow->_borderInsideHColor);
unset($this->_firstRow->_borderInsideHSize);
foreach ($styleFirstRow as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->_firstRow->setStyleValue($key, $value);
}
}
if (!is_null($styleTable) && is_array($styleTable)) {
foreach ($styleTable as $key => $value) {
if (substr($key, 0, 1) != '_') {
$key = '_' . $key;
}
$this->setStyleValue($key, $value);
}
}
}
/**
* Set style value
*
* @param string $key
* @param mixed $value
*/
public function setStyleValue($key, $value)
{
if ($key == '_borderSize') {
$this->setBorderSize($value);
} elseif ($key == '_borderColor') {
$this->setBorderColor($value);
} elseif ($key == '_cellMargin') {
$this->setCellMargin($value);
} else {
$this->$key = $value;
}
}
/**
* Get First Row Style
*
* @return \PhpOffice\PhpWord\Style\TableFull
*/
public function getFirstRow()
{
return $this->_firstRow;
}
/**
* Get Last Row Style
*
* @return \PhpOffice\PhpWord\Style\TableFull
*/
public function getLastRow()
{
return $this->_lastRow;
}
/**
* Get background
*
* @return \PhpOffice\PhpWord\Style\TableFull
*/
public function getBgColor()
{
return $this->_bgColor;
}
/**
* Set background
*
* @param string $pValue
* @return \PhpOffice\PhpWord\Style\TableFull
*/
public function setBgColor($pValue = null)
{
$this->_bgColor = $pValue;
}
/**
* Set TLRBVH Border Size
*
* @param int $pValue Border size in eighths of a point (1/8 point)
*/
public function setBorderSize($pValue = null)
{
$this->_borderTopSize = $pValue;
$this->_borderLeftSize = $pValue;
$this->_borderRightSize = $pValue;
$this->_borderBottomSize = $pValue;
$this->_borderInsideHSize = $pValue;
$this->_borderInsideVSize = $pValue;
}
/**
* Get TLRBVH Border Size
*
* @return array
*/
public function getBorderSize()
{
$t = $this->getBorderTopSize();
$l = $this->getBorderLeftSize();
$r = $this->getBorderRightSize();
$b = $this->getBorderBottomSize();
$h = $this->getBorderInsideHSize();
$v = $this->getBorderInsideVSize();
return array($t, $l, $r, $b, $h, $v);
}
/**
* Set TLRBVH Border Color
* @param string $pValue
*/
public function setBorderColor($pValue = null)
{
$this->_borderTopColor = $pValue;
$this->_borderLeftColor = $pValue;
$this->_borderRightColor = $pValue;
$this->_borderBottomColor = $pValue;
$this->_borderInsideHColor = $pValue;
$this->_borderInsideVColor = $pValue;
}
/**
* Get TLRB Border Color
*
* @return array
*/
public function getBorderColor()
{
$t = $this->getBorderTopColor();
$l = $this->getBorderLeftColor();
$r = $this->getBorderRightColor();
$b = $this->getBorderBottomColor();
$h = $this->getBorderInsideHColor();
$v = $this->getBorderInsideVColor();
return array($t, $l, $r, $b, $h, $v);
}
/**
* Set border size top
*
* @param $pValue
*/
public function setBorderTopSize($pValue = null)
{
$this->_borderTopSize = $pValue;
}
/**
* Get border size top
*
* @return
*/
public function getBorderTopSize()
{
return $this->_borderTopSize;
}
/**
* Set border color top
*
* @param $pValue
*/
public function setBorderTopColor($pValue = null)
{
$this->_borderTopColor = $pValue;
}
/**
* Get border color top
*
* @return
*/
public function getBorderTopColor()
{
return $this->_borderTopColor;
}
/**
* Set border size left
*
* @param $pValue
*/
public function setBorderLeftSize($pValue = null)
{
$this->_borderLeftSize = $pValue;
}
/**
* Get border size left
*
* @return
*/
public function getBorderLeftSize()
{
return $this->_borderLeftSize;
}
/**
* Set border color left
*
* @param $pValue
*/
public function setBorderLeftColor($pValue = null)
{
$this->_borderLeftColor = $pValue;
}
/**
* Get border color left
*
* @return
*/
public function getBorderLeftColor()
{
return $this->_borderLeftColor;
}
/**
* Set border size right
*
* @param $pValue
*/
public function setBorderRightSize($pValue = null)
{
$this->_borderRightSize = $pValue;
}
/**
* Get border size right
*
* @return
*/
public function getBorderRightSize()
{
return $this->_borderRightSize;
}
/**
* Set border color right
*
* @param $pValue
*/
public function setBorderRightColor($pValue = null)
{
$this->_borderRightColor = $pValue;
}
/**
* Get border color right
*
* @return
*/
public function getBorderRightColor()
{
return $this->_borderRightColor;
}
/**
* Set border size bottom
*
* @param $pValue
*/
public function setBorderBottomSize($pValue = null)
{
$this->_borderBottomSize = $pValue;
}
/**
* Get border size bottom
*
* @return
*/
public function getBorderBottomSize()
{
return $this->_borderBottomSize;
}
/**
* Set border color bottom
*
* @param $pValue
*/
public function setBorderBottomColor($pValue = null)
{
$this->_borderBottomColor = $pValue;
}
/**
* Get border color bottom
*
* @return
*/
public function getBorderBottomColor()
{
return $this->_borderBottomColor;
}
/**
* Set border color inside horizontal
*
* @param $pValue
*/
public function setBorderInsideHColor($pValue = null)
{
$this->_borderInsideHColor = $pValue;
}
/**
* Get border color inside horizontal
*
* @return
*/
public function getBorderInsideHColor()
{
return (isset($this->_borderInsideHColor)) ? $this->_borderInsideHColor : null;
}
/**
* Set border color inside vertical
*
* @param $pValue
*/
public function setBorderInsideVColor($pValue = null)
{
$this->_borderInsideVColor = $pValue;
}
/**
* Get border color inside vertical
*
* @return
*/
public function getBorderInsideVColor()
{
return (isset($this->_borderInsideVColor)) ? $this->_borderInsideVColor : null;
}
/**
* Set border size inside horizontal
*
* @param $pValue
*/
public function setBorderInsideHSize($pValue = null)
{
$this->_borderInsideHSize = $pValue;
}
/**
* Get border size inside horizontal
*
* @return
*/
public function getBorderInsideHSize()
{
return (isset($this->_borderInsideHSize)) ? $this->_borderInsideHSize : null;
}
/**
* Set border size inside vertical
*
* @param $pValue
*/
public function setBorderInsideVSize($pValue = null)
{
$this->_borderInsideVSize = $pValue;
}
/**
* Get border size inside vertical
*
* @return
*/
public function getBorderInsideVSize()
{
return (isset($this->_borderInsideVSize)) ? $this->_borderInsideVSize : null;
}
/**
* Set cell margin top
*
* @param int $pValue
*/
public function setCellMarginTop($pValue = null)
{
$this->_cellMarginTop = $pValue;
}
/**
* Get cell margin top
*
* @return int
*/
public function getCellMarginTop()
{
return $this->_cellMarginTop;
}
/**
* Set cell margin left
*
* @param int $pValue
*/
public function setCellMarginLeft($pValue = null)
{
$this->_cellMarginLeft = $pValue;
}
/**
* Get cell margin left
*
* @return int
*/
public function getCellMarginLeft()
{
return $this->_cellMarginLeft;
}
/**
* Set cell margin right
*
* @param int $pValue
*/
public function setCellMarginRight($pValue = null)
{
$this->_cellMarginRight = $pValue;
}
/**
* Get cell margin right
*
* @return int
*/
public function getCellMarginRight()
{
return $this->_cellMarginRight;
}
/**
* Set cell margin bottom
*
* @param int $pValue
*/
public function setCellMarginBottom($pValue = null)
{
$this->_cellMarginBottom = $pValue;
}
/**
* Get cell margin bottom
*
* @return int
*/
public function getCellMarginBottom()
{
return $this->_cellMarginBottom;
}
/**
* Set TLRB cell margin
*
* @param int $pValue Margin in twips
*/
public function setCellMargin($pValue = null)
{
$this->_cellMarginTop = $pValue;
$this->_cellMarginLeft = $pValue;
$this->_cellMarginRight = $pValue;
$this->_cellMarginBottom = $pValue;
}
/**
* Get cell margin
*
* @return array
*/
public function getCellMargin()
{
return array($this->_cellMarginTop, $this->_cellMarginLeft, $this->_cellMarginRight, $this->_cellMarginBottom);
}
}

View File

@ -30,7 +30,6 @@ use PhpOffice\PhpWord\Section;
use PhpOffice\PhpWord\Section\Image;
use PhpOffice\PhpWord\Section\Link;
use PhpOffice\PhpWord\Section\ListItem;
use PhpOffice\PhpWord\Section\MemoryImage;
use PhpOffice\PhpWord\Section\Object;
use PhpOffice\PhpWord\Section\PageBreak;
use PhpOffice\PhpWord\Section\Table;
@ -281,8 +280,7 @@ class Content extends WriterPart
$this->writeUnsupportedElement($xmlWriter, 'Table');
} elseif ($element instanceof ListItem) {
$this->writeUnsupportedElement($xmlWriter, 'List Item');
} elseif ($element instanceof Image ||
$element instanceof MemoryImage) {
} elseif ($element instanceof Image) {
$this->writeUnsupportedElement($xmlWriter, 'Image');
} elseif ($element instanceof Object) {
$this->writeUnsupportedElement($xmlWriter, 'Object');

View File

@ -30,7 +30,7 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\Style\TableFull;
use PhpOffice\PhpWord\Style\Table;
/**
* ODText styloes part writer
@ -203,8 +203,8 @@ class Styles extends WriterPart
$xmlWriter->endElement();
$xmlWriter->endElement();
} elseif ($style instanceof TableFull) {
// PhpOffice\PhpWord\Style\TableFull
} elseif ($style instanceof Table) {
// PhpOffice\PhpWord\Style\Table
}
}
}

View File

@ -31,7 +31,6 @@ use PhpOffice\PhpWord\HashTable;
use PhpOffice\PhpWord\Section\Image;
use PhpOffice\PhpWord\Section\Link;
use PhpOffice\PhpWord\Section\ListItem;
use PhpOffice\PhpWord\Section\MemoryImage;
use PhpOffice\PhpWord\Section\Object;
use PhpOffice\PhpWord\Section\PageBreak;
use PhpOffice\PhpWord\Section\Table;
@ -379,8 +378,7 @@ class RTF implements IWriter
$sRTFBody .= $this->getDataContentUnsupportedElement('Table');
} elseif ($element instanceof ListItem) {
$sRTFBody .= $this->getDataContentUnsupportedElement('List Item');
} elseif ($element instanceof Image ||
$element instanceof MemoryImage) {
} elseif ($element instanceof Image) {
$sRTFBody .= $this->getDataContentUnsupportedElement('Image');
} elseif ($element instanceof Object) {
$sRTFBody .= $this->getDataContentUnsupportedElement('Object');

View File

@ -31,7 +31,6 @@ use PhpOffice\PhpWord\Section\Footnote;
use PhpOffice\PhpWord\Section\Image;
use PhpOffice\PhpWord\Section\Link;
use PhpOffice\PhpWord\Section\ListItem;
use PhpOffice\PhpWord\Section\MemoryImage;
use PhpOffice\PhpWord\Section\Object;
use PhpOffice\PhpWord\Section\Table;
use PhpOffice\PhpWord\Section\Text;
@ -575,7 +574,7 @@ class Base extends WriterPart
$tblStyle = $table->getStyle();
$tblWidth = $table->getWidth();
if ($tblStyle instanceof PhpOffice\PhpWord\Style\Table) {
$this->_writeTableStyle($xmlWriter, $tblStyle);
$this->_writeTableStyle($xmlWriter, $tblStyle, false);
} else {
if (!empty($tblStyle)) {
$xmlWriter->startElement('w:tblPr');
@ -652,9 +651,7 @@ class Base extends WriterPart
$this->_writeTextBreak($xmlWriter, $element);
} elseif ($element instanceof ListItem) {
$this->_writeListItem($xmlWriter, $element);
} elseif ($element instanceof Image ||
$element instanceof MemoryImage
) {
} elseif ($element instanceof Image) {
$this->_writeImage($xmlWriter, $element);
} elseif ($element instanceof Object) {
$this->_writeObject($xmlWriter, $element);
@ -679,52 +676,199 @@ class Base extends WriterPart
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param PhpOffice\PhpWord\Style\Table $style
* @param boolean $isFullStyle
*/
protected function _writeTableStyle(
XMLWriter $xmlWriter,
\PhpOffice\PhpWord\Style\Table $style = null
\PhpOffice\PhpWord\Style\Table $style,
$isFullStyle = true
) {
$margins = $style->getCellMargin();
$mTop = (!is_null($margins[0])) ? true : false;
$mLeft = (!is_null($margins[1])) ? true : false;
$mRight = (!is_null($margins[2])) ? true : false;
$mBottom = (!is_null($margins[3])) ? true : false;
$bgColor = $style->getBgColor();
$brdCol = $style->getBorderColor();
if ($mTop || $mLeft || $mRight || $mBottom) {
$brdSz = $style->getBorderSize();
$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;
$cellMargin = $style->getCellMargin();
$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;
if ($margins || $borders) {
$xmlWriter->startElement('w:tblPr');
$xmlWriter->startElement('w:tblCellMar');
if ($mTop) {
$xmlWriter->startElement('w:top');
$xmlWriter->writeAttribute('w:w', $margins[0]);
$xmlWriter->writeAttribute('w:type', 'dxa');
if ($margins) {
$xmlWriter->startElement('w:tblCellMar');
if ($mTop) {
echo $margins[0];
$xmlWriter->startElement('w:top');
$xmlWriter->writeAttribute('w:w', $cellMargin[0]);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement();
}
if ($mLeft) {
$xmlWriter->startElement('w:left');
$xmlWriter->writeAttribute('w:w', $cellMargin[1]);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement();
}
if ($mRight) {
$xmlWriter->startElement('w:right');
$xmlWriter->writeAttribute('w:w', $cellMargin[2]);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement();
}
if ($mBottom) {
$xmlWriter->startElement('w:bottom');
$xmlWriter->writeAttribute('w:w', $cellMargin[3]);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement();
}
$xmlWriter->endElement();
}
if ($mLeft) {
$xmlWriter->startElement('w:left');
$xmlWriter->writeAttribute('w:w', $margins[1]);
$xmlWriter->writeAttribute('w:type', 'dxa');
if ($borders) {
$xmlWriter->startElement('w:tblBorders');
if ($bTop) {
$xmlWriter->startElement('w:top');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[0]);
$xmlWriter->writeAttribute('w:color', $brdCol[0]);
$xmlWriter->endElement();
}
if ($bLeft) {
$xmlWriter->startElement('w:left');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[1]);
$xmlWriter->writeAttribute('w:color', $brdCol[1]);
$xmlWriter->endElement();
}
if ($bRight) {
$xmlWriter->startElement('w:right');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[2]);
$xmlWriter->writeAttribute('w:color', $brdCol[2]);
$xmlWriter->endElement();
}
if ($bBottom) {
$xmlWriter->startElement('w:bottom');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[3]);
$xmlWriter->writeAttribute('w:color', $brdCol[3]);
$xmlWriter->endElement();
}
if ($bInsH) {
$xmlWriter->startElement('w:insideH');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[4]);
$xmlWriter->writeAttribute('w:color', $brdCol[4]);
$xmlWriter->endElement();
}
if ($bInsV) {
$xmlWriter->startElement('w:insideV');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[5]);
$xmlWriter->writeAttribute('w:color', $brdCol[5]);
$xmlWriter->endElement();
}
$xmlWriter->endElement();
}
if ($mRight) {
$xmlWriter->startElement('w:right');
$xmlWriter->writeAttribute('w:w', $margins[2]);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement(); // w:tblPr
}
// Only write background color and first row for full style
if ($isFullStyle) {
// Background color
if (!is_null($bgColor)) {
$xmlWriter->startElement('w:tcPr');
$xmlWriter->startElement('w:shd');
$xmlWriter->writeAttribute('w:val', 'clear');
$xmlWriter->writeAttribute('w:color', 'auto');
$xmlWriter->writeAttribute('w:fill', $bgColor);
$xmlWriter->endElement();
$xmlWriter->endElement();
}
if ($mBottom) {
$xmlWriter->startElement('w:bottom');
$xmlWriter->writeAttribute('w:w', $margins[3]);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement();
// First Row
$firstRow = $style->getFirstRow();
if (!is_null($firstRow)) {
$this->_writeRowStyle($xmlWriter, 'firstRow', $firstRow);
}
}
}
$xmlWriter->endElement();
/**
* Write row style
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $type
* @param PhpOffice\PhpWord\Style\Table $style
*/
protected function _writeRowStyle(
XMLWriter $xmlWriter,
$type,
\PhpOffice\PhpWord\Style\Table $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;
$xmlWriter->startElement('w:tblStylePr');
$xmlWriter->writeAttribute('w:type', $type);
$xmlWriter->startElement('w:tcPr');
if (!is_null($bgColor)) {
$xmlWriter->startElement('w:shd');
$xmlWriter->writeAttribute('w:val', 'clear');
$xmlWriter->writeAttribute('w:color', 'auto');
$xmlWriter->writeAttribute('w:fill', $bgColor);
$xmlWriter->endElement();
}
$xmlWriter->startElement('w:tcBorders');
if ($bTop) {
$xmlWriter->startElement('w:top');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[0]);
$xmlWriter->writeAttribute('w:color', $brdCol[0]);
$xmlWriter->endElement();
}
if ($bLeft) {
$xmlWriter->startElement('w:left');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[1]);
$xmlWriter->writeAttribute('w:color', $brdCol[1]);
$xmlWriter->endElement();
}
if ($bRight) {
$xmlWriter->startElement('w:right');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[2]);
$xmlWriter->writeAttribute('w:color', $brdCol[2]);
$xmlWriter->endElement();
}
if ($bBottom) {
$xmlWriter->startElement('w:bottom');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[3]);
$xmlWriter->writeAttribute('w:color', $brdCol[3]);
$xmlWriter->endElement();
}
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement();
}
/**

View File

@ -31,7 +31,6 @@ use PhpOffice\PhpWord\Section\Footnote;
use PhpOffice\PhpWord\Section\Image;
use PhpOffice\PhpWord\Section\Link;
use PhpOffice\PhpWord\Section\ListItem;
use PhpOffice\PhpWord\Section\MemoryImage;
use PhpOffice\PhpWord\Section\Object;
use PhpOffice\PhpWord\Section\PageBreak;
use PhpOffice\PhpWord\Section\Table;
@ -108,9 +107,7 @@ class Document extends Base
$this->_writeTable($xmlWriter, $element);
} elseif ($element instanceof ListItem) {
$this->_writeListItem($xmlWriter, $element);
} elseif ($element instanceof Image ||
$element instanceof MemoryImage
) {
} elseif ($element instanceof Image) {
$this->_writeImage($xmlWriter, $element);
} elseif ($element instanceof Object) {
$this->_writeObject($xmlWriter, $element);

View File

@ -27,7 +27,6 @@ namespace PhpOffice\PhpWord\Writer\Word2007;
use PhpOffice\PhpWord\Section\Footer\PreserveText;
use PhpOffice\PhpWord\Section\Image;
use PhpOffice\PhpWord\Section\MemoryImage;
use PhpOffice\PhpWord\Section\Table;
use PhpOffice\PhpWord\Section\Text;
use PhpOffice\PhpWord\Section\TextBreak;
@ -79,9 +78,7 @@ class Footer extends Base
$this->_writeTextBreak($xmlWriter, $element);
} elseif ($element instanceof Table) {
$this->_writeTable($xmlWriter, $element);
} elseif ($element instanceof Image ||
$element instanceof MemoryImage
) {
} elseif ($element instanceof Image) {
$this->_writeImage($xmlWriter, $element);
} elseif ($element instanceof PreserveText) {
$this->_writePreserveText($xmlWriter, $element);

View File

@ -27,7 +27,6 @@ namespace PhpOffice\PhpWord\Writer\Word2007;
use PhpOffice\PhpWord\Section\Footer\PreserveText;
use PhpOffice\PhpWord\Section\Image;
use PhpOffice\PhpWord\Section\MemoryImage;
use PhpOffice\PhpWord\Section\Table;
use PhpOffice\PhpWord\Section\Text;
use PhpOffice\PhpWord\Section\TextBreak;
@ -79,9 +78,7 @@ class Header extends Base
$this->_writeTextBreak($xmlWriter, $element);
} elseif ($element instanceof Table) {
$this->_writeTable($xmlWriter, $element);
} elseif ($element instanceof Image ||
$element instanceof MemoryImage
) {
} elseif ($element instanceof Image) {
if (!$element->getIsWatermark()) {
$this->_writeImage($xmlWriter, $element);
} else {

View File

@ -30,7 +30,6 @@ use PhpOffice\PhpWord\Shared\XMLWriter;
use PhpOffice\PhpWord\Style;
use PhpOffice\PhpWord\Style\Font;
use PhpOffice\PhpWord\Style\Paragraph;
use PhpOffice\PhpWord\Style\TableFull;
/**
* Word2007 styles part writer
@ -72,7 +71,6 @@ class Styles extends Base
// Write DocDefaults
$this->_writeDocDefaults($xmlWriter);
// Write Style Definitions
$styles = Style::getStyles();
@ -170,7 +168,7 @@ class Styles extends Base
$this->_writeParagraphStyle($xmlWriter, $style);
$xmlWriter->endElement();
} elseif ($style instanceof TableFull) {
} elseif ($style instanceof \PhpOffice\PhpWord\Style\Table) {
$xmlWriter->startElement('w:style');
$xmlWriter->writeAttribute('w:type', 'table');
$xmlWriter->writeAttribute('w:customStyle', '1');
@ -184,9 +182,9 @@ class Styles extends Base
$xmlWriter->writeAttribute('w:val', '99');
$xmlWriter->endElement();
$this->_writeFullTableStyle($xmlWriter, $style);
$this->_writeTableStyle($xmlWriter, $style);
$xmlWriter->endElement();
$xmlWriter->endElement(); // w:style
}
}
}
@ -197,200 +195,6 @@ class Styles extends Base
return $xmlWriter->getData();
}
/**
* Write table style
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param PhpOffice\PhpWord\Style\TableFull $style
*/
private function _writeFullTableStyle(XMLWriter $xmlWriter, 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;
$xmlWriter->startElement('w:tblPr');
if ($margins) {
$xmlWriter->startElement('w:tblCellMar');
if ($mTop) {
echo $margins[0];
$xmlWriter->startElement('w:top');
$xmlWriter->writeAttribute('w:w', $cellMargin[0]);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement();
}
if ($mLeft) {
$xmlWriter->startElement('w:left');
$xmlWriter->writeAttribute('w:w', $cellMargin[1]);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement();
}
if ($mRight) {
$xmlWriter->startElement('w:right');
$xmlWriter->writeAttribute('w:w', $cellMargin[2]);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement();
}
if ($mBottom) {
$xmlWriter->startElement('w:bottom');
$xmlWriter->writeAttribute('w:w', $cellMargin[3]);
$xmlWriter->writeAttribute('w:type', 'dxa');
$xmlWriter->endElement();
}
$xmlWriter->endElement();
}
if ($borders) {
$xmlWriter->startElement('w:tblBorders');
if ($bTop) {
$xmlWriter->startElement('w:top');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[0]);
$xmlWriter->writeAttribute('w:color', $brdCol[0]);
$xmlWriter->endElement();
}
if ($bLeft) {
$xmlWriter->startElement('w:left');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[1]);
$xmlWriter->writeAttribute('w:color', $brdCol[1]);
$xmlWriter->endElement();
}
if ($bRight) {
$xmlWriter->startElement('w:right');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[2]);
$xmlWriter->writeAttribute('w:color', $brdCol[2]);
$xmlWriter->endElement();
}
if ($bBottom) {
$xmlWriter->startElement('w:bottom');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[3]);
$xmlWriter->writeAttribute('w:color', $brdCol[3]);
$xmlWriter->endElement();
}
if ($bInsH) {
$xmlWriter->startElement('w:insideH');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[4]);
$xmlWriter->writeAttribute('w:color', $brdCol[4]);
$xmlWriter->endElement();
}
if ($bInsV) {
$xmlWriter->startElement('w:insideV');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[5]);
$xmlWriter->writeAttribute('w:color', $brdCol[5]);
$xmlWriter->endElement();
}
$xmlWriter->endElement();
}
$xmlWriter->endElement();
if (!is_null($bgColor)) {
$xmlWriter->startElement('w:tcPr');
$xmlWriter->startElement('w:shd');
$xmlWriter->writeAttribute('w:val', 'clear');
$xmlWriter->writeAttribute('w:color', 'auto');
$xmlWriter->writeAttribute('w:fill', $bgColor);
$xmlWriter->endElement();
$xmlWriter->endElement();
}
// First Row
$firstRow = $style->getFirstRow();
if (!is_null($firstRow)) {
$this->_writeRowStyle($xmlWriter, 'firstRow', $firstRow);
}
}
/**
* Write first row style
*
* @param PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
* @param string $type
* @param PhpOffice\PhpWord\Style\TableFull $style
*/
private function _writeRowStyle(XMLWriter $xmlWriter, $type, 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;
$xmlWriter->startElement('w:tblStylePr');
$xmlWriter->writeAttribute('w:type', $type);
$xmlWriter->startElement('w:tcPr');
if (!is_null($bgColor)) {
$xmlWriter->startElement('w:shd');
$xmlWriter->writeAttribute('w:val', 'clear');
$xmlWriter->writeAttribute('w:color', 'auto');
$xmlWriter->writeAttribute('w:fill', $bgColor);
$xmlWriter->endElement();
}
$xmlWriter->startElement('w:tcBorders');
if ($bTop) {
$xmlWriter->startElement('w:top');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[0]);
$xmlWriter->writeAttribute('w:color', $brdCol[0]);
$xmlWriter->endElement();
}
if ($bLeft) {
$xmlWriter->startElement('w:left');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[1]);
$xmlWriter->writeAttribute('w:color', $brdCol[1]);
$xmlWriter->endElement();
}
if ($bRight) {
$xmlWriter->startElement('w:right');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[2]);
$xmlWriter->writeAttribute('w:color', $brdCol[2]);
$xmlWriter->endElement();
}
if ($bBottom) {
$xmlWriter->startElement('w:bottom');
$xmlWriter->writeAttribute('w:val', 'single');
$xmlWriter->writeAttribute('w:sz', $brdSz[3]);
$xmlWriter->writeAttribute('w:color', $brdCol[3]);
$xmlWriter->endElement();
}
$xmlWriter->endElement();
$xmlWriter->endElement();
$xmlWriter->endElement();
}
/**
* Write document defaults
*

View File

@ -101,7 +101,7 @@ class PhpWordTest extends \PHPUnit_Framework_TestCase
$styles = array(
'Paragraph' => 'Paragraph',
'Font' => 'Font',
'Table' => 'TableFull',
'Table' => 'Table',
'Link' => 'Font',
);
foreach ($styles as $key => $value) {

View File

@ -79,15 +79,15 @@ class FooterTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
}
public function testAddMemoryImage()
public function testAddImageByUrl()
{
$oFooter = new Footer(1);
$element = $oFooter->addMemoryImage(
$element = $oFooter->addImage(
'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'
);
$this->assertCount(1, $oFooter->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $element);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
}
public function testAddPreserveText()

View File

@ -76,15 +76,15 @@ class HeaderTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
}
public function testAddMemoryImage()
public function testAddImageByUrl()
{
$oHeader = new Header(1);
$element = $oHeader->addMemoryImage(
$element = $oHeader->addImage(
'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'
);
$this->assertCount(1, $oHeader->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $element);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
}
public function testAddPreserveText()

View File

@ -87,4 +87,56 @@ class ImageTest extends \PHPUnit_Framework_TestCase
$oImage->setIsWatermark(true);
$this->assertEquals($oImage->getIsWatermark(), true);
}
public function testPNG()
{
$src = __DIR__ . "/../_files/images/firefox.png";
$oImage = new Image($src);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $oImage);
$this->assertEquals($oImage->getSource(), $src);
$this->assertEquals($oImage->getMediaId(), md5($src));
$this->assertEquals($oImage->getImageCreateFunction(), 'imagecreatefrompng');
$this->assertEquals($oImage->getImageFunction(), 'imagepng');
$this->assertEquals($oImage->getImageExtension(), 'png');
$this->assertEquals($oImage->getImageType(), 'image/png');
}
public function testGIF()
{
$src = __DIR__ . "/../_files/images/mario.gif";
$oImage = new Image($src);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $oImage);
$this->assertEquals($oImage->getSource(), $src);
$this->assertEquals($oImage->getMediaId(), md5($src));
$this->assertEquals($oImage->getImageCreateFunction(), 'imagecreatefromgif');
$this->assertEquals($oImage->getImageFunction(), 'imagegif');
$this->assertEquals($oImage->getImageExtension(), 'gif');
$this->assertEquals($oImage->getImageType(), 'image/gif');
}
public function testJPG()
{
$src = __DIR__ . "/../_files/images/earth.jpg";
$oImage = new Image($src);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $oImage);
$this->assertEquals($oImage->getSource(), $src);
$this->assertEquals($oImage->getMediaId(), md5($src));
$this->assertEquals($oImage->getImageCreateFunction(), 'imagecreatefromjpeg');
$this->assertEquals($oImage->getImageFunction(), 'imagejpeg');
$this->assertEquals($oImage->getImageExtension(), 'jpg');
$this->assertEquals($oImage->getImageType(), 'image/jpeg');
}
public function testBMP()
{
$oImage = new Image(__DIR__ . "/../_files/images/duke_nukem.bmp");
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $oImage);
$this->assertEquals($oImage->getImageCreateFunction(), null);
$this->assertEquals($oImage->getImageFunction(), null);
$this->assertEquals($oImage->getImageExtension(), 'bmp');
$this->assertEquals($oImage->getImageType(), 'image/bmp');
}
}

View File

@ -1,78 +0,0 @@
<?php
namespace PhpOffice\PhpWord\Tests\Section;
use PhpOffice\PhpWord\Section\MemoryImage;
class MemoryImageTest extends \PHPUnit_Framework_TestCase
{
public function testPNG()
{
$src = __DIR__ . "/../_files/images/firefox.png";
$oMemoryImage = new MemoryImage($src);
$this->assertInstanceOf('PhpOffice\\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 = __DIR__ . "/../_files/images/mario.gif";
$oMemoryImage = new MemoryImage($src);
$this->assertInstanceOf('PhpOffice\\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 = __DIR__ . "/../_files/images/earth.jpg";
$oMemoryImage = new MemoryImage($src);
$this->assertInstanceOf('PhpOffice\\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 MemoryImage(__DIR__ . "/../_files/images/duke_nukem.bmp");
$this->assertInstanceOf('PhpOffice\\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 MemoryImage(
__DIR__ . "/../_files/images/earth.jpg",
array('width' => 210, 'height' => 210, 'align' => 'center')
);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Image', $oMemoryImage->getStyle());
}
public function testRelationID()
{
$oMemoryImage = new MemoryImage(__DIR__ . "/../_files/images/earth.jpg");
$iVal = rand(1, 1000);
$oMemoryImage->setRelationId($iVal);
$this->assertEquals($oMemoryImage->getRelationId(), $iVal);
}
}

View File

@ -117,37 +117,37 @@ class CellTest extends \PHPUnit_Framework_TestCase
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
}
public function testAddMemoryImageSection()
public function testAddSectionImageByUrl()
{
$oCell = new Cell('section', 1);
$element = $oCell->addMemoryImage(
$element = $oCell->addImage(
'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'
);
$this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $element);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
}
public function testAddMemoryImageHeader()
public function testAddHeaderImageByUrl()
{
$oCell = new Cell('header', 1);
$element = $oCell->addMemoryImage(
$element = $oCell->addImage(
'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'
);
$this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $element);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
}
public function testAddMemoryImageFooter()
public function testAddFooterImageByUrl()
{
$oCell = new Cell('footer', 1);
$element = $oCell->addMemoryImage(
$element = $oCell->addImage(
'https://assets.mozillalabs.com/Brands-Logos/Thunderbird/logo-only/thunderbird_logo-only_RGB.png'
);
$this->assertCount(1, $oCell->getElements());
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\MemoryImage', $element);
$this->assertInstanceOf('PhpOffice\\PhpWord\\Section\\Image', $element);
}
public function testAddObjectXLS()

View File

@ -65,7 +65,6 @@ class SectionTest extends \PHPUnit_Framework_TestCase
* @covers ::addListItem
* @covers ::addObject
* @covers ::addImage
* @covers ::addMemoryImage
* @covers ::addTOC
* @covers ::addTitle
* @covers ::createTextRun
@ -86,7 +85,7 @@ class SectionTest extends \PHPUnit_Framework_TestCase
$section->addListItem(utf8_decode('ä'));
$section->addObject($objectSource);
$section->addImage($imageSource);
$section->addMemoryImage($imageUrl);
$section->addImage($imageUrl);
$section->addTOC();
$section->addTitle(utf8_decode('ä'), 1);
$section->createTextRun();
@ -96,7 +95,7 @@ class SectionTest extends \PHPUnit_Framework_TestCase
$elementType = 'Link';
$this->assertInstanceOf("PhpOffice\\PhpWord\\Section\\{$elementType}", $elementCollection[1]);
// $elementTypes = array('Text', 'Link', 'TextBreak', 'PageBreak',
// 'Table', 'ListItem', 'Object', 'Image', 'MemoryImage', 'TOC',
// 'Table', 'ListItem', 'Object', 'Image', 'Image', 'TOC',
// 'Title', 'TextRun');
// $i = 0;
// foreach ($elementTypes as $elementType) {

View File

@ -1,130 +0,0 @@
<?php
namespace PhpOffice\PhpWord\Tests\Style;
use PhpOffice\PhpWord\Style\TableFull;
/**
* @runTestsInSeparateProcesses
*/
class TableFullTest extends \PHPUnit_Framework_TestCase
{
/**
* Test class construction
*
* There are 3 variables for class constructor:
* - $styleTable: Define table styles
* - $styleFirstRow: Define style for the first row
* - $styleLastRow: Define style for the last row (reserved)
*/
public function testConstruct()
{
$styleTable = array('bgColor' => 'FF0000');
$styleFirstRow = array('borderBottomSize' => 3);
$object = new TableFull($styleTable, $styleFirstRow);
$this->assertEquals('FF0000', $object->getBgColor());
$firstRow = $object->getFirstRow();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\TableFull', $firstRow);
$this->assertEquals(3, $firstRow->getBorderBottomSize());
}
/**
* Test setting style with normal value
*/
public function testSetGetNormal()
{
$object = new TableFull();
$attributes = array(
'bgColor' => 'FF0000',
'borderTopSize' => 4,
'borderTopColor' => 'FF0000',
'borderLeftSize' => 4,
'borderLeftColor' => 'FF0000',
'borderRightSize' => 4,
'borderRightColor' => 'FF0000',
'borderBottomSize' => 4,
'borderBottomColor' => 'FF0000',
'borderInsideHSize' => 4,
'borderInsideHColor' => 'FF0000',
'borderInsideVSize' => 4,
'borderInsideVColor' => 'FF0000',
'cellMarginTop' => 240,
'cellMarginLeft' => 240,
'cellMarginRight' => 240,
'cellMarginBottom' => 240,
);
foreach ($attributes as $key => $value) {
$set = "set{$key}";
$get = "get{$key}";
$object->$set($value);
$this->assertEquals($value, $object->$get());
}
}
/**
* Test border color
*
* Set border color and test if each part has the same color
* While looping, push values array to be asserted with getBorderColor
*/
public function testBorderColor()
{
$object = new TableFull();
$parts = array('Top', 'Left', 'Right', 'Bottom', 'InsideH', 'InsideV');
$value = 'FF0000';
$object->setBorderColor($value);
foreach ($parts as $part) {
$get = "getBorder{$part}Color";
$values[] = $value;
$this->assertEquals($value, $object->$get());
}
$this->assertEquals($values, $object->getBorderColor());
}
/**
* Test border size
*
* Set border size and test if each part has the same size
* While looping, push values array to be asserted with getBorderSize
* Value is in eights of a point, i.e. 4 / 8 = .5pt
*/
public function testBorderSize()
{
$object = new TableFull();
$parts = array('Top', 'Left', 'Right', 'Bottom', 'InsideH', 'InsideV');
$value = 4;
$object->setBorderSize($value);
foreach ($parts as $part) {
$get = "getBorder{$part}Size";
$values[] = $value;
$this->assertEquals($value, $object->$get());
}
$this->assertEquals($values, $object->getBorderSize());
}
/**
* Test cell margin
*
* Set cell margin and test if each part has the same margin
* While looping, push values array to be asserted with getCellMargin
* Value is in twips
*/
public function testCellMargin()
{
$object = new TableFull();
$parts = array('Top', 'Left', 'Right', 'Bottom');
$value = 240;
$object->setCellMargin($value);
foreach ($parts as $part) {
$get = "getCellMargin{$part}";
$values[] = $value;
$this->assertEquals($value, $object->$get());
}
$this->assertEquals($values, $object->getCellMargin());
}
}

View File

@ -9,38 +9,120 @@ use PhpOffice\PhpWord\Style\Table;
class TableTest extends \PHPUnit_Framework_TestCase
{
/**
* Test set style value
* Test class construction
*
* There are 3 variables for class constructor:
* - $styleTable: Define table styles
* - $styleFirstRow: Define style for the first row
* - $styleLastRow: Define style for the last row (reserved)
*/
public function testSetStyleValue()
public function testConstruct()
{
$styleTable = array('bgColor' => 'FF0000');
$styleFirstRow = array('borderBottomSize' => 3);
$object = new Table($styleTable, $styleFirstRow);
$this->assertEquals('FF0000', $object->getBgColor());
$firstRow = $object->getFirstRow();
$this->assertInstanceOf('PhpOffice\\PhpWord\\Style\\Table', $firstRow);
$this->assertEquals(3, $firstRow->getBorderBottomSize());
}
/**
* Test setting style with normal value
*/
public function testSetGetNormal()
{
$object = new 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);
$attributes = array(
'bgColor' => 'FF0000',
'borderTopSize' => 4,
'borderTopColor' => 'FF0000',
'borderLeftSize' => 4,
'borderLeftColor' => 'FF0000',
'borderRightSize' => 4,
'borderRightColor' => 'FF0000',
'borderBottomSize' => 4,
'borderBottomColor' => 'FF0000',
'borderInsideHSize' => 4,
'borderInsideHColor' => 'FF0000',
'borderInsideVSize' => 4,
'borderInsideVColor' => 'FF0000',
'cellMarginTop' => 240,
'cellMarginLeft' => 240,
'cellMarginRight' => 240,
'cellMarginBottom' => 240,
);
foreach ($attributes as $key => $value) {
$set = "set{$key}";
$get = "get{$key}";
$object->$set($value);
$this->assertEquals($value, $object->$get());
}
}
/**
* Test border color
*
* Set border color and test if each part has the same color
* While looping, push values array to be asserted with getBorderColor
*/
public function testBorderColor()
{
$object = new Table();
$parts = array('Top', 'Left', 'Right', 'Bottom', 'InsideH', 'InsideV');
$value = 'FF0000';
$object->setBorderColor($value);
foreach ($parts as $part) {
$get = "getBorder{$part}Color";
$values[] = $value;
$this->assertEquals($value, $object->$get());
}
$this->assertEquals($values, $object->getBorderColor());
}
/**
* Test border size
*
* Set border size and test if each part has the same size
* While looping, push values array to be asserted with getBorderSize
* Value is in eights of a point, i.e. 4 / 8 = .5pt
*/
public function testBorderSize()
{
$object = new Table();
$parts = array('Top', 'Left', 'Right', 'Bottom', 'InsideH', 'InsideV');
$value = 4;
$object->setBorderSize($value);
foreach ($parts as $part) {
$get = "getBorder{$part}Size";
$values[] = $value;
$this->assertEquals($value, $object->$get());
}
$this->assertEquals($values, $object->getBorderSize());
}
/**
* Test cell margin
*
* Set cell margin and test if each part has the same margin
* While looping, push values array to be asserted with getCellMargin
* Value is in twips
*/
public function testCellMargin()
{
$object = new 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
$value = 240;
$object->setCellMargin($value);
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

@ -21,7 +21,7 @@ class StyleTest extends \PHPUnit_Framework_TestCase
$font = array('italic' => true);
$table = array('bgColor' => 'CCCCCC');
$styles = array('Paragraph' => 'Paragraph', 'Font' => 'Font',
'Link' => 'Font', 'Table' => 'TableFull',
'Link' => 'Font', 'Table' => 'Table',
'Heading_1' => 'Font', 'Normal' => 'Paragraph');
$elementCount = 6;
Style::addParagraphStyle('Paragraph', $paragraph);

View File

@ -5,6 +5,7 @@ use PhpOffice\PhpWord\PhpWord;
use PhpOffice\PhpWord\Template;
/**
* @covers \PhpOffice\PhpWord\Template
* @coversDefaultClass \PhpOffice\PhpWord\Template
*/
final class TemplateTest extends \PHPUnit_Framework_TestCase
@ -115,8 +116,8 @@ final class TemplateTest extends \PHPUnit_Framework_TestCase
}
/**
* @covers ::setValue
* @covers ::getVariables
* @covers ::setValue
* @covers ::cloneRow
* @covers ::saveAs
*/
@ -126,13 +127,13 @@ final class TemplateTest extends \PHPUnit_Framework_TestCase
$expectedVar = array('tableHeader', 'userId', 'userName', 'userLocation');
$docName = 'clone-test-result.docx';
$phpWord = new PhpWord();
$document = $phpWord->loadTemplate($template);
$document = new Template($template);
$actualVar = $document->getVariables();
$document->setValue('tableHeader', utf8_decode('ééé'));
$document->cloneRow('userId', 1);
$document->setValue('userId#1', 'Test');
$document->saveAs($docName);
$docFound = \file_exists($docName);
$docFound = file_exists($docName);
unlink($docName);
$this->assertEquals($expectedVar, $actualVar);