2010-08-26 19:14:53 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* PHPExcel
|
|
|
|
*
|
2013-05-14 11:20:28 +00:00
|
|
|
* Copyright (c) 2006 - 2013 PHPExcel
|
2010-08-26 19:14:53 +00:00
|
|
|
*
|
|
|
|
* 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 PHPExcel
|
2010-12-09 12:07:50 +00:00
|
|
|
* @package PHPExcel_Style
|
2013-05-14 11:20:28 +00:00
|
|
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
2010-12-09 12:07:50 +00:00
|
|
|
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
|
|
|
* @version ##VERSION##, ##DATE##
|
2010-08-26 19:14:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* PHPExcel_Style_Alignment
|
|
|
|
*
|
|
|
|
* @category PHPExcel
|
2010-12-09 12:07:50 +00:00
|
|
|
* @package PHPExcel_Style
|
2013-05-14 11:20:28 +00:00
|
|
|
* @copyright Copyright (c) 2006 - 2013 PHPExcel (http://www.codeplex.com/PHPExcel)
|
2010-08-26 19:14:53 +00:00
|
|
|
*/
|
2012-10-23 12:16:30 +00:00
|
|
|
class PHPExcel_Style_Alignment extends PHPExcel_Style_Supervisor implements PHPExcel_IComparable
|
2010-08-26 19:14:53 +00:00
|
|
|
{
|
|
|
|
/* Horizontal alignment styles */
|
|
|
|
const HORIZONTAL_GENERAL = 'general';
|
|
|
|
const HORIZONTAL_LEFT = 'left';
|
|
|
|
const HORIZONTAL_RIGHT = 'right';
|
|
|
|
const HORIZONTAL_CENTER = 'center';
|
|
|
|
const HORIZONTAL_CENTER_CONTINUOUS = 'centerContinuous';
|
|
|
|
const HORIZONTAL_JUSTIFY = 'justify';
|
|
|
|
|
|
|
|
/* Vertical alignment styles */
|
|
|
|
const VERTICAL_BOTTOM = 'bottom';
|
|
|
|
const VERTICAL_TOP = 'top';
|
|
|
|
const VERTICAL_CENTER = 'center';
|
|
|
|
const VERTICAL_JUSTIFY = 'justify';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Horizontal
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2012-10-23 12:16:30 +00:00
|
|
|
protected $_horizontal = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL;
|
2010-08-26 19:14:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Vertical
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2012-10-23 12:16:30 +00:00
|
|
|
protected $_vertical = PHPExcel_Style_Alignment::VERTICAL_BOTTOM;
|
2010-08-26 19:14:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Text rotation
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
2012-10-23 12:16:30 +00:00
|
|
|
protected $_textRotation = 0;
|
2010-08-26 19:14:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrap text
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
2012-10-23 12:16:30 +00:00
|
|
|
protected $_wrapText = FALSE;
|
2010-08-26 19:14:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shrink to fit
|
|
|
|
*
|
|
|
|
* @var boolean
|
|
|
|
*/
|
2012-10-23 12:16:30 +00:00
|
|
|
protected $_shrinkToFit = FALSE;
|
2010-08-26 19:14:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Indent - only possible with horizontal alignment left and right
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
2012-10-23 12:16:30 +00:00
|
|
|
protected $_indent = 0;
|
2010-08-26 19:14:53 +00:00
|
|
|
|
2010-12-09 12:07:50 +00:00
|
|
|
/**
|
|
|
|
* Create a new PHPExcel_Style_Alignment
|
2012-03-18 16:26:03 +00:00
|
|
|
*
|
|
|
|
* @param boolean $isSupervisor Flag indicating if this is a supervisor or not
|
2012-07-02 21:38:24 +00:00
|
|
|
* Leave this value at default unless you understand exactly what
|
|
|
|
* its ramifications are
|
|
|
|
* @param boolean $isConditional Flag indicating if this is a conditional style or not
|
|
|
|
* Leave this value at default unless you understand exactly what
|
|
|
|
* its ramifications are
|
2010-12-09 12:07:50 +00:00
|
|
|
*/
|
2012-10-23 12:16:30 +00:00
|
|
|
public function __construct($isSupervisor = FALSE, $isConditional = FALSE)
|
2010-12-09 12:07:50 +00:00
|
|
|
{
|
|
|
|
// Supervisor?
|
2012-10-23 12:16:30 +00:00
|
|
|
parent::__construct($isSupervisor);
|
2012-07-02 21:38:24 +00:00
|
|
|
|
|
|
|
if ($isConditional) {
|
|
|
|
$this->_horizontal = NULL;
|
|
|
|
$this->_vertical = NULL;
|
|
|
|
$this->_textRotation = NULL;
|
|
|
|
}
|
2010-12-09 12:07:50 +00:00
|
|
|
}
|
2010-08-26 19:14:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the shared style component for the currently active cell in currently active sheet.
|
|
|
|
* Only used for style supervisor
|
|
|
|
*
|
|
|
|
* @return PHPExcel_Style_Alignment
|
|
|
|
*/
|
|
|
|
public function getSharedComponent()
|
|
|
|
{
|
|
|
|
return $this->_parent->getSharedComponent()->getAlignment();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build style array from subcomponents
|
|
|
|
*
|
|
|
|
* @param array $array
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function getStyleArray($array)
|
|
|
|
{
|
|
|
|
return array('alignment' => $array);
|
|
|
|
}
|
|
|
|
|
2010-12-09 12:07:50 +00:00
|
|
|
/**
|
|
|
|
* Apply styles from array
|
|
|
|
*
|
|
|
|
* <code>
|
|
|
|
* $objPHPExcel->getActiveSheet()->getStyle('B2')->getAlignment()->applyFromArray(
|
|
|
|
* array(
|
|
|
|
* 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
|
|
|
|
* 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
|
|
|
|
* 'rotation' => 0,
|
2012-10-23 12:16:30 +00:00
|
|
|
* 'wrap' => TRUE
|
2010-12-09 12:07:50 +00:00
|
|
|
* )
|
|
|
|
* );
|
|
|
|
* </code>
|
|
|
|
*
|
|
|
|
* @param array $pStyles Array containing style information
|
2012-10-23 12:16:30 +00:00
|
|
|
* @throws PHPExcel_Exception
|
2010-12-09 12:07:50 +00:00
|
|
|
* @return PHPExcel_Style_Alignment
|
|
|
|
*/
|
2012-10-23 12:16:30 +00:00
|
|
|
public function applyFromArray($pStyles = NULL) {
|
2010-08-26 19:14:53 +00:00
|
|
|
if (is_array($pStyles)) {
|
|
|
|
if ($this->_isSupervisor) {
|
2012-10-23 12:16:30 +00:00
|
|
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())
|
|
|
|
->applyFromArray($this->getStyleArray($pStyles));
|
2010-08-26 19:14:53 +00:00
|
|
|
} else {
|
2012-10-23 12:16:30 +00:00
|
|
|
if (isset($pStyles['horizontal'])) {
|
2010-08-26 19:14:53 +00:00
|
|
|
$this->setHorizontal($pStyles['horizontal']);
|
|
|
|
}
|
2012-10-23 12:16:30 +00:00
|
|
|
if (isset($pStyles['vertical'])) {
|
2010-08-26 19:14:53 +00:00
|
|
|
$this->setVertical($pStyles['vertical']);
|
|
|
|
}
|
2012-10-23 12:16:30 +00:00
|
|
|
if (isset($pStyles['rotation'])) {
|
2010-08-26 19:14:53 +00:00
|
|
|
$this->setTextRotation($pStyles['rotation']);
|
|
|
|
}
|
2012-10-23 12:16:30 +00:00
|
|
|
if (isset($pStyles['wrap'])) {
|
2010-08-26 19:14:53 +00:00
|
|
|
$this->setWrapText($pStyles['wrap']);
|
|
|
|
}
|
2012-10-23 12:16:30 +00:00
|
|
|
if (isset($pStyles['shrinkToFit'])) {
|
2010-08-26 19:14:53 +00:00
|
|
|
$this->setShrinkToFit($pStyles['shrinkToFit']);
|
|
|
|
}
|
2012-10-23 12:16:30 +00:00
|
|
|
if (isset($pStyles['indent'])) {
|
2010-08-26 19:14:53 +00:00
|
|
|
$this->setIndent($pStyles['indent']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2012-10-23 12:16:30 +00:00
|
|
|
throw new PHPExcel_Exception("Invalid style array passed.");
|
2010-08-26 19:14:53 +00:00
|
|
|
}
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2010-12-09 12:07:50 +00:00
|
|
|
/**
|
|
|
|
* Get Horizontal
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getHorizontal() {
|
2010-08-26 19:14:53 +00:00
|
|
|
if ($this->_isSupervisor) {
|
|
|
|
return $this->getSharedComponent()->getHorizontal();
|
|
|
|
}
|
2010-12-09 12:07:50 +00:00
|
|
|
return $this->_horizontal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set Horizontal
|
|
|
|
*
|
|
|
|
* @param string $pValue
|
|
|
|
* @return PHPExcel_Style_Alignment
|
|
|
|
*/
|
|
|
|
public function setHorizontal($pValue = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL) {
|
|
|
|
if ($pValue == '') {
|
|
|
|
$pValue = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL;
|
|
|
|
}
|
2010-08-26 19:14:53 +00:00
|
|
|
|
|
|
|
if ($this->_isSupervisor) {
|
|
|
|
$styleArray = $this->getStyleArray(array('horizontal' => $pValue));
|
|
|
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$this->_horizontal = $pValue;
|
|
|
|
}
|
|
|
|
return $this;
|
2010-12-09 12:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Vertical
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getVertical() {
|
2010-08-26 19:14:53 +00:00
|
|
|
if ($this->_isSupervisor) {
|
|
|
|
return $this->getSharedComponent()->getVertical();
|
|
|
|
}
|
2010-12-09 12:07:50 +00:00
|
|
|
return $this->_vertical;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set Vertical
|
|
|
|
*
|
|
|
|
* @param string $pValue
|
|
|
|
* @return PHPExcel_Style_Alignment
|
|
|
|
*/
|
|
|
|
public function setVertical($pValue = PHPExcel_Style_Alignment::VERTICAL_BOTTOM) {
|
|
|
|
if ($pValue == '') {
|
|
|
|
$pValue = PHPExcel_Style_Alignment::VERTICAL_BOTTOM;
|
|
|
|
}
|
2010-08-26 19:14:53 +00:00
|
|
|
|
|
|
|
if ($this->_isSupervisor) {
|
|
|
|
$styleArray = $this->getStyleArray(array('vertical' => $pValue));
|
|
|
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
|
|
|
|
} else {
|
|
|
|
$this->_vertical = $pValue;
|
|
|
|
}
|
|
|
|
return $this;
|
2010-12-09 12:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get TextRotation
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getTextRotation() {
|
2010-08-26 19:14:53 +00:00
|
|
|
if ($this->_isSupervisor) {
|
|
|
|
return $this->getSharedComponent()->getTextRotation();
|
|
|
|
}
|
2010-12-09 12:07:50 +00:00
|
|
|
return $this->_textRotation;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set TextRotation
|
|
|
|
*
|
|
|
|
* @param int $pValue
|
2012-10-23 12:16:30 +00:00
|
|
|
* @throws PHPExcel_Exception
|
2010-12-09 12:07:50 +00:00
|
|
|
* @return PHPExcel_Style_Alignment
|
|
|
|
*/
|
|
|
|
public function setTextRotation($pValue = 0) {
|
2010-08-26 19:14:53 +00:00
|
|
|
// Excel2007 value 255 => PHPExcel value -165
|
2010-12-09 12:07:50 +00:00
|
|
|
if ($pValue == 255) {
|
|
|
|
$pValue = -165;
|
|
|
|
}
|
2010-08-26 19:14:53 +00:00
|
|
|
|
|
|
|
// Set rotation
|
2010-12-09 12:07:50 +00:00
|
|
|
if ( ($pValue >= -90 && $pValue <= 90) || $pValue == -165 ) {
|
2010-08-26 19:14:53 +00:00
|
|
|
if ($this->_isSupervisor) {
|
|
|
|
$styleArray = $this->getStyleArray(array('rotation' => $pValue));
|
|
|
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
|
|
|
|
} else {
|
|
|
|
$this->_textRotation = $pValue;
|
|
|
|
}
|
2010-12-09 12:07:50 +00:00
|
|
|
} else {
|
2012-10-23 12:16:30 +00:00
|
|
|
throw new PHPExcel_Exception("Text rotation should be a value between -90 and 90.");
|
2010-12-09 12:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Wrap Text
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function getWrapText() {
|
2010-08-26 19:14:53 +00:00
|
|
|
if ($this->_isSupervisor) {
|
|
|
|
return $this->getSharedComponent()->getWrapText();
|
|
|
|
}
|
2010-12-09 12:07:50 +00:00
|
|
|
return $this->_wrapText;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set Wrap Text
|
|
|
|
*
|
|
|
|
* @param boolean $pValue
|
|
|
|
* @return PHPExcel_Style_Alignment
|
|
|
|
*/
|
2012-10-23 12:16:30 +00:00
|
|
|
public function setWrapText($pValue = FALSE) {
|
2010-12-09 12:07:50 +00:00
|
|
|
if ($pValue == '') {
|
2012-10-23 12:16:30 +00:00
|
|
|
$pValue = FALSE;
|
2010-12-09 12:07:50 +00:00
|
|
|
}
|
2010-08-26 19:14:53 +00:00
|
|
|
if ($this->_isSupervisor) {
|
|
|
|
$styleArray = $this->getStyleArray(array('wrap' => $pValue));
|
|
|
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
|
|
|
|
} else {
|
|
|
|
$this->_wrapText = $pValue;
|
|
|
|
}
|
|
|
|
return $this;
|
2010-12-09 12:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Shrink to fit
|
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function getShrinkToFit() {
|
2010-08-26 19:14:53 +00:00
|
|
|
if ($this->_isSupervisor) {
|
|
|
|
return $this->getSharedComponent()->getShrinkToFit();
|
|
|
|
}
|
2010-12-09 12:07:50 +00:00
|
|
|
return $this->_shrinkToFit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set Shrink to fit
|
|
|
|
*
|
|
|
|
* @param boolean $pValue
|
|
|
|
* @return PHPExcel_Style_Alignment
|
|
|
|
*/
|
2012-10-23 12:16:30 +00:00
|
|
|
public function setShrinkToFit($pValue = FALSE) {
|
2010-12-09 12:07:50 +00:00
|
|
|
if ($pValue == '') {
|
2012-10-23 12:16:30 +00:00
|
|
|
$pValue = FALSE;
|
2010-12-09 12:07:50 +00:00
|
|
|
}
|
2010-08-26 19:14:53 +00:00
|
|
|
if ($this->_isSupervisor) {
|
|
|
|
$styleArray = $this->getStyleArray(array('shrinkToFit' => $pValue));
|
|
|
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
|
|
|
|
} else {
|
|
|
|
$this->_shrinkToFit = $pValue;
|
|
|
|
}
|
|
|
|
return $this;
|
2010-12-09 12:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get indent
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getIndent() {
|
2010-08-26 19:14:53 +00:00
|
|
|
if ($this->_isSupervisor) {
|
|
|
|
return $this->getSharedComponent()->getIndent();
|
|
|
|
}
|
2010-12-09 12:07:50 +00:00
|
|
|
return $this->_indent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set indent
|
|
|
|
*
|
|
|
|
* @param int $pValue
|
|
|
|
* @return PHPExcel_Style_Alignment
|
|
|
|
*/
|
|
|
|
public function setIndent($pValue = 0) {
|
2010-08-26 19:14:53 +00:00
|
|
|
if ($pValue > 0) {
|
2012-10-23 12:16:30 +00:00
|
|
|
if ($this->getHorizontal() != self::HORIZONTAL_GENERAL &&
|
|
|
|
$this->getHorizontal() != self::HORIZONTAL_LEFT &&
|
|
|
|
$this->getHorizontal() != self::HORIZONTAL_RIGHT) {
|
2010-08-26 19:14:53 +00:00
|
|
|
$pValue = 0; // indent not supported
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($this->_isSupervisor) {
|
|
|
|
$styleArray = $this->getStyleArray(array('indent' => $pValue));
|
|
|
|
$this->getActiveSheet()->getStyle($this->getSelectedCells())->applyFromArray($styleArray);
|
|
|
|
} else {
|
|
|
|
$this->_indent = $pValue;
|
|
|
|
}
|
|
|
|
return $this;
|
2010-12-09 12:07:50 +00:00
|
|
|
}
|
2010-08-26 19:14:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get hash code
|
|
|
|
*
|
|
|
|
* @return string Hash code
|
|
|
|
*/
|
|
|
|
public function getHashCode() {
|
|
|
|
if ($this->_isSupervisor) {
|
|
|
|
return $this->getSharedComponent()->getHashCode();
|
|
|
|
}
|
2010-12-09 12:07:50 +00:00
|
|
|
return md5(
|
|
|
|
$this->_horizontal
|
|
|
|
. $this->_vertical
|
|
|
|
. $this->_textRotation
|
|
|
|
. ($this->_wrapText ? 't' : 'f')
|
|
|
|
. ($this->_shrinkToFit ? 't' : 'f')
|
2010-08-26 19:14:53 +00:00
|
|
|
. $this->_indent
|
2010-12-09 12:07:50 +00:00
|
|
|
. __CLASS__
|
|
|
|
);
|
|
|
|
}
|
2010-08-26 19:14:53 +00:00
|
|
|
|
|
|
|
}
|