From 756dfad85aef13f8f79e9276c835266a7dbb3f88 Mon Sep 17 00:00:00 2001 From: Dominik Bonsch Date: Tue, 22 Jan 2013 20:10:01 +0100 Subject: [PATCH 01/17] added the actual number of sheets in the out of bounds exception --- Classes/PHPExcel.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Classes/PHPExcel.php b/Classes/PHPExcel.php index 8d4101ce..8f40bd67 100644 --- a/Classes/PHPExcel.php +++ b/Classes/PHPExcel.php @@ -260,8 +260,11 @@ class PHPExcel */ public function removeSheetByIndex($pIndex = 0) { + + $numSheets = count($this->_workSheetCollection); + if ($pIndex > count($this->_workSheetCollection) - 1) { - throw new PHPExcel_Exception("Sheet index is out of bounds."); + throw new PHPExcel_Exception("Sheet index is out of bounds. Actual number of sheets is {$numSheets}"); } else { array_splice($this->_workSheetCollection, $pIndex, 1); } @@ -282,8 +285,11 @@ class PHPExcel */ public function getSheet($pIndex = 0) { - if ($pIndex > count($this->_workSheetCollection) - 1) { - throw new PHPExcel_Exception("Sheet index is out of bounds."); + + $numSheets = count($this->_workSheetCollection); + + if ($pIndex > $numSheets - 1) { + throw new PHPExcel_Exception("Sheet index is out of bounds. Actual number of sheets is {$numSheets}"); } else { return $this->_workSheetCollection[$pIndex]; } From 9926c643141ee0b03aa480835989be2b29fe53a8 Mon Sep 17 00:00:00 2001 From: Dominik Bonsch Date: Tue, 22 Jan 2013 20:12:12 +0100 Subject: [PATCH 02/17] added the requested index to the out of bounds exception --- Classes/PHPExcel.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Classes/PHPExcel.php b/Classes/PHPExcel.php index 8f40bd67..8304b18f 100644 --- a/Classes/PHPExcel.php +++ b/Classes/PHPExcel.php @@ -227,7 +227,9 @@ class PHPExcel public function addSheet(PHPExcel_Worksheet $pSheet, $iSheetIndex = NULL) { if ($this->sheetNameExists($pSheet->getTitle())) { - throw new PHPExcel_Exception("Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename this worksheet first."); + throw new PHPExcel_Exception( + "Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename this worksheet first." + ); } if($iSheetIndex === NULL) { @@ -264,7 +266,9 @@ class PHPExcel $numSheets = count($this->_workSheetCollection); if ($pIndex > count($this->_workSheetCollection) - 1) { - throw new PHPExcel_Exception("Sheet index is out of bounds. Actual number of sheets is {$numSheets}"); + throw new PHPExcel_Exception( + "The requested Sheet index: {$pIndex} is out of bounds. Actual number of sheets is {$numSheets}" + ); } else { array_splice($this->_workSheetCollection, $pIndex, 1); } @@ -289,7 +293,9 @@ class PHPExcel $numSheets = count($this->_workSheetCollection); if ($pIndex > $numSheets - 1) { - throw new PHPExcel_Exception("Sheet index is out of bounds. Actual number of sheets is {$numSheets}"); + throw new PHPExcel_Exception( + "The requested Sheet index: {$pIndex} is out of bounds. Actual number of sheets is {$numSheets}" + ); } else { return $this->_workSheetCollection[$pIndex]; } From aadc933827ff66178ad0737f794d37450550b605 Mon Sep 17 00:00:00 2001 From: Dominik Bonsch Date: Tue, 22 Jan 2013 20:19:06 +0100 Subject: [PATCH 03/17] Still improving the out of bounds error messages in the exceptions. --- Classes/PHPExcel.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Classes/PHPExcel.php b/Classes/PHPExcel.php index 8304b18f..614fa78d 100644 --- a/Classes/PHPExcel.php +++ b/Classes/PHPExcel.php @@ -267,7 +267,7 @@ class PHPExcel if ($pIndex > count($this->_workSheetCollection) - 1) { throw new PHPExcel_Exception( - "The requested Sheet index: {$pIndex} is out of bounds. Actual number of sheets is {$numSheets}" + "Your requested sheet index: {$pIndex} is out of bounds. The actual number of sheets is {$numSheets}" ); } else { array_splice($this->_workSheetCollection, $pIndex, 1); @@ -294,7 +294,7 @@ class PHPExcel if ($pIndex > $numSheets - 1) { throw new PHPExcel_Exception( - "The requested Sheet index: {$pIndex} is out of bounds. Actual number of sheets is {$numSheets}" + "Your requested sheet index: {$pIndex} is out of bounds. The actual number of sheets is {$numSheets}" ); } else { return $this->_workSheetCollection[$pIndex]; @@ -401,8 +401,12 @@ class PHPExcel */ public function setActiveSheetIndex($pIndex = 0) { - if ($pIndex > count($this->_workSheetCollection) - 1) { - throw new PHPExcel_Exception("Active sheet index is out of bounds."); + $numSheets = count($this->_workSheetCollection); + + if ($pIndex > $numSheets - 1) { + throw new PHPExcel_Exception( + "You tried to set a sheet active by an out of bounds index: {$pIndex}. The actual number of sheets is {$numSheets}." + ); } else { $this->_activeSheetIndex = $pIndex; } From acca05f1cfcc51bfdd91d00ede50d07d002e75ed Mon Sep 17 00:00:00 2001 From: Dominik Bonsch Date: Tue, 22 Jan 2013 20:39:45 +0100 Subject: [PATCH 04/17] minor architecture improvement - used strtoupper to get rid of case sensitive name checks - added "else if", it's not nessecary to check for the second "if", if the first one was allready true --- Classes/PHPExcel/Shared/OLERead.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Classes/PHPExcel/Shared/OLERead.php b/Classes/PHPExcel/Shared/OLERead.php index f67eeac3..6f2696ed 100644 --- a/Classes/PHPExcel/Shared/OLERead.php +++ b/Classes/PHPExcel/Shared/OLERead.php @@ -251,19 +251,22 @@ class PHPExcel_Shared_OLERead { $name = str_replace("\x00", "", substr($d,0,$nameSize)); + $this->props[] = array ( 'name' => $name, 'type' => $type, 'startBlock' => $startBlock, 'size' => $size); + // tmp helper to simplify checks + $upName = strtoupper($name); + // Workbook directory entry (BIFF5 uses Book, BIFF8 uses Workbook) - if (($name == 'Workbook') || ($name == 'Book') || ($name == 'WORKBOOK') || ($name == 'BOOK')) { + if (($upName === 'WORKBOOK') || ($upName === 'BOOK')) { $this->wrkbook = count($this->props) - 1; } - - // Root entry - if ($name == 'Root Entry' || $name == 'ROOT ENTRY' || $name == 'R') { + else if ( $upName === 'ROOT ENTRY' || $upName === 'R') { + // Root entry $this->rootentry = count($this->props) - 1; } From 7dbe92b8219fa2257c864c39f125ac2125690516 Mon Sep 17 00:00:00 2001 From: Dominik Bonsch Date: Tue, 22 Jan 2013 20:43:49 +0100 Subject: [PATCH 05/17] Improved the phrasing of the error messages. --- Classes/PHPExcel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Classes/PHPExcel.php b/Classes/PHPExcel.php index 614fa78d..1c815843 100644 --- a/Classes/PHPExcel.php +++ b/Classes/PHPExcel.php @@ -265,9 +265,9 @@ class PHPExcel $numSheets = count($this->_workSheetCollection); - if ($pIndex > count($this->_workSheetCollection) - 1) { + if ($pIndex > $numSheets - 1) { throw new PHPExcel_Exception( - "Your requested sheet index: {$pIndex} is out of bounds. The actual number of sheets is {$numSheets}" + "You tried to remove a sheet by the out of bounds index: {$pIndex}. The actual number of sheets is {$numSheets}." ); } else { array_splice($this->_workSheetCollection, $pIndex, 1); @@ -294,7 +294,7 @@ class PHPExcel if ($pIndex > $numSheets - 1) { throw new PHPExcel_Exception( - "Your requested sheet index: {$pIndex} is out of bounds. The actual number of sheets is {$numSheets}" + "Your requested sheet index: {$pIndex} is out of bounds. The actual number of sheets is {$numSheets}." ); } else { return $this->_workSheetCollection[$pIndex]; @@ -405,7 +405,7 @@ class PHPExcel if ($pIndex > $numSheets - 1) { throw new PHPExcel_Exception( - "You tried to set a sheet active by an out of bounds index: {$pIndex}. The actual number of sheets is {$numSheets}." + "You tried to set a sheet active by the out of bounds index: {$pIndex}. The actual number of sheets is {$numSheets}." ); } else { $this->_activeSheetIndex = $pIndex; From b102d52c58f6d6c3560d04dd94e90308438fe25a Mon Sep 17 00:00:00 2001 From: Dominik Bonsch Date: Tue, 22 Jan 2013 20:56:41 +0100 Subject: [PATCH 06/17] replaced tabs by 4 spaces --- Classes/PHPExcel/Comment.php | 204 +++++++++++++++++------------------ 1 file changed, 102 insertions(+), 102 deletions(-) diff --git a/Classes/PHPExcel/Comment.php b/Classes/PHPExcel/Comment.php index cb846292..47db7ecd 100644 --- a/Classes/PHPExcel/Comment.php +++ b/Classes/PHPExcel/Comment.php @@ -21,7 +21,7 @@ * @category PHPExcel * @package PHPExcel * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version ##VERSION##, ##DATE## */ @@ -35,68 +35,68 @@ */ class PHPExcel_Comment implements PHPExcel_IComparable { - /** - * Author - * - * @var string - */ - private $_author; + /** + * Author + * + * @var string + */ + private $_author; - /** - * Rich text comment - * - * @var PHPExcel_RichText - */ - private $_text; + /** + * Rich text comment + * + * @var PHPExcel_RichText + */ + private $_text; - /** - * Comment width (CSS style, i.e. XXpx or YYpt) - * - * @var string - */ - private $_width = '96pt'; + /** + * Comment width (CSS style, i.e. XXpx or YYpt) + * + * @var string + */ + private $_width = '96pt'; - /** - * Left margin (CSS style, i.e. XXpx or YYpt) - * - * @var string - */ - private $_marginLeft = '59.25pt'; + /** + * Left margin (CSS style, i.e. XXpx or YYpt) + * + * @var string + */ + private $_marginLeft = '59.25pt'; - /** - * Top margin (CSS style, i.e. XXpx or YYpt) - * - * @var string - */ - private $_marginTop = '1.5pt'; + /** + * Top margin (CSS style, i.e. XXpx or YYpt) + * + * @var string + */ + private $_marginTop = '1.5pt'; - /** - * Visible - * - * @var boolean - */ - private $_visible = false; + /** + * Visible + * + * @var boolean + */ + private $_visible = false; - /** - * Comment height (CSS style, i.e. XXpx or YYpt) - * - * @var string - */ - private $_height = '55.5pt'; + /** + * Comment height (CSS style, i.e. XXpx or YYpt) + * + * @var string + */ + private $_height = '55.5pt'; - /** - * Comment fill color - * - * @var PHPExcel_Style_Color - */ - private $_fillColor; + /** + * Comment fill color + * + * @var PHPExcel_Style_Color + */ + private $_fillColor; - /** - * Alignment - * - * @var string - */ - private $_alignment; + /** + * Alignment + * + * @var string + */ + private $_alignment; /** * Create a new PHPExcel_Comment @@ -105,11 +105,11 @@ class PHPExcel_Comment implements PHPExcel_IComparable */ public function __construct() { - // Initialise variables - $this->_author = 'Author'; - $this->_text = new PHPExcel_RichText(); - $this->_fillColor = new PHPExcel_Style_Color('FFFFFFE1'); - $this->_alignment = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL; + // Initialise variables + $this->_author = 'Author'; + $this->_text = new PHPExcel_RichText(); + $this->_fillColor = new PHPExcel_Style_Color('FFFFFFE1'); + $this->_alignment = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL; } /** @@ -118,7 +118,7 @@ class PHPExcel_Comment implements PHPExcel_IComparable * @return string */ public function getAuthor() { - return $this->_author; + return $this->_author; } /** @@ -127,10 +127,10 @@ class PHPExcel_Comment implements PHPExcel_IComparable * @param string $pValue * @return PHPExcel_Comment */ - public function setAuthor($pValue = '') { - $this->_author = $pValue; - return $this; - } + public function setAuthor($pValue = '') { + $this->_author = $pValue; + return $this; + } /** * Get Rich text comment @@ -138,7 +138,7 @@ class PHPExcel_Comment implements PHPExcel_IComparable * @return PHPExcel_RichText */ public function getText() { - return $this->_text; + return $this->_text; } /** @@ -148,8 +148,8 @@ class PHPExcel_Comment implements PHPExcel_IComparable * @return PHPExcel_Comment */ public function setText(PHPExcel_RichText $pValue) { - $this->_text = $pValue; - return $this; + $this->_text = $pValue; + return $this; } /** @@ -268,8 +268,8 @@ class PHPExcel_Comment implements PHPExcel_IComparable * @return PHPExcel_Comment */ public function setAlignment($pValue = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL) { - $this->_alignment = $pValue; - return $this; + $this->_alignment = $pValue; + return $this; } /** @@ -278,40 +278,40 @@ class PHPExcel_Comment implements PHPExcel_IComparable * @return string */ public function getAlignment() { - return $this->_alignment; + return $this->_alignment; } - /** - * Get hash code - * - * @return string Hash code - */ - public function getHashCode() { - return md5( - $this->_author - . $this->_text->getHashCode() - . $this->_width - . $this->_height - . $this->_marginLeft - . $this->_marginTop - . ($this->_visible ? 1 : 0) - . $this->_fillColor->getHashCode() - . $this->_alignment - . __CLASS__ - ); + /** + * Get hash code + * + * @return string Hash code + */ + public function getHashCode() { + return md5( + $this->_author + . $this->_text->getHashCode() + . $this->_width + . $this->_height + . $this->_marginLeft + . $this->_marginTop + . ($this->_visible ? 1 : 0) + . $this->_fillColor->getHashCode() + . $this->_alignment + . __CLASS__ + ); } - /** - * Implement PHP __clone to create a deep clone, not just a shallow copy. - */ - public function __clone() { - $vars = get_object_vars($this); - foreach ($vars as $key => $value) { - if (is_object($value)) { - $this->$key = clone $value; - } else { - $this->$key = $value; - } - } - } + /** + * Implement PHP __clone to create a deep clone, not just a shallow copy. + */ + public function __clone() { + $vars = get_object_vars($this); + foreach ($vars as $key => $value) { + if (is_object($value)) { + $this->$key = clone $value; + } else { + $this->$key = $value; + } + } + } } From 8ccc3a40a050c9908ef1003bf3d38b1cabae0e92 Mon Sep 17 00:00:00 2001 From: Dominik Bonsch Date: Tue, 22 Jan 2013 20:58:54 +0100 Subject: [PATCH 07/17] replaced tabs by 4 spaces --- Classes/PHPExcel/DocumentProperties.php | 1039 +++++++++++------------ 1 file changed, 519 insertions(+), 520 deletions(-) diff --git a/Classes/PHPExcel/DocumentProperties.php b/Classes/PHPExcel/DocumentProperties.php index 6bde10fc..06914646 100644 --- a/Classes/PHPExcel/DocumentProperties.php +++ b/Classes/PHPExcel/DocumentProperties.php @@ -18,571 +18,570 @@ * 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 - * @package PHPExcel - * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL - * @version ##VERSION##, ##DATE## + * @category PHPExcel + * @package PHPExcel + * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @version ##VERSION##, ##DATE## */ /** * PHPExcel_DocumentProperties * - * @category PHPExcel - * @package PHPExcel - * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) + * @category PHPExcel + * @package PHPExcel + * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) */ class PHPExcel_DocumentProperties { - /** constants */ - const PROPERTY_TYPE_BOOLEAN = 'b'; - const PROPERTY_TYPE_INTEGER = 'i'; - const PROPERTY_TYPE_FLOAT = 'f'; - const PROPERTY_TYPE_DATE = 'd'; - const PROPERTY_TYPE_STRING = 's'; - const PROPERTY_TYPE_UNKNOWN = 'u'; + /** constants */ + const PROPERTY_TYPE_BOOLEAN = 'b'; + const PROPERTY_TYPE_INTEGER = 'i'; + const PROPERTY_TYPE_FLOAT = 'f'; + const PROPERTY_TYPE_DATE = 'd'; + const PROPERTY_TYPE_STRING = 's'; + const PROPERTY_TYPE_UNKNOWN = 'u'; + + /** + * Creator + * + * @var string + */ + private $_creator = 'Unknown Creator'; + + /** + * LastModifiedBy + * + * @var string + */ + private $_lastModifiedBy; + + /** + * Created + * + * @var datetime + */ + private $_created; + + /** + * Modified + * + * @var datetime + */ + private $_modified; + + /** + * Title + * + * @var string + */ + private $_title = 'Untitled Spreadsheet'; + + /** + * Description + * + * @var string + */ + private $_description = ''; + + /** + * Subject + * + * @var string + */ + private $_subject = ''; + + /** + * Keywords + * + * @var string + */ + private $_keywords = ''; + + /** + * Category + * + * @var string + */ + private $_category = ''; + + /** + * Manager + * + * @var string + */ + private $_manager = ''; + + /** + * Company + * + * @var string + */ + private $_company = 'Microsoft Corporation'; + + /** + * Custom Properties + * + * @var string + */ + private $_customProperties = array(); - /** - * Creator - * - * @var string - */ - private $_creator = 'Unknown Creator'; + /** + * Create a new PHPExcel_DocumentProperties + */ + public function __construct() + { + // Initialise values + $this->_lastModifiedBy = $this->_creator; + $this->_created = time(); + $this->_modified = time(); + } - /** - * LastModifiedBy - * - * @var string - */ - private $_lastModifiedBy; + /** + * Get Creator + * + * @return string + */ + public function getCreator() { + return $this->_creator; + } - /** - * Created - * - * @var datetime - */ - private $_created; + /** + * Set Creator + * + * @param string $pValue + * @return PHPExcel_DocumentProperties + */ + public function setCreator($pValue = '') { + $this->_creator = $pValue; + return $this; + } - /** - * Modified - * - * @var datetime - */ - private $_modified; + /** + * Get Last Modified By + * + * @return string + */ + public function getLastModifiedBy() { + return $this->_lastModifiedBy; + } - /** - * Title - * - * @var string - */ - private $_title = 'Untitled Spreadsheet'; + /** + * Set Last Modified By + * + * @param string $pValue + * @return PHPExcel_DocumentProperties + */ + public function setLastModifiedBy($pValue = '') { + $this->_lastModifiedBy = $pValue; + return $this; + } - /** - * Description - * - * @var string - */ - private $_description = ''; + /** + * Get Created + * + * @return datetime + */ + public function getCreated() { + return $this->_created; + } - /** - * Subject - * - * @var string - */ - private $_subject = ''; + /** + * Set Created + * + * @param datetime $pValue + * @return PHPExcel_DocumentProperties + */ + public function setCreated($pValue = null) { + if ($pValue === NULL) { + $pValue = time(); + } elseif (is_string($pValue)) { + if (is_numeric($pValue)) { + $pValue = intval($pValue); + } else { + $pValue = strtotime($pValue); + } + } - /** - * Keywords - * - * @var string - */ - private $_keywords = ''; + $this->_created = $pValue; + return $this; + } - /** - * Category - * - * @var string - */ - private $_category = ''; + /** + * Get Modified + * + * @return datetime + */ + public function getModified() { + return $this->_modified; + } - /** - * Manager - * - * @var string - */ - private $_manager = ''; + /** + * Set Modified + * + * @param datetime $pValue + * @return PHPExcel_DocumentProperties + */ + public function setModified($pValue = null) { + if ($pValue === NULL) { + $pValue = time(); + } elseif (is_string($pValue)) { + if (is_numeric($pValue)) { + $pValue = intval($pValue); + } else { + $pValue = strtotime($pValue); + } + } - /** - * Company - * - * @var string - */ - private $_company = 'Microsoft Corporation'; + $this->_modified = $pValue; + return $this; + } - /** - * Custom Properties - * - * @var string - */ - private $_customProperties = array(); + /** + * Get Title + * + * @return string + */ + public function getTitle() { + return $this->_title; + } + /** + * Set Title + * + * @param string $pValue + * @return PHPExcel_DocumentProperties + */ + public function setTitle($pValue = '') { + $this->_title = $pValue; + return $this; + } - /** - * Create a new PHPExcel_DocumentProperties - */ - public function __construct() - { - // Initialise values - $this->_lastModifiedBy = $this->_creator; - $this->_created = time(); - $this->_modified = time(); - } + /** + * Get Description + * + * @return string + */ + public function getDescription() { + return $this->_description; + } - /** - * Get Creator - * - * @return string - */ - public function getCreator() { - return $this->_creator; - } + /** + * Set Description + * + * @param string $pValue + * @return PHPExcel_DocumentProperties + */ + public function setDescription($pValue = '') { + $this->_description = $pValue; + return $this; + } - /** - * Set Creator - * - * @param string $pValue - * @return PHPExcel_DocumentProperties - */ - public function setCreator($pValue = '') { - $this->_creator = $pValue; - return $this; - } + /** + * Get Subject + * + * @return string + */ + public function getSubject() { + return $this->_subject; + } - /** - * Get Last Modified By - * - * @return string - */ - public function getLastModifiedBy() { - return $this->_lastModifiedBy; - } + /** + * Set Subject + * + * @param string $pValue + * @return PHPExcel_DocumentProperties + */ + public function setSubject($pValue = '') { + $this->_subject = $pValue; + return $this; + } - /** - * Set Last Modified By - * - * @param string $pValue - * @return PHPExcel_DocumentProperties - */ - public function setLastModifiedBy($pValue = '') { - $this->_lastModifiedBy = $pValue; - return $this; - } + /** + * Get Keywords + * + * @return string + */ + public function getKeywords() { + return $this->_keywords; + } - /** - * Get Created - * - * @return datetime - */ - public function getCreated() { - return $this->_created; - } + /** + * Set Keywords + * + * @param string $pValue + * @return PHPExcel_DocumentProperties + */ + public function setKeywords($pValue = '') { + $this->_keywords = $pValue; + return $this; + } - /** - * Set Created - * - * @param datetime $pValue - * @return PHPExcel_DocumentProperties - */ - public function setCreated($pValue = null) { - if ($pValue === NULL) { - $pValue = time(); - } elseif (is_string($pValue)) { - if (is_numeric($pValue)) { - $pValue = intval($pValue); - } else { - $pValue = strtotime($pValue); - } - } + /** + * Get Category + * + * @return string + */ + public function getCategory() { + return $this->_category; + } - $this->_created = $pValue; - return $this; - } + /** + * Set Category + * + * @param string $pValue + * @return PHPExcel_DocumentProperties + */ + public function setCategory($pValue = '') { + $this->_category = $pValue; + return $this; + } - /** - * Get Modified - * - * @return datetime - */ - public function getModified() { - return $this->_modified; - } + /** + * Get Company + * + * @return string + */ + public function getCompany() { + return $this->_company; + } - /** - * Set Modified - * - * @param datetime $pValue - * @return PHPExcel_DocumentProperties - */ - public function setModified($pValue = null) { - if ($pValue === NULL) { - $pValue = time(); - } elseif (is_string($pValue)) { - if (is_numeric($pValue)) { - $pValue = intval($pValue); - } else { - $pValue = strtotime($pValue); - } - } + /** + * Set Company + * + * @param string $pValue + * @return PHPExcel_DocumentProperties + */ + public function setCompany($pValue = '') { + $this->_company = $pValue; + return $this; + } - $this->_modified = $pValue; - return $this; - } + /** + * Get Manager + * + * @return string + */ + public function getManager() { + return $this->_manager; + } - /** - * Get Title - * - * @return string - */ - public function getTitle() { - return $this->_title; - } + /** + * Set Manager + * + * @param string $pValue + * @return PHPExcel_DocumentProperties + */ + public function setManager($pValue = '') { + $this->_manager = $pValue; + return $this; + } - /** - * Set Title - * - * @param string $pValue - * @return PHPExcel_DocumentProperties - */ - public function setTitle($pValue = '') { - $this->_title = $pValue; - return $this; - } + /** + * Get a List of Custom Property Names + * + * @return array of string + */ + public function getCustomProperties() { + return array_keys($this->_customProperties); + } - /** - * Get Description - * - * @return string - */ - public function getDescription() { - return $this->_description; - } + /** + * Check if a Custom Property is defined + * + * @param string $propertyName + * @return boolean + */ + public function isCustomPropertySet($propertyName) { + return isset($this->_customProperties[$propertyName]); + } - /** - * Set Description - * - * @param string $pValue - * @return PHPExcel_DocumentProperties - */ - public function setDescription($pValue = '') { - $this->_description = $pValue; - return $this; - } + /** + * Get a Custom Property Value + * + * @param string $propertyName + * @return string + */ + public function getCustomPropertyValue($propertyName) { + if (isset($this->_customProperties[$propertyName])) { + return $this->_customProperties[$propertyName]['value']; + } - /** - * Get Subject - * - * @return string - */ - public function getSubject() { - return $this->_subject; - } + } - /** - * Set Subject - * - * @param string $pValue - * @return PHPExcel_DocumentProperties - */ - public function setSubject($pValue = '') { - $this->_subject = $pValue; - return $this; - } + /** + * Get a Custom Property Type + * + * @param string $propertyName + * @return string + */ + public function getCustomPropertyType($propertyName) { + if (isset($this->_customProperties[$propertyName])) { + return $this->_customProperties[$propertyName]['type']; + } - /** - * Get Keywords - * - * @return string - */ - public function getKeywords() { - return $this->_keywords; - } + } - /** - * Set Keywords - * - * @param string $pValue - * @return PHPExcel_DocumentProperties - */ - public function setKeywords($pValue = '') { - $this->_keywords = $pValue; - return $this; - } + /** + * Set a Custom Property + * + * @param string $propertyName + * @param mixed $propertyValue + * @param string $propertyType + * 'i' : Integer + * 'f' : Floating Point + * 's' : String + * 'd' : Date/Time + * 'b' : Boolean + * @return PHPExcel_DocumentProperties + */ + public function setCustomProperty($propertyName,$propertyValue='',$propertyType=NULL) { + if (($propertyType === NULL) || (!in_array($propertyType,array(self::PROPERTY_TYPE_INTEGER, + self::PROPERTY_TYPE_FLOAT, + self::PROPERTY_TYPE_STRING, + self::PROPERTY_TYPE_DATE, + self::PROPERTY_TYPE_BOOLEAN)))) { + if ($propertyValue === NULL) { + $propertyType = self::PROPERTY_TYPE_STRING; + } elseif (is_float($propertyValue)) { + $propertyType = self::PROPERTY_TYPE_FLOAT; + } elseif(is_int($propertyValue)) { + $propertyType = self::PROPERTY_TYPE_INTEGER; + } elseif (is_bool($propertyValue)) { + $propertyType = self::PROPERTY_TYPE_BOOLEAN; + } else { + $propertyType = self::PROPERTY_TYPE_STRING; + } + } - /** - * Get Category - * - * @return string - */ - public function getCategory() { - return $this->_category; - } + $this->_customProperties[$propertyName] = array('value' => $propertyValue, 'type' => $propertyType); + return $this; + } - /** - * Set Category - * - * @param string $pValue - * @return PHPExcel_DocumentProperties - */ - public function setCategory($pValue = '') { - $this->_category = $pValue; - return $this; - } + /** + * Implement PHP __clone to create a deep clone, not just a shallow copy. + */ + public function __clone() { + $vars = get_object_vars($this); + foreach ($vars as $key => $value) { + if (is_object($value)) { + $this->$key = clone $value; + } else { + $this->$key = $value; + } + } + } - /** - * Get Company - * - * @return string - */ - public function getCompany() { - return $this->_company; - } + public static function convertProperty($propertyValue,$propertyType) { + switch ($propertyType) { + case 'empty' : // Empty + return ''; + break; + case 'null' : // Null + return NULL; + break; + case 'i1' : // 1-Byte Signed Integer + case 'i2' : // 2-Byte Signed Integer + case 'i4' : // 4-Byte Signed Integer + case 'i8' : // 8-Byte Signed Integer + case 'int' : // Integer + return (int) $propertyValue; + break; + case 'ui1' : // 1-Byte Unsigned Integer + case 'ui2' : // 2-Byte Unsigned Integer + case 'ui4' : // 4-Byte Unsigned Integer + case 'ui8' : // 8-Byte Unsigned Integer + case 'uint' : // Unsigned Integer + return abs((int) $propertyValue); + break; + case 'r4' : // 4-Byte Real Number + case 'r8' : // 8-Byte Real Number + case 'decimal' : // Decimal + return (float) $propertyValue; + break; + case 'lpstr' : // LPSTR + case 'lpwstr' : // LPWSTR + case 'bstr' : // Basic String + return $propertyValue; + break; + case 'date' : // Date and Time + case 'filetime' : // File Time + return strtotime($propertyValue); + break; + case 'bool' : // Boolean + return ($propertyValue == 'true') ? True : False; + break; + case 'cy' : // Currency + case 'error' : // Error Status Code + case 'vector' : // Vector + case 'array' : // Array + case 'blob' : // Binary Blob + case 'oblob' : // Binary Blob Object + case 'stream' : // Binary Stream + case 'ostream' : // Binary Stream Object + case 'storage' : // Binary Storage + case 'ostorage' : // Binary Storage Object + case 'vstream' : // Binary Versioned Stream + case 'clsid' : // Class ID + case 'cf' : // Clipboard Data + return $propertyValue; + break; + } + return $propertyValue; + } - /** - * Set Company - * - * @param string $pValue - * @return PHPExcel_DocumentProperties - */ - public function setCompany($pValue = '') { - $this->_company = $pValue; - return $this; - } - - /** - * Get Manager - * - * @return string - */ - public function getManager() { - return $this->_manager; - } - - /** - * Set Manager - * - * @param string $pValue - * @return PHPExcel_DocumentProperties - */ - public function setManager($pValue = '') { - $this->_manager = $pValue; - return $this; - } - - /** - * Get a List of Custom Property Names - * - * @return array of string - */ - public function getCustomProperties() { - return array_keys($this->_customProperties); - } - - /** - * Check if a Custom Property is defined - * - * @param string $propertyName - * @return boolean - */ - public function isCustomPropertySet($propertyName) { - return isset($this->_customProperties[$propertyName]); - } - - /** - * Get a Custom Property Value - * - * @param string $propertyName - * @return string - */ - public function getCustomPropertyValue($propertyName) { - if (isset($this->_customProperties[$propertyName])) { - return $this->_customProperties[$propertyName]['value']; - } - - } - - /** - * Get a Custom Property Type - * - * @param string $propertyName - * @return string - */ - public function getCustomPropertyType($propertyName) { - if (isset($this->_customProperties[$propertyName])) { - return $this->_customProperties[$propertyName]['type']; - } - - } - - /** - * Set a Custom Property - * - * @param string $propertyName - * @param mixed $propertyValue - * @param string $propertyType - * 'i' : Integer - * 'f' : Floating Point - * 's' : String - * 'd' : Date/Time - * 'b' : Boolean - * @return PHPExcel_DocumentProperties - */ - public function setCustomProperty($propertyName,$propertyValue='',$propertyType=NULL) { - if (($propertyType === NULL) || (!in_array($propertyType,array(self::PROPERTY_TYPE_INTEGER, - self::PROPERTY_TYPE_FLOAT, - self::PROPERTY_TYPE_STRING, - self::PROPERTY_TYPE_DATE, - self::PROPERTY_TYPE_BOOLEAN)))) { - if ($propertyValue === NULL) { - $propertyType = self::PROPERTY_TYPE_STRING; - } elseif (is_float($propertyValue)) { - $propertyType = self::PROPERTY_TYPE_FLOAT; - } elseif(is_int($propertyValue)) { - $propertyType = self::PROPERTY_TYPE_INTEGER; - } elseif (is_bool($propertyValue)) { - $propertyType = self::PROPERTY_TYPE_BOOLEAN; - } else { - $propertyType = self::PROPERTY_TYPE_STRING; - } - } - - $this->_customProperties[$propertyName] = array('value' => $propertyValue, 'type' => $propertyType); - return $this; - } - - /** - * Implement PHP __clone to create a deep clone, not just a shallow copy. - */ - public function __clone() { - $vars = get_object_vars($this); - foreach ($vars as $key => $value) { - if (is_object($value)) { - $this->$key = clone $value; - } else { - $this->$key = $value; - } - } - } - - public static function convertProperty($propertyValue,$propertyType) { - switch ($propertyType) { - case 'empty' : // Empty - return ''; - break; - case 'null' : // Null - return NULL; - break; - case 'i1' : // 1-Byte Signed Integer - case 'i2' : // 2-Byte Signed Integer - case 'i4' : // 4-Byte Signed Integer - case 'i8' : // 8-Byte Signed Integer - case 'int' : // Integer - return (int) $propertyValue; - break; - case 'ui1' : // 1-Byte Unsigned Integer - case 'ui2' : // 2-Byte Unsigned Integer - case 'ui4' : // 4-Byte Unsigned Integer - case 'ui8' : // 8-Byte Unsigned Integer - case 'uint' : // Unsigned Integer - return abs((int) $propertyValue); - break; - case 'r4' : // 4-Byte Real Number - case 'r8' : // 8-Byte Real Number - case 'decimal' : // Decimal - return (float) $propertyValue; - break; - case 'lpstr' : // LPSTR - case 'lpwstr' : // LPWSTR - case 'bstr' : // Basic String - return $propertyValue; - break; - case 'date' : // Date and Time - case 'filetime' : // File Time - return strtotime($propertyValue); - break; - case 'bool' : // Boolean - return ($propertyValue == 'true') ? True : False; - break; - case 'cy' : // Currency - case 'error' : // Error Status Code - case 'vector' : // Vector - case 'array' : // Array - case 'blob' : // Binary Blob - case 'oblob' : // Binary Blob Object - case 'stream' : // Binary Stream - case 'ostream' : // Binary Stream Object - case 'storage' : // Binary Storage - case 'ostorage' : // Binary Storage Object - case 'vstream' : // Binary Versioned Stream - case 'clsid' : // Class ID - case 'cf' : // Clipboard Data - return $propertyValue; - break; - } - return $propertyValue; - } - - public static function convertPropertyType($propertyType) { - switch ($propertyType) { - case 'i1' : // 1-Byte Signed Integer - case 'i2' : // 2-Byte Signed Integer - case 'i4' : // 4-Byte Signed Integer - case 'i8' : // 8-Byte Signed Integer - case 'int' : // Integer - case 'ui1' : // 1-Byte Unsigned Integer - case 'ui2' : // 2-Byte Unsigned Integer - case 'ui4' : // 4-Byte Unsigned Integer - case 'ui8' : // 8-Byte Unsigned Integer - case 'uint' : // Unsigned Integer - return self::PROPERTY_TYPE_INTEGER; - break; - case 'r4' : // 4-Byte Real Number - case 'r8' : // 8-Byte Real Number - case 'decimal' : // Decimal - return self::PROPERTY_TYPE_FLOAT; - break; - case 'empty' : // Empty - case 'null' : // Null - case 'lpstr' : // LPSTR - case 'lpwstr' : // LPWSTR - case 'bstr' : // Basic String - return self::PROPERTY_TYPE_STRING; - break; - case 'date' : // Date and Time - case 'filetime' : // File Time - return self::PROPERTY_TYPE_DATE; - break; - case 'bool' : // Boolean - return self::PROPERTY_TYPE_BOOLEAN; - break; - case 'cy' : // Currency - case 'error' : // Error Status Code - case 'vector' : // Vector - case 'array' : // Array - case 'blob' : // Binary Blob - case 'oblob' : // Binary Blob Object - case 'stream' : // Binary Stream - case 'ostream' : // Binary Stream Object - case 'storage' : // Binary Storage - case 'ostorage' : // Binary Storage Object - case 'vstream' : // Binary Versioned Stream - case 'clsid' : // Class ID - case 'cf' : // Clipboard Data - return self::PROPERTY_TYPE_UNKNOWN; - break; - } - return self::PROPERTY_TYPE_UNKNOWN; - } + public static function convertPropertyType($propertyType) { + switch ($propertyType) { + case 'i1' : // 1-Byte Signed Integer + case 'i2' : // 2-Byte Signed Integer + case 'i4' : // 4-Byte Signed Integer + case 'i8' : // 8-Byte Signed Integer + case 'int' : // Integer + case 'ui1' : // 1-Byte Unsigned Integer + case 'ui2' : // 2-Byte Unsigned Integer + case 'ui4' : // 4-Byte Unsigned Integer + case 'ui8' : // 8-Byte Unsigned Integer + case 'uint' : // Unsigned Integer + return self::PROPERTY_TYPE_INTEGER; + break; + case 'r4' : // 4-Byte Real Number + case 'r8' : // 8-Byte Real Number + case 'decimal' : // Decimal + return self::PROPERTY_TYPE_FLOAT; + break; + case 'empty' : // Empty + case 'null' : // Null + case 'lpstr' : // LPSTR + case 'lpwstr' : // LPWSTR + case 'bstr' : // Basic String + return self::PROPERTY_TYPE_STRING; + break; + case 'date' : // Date and Time + case 'filetime' : // File Time + return self::PROPERTY_TYPE_DATE; + break; + case 'bool' : // Boolean + return self::PROPERTY_TYPE_BOOLEAN; + break; + case 'cy' : // Currency + case 'error' : // Error Status Code + case 'vector' : // Vector + case 'array' : // Array + case 'blob' : // Binary Blob + case 'oblob' : // Binary Blob Object + case 'stream' : // Binary Stream + case 'ostream' : // Binary Stream Object + case 'storage' : // Binary Storage + case 'ostorage' : // Binary Storage Object + case 'vstream' : // Binary Versioned Stream + case 'clsid' : // Class ID + case 'cf' : // Clipboard Data + return self::PROPERTY_TYPE_UNKNOWN; + break; + } + return self::PROPERTY_TYPE_UNKNOWN; + } } From ace1796330a9bebe6b9cfdac006036cef2d9b282 Mon Sep 17 00:00:00 2001 From: Dominik Bonsch Date: Tue, 22 Jan 2013 21:05:13 +0100 Subject: [PATCH 08/17] reformated the docblock comments (looked a litle strange after replacing the tabs) --- Classes/PHPExcel/DocumentProperties.php | 112 ++++++++++++------------ 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/Classes/PHPExcel/DocumentProperties.php b/Classes/PHPExcel/DocumentProperties.php index 06914646..952fa7df 100644 --- a/Classes/PHPExcel/DocumentProperties.php +++ b/Classes/PHPExcel/DocumentProperties.php @@ -46,84 +46,84 @@ class PHPExcel_DocumentProperties /** * Creator * - * @var string + * @var string */ private $_creator = 'Unknown Creator'; /** * LastModifiedBy * - * @var string + * @var string */ private $_lastModifiedBy; /** * Created * - * @var datetime + * @var datetime */ private $_created; /** * Modified * - * @var datetime + * @var datetime */ private $_modified; /** * Title * - * @var string + * @var string */ private $_title = 'Untitled Spreadsheet'; /** * Description * - * @var string + * @var string */ private $_description = ''; /** * Subject * - * @var string + * @var string */ private $_subject = ''; /** * Keywords * - * @var string + * @var string */ private $_keywords = ''; /** * Category * - * @var string + * @var string */ private $_category = ''; /** * Manager * - * @var string + * @var string */ private $_manager = ''; /** * Company * - * @var string + * @var string */ private $_company = 'Microsoft Corporation'; /** * Custom Properties * - * @var string + * @var string */ private $_customProperties = array(); @@ -142,7 +142,7 @@ class PHPExcel_DocumentProperties /** * Get Creator * - * @return string + * @return string */ public function getCreator() { return $this->_creator; @@ -151,8 +151,8 @@ class PHPExcel_DocumentProperties /** * Set Creator * - * @param string $pValue - * @return PHPExcel_DocumentProperties + * @param string $pValue + * @return PHPExcel_DocumentProperties */ public function setCreator($pValue = '') { $this->_creator = $pValue; @@ -162,7 +162,7 @@ class PHPExcel_DocumentProperties /** * Get Last Modified By * - * @return string + * @return string */ public function getLastModifiedBy() { return $this->_lastModifiedBy; @@ -171,8 +171,8 @@ class PHPExcel_DocumentProperties /** * Set Last Modified By * - * @param string $pValue - * @return PHPExcel_DocumentProperties + * @param string $pValue + * @return PHPExcel_DocumentProperties */ public function setLastModifiedBy($pValue = '') { $this->_lastModifiedBy = $pValue; @@ -182,7 +182,7 @@ class PHPExcel_DocumentProperties /** * Get Created * - * @return datetime + * @return datetime */ public function getCreated() { return $this->_created; @@ -191,8 +191,8 @@ class PHPExcel_DocumentProperties /** * Set Created * - * @param datetime $pValue - * @return PHPExcel_DocumentProperties + * @param datetime $pValue + * @return PHPExcel_DocumentProperties */ public function setCreated($pValue = null) { if ($pValue === NULL) { @@ -212,7 +212,7 @@ class PHPExcel_DocumentProperties /** * Get Modified * - * @return datetime + * @return datetime */ public function getModified() { return $this->_modified; @@ -221,8 +221,8 @@ class PHPExcel_DocumentProperties /** * Set Modified * - * @param datetime $pValue - * @return PHPExcel_DocumentProperties + * @param datetime $pValue + * @return PHPExcel_DocumentProperties */ public function setModified($pValue = null) { if ($pValue === NULL) { @@ -242,7 +242,7 @@ class PHPExcel_DocumentProperties /** * Get Title * - * @return string + * @return string */ public function getTitle() { return $this->_title; @@ -251,8 +251,8 @@ class PHPExcel_DocumentProperties /** * Set Title * - * @param string $pValue - * @return PHPExcel_DocumentProperties + * @param string $pValue + * @return PHPExcel_DocumentProperties */ public function setTitle($pValue = '') { $this->_title = $pValue; @@ -262,7 +262,7 @@ class PHPExcel_DocumentProperties /** * Get Description * - * @return string + * @return string */ public function getDescription() { return $this->_description; @@ -302,7 +302,7 @@ class PHPExcel_DocumentProperties /** * Get Keywords * - * @return string + * @return string */ public function getKeywords() { return $this->_keywords; @@ -311,8 +311,8 @@ class PHPExcel_DocumentProperties /** * Set Keywords * - * @param string $pValue - * @return PHPExcel_DocumentProperties + * @param string $pValue + * @return PHPExcel_DocumentProperties */ public function setKeywords($pValue = '') { $this->_keywords = $pValue; @@ -322,7 +322,7 @@ class PHPExcel_DocumentProperties /** * Get Category * - * @return string + * @return string */ public function getCategory() { return $this->_category; @@ -331,8 +331,8 @@ class PHPExcel_DocumentProperties /** * Set Category * - * @param string $pValue - * @return PHPExcel_DocumentProperties + * @param string $pValue + * @return PHPExcel_DocumentProperties */ public function setCategory($pValue = '') { $this->_category = $pValue; @@ -342,7 +342,7 @@ class PHPExcel_DocumentProperties /** * Get Company * - * @return string + * @return string */ public function getCompany() { return $this->_company; @@ -351,8 +351,8 @@ class PHPExcel_DocumentProperties /** * Set Company * - * @param string $pValue - * @return PHPExcel_DocumentProperties + * @param string $pValue + * @return PHPExcel_DocumentProperties */ public function setCompany($pValue = '') { $this->_company = $pValue; @@ -362,7 +362,7 @@ class PHPExcel_DocumentProperties /** * Get Manager * - * @return string + * @return string */ public function getManager() { return $this->_manager; @@ -371,8 +371,8 @@ class PHPExcel_DocumentProperties /** * Set Manager * - * @param string $pValue - * @return PHPExcel_DocumentProperties + * @param string $pValue + * @return PHPExcel_DocumentProperties */ public function setManager($pValue = '') { $this->_manager = $pValue; @@ -382,7 +382,7 @@ class PHPExcel_DocumentProperties /** * Get a List of Custom Property Names * - * @return array of string + * @return array of string */ public function getCustomProperties() { return array_keys($this->_customProperties); @@ -391,8 +391,8 @@ class PHPExcel_DocumentProperties /** * Check if a Custom Property is defined * - * @param string $propertyName - * @return boolean + * @param string $propertyName + * @return boolean */ public function isCustomPropertySet($propertyName) { return isset($this->_customProperties[$propertyName]); @@ -401,8 +401,8 @@ class PHPExcel_DocumentProperties /** * Get a Custom Property Value * - * @param string $propertyName - * @return string + * @param string $propertyName + * @return string */ public function getCustomPropertyValue($propertyName) { if (isset($this->_customProperties[$propertyName])) { @@ -414,8 +414,8 @@ class PHPExcel_DocumentProperties /** * Get a Custom Property Type * - * @param string $propertyName - * @return string + * @param string $propertyName + * @return string */ public function getCustomPropertyType($propertyName) { if (isset($this->_customProperties[$propertyName])) { @@ -427,15 +427,15 @@ class PHPExcel_DocumentProperties /** * Set a Custom Property * - * @param string $propertyName - * @param mixed $propertyValue - * @param string $propertyType - * 'i' : Integer - * 'f' : Floating Point - * 's' : String - * 'd' : Date/Time - * 'b' : Boolean - * @return PHPExcel_DocumentProperties + * @param string $propertyName + * @param mixed $propertyValue + * @param string $propertyType + * 'i' : Integer + * 'f' : Floating Point + * 's' : String + * 'd' : Date/Time + * 'b' : Boolean + * @return PHPExcel_DocumentProperties */ public function setCustomProperty($propertyName,$propertyValue='',$propertyType=NULL) { if (($propertyType === NULL) || (!in_array($propertyType,array(self::PROPERTY_TYPE_INTEGER, From c3bb8796ab559154015fc0baa189cb94fafe8eb2 Mon Sep 17 00:00:00 2001 From: Dominik Bonsch Date: Tue, 22 Jan 2013 21:06:17 +0100 Subject: [PATCH 09/17] replaced tabs by 4 spaces --- Classes/PHPExcel/Exception.php | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Classes/PHPExcel/Exception.php b/Classes/PHPExcel/Exception.php index a4354531..8ac53865 100644 --- a/Classes/PHPExcel/Exception.php +++ b/Classes/PHPExcel/Exception.php @@ -21,8 +21,8 @@ * @category PHPExcel * @package PHPExcel * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL - * @version ##VERSION##, ##DATE## + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @version ##VERSION##, ##DATE## */ @@ -34,19 +34,19 @@ * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) */ class PHPExcel_Exception extends Exception { - /** - * Error handler callback - * - * @param mixed $code - * @param mixed $string - * @param mixed $file - * @param mixed $line - * @param mixed $context - */ - public static function errorHandlerCallback($code, $string, $file, $line, $context) { - $e = new self($string, $code); - $e->line = $line; - $e->file = $file; - throw $e; - } + /** + * Error handler callback + * + * @param mixed $code + * @param mixed $string + * @param mixed $file + * @param mixed $line + * @param mixed $context + */ + public static function errorHandlerCallback($code, $string, $file, $line, $context) { + $e = new self($string, $code); + $e->line = $line; + $e->file = $file; + throw $e; + } } From e250e466f9900bab04e5a8c0665dd34544b4611b Mon Sep 17 00:00:00 2001 From: Dominik Bonsch Date: Sat, 9 Feb 2013 11:55:38 +0100 Subject: [PATCH 10/17] PSR-2 --- Classes/PHPExcel/WorksheetIterator.php | 81 ++++++++++++++------------ 1 file changed, 44 insertions(+), 37 deletions(-) diff --git a/Classes/PHPExcel/WorksheetIterator.php b/Classes/PHPExcel/WorksheetIterator.php index b7180f61..cceec417 100644 --- a/Classes/PHPExcel/WorksheetIterator.php +++ b/Classes/PHPExcel/WorksheetIterator.php @@ -21,7 +21,7 @@ * @category PHPExcel * @package PHPExcel * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version ##VERSION##, ##DATE## */ @@ -37,41 +37,44 @@ */ class PHPExcel_WorksheetIterator implements Iterator { - /** - * Spreadsheet to iterate - * - * @var PHPExcel - */ - private $_subject; + /** + * Spreadsheet to iterate + * + * @var PHPExcel + */ + private $_subject; - /** - * Current iterator position - * - * @var int - */ - private $_position = 0; + /** + * Current iterator position + * + * @var int + */ + private $_position = 0; - /** - * Create a new worksheet iterator - * - * @param PHPExcel $subject - */ - public function __construct(PHPExcel $subject = null) { - // Set subject - $this->_subject = $subject; - } + /** + * Create a new worksheet iterator + * + * @param PHPExcel $subject + */ + public function __construct(PHPExcel $subject = null) + { + // Set subject + $this->_subject = $subject; + } - /** - * Destructor - */ - public function __destruct() { - unset($this->_subject); - } + /** + * Destructor + */ + public function __destruct() + { + unset($this->_subject); + } - /** - * Rewind iterator - */ - public function rewind() { + /** + * Rewind iterator + */ + public function rewind() + { $this->_position = 0; } @@ -80,8 +83,9 @@ class PHPExcel_WorksheetIterator implements Iterator * * @return PHPExcel_Worksheet */ - public function current() { - return $this->_subject->getSheet($this->_position); + public function current() + { + return $this->_subject->getSheet($this->_position); } /** @@ -89,14 +93,16 @@ class PHPExcel_WorksheetIterator implements Iterator * * @return int */ - public function key() { + public function key() + { return $this->_position; } /** * Next value */ - public function next() { + public function next() + { ++$this->_position; } @@ -105,7 +111,8 @@ class PHPExcel_WorksheetIterator implements Iterator * * @return boolean */ - public function valid() { + public function valid() + { return $this->_position < $this->_subject->getSheetCount(); } } From 086d12e7af3a46910a5b0ee64698550979a9e6a5 Mon Sep 17 00:00:00 2001 From: Dominik Bonsch Date: Sat, 9 Feb 2013 12:09:28 +0100 Subject: [PATCH 11/17] =?UTF-8?q?phpdoc=20replaced=20array=20of=20by=20[?= =?UTF-8?q?=E2=80=A6]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/PHPExcel/Chart/PlotArea.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/PHPExcel/Chart/PlotArea.php b/Classes/PHPExcel/Chart/PlotArea.php index ec9aee83..2a092ce7 100644 --- a/Classes/PHPExcel/Chart/PlotArea.php +++ b/Classes/PHPExcel/Chart/PlotArea.php @@ -110,7 +110,7 @@ class PHPExcel_Chart_PlotArea /** * Set Plot Series * - * @param array of PHPExcel_Chart_DataSeries + * @param [PHPExcel_Chart_DataSeries] */ public function setPlotSeries($plotSeries = array()) { $this->_plotSeries = $plotSeries; From caced1a5be498c83c7dcdba89c9ad4ce3352bf2d Mon Sep 17 00:00:00 2001 From: Dominik Bonsch Date: Sat, 9 Feb 2013 12:15:01 +0100 Subject: [PATCH 12/17] PSR-2 --- Classes/PHPExcel/Worksheet.php | 5332 ++++++++++++++++---------------- 1 file changed, 2680 insertions(+), 2652 deletions(-) diff --git a/Classes/PHPExcel/Worksheet.php b/Classes/PHPExcel/Worksheet.php index ec201ab5..2cdaca75 100644 --- a/Classes/PHPExcel/Worksheet.php +++ b/Classes/PHPExcel/Worksheet.php @@ -19,10 +19,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * * @category PHPExcel - * @package PHPExcel_Worksheet + * @package PHPExcel_Worksheet * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL - * @version ##VERSION##, ##DATE## + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @version ##VERSION##, ##DATE## */ @@ -30,1849 +30,1856 @@ * PHPExcel_Worksheet * * @category PHPExcel - * @package PHPExcel_Worksheet + * @package PHPExcel_Worksheet * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) */ class PHPExcel_Worksheet implements PHPExcel_IComparable { - /* Break types */ - const BREAK_NONE = 0; - const BREAK_ROW = 1; - const BREAK_COLUMN = 2; - - /* Sheet state */ - const SHEETSTATE_VISIBLE = 'visible'; - const SHEETSTATE_HIDDEN = 'hidden'; - const SHEETSTATE_VERYHIDDEN = 'veryHidden'; - - /** - * Invalid characters in sheet title - * - * @var array - */ - private static $_invalidCharacters = array('*', ':', '/', '\\', '?', '[', ']'); - - /** - * Parent spreadsheet - * - * @var PHPExcel - */ - private $_parent; - - /** - * Cacheable collection of cells - * - * @var PHPExcel_CachedObjectStorage_xxx - */ - private $_cellCollection = null; - - /** - * Collection of row dimensions - * - * @var PHPExcel_Worksheet_RowDimension[] - */ - private $_rowDimensions = array(); - - /** - * Default row dimension - * - * @var PHPExcel_Worksheet_RowDimension - */ - private $_defaultRowDimension = null; - - /** - * Collection of column dimensions - * - * @var PHPExcel_Worksheet_ColumnDimension[] - */ - private $_columnDimensions = array(); - - /** - * Default column dimension - * - * @var PHPExcel_Worksheet_ColumnDimension - */ - private $_defaultColumnDimension = null; - - /** - * Collection of drawings - * - * @var PHPExcel_Worksheet_BaseDrawing[] - */ - private $_drawingCollection = null; - - /** - * Collection of Chart objects - * - * @var PHPExcel_Chart[] - */ - private $_chartCollection = array(); - - /** - * Worksheet title - * - * @var string - */ - private $_title; - - /** - * Sheet state - * - * @var string - */ - private $_sheetState; - - /** - * Page setup - * - * @var PHPExcel_Worksheet_PageSetup - */ - private $_pageSetup; - - /** - * Page margins - * - * @var PHPExcel_Worksheet_PageMargins - */ - private $_pageMargins; - - /** - * Page header/footer - * - * @var PHPExcel_Worksheet_HeaderFooter - */ - private $_headerFooter; - - /** - * Sheet view - * - * @var PHPExcel_Worksheet_SheetView - */ - private $_sheetView; - - /** - * Protection - * - * @var PHPExcel_Worksheet_Protection - */ - private $_protection; - - /** - * Collection of styles - * - * @var PHPExcel_Style[] - */ - private $_styles = array(); - - /** - * Conditional styles. Indexed by cell coordinate, e.g. 'A1' - * - * @var array - */ - private $_conditionalStylesCollection = array(); - - /** - * Is the current cell collection sorted already? - * - * @var boolean - */ - private $_cellCollectionIsSorted = false; - - /** - * Collection of breaks - * - * @var array - */ - private $_breaks = array(); - - /** - * Collection of merged cell ranges - * - * @var array - */ - private $_mergeCells = array(); - - /** - * Collection of protected cell ranges - * - * @var array - */ - private $_protectedCells = array(); - - /** - * Autofilter Range and selection - * - * @var PHPExcel_Worksheet_AutoFilter - */ - private $_autoFilter = NULL; - - /** - * Freeze pane - * - * @var string - */ - private $_freezePane = ''; - - /** - * Show gridlines? - * - * @var boolean - */ - private $_showGridlines = true; - - /** - * Print gridlines? - * - * @var boolean - */ - private $_printGridlines = false; - - /** - * Show row and column headers? - * - * @var boolean - */ - private $_showRowColHeaders = true; - - /** - * Show summary below? (Row/Column outline) - * - * @var boolean - */ - private $_showSummaryBelow = true; - - /** - * Show summary right? (Row/Column outline) - * - * @var boolean - */ - private $_showSummaryRight = true; - - /** - * Collection of comments - * - * @var PHPExcel_Comment[] - */ - private $_comments = array(); - - /** - * Active cell. (Only one!) - * - * @var string - */ - private $_activeCell = 'A1'; - - /** - * Selected cells - * - * @var string - */ - private $_selectedCells = 'A1'; - - /** - * Cached highest column - * - * @var string - */ - private $_cachedHighestColumn = 'A'; - - /** - * Cached highest row - * - * @var int - */ - private $_cachedHighestRow = 1; - - /** - * Right-to-left? - * - * @var boolean - */ - private $_rightToLeft = false; - - /** - * Hyperlinks. Indexed by cell coordinate, e.g. 'A1' - * - * @var array - */ - private $_hyperlinkCollection = array(); - - /** - * Data validation objects. Indexed by cell coordinate, e.g. 'A1' - * - * @var array - */ - private $_dataValidationCollection = array(); - - /** - * Tab color - * - * @var PHPExcel_Style_Color - */ - private $_tabColor; - - /** - * Dirty flag - * - * @var boolean - */ - private $_dirty = true; - - /** - * Hash - * - * @var string - */ - private $_hash = null; - - /** - * Create a new worksheet - * - * @param PHPExcel $pParent - * @param string $pTitle - */ - public function __construct(PHPExcel $pParent = null, $pTitle = 'Worksheet') - { - // Set parent and title - $this->_parent = $pParent; - $this->setTitle($pTitle, FALSE); - $this->setSheetState(PHPExcel_Worksheet::SHEETSTATE_VISIBLE); - - $this->_cellCollection = PHPExcel_CachedObjectStorageFactory::getInstance($this); - - // Set page setup - $this->_pageSetup = new PHPExcel_Worksheet_PageSetup(); - - // Set page margins - $this->_pageMargins = new PHPExcel_Worksheet_PageMargins(); - - // Set page header/footer - $this->_headerFooter = new PHPExcel_Worksheet_HeaderFooter(); - - // Set sheet view - $this->_sheetView = new PHPExcel_Worksheet_SheetView(); - - // Drawing collection - $this->_drawingCollection = new ArrayObject(); - - // Chart collection - $this->_chartCollection = new ArrayObject(); - - // Protection - $this->_protection = new PHPExcel_Worksheet_Protection(); - - // Default row dimension - $this->_defaultRowDimension = new PHPExcel_Worksheet_RowDimension(NULL); - - // Default column dimension - $this->_defaultColumnDimension = new PHPExcel_Worksheet_ColumnDimension(NULL); - - $this->_autoFilter = new PHPExcel_Worksheet_AutoFilter(NULL, $this); - } - - - /** - * Disconnect all cells from this PHPExcel_Worksheet object, - * typically so that the worksheet object can be unset - * - */ - public function disconnectCells() { - $this->_cellCollection->unsetWorksheetCells(); - $this->_cellCollection = null; - - // detach ourself from the workbook, so that it can then delete this worksheet successfully - $this->_parent = null; - } - - /** - * Return the cache controller for the cell collection - * - * @return PHPExcel_CachedObjectStorage_xxx - */ - public function getCellCacheController() { - return $this->_cellCollection; - } // function getCellCacheController() - - - /** - * Get array of invalid characters for sheet title - * - * @return array - */ - public static function getInvalidCharacters() - { - return self::$_invalidCharacters; - } - - /** - * Check sheet title for valid Excel syntax - * - * @param string $pValue The string to check - * @return string The valid string - * @throws PHPExcel_Exception - */ - private static function _checkSheetTitle($pValue) - { - // Some of the printable ASCII characters are invalid: * : / \ ? [ ] - if (str_replace(self::$_invalidCharacters, '', $pValue) !== $pValue) { - throw new PHPExcel_Exception('Invalid character found in sheet title'); - } - - // Maximum 31 characters allowed for sheet title - if (PHPExcel_Shared_String::CountCharacters($pValue) > 31) { - throw new PHPExcel_Exception('Maximum 31 characters allowed in sheet title.'); - } - - return $pValue; - } - - /** - * Get collection of cells - * - * @param boolean $pSorted Also sort the cell collection? - * @return PHPExcel_Cell[] - */ - public function getCellCollection($pSorted = true) - { - if ($pSorted) { - // Re-order cell collection - return $this->sortCellCollection(); - } - if ($this->_cellCollection !== NULL) { - return $this->_cellCollection->getCellList(); - } - return array(); - } - - /** - * Sort collection of cells - * - * @return PHPExcel_Worksheet - */ - public function sortCellCollection() - { - if ($this->_cellCollection !== NULL) { - return $this->_cellCollection->getSortedCellList(); - } - return array(); - } - - /** - * Get collection of row dimensions - * - * @return PHPExcel_Worksheet_RowDimension[] - */ - public function getRowDimensions() - { - return $this->_rowDimensions; - } - - /** - * Get default row dimension - * - * @return PHPExcel_Worksheet_RowDimension - */ - public function getDefaultRowDimension() - { - return $this->_defaultRowDimension; - } - - /** - * Get collection of column dimensions - * - * @return PHPExcel_Worksheet_ColumnDimension[] - */ - public function getColumnDimensions() - { - return $this->_columnDimensions; - } - - /** - * Get default column dimension - * - * @return PHPExcel_Worksheet_ColumnDimension - */ - public function getDefaultColumnDimension() - { - return $this->_defaultColumnDimension; - } - - /** - * Get collection of drawings - * - * @return PHPExcel_Worksheet_BaseDrawing[] - */ - public function getDrawingCollection() - { - return $this->_drawingCollection; - } - - /** - * Get collection of charts - * - * @return PHPExcel_Chart[] - */ - public function getChartCollection() - { - return $this->_chartCollection; - } - - /** - * Add chart - * - * @param PHPExcel_Chart $pChart - * @param int|null $iChartIndex Index where chart should go (0,1,..., or null for last) - * @return PHPExcel_Chart - */ - public function addChart(PHPExcel_Chart $pChart = null, $iChartIndex = null) - { - $pChart->setWorksheet($this); - if (is_null($iChartIndex)) { - $this->_chartCollection[] = $pChart; - } else { - // Insert the chart at the requested index - array_splice($this->_chartCollection, $iChartIndex, 0, array($pChart)); - } - - return $pChart; - } - - /** - * Return the count of charts on this worksheet - * - * @return int The number of charts - */ - public function getChartCount() - { - return count($this->_chartCollection); - } - - /** - * Get a chart by its index position - * - * @param string $index Chart index position - * @return false|PHPExcel_Chart - * @throws PHPExcel_Exception - */ - public function getChartByIndex($index = null) - { - $chartCount = count($this->_chartCollection); - if ($chartCount == 0) { - return false; - } - if (is_null($index)) { - $index = --$chartCount; - } - if (!isset($this->_chartCollection[$index])) { - return false; - } - - return $this->_chartCollection[$index]; - } - - /** - * Return an array of the names of charts on this worksheet - * - * @return string[] The names of charts - * @throws PHPExcel_Exception - */ - public function getChartNames() - { - $chartNames = array(); - foreach($this->_chartCollection as $chart) { - $chartNames[] = $chart->getName(); - } - return $chartNames; - } - - /** - * Get a chart by name - * - * @param string $chartName Chart name - * @return false|PHPExcel_Chart - * @throws PHPExcel_Exception - */ - public function getChartByName($chartName = '') - { - $chartCount = count($this->_chartCollection); - if ($chartCount == 0) { - return false; - } - foreach($this->_chartCollection as $index => $chart) { - if ($chart->getName() == $chartName) { - return $this->_chartCollection[$index]; - } - } - return false; - } - - /** - * Refresh column dimensions - * - * @return PHPExcel_Worksheet - */ - public function refreshColumnDimensions() - { - $currentColumnDimensions = $this->getColumnDimensions(); - $newColumnDimensions = array(); - - foreach ($currentColumnDimensions as $objColumnDimension) { - $newColumnDimensions[$objColumnDimension->getColumnIndex()] = $objColumnDimension; - } - - $this->_columnDimensions = $newColumnDimensions; - - return $this; - } - - /** - * Refresh row dimensions - * - * @return PHPExcel_Worksheet - */ - public function refreshRowDimensions() - { - $currentRowDimensions = $this->getRowDimensions(); - $newRowDimensions = array(); - - foreach ($currentRowDimensions as $objRowDimension) { - $newRowDimensions[$objRowDimension->getRowIndex()] = $objRowDimension; - } - - $this->_rowDimensions = $newRowDimensions; - - return $this; - } - - /** - * Calculate worksheet dimension - * - * @return string String containing the dimension of this worksheet - */ - public function calculateWorksheetDimension() - { - // Return - return 'A1' . ':' . $this->getHighestColumn() . $this->getHighestRow(); - } - - /** - * Calculate worksheet data dimension - * - * @return string String containing the dimension of this worksheet that actually contain data - */ - public function calculateWorksheetDataDimension() - { - // Return - return 'A1' . ':' . $this->getHighestDataColumn() . $this->getHighestDataRow(); - } - - /** - * Calculate widths for auto-size columns - * - * @param boolean $calculateMergeCells Calculate merge cell width - * @return PHPExcel_Worksheet; - */ - public function calculateColumnWidths($calculateMergeCells = false) - { - // initialize $autoSizes array - $autoSizes = array(); - foreach ($this->getColumnDimensions() as $colDimension) { - if ($colDimension->getAutoSize()) { - $autoSizes[$colDimension->getColumnIndex()] = -1; - } - } - - // There is only something to do if there are some auto-size columns - if (!empty($autoSizes)) { - - // build list of cells references that participate in a merge - $isMergeCell = array(); - foreach ($this->getMergeCells() as $cells) { - foreach (PHPExcel_Cell::extractAllCellReferencesInRange($cells) as $cellReference) { - $isMergeCell[$cellReference] = true; - } - } - - // loop through all cells in the worksheet - foreach ($this->getCellCollection(false) as $cellID) { - $cell = $this->getCell($cellID); - if (isset($autoSizes[$cell->getColumn()])) { - // Determine width if cell does not participate in a merge - if (!isset($isMergeCell[$cell->getCoordinate()])) { - // Calculated value - $cellValue = $cell->getCalculatedValue(); - - // To formatted string - $cellValue = PHPExcel_Style_NumberFormat::toFormattedString($cellValue, $this->getParent()->getCellXfByIndex($cell->getXfIndex())->getNumberFormat()->getFormatCode()); - - $autoSizes[$cell->getColumn()] = max( - (float)$autoSizes[$cell->getColumn()], - (float)PHPExcel_Shared_Font::calculateColumnWidth( - $this->getParent()->getCellXfByIndex($cell->getXfIndex())->getFont(), - $cellValue, - $this->getParent()->getCellXfByIndex($cell->getXfIndex())->getAlignment()->getTextRotation(), - $this->getDefaultStyle()->getFont() - ) - ); - } - } - } - - // adjust column widths - foreach ($autoSizes as $columnIndex => $width) { - if ($width == -1) $width = $this->getDefaultColumnDimension()->getWidth(); - $this->getColumnDimension($columnIndex)->setWidth($width); - } - } - - return $this; - } - - /** - * Get parent - * - * @return PHPExcel - */ - public function getParent() { - return $this->_parent; - } - - /** - * Re-bind parent - * - * @param PHPExcel $parent - * @return PHPExcel_Worksheet - */ - public function rebindParent(PHPExcel $parent) { - $namedRanges = $this->_parent->getNamedRanges(); - foreach ($namedRanges as $namedRange) { - $parent->addNamedRange($namedRange); - } - - $this->_parent->removeSheetByIndex( - $this->_parent->getIndex($this) - ); - $this->_parent = $parent; - - return $this; - } - - /** - * Get title - * - * @return string - */ - public function getTitle() - { - return $this->_title; - } - - /** - * Set title - * - * @param string $pValue String containing the dimension of this worksheet - * @param string $updateFormulaCellReferences boolean Flag indicating whether cell references in formulae should - * be updated to reflect the new sheet name. - * This should be left as the default true, unless you are - * certain that no formula cells on any worksheet contain - * references to this worksheet - * @return PHPExcel_Worksheet - */ - public function setTitle($pValue = 'Worksheet', $updateFormulaCellReferences = true) - { - // Is this a 'rename' or not? - if ($this->getTitle() == $pValue) { - return $this; - } - - // Syntax check - self::_checkSheetTitle($pValue); - - // Old title - $oldTitle = $this->getTitle(); + /* Break types */ + const BREAK_NONE = 0; + const BREAK_ROW = 1; + const BREAK_COLUMN = 2; + + /* Sheet state */ + const SHEETSTATE_VISIBLE = 'visible'; + const SHEETSTATE_HIDDEN = 'hidden'; + const SHEETSTATE_VERYHIDDEN = 'veryHidden'; + + /** + * Invalid characters in sheet title + * + * @var array + */ + private static $_invalidCharacters = array('*', ':', '/', '\\', '?', '[', ']'); + + /** + * Parent spreadsheet + * + * @var PHPExcel + */ + private $_parent; + + /** + * Cacheable collection of cells + * + * @var PHPExcel_CachedObjectStorage_xxx + */ + private $_cellCollection = null; + + /** + * Collection of row dimensions + * + * @var PHPExcel_Worksheet_RowDimension[] + */ + private $_rowDimensions = array(); + + /** + * Default row dimension + * + * @var PHPExcel_Worksheet_RowDimension + */ + private $_defaultRowDimension = null; + + /** + * Collection of column dimensions + * + * @var PHPExcel_Worksheet_ColumnDimension[] + */ + private $_columnDimensions = array(); + + /** + * Default column dimension + * + * @var PHPExcel_Worksheet_ColumnDimension + */ + private $_defaultColumnDimension = null; + + /** + * Collection of drawings + * + * @var PHPExcel_Worksheet_BaseDrawing[] + */ + private $_drawingCollection = null; + + /** + * Collection of Chart objects + * + * @var PHPExcel_Chart[] + */ + private $_chartCollection = array(); + + /** + * Worksheet title + * + * @var string + */ + private $_title; + + /** + * Sheet state + * + * @var string + */ + private $_sheetState; + + /** + * Page setup + * + * @var PHPExcel_Worksheet_PageSetup + */ + private $_pageSetup; + + /** + * Page margins + * + * @var PHPExcel_Worksheet_PageMargins + */ + private $_pageMargins; + + /** + * Page header/footer + * + * @var PHPExcel_Worksheet_HeaderFooter + */ + private $_headerFooter; + + /** + * Sheet view + * + * @var PHPExcel_Worksheet_SheetView + */ + private $_sheetView; + + /** + * Protection + * + * @var PHPExcel_Worksheet_Protection + */ + private $_protection; + + /** + * Collection of styles + * + * @var PHPExcel_Style[] + */ + private $_styles = array(); + + /** + * Conditional styles. Indexed by cell coordinate, e.g. 'A1' + * + * @var array + */ + private $_conditionalStylesCollection = array(); + + /** + * Is the current cell collection sorted already? + * + * @var boolean + */ + private $_cellCollectionIsSorted = false; + + /** + * Collection of breaks + * + * @var array + */ + private $_breaks = array(); + + /** + * Collection of merged cell ranges + * + * @var array + */ + private $_mergeCells = array(); + + /** + * Collection of protected cell ranges + * + * @var array + */ + private $_protectedCells = array(); + + /** + * Autofilter Range and selection + * + * @var PHPExcel_Worksheet_AutoFilter + */ + private $_autoFilter = NULL; + + /** + * Freeze pane + * + * @var string + */ + private $_freezePane = ''; + + /** + * Show gridlines? + * + * @var boolean + */ + private $_showGridlines = true; + + /** + * Print gridlines? + * + * @var boolean + */ + private $_printGridlines = false; + + /** + * Show row and column headers? + * + * @var boolean + */ + private $_showRowColHeaders = true; + + /** + * Show summary below? (Row/Column outline) + * + * @var boolean + */ + private $_showSummaryBelow = true; + + /** + * Show summary right? (Row/Column outline) + * + * @var boolean + */ + private $_showSummaryRight = true; + + /** + * Collection of comments + * + * @var PHPExcel_Comment[] + */ + private $_comments = array(); + + /** + * Active cell. (Only one!) + * + * @var string + */ + private $_activeCell = 'A1'; + + /** + * Selected cells + * + * @var string + */ + private $_selectedCells = 'A1'; + + /** + * Cached highest column + * + * @var string + */ + private $_cachedHighestColumn = 'A'; + + /** + * Cached highest row + * + * @var int + */ + private $_cachedHighestRow = 1; + + /** + * Right-to-left? + * + * @var boolean + */ + private $_rightToLeft = false; + + /** + * Hyperlinks. Indexed by cell coordinate, e.g. 'A1' + * + * @var array + */ + private $_hyperlinkCollection = array(); + + /** + * Data validation objects. Indexed by cell coordinate, e.g. 'A1' + * + * @var array + */ + private $_dataValidationCollection = array(); + + /** + * Tab color + * + * @var PHPExcel_Style_Color + */ + private $_tabColor; + + /** + * Dirty flag + * + * @var boolean + */ + private $_dirty = true; + + /** + * Hash + * + * @var string + */ + private $_hash = null; + + /** + * Create a new worksheet + * + * @param PHPExcel $pParent + * @param string $pTitle + */ + public function __construct(PHPExcel $pParent = null, $pTitle = 'Worksheet') + { + // Set parent and title + $this->_parent = $pParent; + $this->setTitle($pTitle, FALSE); + $this->setSheetState(PHPExcel_Worksheet::SHEETSTATE_VISIBLE); + + $this->_cellCollection = PHPExcel_CachedObjectStorageFactory::getInstance($this); + + // Set page setup + $this->_pageSetup = new PHPExcel_Worksheet_PageSetup(); + + // Set page margins + $this->_pageMargins = new PHPExcel_Worksheet_PageMargins(); + + // Set page header/footer + $this->_headerFooter = new PHPExcel_Worksheet_HeaderFooter(); + + // Set sheet view + $this->_sheetView = new PHPExcel_Worksheet_SheetView(); + + // Drawing collection + $this->_drawingCollection = new ArrayObject(); + + // Chart collection + $this->_chartCollection = new ArrayObject(); + + // Protection + $this->_protection = new PHPExcel_Worksheet_Protection(); + + // Default row dimension + $this->_defaultRowDimension = new PHPExcel_Worksheet_RowDimension(NULL); + + // Default column dimension + $this->_defaultColumnDimension = new PHPExcel_Worksheet_ColumnDimension(NULL); + + $this->_autoFilter = new PHPExcel_Worksheet_AutoFilter(NULL, $this); + } + + + /** + * Disconnect all cells from this PHPExcel_Worksheet object, + * typically so that the worksheet object can be unset + * + */ + public function disconnectCells() + { + $this->_cellCollection->unsetWorksheetCells(); + $this->_cellCollection = null; + + // detach ourself from the workbook, so that it can then delete this worksheet successfully + $this->_parent = null; + } + + /** + * Return the cache controller for the cell collection + * + * @return PHPExcel_CachedObjectStorage_xxx + */ + public function getCellCacheController() + { + return $this->_cellCollection; + } // function getCellCacheController() + + + /** + * Get array of invalid characters for sheet title + * + * @return array + */ + public static function getInvalidCharacters() + { + return self::$_invalidCharacters; + } + + /** + * Check sheet title for valid Excel syntax + * + * @param string $pValue The string to check + * @return string The valid string + * @throws PHPExcel_Exception + */ + private static function _checkSheetTitle($pValue) + { + // Some of the printable ASCII characters are invalid: * : / \ ? [ ] + if (str_replace(self::$_invalidCharacters, '', $pValue) !== $pValue) { + throw new PHPExcel_Exception('Invalid character found in sheet title'); + } + + // Maximum 31 characters allowed for sheet title + if (PHPExcel_Shared_String::CountCharacters($pValue) > 31) { + throw new PHPExcel_Exception('Maximum 31 characters allowed in sheet title.'); + } + + return $pValue; + } + + /** + * Get collection of cells + * + * @param boolean $pSorted Also sort the cell collection? + * @return PHPExcel_Cell[] + */ + public function getCellCollection($pSorted = true) + { + if ($pSorted) { + // Re-order cell collection + return $this->sortCellCollection(); + } + if ($this->_cellCollection !== NULL) { + return $this->_cellCollection->getCellList(); + } + return array(); + } + + /** + * Sort collection of cells + * + * @return PHPExcel_Worksheet + */ + public function sortCellCollection() + { + if ($this->_cellCollection !== NULL) { + return $this->_cellCollection->getSortedCellList(); + } + return array(); + } + + /** + * Get collection of row dimensions + * + * @return PHPExcel_Worksheet_RowDimension[] + */ + public function getRowDimensions() + { + return $this->_rowDimensions; + } + + /** + * Get default row dimension + * + * @return PHPExcel_Worksheet_RowDimension + */ + public function getDefaultRowDimension() + { + return $this->_defaultRowDimension; + } + + /** + * Get collection of column dimensions + * + * @return PHPExcel_Worksheet_ColumnDimension[] + */ + public function getColumnDimensions() + { + return $this->_columnDimensions; + } + + /** + * Get default column dimension + * + * @return PHPExcel_Worksheet_ColumnDimension + */ + public function getDefaultColumnDimension() + { + return $this->_defaultColumnDimension; + } + + /** + * Get collection of drawings + * + * @return PHPExcel_Worksheet_BaseDrawing[] + */ + public function getDrawingCollection() + { + return $this->_drawingCollection; + } + + /** + * Get collection of charts + * + * @return PHPExcel_Chart[] + */ + public function getChartCollection() + { + return $this->_chartCollection; + } + + /** + * Add chart + * + * @param PHPExcel_Chart $pChart + * @param int|null $iChartIndex Index where chart should go (0,1,..., or null for last) + * @return PHPExcel_Chart + */ + public function addChart(PHPExcel_Chart $pChart = null, $iChartIndex = null) + { + $pChart->setWorksheet($this); + if (is_null($iChartIndex)) { + $this->_chartCollection[] = $pChart; + } else { + // Insert the chart at the requested index + array_splice($this->_chartCollection, $iChartIndex, 0, array($pChart)); + } + + return $pChart; + } + + /** + * Return the count of charts on this worksheet + * + * @return int The number of charts + */ + public function getChartCount() + { + return count($this->_chartCollection); + } + + /** + * Get a chart by its index position + * + * @param string $index Chart index position + * @return false|PHPExcel_Chart + * @throws PHPExcel_Exception + */ + public function getChartByIndex($index = null) + { + $chartCount = count($this->_chartCollection); + if ($chartCount == 0) { + return false; + } + if (is_null($index)) { + $index = --$chartCount; + } + if (!isset($this->_chartCollection[$index])) { + return false; + } + + return $this->_chartCollection[$index]; + } + + /** + * Return an array of the names of charts on this worksheet + * + * @return string[] The names of charts + * @throws PHPExcel_Exception + */ + public function getChartNames() + { + $chartNames = array(); + foreach($this->_chartCollection as $chart) { + $chartNames[] = $chart->getName(); + } + return $chartNames; + } + + /** + * Get a chart by name + * + * @param string $chartName Chart name + * @return false|PHPExcel_Chart + * @throws PHPExcel_Exception + */ + public function getChartByName($chartName = '') + { + $chartCount = count($this->_chartCollection); + if ($chartCount == 0) { + return false; + } + foreach($this->_chartCollection as $index => $chart) { + if ($chart->getName() == $chartName) { + return $this->_chartCollection[$index]; + } + } + return false; + } + + /** + * Refresh column dimensions + * + * @return PHPExcel_Worksheet + */ + public function refreshColumnDimensions() + { + $currentColumnDimensions = $this->getColumnDimensions(); + $newColumnDimensions = array(); + + foreach ($currentColumnDimensions as $objColumnDimension) { + $newColumnDimensions[$objColumnDimension->getColumnIndex()] = $objColumnDimension; + } + + $this->_columnDimensions = $newColumnDimensions; + + return $this; + } + + /** + * Refresh row dimensions + * + * @return PHPExcel_Worksheet + */ + public function refreshRowDimensions() + { + $currentRowDimensions = $this->getRowDimensions(); + $newRowDimensions = array(); + + foreach ($currentRowDimensions as $objRowDimension) { + $newRowDimensions[$objRowDimension->getRowIndex()] = $objRowDimension; + } + + $this->_rowDimensions = $newRowDimensions; + + return $this; + } + + /** + * Calculate worksheet dimension + * + * @return string String containing the dimension of this worksheet + */ + public function calculateWorksheetDimension() + { + // Return + return 'A1' . ':' . $this->getHighestColumn() . $this->getHighestRow(); + } + + /** + * Calculate worksheet data dimension + * + * @return string String containing the dimension of this worksheet that actually contain data + */ + public function calculateWorksheetDataDimension() + { + // Return + return 'A1' . ':' . $this->getHighestDataColumn() . $this->getHighestDataRow(); + } + + /** + * Calculate widths for auto-size columns + * + * @param boolean $calculateMergeCells Calculate merge cell width + * @return PHPExcel_Worksheet; + */ + public function calculateColumnWidths($calculateMergeCells = false) + { + // initialize $autoSizes array + $autoSizes = array(); + foreach ($this->getColumnDimensions() as $colDimension) { + if ($colDimension->getAutoSize()) { + $autoSizes[$colDimension->getColumnIndex()] = -1; + } + } + + // There is only something to do if there are some auto-size columns + if (!empty($autoSizes)) { + + // build list of cells references that participate in a merge + $isMergeCell = array(); + foreach ($this->getMergeCells() as $cells) { + foreach (PHPExcel_Cell::extractAllCellReferencesInRange($cells) as $cellReference) { + $isMergeCell[$cellReference] = true; + } + } + + // loop through all cells in the worksheet + foreach ($this->getCellCollection(false) as $cellID) { + $cell = $this->getCell($cellID); + if (isset($autoSizes[$cell->getColumn()])) { + // Determine width if cell does not participate in a merge + if (!isset($isMergeCell[$cell->getCoordinate()])) { + // Calculated value + $cellValue = $cell->getCalculatedValue(); + + // To formatted string + $cellValue = PHPExcel_Style_NumberFormat::toFormattedString($cellValue, $this->getParent()->getCellXfByIndex($cell->getXfIndex())->getNumberFormat()->getFormatCode()); + + $autoSizes[$cell->getColumn()] = max( + (float)$autoSizes[$cell->getColumn()], + (float)PHPExcel_Shared_Font::calculateColumnWidth( + $this->getParent()->getCellXfByIndex($cell->getXfIndex())->getFont(), + $cellValue, + $this->getParent()->getCellXfByIndex($cell->getXfIndex())->getAlignment()->getTextRotation(), + $this->getDefaultStyle()->getFont() + ) + ); + } + } + } + + // adjust column widths + foreach ($autoSizes as $columnIndex => $width) { + if ($width == -1) $width = $this->getDefaultColumnDimension()->getWidth(); + $this->getColumnDimension($columnIndex)->setWidth($width); + } + } + + return $this; + } + + /** + * Get parent + * + * @return PHPExcel + */ + public function getParent() + { + return $this->_parent; + } + + /** + * Re-bind parent + * + * @param PHPExcel $parent + * @return PHPExcel_Worksheet + */ + public function rebindParent(PHPExcel $parent) + { + $namedRanges = $this->_parent->getNamedRanges(); + foreach ($namedRanges as $namedRange) { + $parent->addNamedRange($namedRange); + } + + $this->_parent->removeSheetByIndex( + $this->_parent->getIndex($this) + ); + $this->_parent = $parent; + + return $this; + } + + /** + * Get title + * + * @return string + */ + public function getTitle() + { + return $this->_title; + } + + /** + * Set title + * + * @param string $pValue String containing the dimension of this worksheet + * @param string $updateFormulaCellReferences boolean Flag indicating whether cell references in formulae should + * be updated to reflect the new sheet name. + * This should be left as the default true, unless you are + * certain that no formula cells on any worksheet contain + * references to this worksheet + * + * @return PHPExcel_Worksheet + */ + public function setTitle($pValue = 'Worksheet', $updateFormulaCellReferences = true) + { + // Is this a 'rename' or not? + if ($this->getTitle() == $pValue) { + return $this; + } + + // Syntax check + self::_checkSheetTitle($pValue); + + // Old title + $oldTitle = $this->getTitle(); if ($this->getParent()) { - // Is there already such sheet name? - if ($this->getParent()->sheetNameExists($pValue)) { - // Use name, but append with lowest possible integer + // Is there already such sheet name? + if ($this->getParent()->sheetNameExists($pValue)) { + // Use name, but append with lowest possible integer - if (PHPExcel_Shared_String::CountCharacters($pValue) > 29) { - $pValue = PHPExcel_Shared_String::Substring($pValue,0,29); - } - $i = 1; - while ($this->getParent()->sheetNameExists($pValue . ' ' . $i)) { - ++$i; - if ($i == 10) { - if (PHPExcel_Shared_String::CountCharacters($pValue) > 28) { - $pValue = PHPExcel_Shared_String::Substring($pValue,0,28); - } - } elseif ($i == 100) { - if (PHPExcel_Shared_String::CountCharacters($pValue) > 27) { - $pValue = PHPExcel_Shared_String::Substring($pValue,0,27); - } - } - } + if (PHPExcel_Shared_String::CountCharacters($pValue) > 29) { + $pValue = PHPExcel_Shared_String::Substring($pValue,0,29); + } + $i = 1; + while ($this->getParent()->sheetNameExists($pValue . ' ' . $i)) { + ++$i; + if ($i == 10) { + if (PHPExcel_Shared_String::CountCharacters($pValue) > 28) { + $pValue = PHPExcel_Shared_String::Substring($pValue,0,28); + } + } elseif ($i == 100) { + if (PHPExcel_Shared_String::CountCharacters($pValue) > 27) { + $pValue = PHPExcel_Shared_String::Substring($pValue,0,27); + } + } + } - $altTitle = $pValue . ' ' . $i; - return $this->setTitle($altTitle,$updateFormulaCellReferences); - } - } + $altTitle = $pValue . ' ' . $i; + return $this->setTitle($altTitle,$updateFormulaCellReferences); + } + } - // Set title - $this->_title = $pValue; - $this->_dirty = true; + // Set title + $this->_title = $pValue; + $this->_dirty = true; if ($this->getParent()) { - // New title - $newTitle = $this->getTitle(); - if ($updateFormulaCellReferences) - PHPExcel_ReferenceHelper::getInstance()->updateNamedFormulas($this->getParent(), $oldTitle, $newTitle); - } - - return $this; - } - - /** - * Get sheet state - * - * @return string Sheet state (visible, hidden, veryHidden) - */ - public function getSheetState() { - return $this->_sheetState; - } - - /** - * Set sheet state - * - * @param string $value Sheet state (visible, hidden, veryHidden) - * @return PHPExcel_Worksheet - */ - public function setSheetState($value = PHPExcel_Worksheet::SHEETSTATE_VISIBLE) { - $this->_sheetState = $value; - return $this; - } - - /** - * Get page setup - * - * @return PHPExcel_Worksheet_PageSetup - */ - public function getPageSetup() - { - return $this->_pageSetup; - } - - /** - * Set page setup - * - * @param PHPExcel_Worksheet_PageSetup $pValue - * @return PHPExcel_Worksheet - */ - public function setPageSetup(PHPExcel_Worksheet_PageSetup $pValue) - { - $this->_pageSetup = $pValue; - return $this; - } - - /** - * Get page margins - * - * @return PHPExcel_Worksheet_PageMargins - */ - public function getPageMargins() - { - return $this->_pageMargins; - } - - /** - * Set page margins - * - * @param PHPExcel_Worksheet_PageMargins $pValue - * @return PHPExcel_Worksheet - */ - public function setPageMargins(PHPExcel_Worksheet_PageMargins $pValue) - { - $this->_pageMargins = $pValue; - return $this; - } - - /** - * Get page header/footer - * - * @return PHPExcel_Worksheet_HeaderFooter - */ - public function getHeaderFooter() - { - return $this->_headerFooter; - } - - /** - * Set page header/footer - * - * @param PHPExcel_Worksheet_HeaderFooter $pValue - * @return PHPExcel_Worksheet - */ - public function setHeaderFooter(PHPExcel_Worksheet_HeaderFooter $pValue) - { - $this->_headerFooter = $pValue; - return $this; - } - - /** - * Get sheet view - * - * @return PHPExcel_Worksheet_SheetView - */ - public function getSheetView() - { - return $this->_sheetView; - } - - /** - * Set sheet view - * - * @param PHPExcel_Worksheet_SheetView $pValue - * @return PHPExcel_Worksheet - */ - public function setSheetView(PHPExcel_Worksheet_SheetView $pValue) - { - $this->_sheetView = $pValue; - return $this; - } - - /** - * Get Protection - * - * @return PHPExcel_Worksheet_Protection - */ - public function getProtection() - { - return $this->_protection; - } - - /** - * Set Protection - * - * @param PHPExcel_Worksheet_Protection $pValue - * @return PHPExcel_Worksheet - */ - public function setProtection(PHPExcel_Worksheet_Protection $pValue) - { - $this->_protection = $pValue; - $this->_dirty = true; - - return $this; - } - - /** - * Get highest worksheet column - * - * @return string Highest column name - */ - public function getHighestColumn() - { - return $this->_cachedHighestColumn; - } - - /** - * Get highest worksheet column that contains data - * - * @return string Highest column name that contains data - */ - public function getHighestDataColumn() - { - return $this->_cellCollection->getHighestColumn(); - } - - /** - * Get highest worksheet row - * - * @return int Highest row number - */ - public function getHighestRow() - { - return $this->_cachedHighestRow; - } - - /** - * Get highest worksheet row that contains data - * - * @return string Highest row number that contains data - */ - public function getHighestDataRow() - { - return $this->_cellCollection->getHighestRow(); - } - - /** - * Get highest worksheet column and highest row that have cell records - * - * @return array Highest column name and highest row number - */ - public function getHighestRowAndColumn() - { - return $this->_cellCollection->getHighestRowAndColumn(); - } - - /** - * Set a cell value - * - * @param string $pCoordinate Coordinate of the cell - * @param mixed $pValue Value of the cell - * @param bool $returnCell Return the worksheet (false, default) or the cell (true) - * @return PHPExcel_Worksheet|PHPExcel_Cell Depending on the last parameter being specified - */ - public function setCellValue($pCoordinate = 'A1', $pValue = null, $returnCell = false) - { - $cell = $this->getCell($pCoordinate)->setValue($pValue); - return ($returnCell) ? $cell : $this; - } - - /** - * Set a cell value by using numeric cell coordinates - * - * @param string $pColumn Numeric column coordinate of the cell (A = 0) - * @param string $pRow Numeric row coordinate of the cell - * @param mixed $pValue Value of the cell - * @param bool $returnCell Return the worksheet (false, default) or the cell (true) - * @return PHPExcel_Worksheet|PHPExcel_Cell Depending on the last parameter being specified - */ - public function setCellValueByColumnAndRow($pColumn = 0, $pRow = 1, $pValue = null, $returnCell = false) - { - $cell = $this->getCell(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow)->setValue($pValue); - return ($returnCell) ? $cell : $this; - } - - /** - * Set a cell value - * - * @param string $pCoordinate Coordinate of the cell - * @param mixed $pValue Value of the cell - * @param string $pDataType Explicit data type - * @param bool $returnCell Return the worksheet (false, default) or the cell (true) - * @return PHPExcel_Worksheet|PHPExcel_Cell Depending on the last parameter being specified - */ - public function setCellValueExplicit($pCoordinate = 'A1', $pValue = null, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING, $returnCell = false) - { - // Set value - $cell = $this->getCell($pCoordinate)->setValueExplicit($pValue, $pDataType); - return ($returnCell) ? $cell : $this; - } - - /** - * Set a cell value by using numeric cell coordinates - * - * @param string $pColumn Numeric column coordinate of the cell - * @param string $pRow Numeric row coordinate of the cell - * @param mixed $pValue Value of the cell - * @param string $pDataType Explicit data type - * @param bool $returnCell Return the worksheet (false, default) or the cell (true) - * @return PHPExcel_Worksheet|PHPExcel_Cell Depending on the last parameter being specified - */ - public function setCellValueExplicitByColumnAndRow($pColumn = 0, $pRow = 1, $pValue = null, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING, $returnCell = false) - { - $cell = $this->getCell(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow)->setValueExplicit($pValue, $pDataType); - return ($returnCell) ? $cell : $this; - } - - /** - * Get cell at a specific coordinate - * - * @param string $pCoordinate Coordinate of the cell - * @throws PHPExcel_Exception - * @return PHPExcel_Cell Cell that was found - */ - public function getCell($pCoordinate = 'A1') - { - // Check cell collection - if ($this->_cellCollection->isDataSet($pCoordinate)) { - return $this->_cellCollection->getCacheData($pCoordinate); - } - - // Worksheet reference? - if (strpos($pCoordinate, '!') !== false) { - $worksheetReference = PHPExcel_Worksheet::extractSheetTitle($pCoordinate, true); - return $this->getParent()->getSheetByName($worksheetReference[0])->getCell($worksheetReference[1]); - } - - // Named range? - if ((!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $pCoordinate, $matches)) && - (preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_NAMEDRANGE.'$/i', $pCoordinate, $matches))) { - $namedRange = PHPExcel_NamedRange::resolveRange($pCoordinate, $this); - if ($namedRange !== NULL) { - $pCoordinate = $namedRange->getRange(); - return $namedRange->getWorksheet()->getCell($pCoordinate); - } - } - - // Uppercase coordinate - $pCoordinate = strtoupper($pCoordinate); - - if (strpos($pCoordinate,':') !== false || strpos($pCoordinate,',') !== false) { - throw new PHPExcel_Exception('Cell coordinate can not be a range of cells.'); - } elseif (strpos($pCoordinate,'$') !== false) { - throw new PHPExcel_Exception('Cell coordinate must not be absolute.'); - } else { - // Create new cell object - - // Coordinates - $aCoordinates = PHPExcel_Cell::coordinateFromString($pCoordinate); - - $cell = $this->_cellCollection->addCacheData($pCoordinate,new PHPExcel_Cell($pCoordinate, NULL, PHPExcel_Cell_DataType::TYPE_NULL, $this)); - $this->_cellCollectionIsSorted = false; - - if (PHPExcel_Cell::columnIndexFromString($this->_cachedHighestColumn) < PHPExcel_Cell::columnIndexFromString($aCoordinates[0])) - $this->_cachedHighestColumn = $aCoordinates[0]; - - $this->_cachedHighestRow = max($this->_cachedHighestRow,$aCoordinates[1]); - - // Cell needs appropriate xfIndex - $rowDimensions = $this->getRowDimensions(); - $columnDimensions = $this->getColumnDimensions(); - - if ( isset($rowDimensions[$aCoordinates[1]]) && $rowDimensions[$aCoordinates[1]]->getXfIndex() !== null ) { - // then there is a row dimension with explicit style, assign it to the cell - $cell->setXfIndex($rowDimensions[$aCoordinates[1]]->getXfIndex()); - } else if ( isset($columnDimensions[$aCoordinates[0]]) ) { - // then there is a column dimension, assign it to the cell - $cell->setXfIndex($columnDimensions[$aCoordinates[0]]->getXfIndex()); - } else { - // set to default index - $cell->setXfIndex(0); - } - - return $cell; - } - } - - /** - * Get cell at a specific coordinate by using numeric cell coordinates - * - * @param string $pColumn Numeric column coordinate of the cell - * @param string $pRow Numeric row coordinate of the cell - * @return PHPExcel_Cell Cell that was found - */ - public function getCellByColumnAndRow($pColumn = 0, $pRow = 1) - { - $columnLetter = PHPExcel_Cell::stringFromColumnIndex($pColumn); - $coordinate = $columnLetter . $pRow; - - if (!$this->_cellCollection->isDataSet($coordinate)) { - $cell = $this->_cellCollection->addCacheData($coordinate, new PHPExcel_Cell($coordinate, NULL, PHPExcel_Cell_DataType::TYPE_NULL, $this)); - $this->_cellCollectionIsSorted = false; - - if (PHPExcel_Cell::columnIndexFromString($this->_cachedHighestColumn) < $pColumn) - $this->_cachedHighestColumn = $columnLetter; - - $this->_cachedHighestRow = max($this->_cachedHighestRow,$pRow); - - return $cell; - } - - return $this->_cellCollection->getCacheData($coordinate); - } - - /** - * Cell at a specific coordinate exists? - * - * @param string $pCoordinate Coordinate of the cell - * @throws PHPExcel_Exception - * @return boolean - */ - public function cellExists($pCoordinate = 'A1') - { - // Worksheet reference? - if (strpos($pCoordinate, '!') !== false) { - $worksheetReference = PHPExcel_Worksheet::extractSheetTitle($pCoordinate, true); - return $this->getParent()->getSheetByName($worksheetReference[0])->cellExists($worksheetReference[1]); - } - - // Named range? - if ((!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $pCoordinate, $matches)) && - (preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_NAMEDRANGE.'$/i', $pCoordinate, $matches))) { - $namedRange = PHPExcel_NamedRange::resolveRange($pCoordinate, $this); - if ($namedRange !== NULL) { - $pCoordinate = $namedRange->getRange(); - if ($this->getHashCode() != $namedRange->getWorksheet()->getHashCode()) { - if (!$namedRange->getLocalOnly()) { - return $namedRange->getWorksheet()->cellExists($pCoordinate); - } else { - throw new PHPExcel_Exception('Named range ' . $namedRange->getName() . ' is not accessible from within sheet ' . $this->getTitle()); - } - } - } - else { return false; } - } - - // Uppercase coordinate - $pCoordinate = strtoupper($pCoordinate); - - if (strpos($pCoordinate,':') !== false || strpos($pCoordinate,',') !== false) { - throw new PHPExcel_Exception('Cell coordinate can not be a range of cells.'); - } elseif (strpos($pCoordinate,'$') !== false) { - throw new PHPExcel_Exception('Cell coordinate must not be absolute.'); - } else { - // Coordinates - $aCoordinates = PHPExcel_Cell::coordinateFromString($pCoordinate); - - // Cell exists? - return $this->_cellCollection->isDataSet($pCoordinate); - } - } - - /** - * Cell at a specific coordinate by using numeric cell coordinates exists? - * - * @param string $pColumn Numeric column coordinate of the cell - * @param string $pRow Numeric row coordinate of the cell - * @return boolean - */ - public function cellExistsByColumnAndRow($pColumn = 0, $pRow = 1) - { - return $this->cellExists(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow); - } - - /** - * Get row dimension at a specific row - * - * @param int $pRow Numeric index of the row - * @return PHPExcel_Worksheet_RowDimension - */ - public function getRowDimension($pRow = 1) - { - // Found - $found = null; - - // Get row dimension - if (!isset($this->_rowDimensions[$pRow])) { - $this->_rowDimensions[$pRow] = new PHPExcel_Worksheet_RowDimension($pRow); - - $this->_cachedHighestRow = max($this->_cachedHighestRow,$pRow); - } - return $this->_rowDimensions[$pRow]; - } - - /** - * Get column dimension at a specific column - * - * @param string $pColumn String index of the column - * @return PHPExcel_Worksheet_ColumnDimension - */ - public function getColumnDimension($pColumn = 'A') - { - // Uppercase coordinate - $pColumn = strtoupper($pColumn); - - // Fetch dimensions - if (!isset($this->_columnDimensions[$pColumn])) { - $this->_columnDimensions[$pColumn] = new PHPExcel_Worksheet_ColumnDimension($pColumn); - - if (PHPExcel_Cell::columnIndexFromString($this->_cachedHighestColumn) < PHPExcel_Cell::columnIndexFromString($pColumn)) - $this->_cachedHighestColumn = $pColumn; - } - return $this->_columnDimensions[$pColumn]; - } - - /** - * Get column dimension at a specific column by using numeric cell coordinates - * - * @param string $pColumn Numeric column coordinate of the cell - * @return PHPExcel_Worksheet_ColumnDimension - */ - public function getColumnDimensionByColumn($pColumn = 0) - { - return $this->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($pColumn)); - } - - /** - * Get styles - * - * @return PHPExcel_Style[] - */ - public function getStyles() - { - return $this->_styles; - } - - /** - * Get default style of workbook. - * - * @deprecated - * @return PHPExcel_Style - * @throws PHPExcel_Exception - */ - public function getDefaultStyle() - { - return $this->_parent->getDefaultStyle(); - } - - /** - * Set default style - should only be used by PHPExcel_IReader implementations! - * - * @deprecated - * @param PHPExcel_Style $pValue - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function setDefaultStyle(PHPExcel_Style $pValue) - { - $this->_parent->getDefaultStyle()->applyFromArray(array( - 'font' => array( - 'name' => $pValue->getFont()->getName(), - 'size' => $pValue->getFont()->getSize(), - ), - )); - return $this; - } - - /** - * Get style for cell - * - * @param string $pCellCoordinate Cell coordinate to get style for - * @return PHPExcel_Style - * @throws PHPExcel_Exception - */ - public function getStyle($pCellCoordinate = 'A1') - { - // set this sheet as active - $this->_parent->setActiveSheetIndex($this->_parent->getIndex($this)); - - // set cell coordinate as active - $this->setSelectedCells($pCellCoordinate); - - return $this->_parent->getCellXfSupervisor(); - } - - /** - * Get conditional styles for a cell - * - * @param string $pCoordinate - * @return PHPExcel_Style_Conditional[] - */ - public function getConditionalStyles($pCoordinate = 'A1') - { - if (!isset($this->_conditionalStylesCollection[$pCoordinate])) { - $this->_conditionalStylesCollection[$pCoordinate] = array(); - } - return $this->_conditionalStylesCollection[$pCoordinate]; - } - - /** - * Do conditional styles exist for this cell? - * - * @param string $pCoordinate - * @return boolean - */ - public function conditionalStylesExists($pCoordinate = 'A1') - { - if (isset($this->_conditionalStylesCollection[$pCoordinate])) { - return true; - } - return false; - } - - /** - * Removes conditional styles for a cell - * - * @param string $pCoordinate - * @return PHPExcel_Worksheet - */ - public function removeConditionalStyles($pCoordinate = 'A1') - { - unset($this->_conditionalStylesCollection[$pCoordinate]); - return $this; - } - - /** - * Get collection of conditional styles - * - * @return array - */ - public function getConditionalStylesCollection() - { - return $this->_conditionalStylesCollection; - } - - /** - * Set conditional styles - * - * @param $pCoordinate string E.g. 'A1' - * @param $pValue PHPExcel_Style_Conditional[] - * @return PHPExcel_Worksheet - */ - public function setConditionalStyles($pCoordinate = 'A1', $pValue) - { - $this->_conditionalStylesCollection[$pCoordinate] = $pValue; - return $this; - } - - /** - * Get style for cell by using numeric cell coordinates - * - * @param int $pColumn Numeric column coordinate of the cell - * @param int $pRow Numeric row coordinate of the cell - * @return PHPExcel_Style - */ - public function getStyleByColumnAndRow($pColumn = 0, $pRow = 1) - { - return $this->getStyle(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow); - } - - /** - * Set shared cell style to a range of cells - * - * Please note that this will overwrite existing cell styles for cells in range! - * - * @deprecated - * @param PHPExcel_Style $pSharedCellStyle Cell style to share - * @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1") - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function setSharedStyle(PHPExcel_Style $pSharedCellStyle = null, $pRange = '') - { - $this->duplicateStyle($pSharedCellStyle, $pRange); - return $this; - } - - /** - * Duplicate cell style to a range of cells - * - * Please note that this will overwrite existing cell styles for cells in range! - * - * @param PHPExcel_Style $pCellStyle Cell style to duplicate - * @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1") - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function duplicateStyle(PHPExcel_Style $pCellStyle = null, $pRange = '') - { - // make sure we have a real style and not supervisor - $style = $pCellStyle->getIsSupervisor() ? $pCellStyle->getSharedComponent() : $pCellStyle; - - // Add the style to the workbook if necessary - $workbook = $this->_parent; - if ($this->_parent->cellXfExists($pCellStyle)) { - // there is already this cell Xf in our collection - $xfIndex = $pCellStyle->getIndex(); - } else { - // we don't have such a cell Xf, need to add - $workbook->addCellXf($pCellStyle); - $xfIndex = $pCellStyle->getIndex(); - } - - // Uppercase coordinate - $pRange = strtoupper($pRange); - - // Is it a cell range or a single cell? - $rangeA = ''; - $rangeB = ''; - if (strpos($pRange, ':') === false) { - $rangeA = $pRange; - $rangeB = $pRange; - } else { - list($rangeA, $rangeB) = explode(':', $pRange); - } - - // Calculate range outer borders - $rangeStart = PHPExcel_Cell::coordinateFromString($rangeA); - $rangeEnd = PHPExcel_Cell::coordinateFromString($rangeB); - - // Translate column into index - $rangeStart[0] = PHPExcel_Cell::columnIndexFromString($rangeStart[0]) - 1; - $rangeEnd[0] = PHPExcel_Cell::columnIndexFromString($rangeEnd[0]) - 1; - - // Make sure we can loop upwards on rows and columns - if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) { - $tmp = $rangeStart; - $rangeStart = $rangeEnd; - $rangeEnd = $tmp; - } - - // Loop through cells and apply styles - for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) { - for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) { - $this->getCell(PHPExcel_Cell::stringFromColumnIndex($col) . $row)->setXfIndex($xfIndex); - } - } - - return $this; - } - - /** - * Duplicate conditional style to a range of cells - * - * Please note that this will overwrite existing cell styles for cells in range! - * - * @param array of PHPExcel_Style_Conditional $pCellStyle Cell style to duplicate - * @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1") - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function duplicateConditionalStyle(array $pCellStyle = null, $pRange = '') - { - foreach($pCellStyle as $cellStyle) { - if (!($cellStyle instanceof PHPExcel_Style_Conditional)) { - throw new PHPExcel_Exception('Style is not a conditional style'); - } - } - - // Uppercase coordinate - $pRange = strtoupper($pRange); - - // Is it a cell range or a single cell? - $rangeA = ''; - $rangeB = ''; - if (strpos($pRange, ':') === false) { - $rangeA = $pRange; - $rangeB = $pRange; - } else { - list($rangeA, $rangeB) = explode(':', $pRange); - } - - // Calculate range outer borders - $rangeStart = PHPExcel_Cell::coordinateFromString($rangeA); - $rangeEnd = PHPExcel_Cell::coordinateFromString($rangeB); - - // Translate column into index - $rangeStart[0] = PHPExcel_Cell::columnIndexFromString($rangeStart[0]) - 1; - $rangeEnd[0] = PHPExcel_Cell::columnIndexFromString($rangeEnd[0]) - 1; - - // Make sure we can loop upwards on rows and columns - if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) { - $tmp = $rangeStart; - $rangeStart = $rangeEnd; - $rangeEnd = $tmp; - } - - // Loop through cells and apply styles - for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) { - for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) { - $this->setConditionalStyles(PHPExcel_Cell::stringFromColumnIndex($col) . $row, $pCellStyle); - } - } - - return $this; - } - - /** - * Duplicate cell style array to a range of cells - * - * Please note that this will overwrite existing cell styles for cells in range, - * if they are in the styles array. For example, if you decide to set a range of - * cells to font bold, only include font bold in the styles array. - * - * @deprecated - * @param array $pStyles Array containing style information - * @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1") - * @param boolean $pAdvanced Advanced mode for setting borders. - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function duplicateStyleArray($pStyles = null, $pRange = '', $pAdvanced = true) - { - $this->getStyle($pRange)->applyFromArray($pStyles, $pAdvanced); - return $this; - } - - /** - * Set break on a cell - * - * @param string $pCell Cell coordinate (e.g. A1) - * @param int $pBreak Break type (type of PHPExcel_Worksheet::BREAK_*) - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function setBreak($pCell = 'A1', $pBreak = PHPExcel_Worksheet::BREAK_NONE) - { - // Uppercase coordinate - $pCell = strtoupper($pCell); - - if ($pCell != '') { - $this->_breaks[$pCell] = $pBreak; - } else { - throw new PHPExcel_Exception('No cell coordinate specified.'); - } - - return $this; - } - - /** - * Set break on a cell by using numeric cell coordinates - * - * @param integer $pColumn Numeric column coordinate of the cell - * @param integer $pRow Numeric row coordinate of the cell - * @param integer $pBreak Break type (type of PHPExcel_Worksheet::BREAK_*) - * @return PHPExcel_Worksheet - */ - public function setBreakByColumnAndRow($pColumn = 0, $pRow = 1, $pBreak = PHPExcel_Worksheet::BREAK_NONE) - { - return $this->setBreak(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow, $pBreak); - } - - /** - * Get breaks - * - * @return array[] - */ - public function getBreaks() - { - return $this->_breaks; - } - - /** - * Set merge on a cell range - * - * @param string $pRange Cell range (e.g. A1:E1) - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function mergeCells($pRange = 'A1:A1') - { - // Uppercase coordinate - $pRange = strtoupper($pRange); - - if (strpos($pRange,':') !== false) { - $this->_mergeCells[$pRange] = $pRange; - - // make sure cells are created - - // get the cells in the range - $aReferences = PHPExcel_Cell::extractAllCellReferencesInRange($pRange); - - // create upper left cell if it does not already exist - $upperLeft = $aReferences[0]; - if (!$this->cellExists($upperLeft)) { - $this->getCell($upperLeft)->setValueExplicit(null, PHPExcel_Cell_DataType::TYPE_NULL); - } - - // create or blank out the rest of the cells in the range - $count = count($aReferences); - for ($i = 1; $i < $count; $i++) { - $this->getCell($aReferences[$i])->setValueExplicit(null, PHPExcel_Cell_DataType::TYPE_NULL); - } - - } else { - throw new PHPExcel_Exception('Merge must be set on a range of cells.'); - } - - return $this; - } - - /** - * Set merge on a cell range by using numeric cell coordinates - * - * @param int $pColumn1 Numeric column coordinate of the first cell - * @param int $pRow1 Numeric row coordinate of the first cell - * @param int $pColumn2 Numeric column coordinate of the last cell - * @param int $pRow2 Numeric row coordinate of the last cell - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function mergeCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1) - { - $cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2; - return $this->mergeCells($cellRange); - } - - /** - * Remove merge on a cell range - * - * @param string $pRange Cell range (e.g. A1:E1) - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function unmergeCells($pRange = 'A1:A1') - { - // Uppercase coordinate - $pRange = strtoupper($pRange); - - if (strpos($pRange,':') !== false) { - if (isset($this->_mergeCells[$pRange])) { - unset($this->_mergeCells[$pRange]); - } else { - throw new PHPExcel_Exception('Cell range ' . $pRange . ' not known as merged.'); - } - } else { - throw new PHPExcel_Exception('Merge can only be removed from a range of cells.'); - } - - return $this; - } - - /** - * Remove merge on a cell range by using numeric cell coordinates - * - * @param int $pColumn1 Numeric column coordinate of the first cell - * @param int $pRow1 Numeric row coordinate of the first cell - * @param int $pColumn2 Numeric column coordinate of the last cell - * @param int $pRow2 Numeric row coordinate of the last cell - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function unmergeCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1) - { - $cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2; - return $this->unmergeCells($cellRange); - } - - /** - * Get merge cells array. - * - * @return array[] - */ - public function getMergeCells() - { - return $this->_mergeCells; - } - - /** - * Set merge cells array for the entire sheet. Use instead mergeCells() to merge - * a single cell range. - * - * @param array - */ - public function setMergeCells($pValue = array()) - { - $this->_mergeCells = $pValue; - - return $this; - } - - /** - * Set protection on a cell range - * - * @param string $pRange Cell (e.g. A1) or cell range (e.g. A1:E1) - * @param string $pPassword Password to unlock the protection - * @param boolean $pAlreadyHashed If the password has already been hashed, set this to true - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function protectCells($pRange = 'A1', $pPassword = '', $pAlreadyHashed = false) - { - // Uppercase coordinate - $pRange = strtoupper($pRange); - - if (!$pAlreadyHashed) { - $pPassword = PHPExcel_Shared_PasswordHasher::hashPassword($pPassword); - } - $this->_protectedCells[$pRange] = $pPassword; - - return $this; - } - - /** - * Set protection on a cell range by using numeric cell coordinates - * - * @param int $pColumn1 Numeric column coordinate of the first cell - * @param int $pRow1 Numeric row coordinate of the first cell - * @param int $pColumn2 Numeric column coordinate of the last cell - * @param int $pRow2 Numeric row coordinate of the last cell - * @param string $pPassword Password to unlock the protection - * @param boolean $pAlreadyHashed If the password has already been hashed, set this to true - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function protectCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1, $pPassword = '', $pAlreadyHashed = false) - { - $cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2; - return $this->protectCells($cellRange, $pPassword, $pAlreadyHashed); - } - - /** - * Remove protection on a cell range - * - * @param string $pRange Cell (e.g. A1) or cell range (e.g. A1:E1) - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function unprotectCells($pRange = 'A1') - { - // Uppercase coordinate - $pRange = strtoupper($pRange); - - if (isset($this->_protectedCells[$pRange])) { - unset($this->_protectedCells[$pRange]); - } else { - throw new PHPExcel_Exception('Cell range ' . $pRange . ' not known as protected.'); - } - return $this; - } - - /** - * Remove protection on a cell range by using numeric cell coordinates - * - * @param int $pColumn1 Numeric column coordinate of the first cell - * @param int $pRow1 Numeric row coordinate of the first cell - * @param int $pColumn2 Numeric column coordinate of the last cell - * @param int $pRow2 Numeric row coordinate of the last cell - * @param string $pPassword Password to unlock the protection - * @param boolean $pAlreadyHashed If the password has already been hashed, set this to true - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function unprotectCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1, $pPassword = '', $pAlreadyHashed = false) - { - $cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2; - return $this->unprotectCells($cellRange, $pPassword, $pAlreadyHashed); - } - - /** - * Get protected cells - * - * @return array[] - */ - public function getProtectedCells() - { - return $this->_protectedCells; - } - - /** - * Get Autofilter - * - * @return PHPExcel_Worksheet_AutoFilter - */ - public function getAutoFilter() - { - return $this->_autoFilter; - } - - /** - * Set AutoFilter - * - * @param PHPExcel_Worksheet_AutoFilter|string $pValue - * A simple string containing a Cell range like 'A1:E10' is permitted for backward compatibility - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function setAutoFilter($pValue) - { - if (is_string($pValue)) { - $this->_autoFilter->setRange($pValue); - } elseif(is_object($pValue) && ($pValue instanceof PHPExcel_Worksheet_AutoFilter)) { - $this->_autoFilter = $pValue; - } - return $this; - } - - /** - * Set Autofilter Range by using numeric cell coordinates - * - * @param int $pColumn1 Numeric column coordinate of the first cell - * @param int $pRow1 Numeric row coordinate of the first cell - * @param int $pColumn2 Numeric column coordinate of the second cell - * @param int $pRow2 Numeric row coordinate of the second cell - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function setAutoFilterByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1) - { - return $this->setAutoFilter( - PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 - . ':' . - PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2 - ); - } + // New title + $newTitle = $this->getTitle(); + if ($updateFormulaCellReferences) + PHPExcel_ReferenceHelper::getInstance()->updateNamedFormulas($this->getParent(), $oldTitle, $newTitle); + } + + return $this; + } + + /** + * Get sheet state + * + * @return string Sheet state (visible, hidden, veryHidden) + */ + public function getSheetState() + { + return $this->_sheetState; + } + + /** + * Set sheet state + * + * @param string $value Sheet state (visible, hidden, veryHidden) + * @return PHPExcel_Worksheet + */ + public function setSheetState($value = PHPExcel_Worksheet::SHEETSTATE_VISIBLE) + { + $this->_sheetState = $value; + return $this; + } + + /** + * Get page setup + * + * @return PHPExcel_Worksheet_PageSetup + */ + public function getPageSetup() + { + return $this->_pageSetup; + } + + /** + * Set page setup + * + * @param PHPExcel_Worksheet_PageSetup $pValue + * @return PHPExcel_Worksheet + */ + public function setPageSetup(PHPExcel_Worksheet_PageSetup $pValue) + { + $this->_pageSetup = $pValue; + return $this; + } + + /** + * Get page margins + * + * @return PHPExcel_Worksheet_PageMargins + */ + public function getPageMargins() + { + return $this->_pageMargins; + } + + /** + * Set page margins + * + * @param PHPExcel_Worksheet_PageMargins $pValue + * @return PHPExcel_Worksheet + */ + public function setPageMargins(PHPExcel_Worksheet_PageMargins $pValue) + { + $this->_pageMargins = $pValue; + return $this; + } + + /** + * Get page header/footer + * + * @return PHPExcel_Worksheet_HeaderFooter + */ + public function getHeaderFooter() + { + return $this->_headerFooter; + } + + /** + * Set page header/footer + * + * @param PHPExcel_Worksheet_HeaderFooter $pValue + * @return PHPExcel_Worksheet + */ + public function setHeaderFooter(PHPExcel_Worksheet_HeaderFooter $pValue) + { + $this->_headerFooter = $pValue; + return $this; + } + + /** + * Get sheet view + * + * @return PHPExcel_Worksheet_SheetView + */ + public function getSheetView() + { + return $this->_sheetView; + } + + /** + * Set sheet view + * + * @param PHPExcel_Worksheet_SheetView $pValue + * @return PHPExcel_Worksheet + */ + public function setSheetView(PHPExcel_Worksheet_SheetView $pValue) + { + $this->_sheetView = $pValue; + return $this; + } + + /** + * Get Protection + * + * @return PHPExcel_Worksheet_Protection + */ + public function getProtection() + { + return $this->_protection; + } + + /** + * Set Protection + * + * @param PHPExcel_Worksheet_Protection $pValue + * @return PHPExcel_Worksheet + */ + public function setProtection(PHPExcel_Worksheet_Protection $pValue) + { + $this->_protection = $pValue; + $this->_dirty = true; + + return $this; + } + + /** + * Get highest worksheet column + * + * @return string Highest column name + */ + public function getHighestColumn() + { + return $this->_cachedHighestColumn; + } + + /** + * Get highest worksheet column that contains data + * + * @return string Highest column name that contains data + */ + public function getHighestDataColumn() + { + return $this->_cellCollection->getHighestColumn(); + } + + /** + * Get highest worksheet row + * + * @return int Highest row number + */ + public function getHighestRow() + { + return $this->_cachedHighestRow; + } + + /** + * Get highest worksheet row that contains data + * + * @return string Highest row number that contains data + */ + public function getHighestDataRow() + { + return $this->_cellCollection->getHighestRow(); + } + + /** + * Get highest worksheet column and highest row that have cell records + * + * @return array Highest column name and highest row number + */ + public function getHighestRowAndColumn() + { + return $this->_cellCollection->getHighestRowAndColumn(); + } + + /** + * Set a cell value + * + * @param string $pCoordinate Coordinate of the cell + * @param mixed $pValue Value of the cell + * @param bool $returnCell Return the worksheet (false, default) or the cell (true) + * @return PHPExcel_Worksheet|PHPExcel_Cell Depending on the last parameter being specified + */ + public function setCellValue($pCoordinate = 'A1', $pValue = null, $returnCell = false) + { + $cell = $this->getCell($pCoordinate)->setValue($pValue); + return ($returnCell) ? $cell : $this; + } + + /** + * Set a cell value by using numeric cell coordinates + * + * @param string $pColumn Numeric column coordinate of the cell (A = 0) + * @param string $pRow Numeric row coordinate of the cell + * @param mixed $pValue Value of the cell + * @param bool $returnCell Return the worksheet (false, default) or the cell (true) + * @return PHPExcel_Worksheet|PHPExcel_Cell Depending on the last parameter being specified + */ + public function setCellValueByColumnAndRow($pColumn = 0, $pRow = 1, $pValue = null, $returnCell = false) + { + $cell = $this->getCell(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow)->setValue($pValue); + return ($returnCell) ? $cell : $this; + } + + /** + * Set a cell value + * + * @param string $pCoordinate Coordinate of the cell + * @param mixed $pValue Value of the cell + * @param string $pDataType Explicit data type + * @param bool $returnCell Return the worksheet (false, default) or the cell (true) + * @return PHPExcel_Worksheet|PHPExcel_Cell Depending on the last parameter being specified + */ + public function setCellValueExplicit($pCoordinate = 'A1', $pValue = null, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING, $returnCell = false) + { + // Set value + $cell = $this->getCell($pCoordinate)->setValueExplicit($pValue, $pDataType); + return ($returnCell) ? $cell : $this; + } + + /** + * Set a cell value by using numeric cell coordinates + * + * @param string $pColumn Numeric column coordinate of the cell + * @param string $pRow Numeric row coordinate of the cell + * @param mixed $pValue Value of the cell + * @param string $pDataType Explicit data type + * @param bool $returnCell Return the worksheet (false, default) or the cell (true) + * @return PHPExcel_Worksheet|PHPExcel_Cell Depending on the last parameter being specified + */ + public function setCellValueExplicitByColumnAndRow($pColumn = 0, $pRow = 1, $pValue = null, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING, $returnCell = false) + { + $cell = $this->getCell(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow)->setValueExplicit($pValue, $pDataType); + return ($returnCell) ? $cell : $this; + } + + /** + * Get cell at a specific coordinate + * + * @param string $pCoordinate Coordinate of the cell + * @throws PHPExcel_Exception + * @return PHPExcel_Cell Cell that was found + */ + public function getCell($pCoordinate = 'A1') + { + // Check cell collection + if ($this->_cellCollection->isDataSet($pCoordinate)) { + return $this->_cellCollection->getCacheData($pCoordinate); + } + + // Worksheet reference? + if (strpos($pCoordinate, '!') !== false) { + $worksheetReference = PHPExcel_Worksheet::extractSheetTitle($pCoordinate, true); + return $this->getParent()->getSheetByName($worksheetReference[0])->getCell($worksheetReference[1]); + } + + // Named range? + if ((!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $pCoordinate, $matches)) && + (preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_NAMEDRANGE.'$/i', $pCoordinate, $matches))) { + $namedRange = PHPExcel_NamedRange::resolveRange($pCoordinate, $this); + if ($namedRange !== NULL) { + $pCoordinate = $namedRange->getRange(); + return $namedRange->getWorksheet()->getCell($pCoordinate); + } + } + + // Uppercase coordinate + $pCoordinate = strtoupper($pCoordinate); + + if (strpos($pCoordinate,':') !== false || strpos($pCoordinate,',') !== false) { + throw new PHPExcel_Exception('Cell coordinate can not be a range of cells.'); + } elseif (strpos($pCoordinate,'$') !== false) { + throw new PHPExcel_Exception('Cell coordinate must not be absolute.'); + } else { + // Create new cell object + + // Coordinates + $aCoordinates = PHPExcel_Cell::coordinateFromString($pCoordinate); + + $cell = $this->_cellCollection->addCacheData($pCoordinate,new PHPExcel_Cell($pCoordinate, NULL, PHPExcel_Cell_DataType::TYPE_NULL, $this)); + $this->_cellCollectionIsSorted = false; + + if (PHPExcel_Cell::columnIndexFromString($this->_cachedHighestColumn) < PHPExcel_Cell::columnIndexFromString($aCoordinates[0])) + $this->_cachedHighestColumn = $aCoordinates[0]; + + $this->_cachedHighestRow = max($this->_cachedHighestRow,$aCoordinates[1]); + + // Cell needs appropriate xfIndex + $rowDimensions = $this->getRowDimensions(); + $columnDimensions = $this->getColumnDimensions(); + + if ( isset($rowDimensions[$aCoordinates[1]]) && $rowDimensions[$aCoordinates[1]]->getXfIndex() !== null ) { + // then there is a row dimension with explicit style, assign it to the cell + $cell->setXfIndex($rowDimensions[$aCoordinates[1]]->getXfIndex()); + } else if ( isset($columnDimensions[$aCoordinates[0]]) ) { + // then there is a column dimension, assign it to the cell + $cell->setXfIndex($columnDimensions[$aCoordinates[0]]->getXfIndex()); + } else { + // set to default index + $cell->setXfIndex(0); + } + + return $cell; + } + } + + /** + * Get cell at a specific coordinate by using numeric cell coordinates + * + * @param string $pColumn Numeric column coordinate of the cell + * @param string $pRow Numeric row coordinate of the cell + * @return PHPExcel_Cell Cell that was found + */ + public function getCellByColumnAndRow($pColumn = 0, $pRow = 1) + { + $columnLetter = PHPExcel_Cell::stringFromColumnIndex($pColumn); + $coordinate = $columnLetter . $pRow; + + if (!$this->_cellCollection->isDataSet($coordinate)) { + $cell = $this->_cellCollection->addCacheData($coordinate, new PHPExcel_Cell($coordinate, NULL, PHPExcel_Cell_DataType::TYPE_NULL, $this)); + $this->_cellCollectionIsSorted = false; + + if (PHPExcel_Cell::columnIndexFromString($this->_cachedHighestColumn) < $pColumn) + $this->_cachedHighestColumn = $columnLetter; + + $this->_cachedHighestRow = max($this->_cachedHighestRow,$pRow); + + return $cell; + } + + return $this->_cellCollection->getCacheData($coordinate); + } + + /** + * Cell at a specific coordinate exists? + * + * @param string $pCoordinate Coordinate of the cell + * @throws PHPExcel_Exception + * @return boolean + */ + public function cellExists($pCoordinate = 'A1') + { + // Worksheet reference? + if (strpos($pCoordinate, '!') !== false) { + $worksheetReference = PHPExcel_Worksheet::extractSheetTitle($pCoordinate, true); + return $this->getParent()->getSheetByName($worksheetReference[0])->cellExists($worksheetReference[1]); + } + + // Named range? + if ((!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i', $pCoordinate, $matches)) && + (preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_NAMEDRANGE.'$/i', $pCoordinate, $matches))) { + $namedRange = PHPExcel_NamedRange::resolveRange($pCoordinate, $this); + if ($namedRange !== NULL) { + $pCoordinate = $namedRange->getRange(); + if ($this->getHashCode() != $namedRange->getWorksheet()->getHashCode()) { + if (!$namedRange->getLocalOnly()) { + return $namedRange->getWorksheet()->cellExists($pCoordinate); + } else { + throw new PHPExcel_Exception('Named range ' . $namedRange->getName() . ' is not accessible from within sheet ' . $this->getTitle()); + } + } + } + else { return false; } + } + + // Uppercase coordinate + $pCoordinate = strtoupper($pCoordinate); + + if (strpos($pCoordinate,':') !== false || strpos($pCoordinate,',') !== false) { + throw new PHPExcel_Exception('Cell coordinate can not be a range of cells.'); + } elseif (strpos($pCoordinate,'$') !== false) { + throw new PHPExcel_Exception('Cell coordinate must not be absolute.'); + } else { + // Coordinates + $aCoordinates = PHPExcel_Cell::coordinateFromString($pCoordinate); + + // Cell exists? + return $this->_cellCollection->isDataSet($pCoordinate); + } + } + + /** + * Cell at a specific coordinate by using numeric cell coordinates exists? + * + * @param string $pColumn Numeric column coordinate of the cell + * @param string $pRow Numeric row coordinate of the cell + * @return boolean + */ + public function cellExistsByColumnAndRow($pColumn = 0, $pRow = 1) + { + return $this->cellExists(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow); + } + + /** + * Get row dimension at a specific row + * + * @param int $pRow Numeric index of the row + * @return PHPExcel_Worksheet_RowDimension + */ + public function getRowDimension($pRow = 1) + { + // Found + $found = null; + + // Get row dimension + if (!isset($this->_rowDimensions[$pRow])) { + $this->_rowDimensions[$pRow] = new PHPExcel_Worksheet_RowDimension($pRow); + + $this->_cachedHighestRow = max($this->_cachedHighestRow,$pRow); + } + return $this->_rowDimensions[$pRow]; + } + + /** + * Get column dimension at a specific column + * + * @param string $pColumn String index of the column + * @return PHPExcel_Worksheet_ColumnDimension + */ + public function getColumnDimension($pColumn = 'A') + { + // Uppercase coordinate + $pColumn = strtoupper($pColumn); + + // Fetch dimensions + if (!isset($this->_columnDimensions[$pColumn])) { + $this->_columnDimensions[$pColumn] = new PHPExcel_Worksheet_ColumnDimension($pColumn); + + if (PHPExcel_Cell::columnIndexFromString($this->_cachedHighestColumn) < PHPExcel_Cell::columnIndexFromString($pColumn)) + $this->_cachedHighestColumn = $pColumn; + } + return $this->_columnDimensions[$pColumn]; + } + + /** + * Get column dimension at a specific column by using numeric cell coordinates + * + * @param string $pColumn Numeric column coordinate of the cell + * @return PHPExcel_Worksheet_ColumnDimension + */ + public function getColumnDimensionByColumn($pColumn = 0) + { + return $this->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($pColumn)); + } + + /** + * Get styles + * + * @return PHPExcel_Style[] + */ + public function getStyles() + { + return $this->_styles; + } + + /** + * Get default style of workbook. + * + * @deprecated + * @return PHPExcel_Style + * @throws PHPExcel_Exception + */ + public function getDefaultStyle() + { + return $this->_parent->getDefaultStyle(); + } + + /** + * Set default style - should only be used by PHPExcel_IReader implementations! + * + * @deprecated + * @param PHPExcel_Style $pValue + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function setDefaultStyle(PHPExcel_Style $pValue) + { + $this->_parent->getDefaultStyle()->applyFromArray(array( + 'font' => array( + 'name' => $pValue->getFont()->getName(), + 'size' => $pValue->getFont()->getSize(), + ), + )); + return $this; + } + + /** + * Get style for cell + * + * @param string $pCellCoordinate Cell coordinate to get style for + * @return PHPExcel_Style + * @throws PHPExcel_Exception + */ + public function getStyle($pCellCoordinate = 'A1') + { + // set this sheet as active + $this->_parent->setActiveSheetIndex($this->_parent->getIndex($this)); + + // set cell coordinate as active + $this->setSelectedCells($pCellCoordinate); + + return $this->_parent->getCellXfSupervisor(); + } + + /** + * Get conditional styles for a cell + * + * @param string $pCoordinate + * @return PHPExcel_Style_Conditional[] + */ + public function getConditionalStyles($pCoordinate = 'A1') + { + if (!isset($this->_conditionalStylesCollection[$pCoordinate])) { + $this->_conditionalStylesCollection[$pCoordinate] = array(); + } + return $this->_conditionalStylesCollection[$pCoordinate]; + } + + /** + * Do conditional styles exist for this cell? + * + * @param string $pCoordinate + * @return boolean + */ + public function conditionalStylesExists($pCoordinate = 'A1') + { + if (isset($this->_conditionalStylesCollection[$pCoordinate])) { + return true; + } + return false; + } + + /** + * Removes conditional styles for a cell + * + * @param string $pCoordinate + * @return PHPExcel_Worksheet + */ + public function removeConditionalStyles($pCoordinate = 'A1') + { + unset($this->_conditionalStylesCollection[$pCoordinate]); + return $this; + } + + /** + * Get collection of conditional styles + * + * @return array + */ + public function getConditionalStylesCollection() + { + return $this->_conditionalStylesCollection; + } + + /** + * Set conditional styles + * + * @param $pCoordinate string E.g. 'A1' + * @param $pValue PHPExcel_Style_Conditional[] + * @return PHPExcel_Worksheet + */ + public function setConditionalStyles($pCoordinate = 'A1', $pValue) + { + $this->_conditionalStylesCollection[$pCoordinate] = $pValue; + return $this; + } + + /** + * Get style for cell by using numeric cell coordinates + * + * @param int $pColumn Numeric column coordinate of the cell + * @param int $pRow Numeric row coordinate of the cell + * @return PHPExcel_Style + */ + public function getStyleByColumnAndRow($pColumn = 0, $pRow = 1) + { + return $this->getStyle(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow); + } + + /** + * Set shared cell style to a range of cells + * + * Please note that this will overwrite existing cell styles for cells in range! + * + * @deprecated + * @param PHPExcel_Style $pSharedCellStyle Cell style to share + * @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1") + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function setSharedStyle(PHPExcel_Style $pSharedCellStyle = null, $pRange = '') + { + $this->duplicateStyle($pSharedCellStyle, $pRange); + return $this; + } + + /** + * Duplicate cell style to a range of cells + * + * Please note that this will overwrite existing cell styles for cells in range! + * + * @param PHPExcel_Style $pCellStyle Cell style to duplicate + * @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1") + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function duplicateStyle(PHPExcel_Style $pCellStyle = null, $pRange = '') + { + // make sure we have a real style and not supervisor + $style = $pCellStyle->getIsSupervisor() ? $pCellStyle->getSharedComponent() : $pCellStyle; + + // Add the style to the workbook if necessary + $workbook = $this->_parent; + if ($this->_parent->cellXfExists($pCellStyle)) { + // there is already this cell Xf in our collection + $xfIndex = $pCellStyle->getIndex(); + } else { + // we don't have such a cell Xf, need to add + $workbook->addCellXf($pCellStyle); + $xfIndex = $pCellStyle->getIndex(); + } + + // Uppercase coordinate + $pRange = strtoupper($pRange); + + // Is it a cell range or a single cell? + $rangeA = ''; + $rangeB = ''; + if (strpos($pRange, ':') === false) { + $rangeA = $pRange; + $rangeB = $pRange; + } else { + list($rangeA, $rangeB) = explode(':', $pRange); + } + + // Calculate range outer borders + $rangeStart = PHPExcel_Cell::coordinateFromString($rangeA); + $rangeEnd = PHPExcel_Cell::coordinateFromString($rangeB); + + // Translate column into index + $rangeStart[0] = PHPExcel_Cell::columnIndexFromString($rangeStart[0]) - 1; + $rangeEnd[0] = PHPExcel_Cell::columnIndexFromString($rangeEnd[0]) - 1; + + // Make sure we can loop upwards on rows and columns + if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) { + $tmp = $rangeStart; + $rangeStart = $rangeEnd; + $rangeEnd = $tmp; + } + + // Loop through cells and apply styles + for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) { + for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) { + $this->getCell(PHPExcel_Cell::stringFromColumnIndex($col) . $row)->setXfIndex($xfIndex); + } + } + + return $this; + } + + /** + * Duplicate conditional style to a range of cells + * + * Please note that this will overwrite existing cell styles for cells in range! + * + * @param [PHPExcel_Style_Conditional] $pCellStyle Cell style to duplicate + * @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1") + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function duplicateConditionalStyle(array $pCellStyle = null, $pRange = '') + { + foreach($pCellStyle as $cellStyle) { + if (!($cellStyle instanceof PHPExcel_Style_Conditional)) { + throw new PHPExcel_Exception('Style is not a conditional style'); + } + } + + // Uppercase coordinate + $pRange = strtoupper($pRange); + + // Is it a cell range or a single cell? + $rangeA = ''; + $rangeB = ''; + if (strpos($pRange, ':') === false) { + $rangeA = $pRange; + $rangeB = $pRange; + } else { + list($rangeA, $rangeB) = explode(':', $pRange); + } + + // Calculate range outer borders + $rangeStart = PHPExcel_Cell::coordinateFromString($rangeA); + $rangeEnd = PHPExcel_Cell::coordinateFromString($rangeB); + + // Translate column into index + $rangeStart[0] = PHPExcel_Cell::columnIndexFromString($rangeStart[0]) - 1; + $rangeEnd[0] = PHPExcel_Cell::columnIndexFromString($rangeEnd[0]) - 1; + + // Make sure we can loop upwards on rows and columns + if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) { + $tmp = $rangeStart; + $rangeStart = $rangeEnd; + $rangeEnd = $tmp; + } + + // Loop through cells and apply styles + for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) { + for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) { + $this->setConditionalStyles(PHPExcel_Cell::stringFromColumnIndex($col) . $row, $pCellStyle); + } + } + + return $this; + } + + /** + * Duplicate cell style array to a range of cells + * + * Please note that this will overwrite existing cell styles for cells in range, + * if they are in the styles array. For example, if you decide to set a range of + * cells to font bold, only include font bold in the styles array. + * + * @deprecated + * @param array $pStyles Array containing style information + * @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1") + * @param boolean $pAdvanced Advanced mode for setting borders. + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function duplicateStyleArray($pStyles = null, $pRange = '', $pAdvanced = true) + { + $this->getStyle($pRange)->applyFromArray($pStyles, $pAdvanced); + return $this; + } + + /** + * Set break on a cell + * + * @param string $pCell Cell coordinate (e.g. A1) + * @param int $pBreak Break type (type of PHPExcel_Worksheet::BREAK_*) + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function setBreak($pCell = 'A1', $pBreak = PHPExcel_Worksheet::BREAK_NONE) + { + // Uppercase coordinate + $pCell = strtoupper($pCell); + + if ($pCell != '') { + $this->_breaks[$pCell] = $pBreak; + } else { + throw new PHPExcel_Exception('No cell coordinate specified.'); + } + + return $this; + } + + /** + * Set break on a cell by using numeric cell coordinates + * + * @param integer $pColumn Numeric column coordinate of the cell + * @param integer $pRow Numeric row coordinate of the cell + * @param integer $pBreak Break type (type of PHPExcel_Worksheet::BREAK_*) + * @return PHPExcel_Worksheet + */ + public function setBreakByColumnAndRow($pColumn = 0, $pRow = 1, $pBreak = PHPExcel_Worksheet::BREAK_NONE) + { + return $this->setBreak(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow, $pBreak); + } + + /** + * Get breaks + * + * @return array[] + */ + public function getBreaks() + { + return $this->_breaks; + } + + /** + * Set merge on a cell range + * + * @param string $pRange Cell range (e.g. A1:E1) + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function mergeCells($pRange = 'A1:A1') + { + // Uppercase coordinate + $pRange = strtoupper($pRange); + + if (strpos($pRange,':') !== false) { + $this->_mergeCells[$pRange] = $pRange; + + // make sure cells are created + + // get the cells in the range + $aReferences = PHPExcel_Cell::extractAllCellReferencesInRange($pRange); + + // create upper left cell if it does not already exist + $upperLeft = $aReferences[0]; + if (!$this->cellExists($upperLeft)) { + $this->getCell($upperLeft)->setValueExplicit(null, PHPExcel_Cell_DataType::TYPE_NULL); + } + + // create or blank out the rest of the cells in the range + $count = count($aReferences); + for ($i = 1; $i < $count; $i++) { + $this->getCell($aReferences[$i])->setValueExplicit(null, PHPExcel_Cell_DataType::TYPE_NULL); + } + + } else { + throw new PHPExcel_Exception('Merge must be set on a range of cells.'); + } + + return $this; + } + + /** + * Set merge on a cell range by using numeric cell coordinates + * + * @param int $pColumn1 Numeric column coordinate of the first cell + * @param int $pRow1 Numeric row coordinate of the first cell + * @param int $pColumn2 Numeric column coordinate of the last cell + * @param int $pRow2 Numeric row coordinate of the last cell + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function mergeCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1) + { + $cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2; + return $this->mergeCells($cellRange); + } + + /** + * Remove merge on a cell range + * + * @param string $pRange Cell range (e.g. A1:E1) + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function unmergeCells($pRange = 'A1:A1') + { + // Uppercase coordinate + $pRange = strtoupper($pRange); + + if (strpos($pRange,':') !== false) { + if (isset($this->_mergeCells[$pRange])) { + unset($this->_mergeCells[$pRange]); + } else { + throw new PHPExcel_Exception('Cell range ' . $pRange . ' not known as merged.'); + } + } else { + throw new PHPExcel_Exception('Merge can only be removed from a range of cells.'); + } + + return $this; + } + + /** + * Remove merge on a cell range by using numeric cell coordinates + * + * @param int $pColumn1 Numeric column coordinate of the first cell + * @param int $pRow1 Numeric row coordinate of the first cell + * @param int $pColumn2 Numeric column coordinate of the last cell + * @param int $pRow2 Numeric row coordinate of the last cell + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function unmergeCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1) + { + $cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2; + return $this->unmergeCells($cellRange); + } + + /** + * Get merge cells array. + * + * @return array[] + */ + public function getMergeCells() + { + return $this->_mergeCells; + } + + /** + * Set merge cells array for the entire sheet. Use instead mergeCells() to merge + * a single cell range. + * + * @param array + */ + public function setMergeCells($pValue = array()) + { + $this->_mergeCells = $pValue; + + return $this; + } + + /** + * Set protection on a cell range + * + * @param string $pRange Cell (e.g. A1) or cell range (e.g. A1:E1) + * @param string $pPassword Password to unlock the protection + * @param boolean $pAlreadyHashed If the password has already been hashed, set this to true + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function protectCells($pRange = 'A1', $pPassword = '', $pAlreadyHashed = false) + { + // Uppercase coordinate + $pRange = strtoupper($pRange); + + if (!$pAlreadyHashed) { + $pPassword = PHPExcel_Shared_PasswordHasher::hashPassword($pPassword); + } + $this->_protectedCells[$pRange] = $pPassword; + + return $this; + } + + /** + * Set protection on a cell range by using numeric cell coordinates + * + * @param int $pColumn1 Numeric column coordinate of the first cell + * @param int $pRow1 Numeric row coordinate of the first cell + * @param int $pColumn2 Numeric column coordinate of the last cell + * @param int $pRow2 Numeric row coordinate of the last cell + * @param string $pPassword Password to unlock the protection + * @param boolean $pAlreadyHashed If the password has already been hashed, set this to true + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function protectCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1, $pPassword = '', $pAlreadyHashed = false) + { + $cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2; + return $this->protectCells($cellRange, $pPassword, $pAlreadyHashed); + } + + /** + * Remove protection on a cell range + * + * @param string $pRange Cell (e.g. A1) or cell range (e.g. A1:E1) + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function unprotectCells($pRange = 'A1') + { + // Uppercase coordinate + $pRange = strtoupper($pRange); + + if (isset($this->_protectedCells[$pRange])) { + unset($this->_protectedCells[$pRange]); + } else { + throw new PHPExcel_Exception('Cell range ' . $pRange . ' not known as protected.'); + } + return $this; + } + + /** + * Remove protection on a cell range by using numeric cell coordinates + * + * @param int $pColumn1 Numeric column coordinate of the first cell + * @param int $pRow1 Numeric row coordinate of the first cell + * @param int $pColumn2 Numeric column coordinate of the last cell + * @param int $pRow2 Numeric row coordinate of the last cell + * @param string $pPassword Password to unlock the protection + * @param boolean $pAlreadyHashed If the password has already been hashed, set this to true + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function unprotectCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1, $pPassword = '', $pAlreadyHashed = false) + { + $cellRange = PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 . ':' . PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2; + return $this->unprotectCells($cellRange, $pPassword, $pAlreadyHashed); + } + + /** + * Get protected cells + * + * @return array[] + */ + public function getProtectedCells() + { + return $this->_protectedCells; + } + + /** + * Get Autofilter + * + * @return PHPExcel_Worksheet_AutoFilter + */ + public function getAutoFilter() + { + return $this->_autoFilter; + } + + /** + * Set AutoFilter + * + * @param PHPExcel_Worksheet_AutoFilter|string $pValue + * A simple string containing a Cell range like 'A1:E10' is permitted for backward compatibility + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function setAutoFilter($pValue) + { + if (is_string($pValue)) { + $this->_autoFilter->setRange($pValue); + } elseif(is_object($pValue) && ($pValue instanceof PHPExcel_Worksheet_AutoFilter)) { + $this->_autoFilter = $pValue; + } + return $this; + } + + /** + * Set Autofilter Range by using numeric cell coordinates + * + * @param int $pColumn1 Numeric column coordinate of the first cell + * @param int $pRow1 Numeric row coordinate of the first cell + * @param int $pColumn2 Numeric column coordinate of the second cell + * @param int $pRow2 Numeric row coordinate of the second cell + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function setAutoFilterByColumnAndRow($pColumn1 = 0, $pRow1 = 1, $pColumn2 = 0, $pRow2 = 1) + { + return $this->setAutoFilter( + PHPExcel_Cell::stringFromColumnIndex($pColumn1) . $pRow1 + . ':' . + PHPExcel_Cell::stringFromColumnIndex($pColumn2) . $pRow2 + ); + } /** * Remove autofilter @@ -1881,912 +1888,933 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable */ public function removeAutoFilter() { - $this->_autoFilter->setRange(NULL); - return $this; + $this->_autoFilter->setRange(NULL); + return $this; } - /** - * Get Freeze Pane - * - * @return string - */ - public function getFreezePane() - { - return $this->_freezePane; - } + /** + * Get Freeze Pane + * + * @return string + */ + public function getFreezePane() + { + return $this->_freezePane; + } - /** - * Freeze Pane - * - * @param string $pCell Cell (i.e. A2) - * Examples: - * A2 will freeze the rows above cell A2 (i.e row 1) - * B1 will freeze the columns to the left of cell B1 (i.e column A) - * B2 will freeze the rows above and to the left of cell A2 - * (i.e row 1 and column A) - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function freezePane($pCell = '') - { - // Uppercase coordinate - $pCell = strtoupper($pCell); + /** + * Freeze Pane + * + * @param string $pCell Cell (i.e. A2) + * Examples: + * A2 will freeze the rows above cell A2 (i.e row 1) + * B1 will freeze the columns to the left of cell B1 (i.e column A) + * B2 will freeze the rows above and to the left of cell A2 + * (i.e row 1 and column A) + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function freezePane($pCell = '') + { + // Uppercase coordinate + $pCell = strtoupper($pCell); - if (strpos($pCell,':') === false && strpos($pCell,',') === false) { - $this->_freezePane = $pCell; - } else { - throw new PHPExcel_Exception('Freeze pane can not be set on a range of cells.'); - } - return $this; - } + if (strpos($pCell,':') === false && strpos($pCell,',') === false) { + $this->_freezePane = $pCell; + } else { + throw new PHPExcel_Exception('Freeze pane can not be set on a range of cells.'); + } + return $this; + } - /** - * Freeze Pane by using numeric cell coordinates - * - * @param int $pColumn Numeric column coordinate of the cell - * @param int $pRow Numeric row coordinate of the cell - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function freezePaneByColumnAndRow($pColumn = 0, $pRow = 1) - { - return $this->freezePane(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow); - } + /** + * Freeze Pane by using numeric cell coordinates + * + * @param int $pColumn Numeric column coordinate of the cell + * @param int $pRow Numeric row coordinate of the cell + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function freezePaneByColumnAndRow($pColumn = 0, $pRow = 1) + { + return $this->freezePane(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow); + } - /** - * Unfreeze Pane - * - * @return PHPExcel_Worksheet - */ - public function unfreezePane() - { - return $this->freezePane(''); - } + /** + * Unfreeze Pane + * + * @return PHPExcel_Worksheet + */ + public function unfreezePane() + { + return $this->freezePane(''); + } - /** - * Insert a new row, updating all possible related data - * - * @param int $pBefore Insert before this one - * @param int $pNumRows Number of rows to insert - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function insertNewRowBefore($pBefore = 1, $pNumRows = 1) { - if ($pBefore >= 1) { - $objReferenceHelper = PHPExcel_ReferenceHelper::getInstance(); - $objReferenceHelper->insertNewBefore('A' . $pBefore, 0, $pNumRows, $this); - } else { - throw new PHPExcel_Exception("Rows can only be inserted before at least row 1."); - } - return $this; - } + /** + * Insert a new row, updating all possible related data + * + * @param int $pBefore Insert before this one + * @param int $pNumRows Number of rows to insert + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function insertNewRowBefore($pBefore = 1, $pNumRows = 1) { + if ($pBefore >= 1) { + $objReferenceHelper = PHPExcel_ReferenceHelper::getInstance(); + $objReferenceHelper->insertNewBefore('A' . $pBefore, 0, $pNumRows, $this); + } else { + throw new PHPExcel_Exception("Rows can only be inserted before at least row 1."); + } + return $this; + } - /** - * Insert a new column, updating all possible related data - * - * @param int $pBefore Insert before this one - * @param int $pNumCols Number of columns to insert - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function insertNewColumnBefore($pBefore = 'A', $pNumCols = 1) { - if (!is_numeric($pBefore)) { - $objReferenceHelper = PHPExcel_ReferenceHelper::getInstance(); - $objReferenceHelper->insertNewBefore($pBefore . '1', $pNumCols, 0, $this); - } else { - throw new PHPExcel_Exception("Column references should not be numeric."); - } - return $this; - } + /** + * Insert a new column, updating all possible related data + * + * @param int $pBefore Insert before this one + * @param int $pNumCols Number of columns to insert + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function insertNewColumnBefore($pBefore = 'A', $pNumCols = 1) { + if (!is_numeric($pBefore)) { + $objReferenceHelper = PHPExcel_ReferenceHelper::getInstance(); + $objReferenceHelper->insertNewBefore($pBefore . '1', $pNumCols, 0, $this); + } else { + throw new PHPExcel_Exception("Column references should not be numeric."); + } + return $this; + } - /** - * Insert a new column, updating all possible related data - * - * @param int $pBefore Insert before this one (numeric column coordinate of the cell) - * @param int $pNumCols Number of columns to insert - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function insertNewColumnBeforeByIndex($pBefore = 0, $pNumCols = 1) { - if ($pBefore >= 0) { - return $this->insertNewColumnBefore(PHPExcel_Cell::stringFromColumnIndex($pBefore), $pNumCols); - } else { - throw new PHPExcel_Exception("Columns can only be inserted before at least column A (0)."); - } - } + /** + * Insert a new column, updating all possible related data + * + * @param int $pBefore Insert before this one (numeric column coordinate of the cell) + * @param int $pNumCols Number of columns to insert + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function insertNewColumnBeforeByIndex($pBefore = 0, $pNumCols = 1) { + if ($pBefore >= 0) { + return $this->insertNewColumnBefore(PHPExcel_Cell::stringFromColumnIndex($pBefore), $pNumCols); + } else { + throw new PHPExcel_Exception("Columns can only be inserted before at least column A (0)."); + } + } - /** - * Delete a row, updating all possible related data - * - * @param int $pRow Remove starting with this one - * @param int $pNumRows Number of rows to remove - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function removeRow($pRow = 1, $pNumRows = 1) { - if ($pRow >= 1) { - $objReferenceHelper = PHPExcel_ReferenceHelper::getInstance(); - $objReferenceHelper->insertNewBefore('A' . ($pRow + $pNumRows), 0, -$pNumRows, $this); - } else { - throw new PHPExcel_Exception("Rows to be deleted should at least start from row 1."); - } - return $this; - } + /** + * Delete a row, updating all possible related data + * + * @param int $pRow Remove starting with this one + * @param int $pNumRows Number of rows to remove + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function removeRow($pRow = 1, $pNumRows = 1) { + if ($pRow >= 1) { + $objReferenceHelper = PHPExcel_ReferenceHelper::getInstance(); + $objReferenceHelper->insertNewBefore('A' . ($pRow + $pNumRows), 0, -$pNumRows, $this); + } else { + throw new PHPExcel_Exception("Rows to be deleted should at least start from row 1."); + } + return $this; + } - /** - * Remove a column, updating all possible related data - * - * @param int $pColumn Remove starting with this one - * @param int $pNumCols Number of columns to remove - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function removeColumn($pColumn = 'A', $pNumCols = 1) { - if (!is_numeric($pColumn)) { - $pColumn = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($pColumn) - 1 + $pNumCols); - $objReferenceHelper = PHPExcel_ReferenceHelper::getInstance(); - $objReferenceHelper->insertNewBefore($pColumn . '1', -$pNumCols, 0, $this); - } else { - throw new PHPExcel_Exception("Column references should not be numeric."); - } - return $this; - } + /** + * Remove a column, updating all possible related data + * + * @param int $pColumn Remove starting with this one + * @param int $pNumCols Number of columns to remove + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function removeColumn($pColumn = 'A', $pNumCols = 1) { + if (!is_numeric($pColumn)) { + $pColumn = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($pColumn) - 1 + $pNumCols); + $objReferenceHelper = PHPExcel_ReferenceHelper::getInstance(); + $objReferenceHelper->insertNewBefore($pColumn . '1', -$pNumCols, 0, $this); + } else { + throw new PHPExcel_Exception("Column references should not be numeric."); + } + return $this; + } - /** - * Remove a column, updating all possible related data - * - * @param int $pColumn Remove starting with this one (numeric column coordinate of the cell) - * @param int $pNumCols Number of columns to remove - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function removeColumnByIndex($pColumn = 0, $pNumCols = 1) { - if ($pColumn >= 0) { - return $this->removeColumn(PHPExcel_Cell::stringFromColumnIndex($pColumn), $pNumCols); - } else { - throw new PHPExcel_Exception("Columns to be deleted should at least start from column 0"); - } - } + /** + * Remove a column, updating all possible related data + * + * @param int $pColumn Remove starting with this one (numeric column coordinate of the cell) + * @param int $pNumCols Number of columns to remove + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function removeColumnByIndex($pColumn = 0, $pNumCols = 1) { + if ($pColumn >= 0) { + return $this->removeColumn(PHPExcel_Cell::stringFromColumnIndex($pColumn), $pNumCols); + } else { + throw new PHPExcel_Exception("Columns to be deleted should at least start from column 0"); + } + } - /** - * Show gridlines? - * - * @return boolean - */ - public function getShowGridlines() { - return $this->_showGridlines; - } + /** + * Show gridlines? + * + * @return boolean + */ + public function getShowGridlines() { + return $this->_showGridlines; + } - /** - * Set show gridlines - * - * @param boolean $pValue Show gridlines (true/false) - * @return PHPExcel_Worksheet - */ - public function setShowGridlines($pValue = false) { - $this->_showGridlines = $pValue; - return $this; - } + /** + * Set show gridlines + * + * @param boolean $pValue Show gridlines (true/false) + * @return PHPExcel_Worksheet + */ + public function setShowGridlines($pValue = false) { + $this->_showGridlines = $pValue; + return $this; + } - /** - * Print gridlines? - * - * @return boolean - */ - public function getPrintGridlines() { - return $this->_printGridlines; - } + /** + * Print gridlines? + * + * @return boolean + */ + public function getPrintGridlines() { + return $this->_printGridlines; + } - /** - * Set print gridlines - * - * @param boolean $pValue Print gridlines (true/false) - * @return PHPExcel_Worksheet - */ - public function setPrintGridlines($pValue = false) { - $this->_printGridlines = $pValue; - return $this; - } + /** + * Set print gridlines + * + * @param boolean $pValue Print gridlines (true/false) + * @return PHPExcel_Worksheet + */ + public function setPrintGridlines($pValue = false) { + $this->_printGridlines = $pValue; + return $this; + } - /** - * Show row and column headers? - * - * @return boolean - */ - public function getShowRowColHeaders() { - return $this->_showRowColHeaders; - } + /** + * Show row and column headers? + * + * @return boolean + */ + public function getShowRowColHeaders() { + return $this->_showRowColHeaders; + } - /** - * Set show row and column headers - * - * @param boolean $pValue Show row and column headers (true/false) - * @return PHPExcel_Worksheet - */ - public function setShowRowColHeaders($pValue = false) { - $this->_showRowColHeaders = $pValue; - return $this; - } + /** + * Set show row and column headers + * + * @param boolean $pValue Show row and column headers (true/false) + * @return PHPExcel_Worksheet + */ + public function setShowRowColHeaders($pValue = false) { + $this->_showRowColHeaders = $pValue; + return $this; + } - /** - * Show summary below? (Row/Column outlining) - * - * @return boolean - */ - public function getShowSummaryBelow() { - return $this->_showSummaryBelow; - } + /** + * Show summary below? (Row/Column outlining) + * + * @return boolean + */ + public function getShowSummaryBelow() { + return $this->_showSummaryBelow; + } - /** - * Set show summary below - * - * @param boolean $pValue Show summary below (true/false) - * @return PHPExcel_Worksheet - */ - public function setShowSummaryBelow($pValue = true) { - $this->_showSummaryBelow = $pValue; - return $this; - } + /** + * Set show summary below + * + * @param boolean $pValue Show summary below (true/false) + * @return PHPExcel_Worksheet + */ + public function setShowSummaryBelow($pValue = true) { + $this->_showSummaryBelow = $pValue; + return $this; + } - /** - * Show summary right? (Row/Column outlining) - * - * @return boolean - */ - public function getShowSummaryRight() { - return $this->_showSummaryRight; - } + /** + * Show summary right? (Row/Column outlining) + * + * @return boolean + */ + public function getShowSummaryRight() { + return $this->_showSummaryRight; + } - /** - * Set show summary right - * - * @param boolean $pValue Show summary right (true/false) - * @return PHPExcel_Worksheet - */ - public function setShowSummaryRight($pValue = true) { - $this->_showSummaryRight = $pValue; - return $this; - } + /** + * Set show summary right + * + * @param boolean $pValue Show summary right (true/false) + * @return PHPExcel_Worksheet + */ + public function setShowSummaryRight($pValue = true) { + $this->_showSummaryRight = $pValue; + return $this; + } - /** - * Get comments - * - * @return PHPExcel_Comment[] - */ - public function getComments() - { - return $this->_comments; - } + /** + * Get comments + * + * @return PHPExcel_Comment[] + */ + public function getComments() + { + return $this->_comments; + } - /** - * Set comments array for the entire sheet. - * - * @param array of PHPExcel_Comment - * @return PHPExcel_Worksheet - */ - public function setComments($pValue = array()) - { - $this->_comments = $pValue; + /** + * Set comments array for the entire sheet. + * + * @param [PHPExcel_Comment] $pValue + * @return PHPExcel_Worksheet + */ + public function setComments($pValue = array()) + { + $this->_comments = $pValue; - return $this; - } + return $this; + } - /** - * Get comment for cell - * - * @param string $pCellCoordinate Cell coordinate to get comment for - * @return PHPExcel_Comment - * @throws PHPExcel_Exception - */ - public function getComment($pCellCoordinate = 'A1') - { - // Uppercase coordinate - $pCellCoordinate = strtoupper($pCellCoordinate); + /** + * Get comment for cell + * + * @param string $pCellCoordinate Cell coordinate to get comment for + * @return PHPExcel_Comment + * @throws PHPExcel_Exception + */ + public function getComment($pCellCoordinate = 'A1') + { + // Uppercase coordinate + $pCellCoordinate = strtoupper($pCellCoordinate); - if (strpos($pCellCoordinate,':') !== false || strpos($pCellCoordinate,',') !== false) { - throw new PHPExcel_Exception('Cell coordinate string can not be a range of cells.'); - } else if (strpos($pCellCoordinate,'$') !== false) { - throw new PHPExcel_Exception('Cell coordinate string must not be absolute.'); - } else if ($pCellCoordinate == '') { - throw new PHPExcel_Exception('Cell coordinate can not be zero-length string.'); - } else { - // Check if we already have a comment for this cell. - // If not, create a new comment. - if (isset($this->_comments[$pCellCoordinate])) { - return $this->_comments[$pCellCoordinate]; - } else { - $newComment = new PHPExcel_Comment(); - $this->_comments[$pCellCoordinate] = $newComment; - return $newComment; - } - } - } + if (strpos($pCellCoordinate,':') !== false || strpos($pCellCoordinate,',') !== false) { + throw new PHPExcel_Exception('Cell coordinate string can not be a range of cells.'); + } else if (strpos($pCellCoordinate,'$') !== false) { + throw new PHPExcel_Exception('Cell coordinate string must not be absolute.'); + } else if ($pCellCoordinate == '') { + throw new PHPExcel_Exception('Cell coordinate can not be zero-length string.'); + } else { + // Check if we already have a comment for this cell. + // If not, create a new comment. + if (isset($this->_comments[$pCellCoordinate])) { + return $this->_comments[$pCellCoordinate]; + } else { + $newComment = new PHPExcel_Comment(); + $this->_comments[$pCellCoordinate] = $newComment; + return $newComment; + } + } + } - /** - * Get comment for cell by using numeric cell coordinates - * - * @param int $pColumn Numeric column coordinate of the cell - * @param int $pRow Numeric row coordinate of the cell - * @return PHPExcel_Comment - */ - public function getCommentByColumnAndRow($pColumn = 0, $pRow = 1) - { - return $this->getComment(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow); - } + /** + * Get comment for cell by using numeric cell coordinates + * + * @param int $pColumn Numeric column coordinate of the cell + * @param int $pRow Numeric row coordinate of the cell + * @return PHPExcel_Comment + */ + public function getCommentByColumnAndRow($pColumn = 0, $pRow = 1) + { + return $this->getComment(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow); + } - /** - * Get selected cell - * - * @deprecated - * @return string - */ - public function getSelectedCell() - { - return $this->getSelectedCells(); - } + /** + * Get selected cell + * + * @deprecated + * @return string + */ + public function getSelectedCell() + { + return $this->getSelectedCells(); + } - /** - * Get active cell - * - * @return string Example: 'A1' - */ - public function getActiveCell() - { - return $this->_activeCell; - } + /** + * Get active cell + * + * @return string Example: 'A1' + */ + public function getActiveCell() + { + return $this->_activeCell; + } - /** - * Get selected cells - * - * @return string - */ - public function getSelectedCells() - { - return $this->_selectedCells; - } + /** + * Get selected cells + * + * @return string + */ + public function getSelectedCells() + { + return $this->_selectedCells; + } - /** - * Selected cell - * - * @param string $pCoordinate Cell (i.e. A1) - * @return PHPExcel_Worksheet - */ - public function setSelectedCell($pCoordinate = 'A1') - { - return $this->setSelectedCells($pCoordinate); - } + /** + * Selected cell + * + * @param string $pCoordinate Cell (i.e. A1) + * @return PHPExcel_Worksheet + */ + public function setSelectedCell($pCoordinate = 'A1') + { + return $this->setSelectedCells($pCoordinate); + } - /** - * Select a range of cells. - * - * @param string $pCoordinate Cell range, examples: 'A1', 'B2:G5', 'A:C', '3:6' - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function setSelectedCells($pCoordinate = 'A1') - { - // Uppercase coordinate - $pCoordinate = strtoupper($pCoordinate); + /** + * Select a range of cells. + * + * @param string $pCoordinate Cell range, examples: 'A1', 'B2:G5', 'A:C', '3:6' + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function setSelectedCells($pCoordinate = 'A1') + { + // Uppercase coordinate + $pCoordinate = strtoupper($pCoordinate); - // Convert 'A' to 'A:A' - $pCoordinate = preg_replace('/^([A-Z]+)$/', '${1}:${1}', $pCoordinate); + // Convert 'A' to 'A:A' + $pCoordinate = preg_replace('/^([A-Z]+)$/', '${1}:${1}', $pCoordinate); - // Convert '1' to '1:1' - $pCoordinate = preg_replace('/^([0-9]+)$/', '${1}:${1}', $pCoordinate); + // Convert '1' to '1:1' + $pCoordinate = preg_replace('/^([0-9]+)$/', '${1}:${1}', $pCoordinate); - // Convert 'A:C' to 'A1:C1048576' - $pCoordinate = preg_replace('/^([A-Z]+):([A-Z]+)$/', '${1}1:${2}1048576', $pCoordinate); + // Convert 'A:C' to 'A1:C1048576' + $pCoordinate = preg_replace('/^([A-Z]+):([A-Z]+)$/', '${1}1:${2}1048576', $pCoordinate); - // Convert '1:3' to 'A1:XFD3' - $pCoordinate = preg_replace('/^([0-9]+):([0-9]+)$/', 'A${1}:XFD${2}', $pCoordinate); + // Convert '1:3' to 'A1:XFD3' + $pCoordinate = preg_replace('/^([0-9]+):([0-9]+)$/', 'A${1}:XFD${2}', $pCoordinate); - if (strpos($pCoordinate,':') !== false || strpos($pCoordinate,',') !== false) { - list($first, ) = PHPExcel_Cell::splitRange($pCoordinate); - $this->_activeCell = $first[0]; - } else { - $this->_activeCell = $pCoordinate; - } - $this->_selectedCells = $pCoordinate; - return $this; - } + if (strpos($pCoordinate,':') !== false || strpos($pCoordinate,',') !== false) { + list($first, ) = PHPExcel_Cell::splitRange($pCoordinate); + $this->_activeCell = $first[0]; + } else { + $this->_activeCell = $pCoordinate; + } + $this->_selectedCells = $pCoordinate; + return $this; + } - /** - * Selected cell by using numeric cell coordinates - * - * @param int $pColumn Numeric column coordinate of the cell - * @param int $pRow Numeric row coordinate of the cell - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function setSelectedCellByColumnAndRow($pColumn = 0, $pRow = 1) - { - return $this->setSelectedCells(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow); - } + /** + * Selected cell by using numeric cell coordinates + * + * @param int $pColumn Numeric column coordinate of the cell + * @param int $pRow Numeric row coordinate of the cell + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function setSelectedCellByColumnAndRow($pColumn = 0, $pRow = 1) + { + return $this->setSelectedCells(PHPExcel_Cell::stringFromColumnIndex($pColumn) . $pRow); + } - /** - * Get right-to-left - * - * @return boolean - */ - public function getRightToLeft() { - return $this->_rightToLeft; - } + /** + * Get right-to-left + * + * @return boolean + */ + public function getRightToLeft() { + return $this->_rightToLeft; + } - /** - * Set right-to-left - * - * @param boolean $value Right-to-left true/false - * @return PHPExcel_Worksheet - */ - public function setRightToLeft($value = false) { - $this->_rightToLeft = $value; - return $this; - } + /** + * Set right-to-left + * + * @param boolean $value Right-to-left true/false + * @return PHPExcel_Worksheet + */ + public function setRightToLeft($value = false) { + $this->_rightToLeft = $value; + return $this; + } - /** - * Fill worksheet from values in array - * - * @param array $source Source array - * @param mixed $nullValue Value in source array that stands for blank cell - * @param string $startCell Insert array starting from this cell address as the top left coordinate - * @param boolean $strictNullComparison Apply strict comparison when testing for null values in the array - * @throws PHPExcel_Exception - * @return PHPExcel_Worksheet - */ - public function fromArray($source = null, $nullValue = null, $startCell = 'A1', $strictNullComparison = false) { - if (is_array($source)) { - // Convert a 1-D array to 2-D (for ease of looping) - if (!is_array(end($source))) { - $source = array($source); - } + /** + * Fill worksheet from values in array + * + * @param array $source Source array + * @param mixed $nullValue Value in source array that stands for blank cell + * @param string $startCell Insert array starting from this cell address as the top left coordinate + * @param boolean $strictNullComparison Apply strict comparison when testing for null values in the array + * @throws PHPExcel_Exception + * @return PHPExcel_Worksheet + */ + public function fromArray($source = null, $nullValue = null, $startCell = 'A1', $strictNullComparison = false) { + if (is_array($source)) { + // Convert a 1-D array to 2-D (for ease of looping) + if (!is_array(end($source))) { + $source = array($source); + } - // start coordinate - list ($startColumn, $startRow) = PHPExcel_Cell::coordinateFromString($startCell); + // start coordinate + list ($startColumn, $startRow) = PHPExcel_Cell::coordinateFromString($startCell); - // Loop through $source - foreach ($source as $rowData) { - $currentColumn = $startColumn; - foreach($rowData as $cellValue) { - if ($strictNullComparison) { - if ($cellValue !== $nullValue) { - // Set cell value - $this->getCell($currentColumn . $startRow)->setValue($cellValue); - } - } else { - if ($cellValue != $nullValue) { - // Set cell value - $this->getCell($currentColumn . $startRow)->setValue($cellValue); - } - } - ++$currentColumn; - } - ++$startRow; - } - } else { - throw new PHPExcel_Exception("Parameter \$source should be an array."); - } - return $this; - } + // Loop through $source + foreach ($source as $rowData) { + $currentColumn = $startColumn; + foreach($rowData as $cellValue) { + if ($strictNullComparison) { + if ($cellValue !== $nullValue) { + // Set cell value + $this->getCell($currentColumn . $startRow)->setValue($cellValue); + } + } else { + if ($cellValue != $nullValue) { + // Set cell value + $this->getCell($currentColumn . $startRow)->setValue($cellValue); + } + } + ++$currentColumn; + } + ++$startRow; + } + } else { + throw new PHPExcel_Exception("Parameter \$source should be an array."); + } + return $this; + } - /** - * Create array from a range of cells - * - * @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1") - * @param mixed $nullValue Value returned in the array entry if a cell doesn't exist - * @param boolean $calculateFormulas Should formulas be calculated? - * @param boolean $formatData Should formatting be applied to cell values? - * @param boolean $returnCellRef False - Return a simple array of rows and columns indexed by number counting from zero - * True - Return rows and columns indexed by their actual row and column IDs - * @return array - */ - public function rangeToArray($pRange = 'A1', $nullValue = null, $calculateFormulas = true, $formatData = true, $returnCellRef = false) { - // Returnvalue - $returnValue = array(); - // Identify the range that we need to extract from the worksheet - list($rangeStart, $rangeEnd) = PHPExcel_Cell::rangeBoundaries($pRange); - $minCol = PHPExcel_Cell::stringFromColumnIndex($rangeStart[0] -1); - $minRow = $rangeStart[1]; - $maxCol = PHPExcel_Cell::stringFromColumnIndex($rangeEnd[0] -1); - $maxRow = $rangeEnd[1]; + /** + * Create array from a range of cells + * + * @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1") + * @param mixed $nullValue Value returned in the array entry if a cell doesn't exist + * @param boolean $calculateFormulas Should formulas be calculated? + * @param boolean $formatData Should formatting be applied to cell values? + * @param boolean $returnCellRef False - Return a simple array of rows and columns indexed by number counting from zero + * True - Return rows and columns indexed by their actual row and column IDs + * @return array + */ + public function rangeToArray( + $pRange = 'A1', $nullValue = null, $calculateFormulas = true, + $formatData = true, $returnCellRef = false) + { + // Returnvalue + $returnValue = array(); + // Identify the range that we need to extract from the worksheet + list($rangeStart, $rangeEnd) = PHPExcel_Cell::rangeBoundaries($pRange); + $minCol = PHPExcel_Cell::stringFromColumnIndex($rangeStart[0] -1); + $minRow = $rangeStart[1]; + $maxCol = PHPExcel_Cell::stringFromColumnIndex($rangeEnd[0] -1); + $maxRow = $rangeEnd[1]; - $maxCol++; - // Loop through rows - $r = -1; - for ($row = $minRow; $row <= $maxRow; ++$row) { - $rRef = ($returnCellRef) ? $row : ++$r; - $c = -1; - // Loop through columns in the current row - for ($col = $minCol; $col != $maxCol; ++$col) { - $cRef = ($returnCellRef) ? $col : ++$c; - // Using getCell() will create a new cell if it doesn't already exist. We don't want that to happen - // so we test and retrieve directly against _cellCollection - if ($this->_cellCollection->isDataSet($col.$row)) { - // Cell exists - $cell = $this->_cellCollection->getCacheData($col.$row); - if ($cell->getValue() !== null) { - if ($cell->getValue() instanceof PHPExcel_RichText) { - $returnValue[$rRef][$cRef] = $cell->getValue()->getPlainText(); - } else { - if ($calculateFormulas) { - $returnValue[$rRef][$cRef] = $cell->getCalculatedValue(); - } else { - $returnValue[$rRef][$cRef] = $cell->getValue(); - } - } + $maxCol++; + // Loop through rows + $r = -1; + for ($row = $minRow; $row <= $maxRow; ++$row) { + $rRef = ($returnCellRef) ? $row : ++$r; + $c = -1; + // Loop through columns in the current row + for ($col = $minCol; $col != $maxCol; ++$col) { + $cRef = ($returnCellRef) ? $col : ++$c; + // Using getCell() will create a new cell if it doesn't already exist. We don't want that to happen + // so we test and retrieve directly against _cellCollection + if ($this->_cellCollection->isDataSet($col.$row)) { + // Cell exists + $cell = $this->_cellCollection->getCacheData($col.$row); + if ($cell->getValue() !== null) { + if ($cell->getValue() instanceof PHPExcel_RichText) { + $returnValue[$rRef][$cRef] = $cell->getValue()->getPlainText(); + } else { + if ($calculateFormulas) { + $returnValue[$rRef][$cRef] = $cell->getCalculatedValue(); + } else { + $returnValue[$rRef][$cRef] = $cell->getValue(); + } + } - if ($formatData) { - $style = $this->_parent->getCellXfByIndex($cell->getXfIndex()); - $returnValue[$rRef][$cRef] = PHPExcel_Style_NumberFormat::toFormattedString($returnValue[$rRef][$cRef], $style->getNumberFormat()->getFormatCode()); - } - } else { - // Cell holds a NULL - $returnValue[$rRef][$cRef] = $nullValue; - } - } else { - // Cell doesn't exist - $returnValue[$rRef][$cRef] = $nullValue; - } - } - } + if ($formatData) { + $style = $this->_parent->getCellXfByIndex($cell->getXfIndex()); + $returnValue[$rRef][$cRef] = PHPExcel_Style_NumberFormat::toFormattedString( + $returnValue[$rRef][$cRef], $style->getNumberFormat()->getFormatCode() + ); + } + } else { + // Cell holds a NULL + $returnValue[$rRef][$cRef] = $nullValue; + } + } else { + // Cell doesn't exist + $returnValue[$rRef][$cRef] = $nullValue; + } + } + } - // Return - return $returnValue; - } + // Return + return $returnValue; + } - /** - * Create array from a range of cells - * - * @param string $pNamedRange Name of the Named Range - * @param mixed $nullValue Value returned in the array entry if a cell doesn't exist - * @param boolean $calculateFormulas Should formulas be calculated? - * @param boolean $formatData Should formatting be applied to cell values? - * @param boolean $returnCellRef False - Return a simple array of rows and columns indexed by number counting from zero - * True - Return rows and columns indexed by their actual row and column IDs - * @return array - * @throws PHPExcel_Exception - */ - public function namedRangeToArray($pNamedRange = '', $nullValue = null, $calculateFormulas = true, $formatData = true, $returnCellRef = false) { - $namedRange = PHPExcel_NamedRange::resolveRange($pNamedRange, $this); - if ($namedRange !== NULL) { - $pWorkSheet = $namedRange->getWorksheet(); - $pCellRange = $namedRange->getRange(); + /** + * Create array from a range of cells + * + * @param string $pNamedRange Name of the Named Range + * @param mixed $nullValue Value returned in the array entry if a cell doesn't exist + * @param boolean $calculateFormulas Should formulas be calculated? + * @param boolean $formatData Should formatting be applied to cell values? + * @param boolean $returnCellRef False - Return a simple array of rows and columns indexed by number counting from zero + * True - Return rows and columns indexed by their actual row and column IDs + * @return array + * @throws PHPExcel_Exception + */ + public function namedRangeToArray( + $pNamedRange = '', $nullValue = null, $calculateFormulas = true, + $formatData = true, $returnCellRef = false + ) + { + $namedRange = PHPExcel_NamedRange::resolveRange($pNamedRange, $this); + if ($namedRange !== NULL) { + $pWorkSheet = $namedRange->getWorksheet(); + $pCellRange = $namedRange->getRange(); - return $pWorkSheet->rangeToArray( $pCellRange, - $nullValue, $calculateFormulas, $formatData, $returnCellRef); - } + return $pWorkSheet->rangeToArray( + $pCellRange, + $nullValue, $calculateFormulas, $formatData, $returnCellRef + ); + } - throw new PHPExcel_Exception('Named Range '.$pNamedRange.' does not exist.'); - } + throw new PHPExcel_Exception('Named Range '.$pNamedRange.' does not exist.'); + } - /** - * Create array from worksheet - * - * @param mixed $nullValue Value returned in the array entry if a cell doesn't exist - * @param boolean $calculateFormulas Should formulas be calculated? - * @param boolean $formatData Should formatting be applied to cell values? - * @param boolean $returnCellRef False - Return a simple array of rows and columns indexed by number counting from zero - * True - Return rows and columns indexed by their actual row and column IDs - * @return array - */ - public function toArray($nullValue = null, $calculateFormulas = true, $formatData = true, $returnCellRef = false) { - // Garbage collect... - $this->garbageCollect(); + /** + * Create array from worksheet + * + * @param mixed $nullValue Value returned in the array entry if a cell doesn't exist + * @param boolean $calculateFormulas Should formulas be calculated? + * @param boolean $formatData Should formatting be applied to cell values? + * @param boolean $returnCellRef False - Return a simple array of rows and columns indexed by number counting from zero + * True - Return rows and columns indexed by their actual row and column IDs + * @return array + */ + public function toArray($nullValue = null, $calculateFormulas = true, $formatData = true, $returnCellRef = false) + { + // Garbage collect... + $this->garbageCollect(); - // Identify the range that we need to extract from the worksheet - $maxCol = $this->getHighestColumn(); - $maxRow = $this->getHighestRow(); - // Return - return $this->rangeToArray( 'A1:'.$maxCol.$maxRow, - $nullValue, $calculateFormulas, $formatData, $returnCellRef); - } + // Identify the range that we need to extract from the worksheet + $maxCol = $this->getHighestColumn(); + $maxRow = $this->getHighestRow(); + // Return + return $this->rangeToArray( + 'A1:'.$maxCol.$maxRow, + $nullValue, $calculateFormulas, $formatData, $returnCellRef + ); + } - /** - * Get row iterator - * + /** + * Get row iterator + * * @param integer $startRow The row number at which to start iterating - * @return PHPExcel_Worksheet_RowIterator - */ - public function getRowIterator($startRow = 1) { - return new PHPExcel_Worksheet_RowIterator($this,$startRow); - } + * @return PHPExcel_Worksheet_RowIterator + */ + public function getRowIterator($startRow = 1) + { + return new PHPExcel_Worksheet_RowIterator($this,$startRow); + } - /** - * Run PHPExcel garabage collector. - * - * @return PHPExcel_Worksheet - */ - public function garbageCollect() { - // Flush cache - $this->_cellCollection->getCacheData('A1'); - // Build a reference table from images -// $imageCoordinates = array(); -// $iterator = $this->getDrawingCollection()->getIterator(); -// while ($iterator->valid()) { -// $imageCoordinates[$iterator->current()->getCoordinates()] = true; + /** + * Run PHPExcel garabage collector. + * + * @return PHPExcel_Worksheet + */ + public function garbageCollect() + { + // Flush cache + $this->_cellCollection->getCacheData('A1'); + // Build a reference table from images +// $imageCoordinates = array(); +// $iterator = $this->getDrawingCollection()->getIterator(); +// while ($iterator->valid()) { +// $imageCoordinates[$iterator->current()->getCoordinates()] = true; // -// $iterator->next(); -// } +// $iterator->next(); +// } // - // Lookup highest column and highest row if cells are cleaned - $colRow = $this->_cellCollection->getHighestRowAndColumn(); - $highestRow = $colRow['row']; - $highestColumn = PHPExcel_Cell::columnIndexFromString($colRow['column']); + // Lookup highest column and highest row if cells are cleaned + $colRow = $this->_cellCollection->getHighestRowAndColumn(); + $highestRow = $colRow['row']; + $highestColumn = PHPExcel_Cell::columnIndexFromString($colRow['column']); - // Loop through column dimensions - foreach ($this->_columnDimensions as $dimension) { - $highestColumn = max($highestColumn,PHPExcel_Cell::columnIndexFromString($dimension->getColumnIndex())); - } + // Loop through column dimensions + foreach ($this->_columnDimensions as $dimension) { + $highestColumn = max($highestColumn,PHPExcel_Cell::columnIndexFromString($dimension->getColumnIndex())); + } - // Loop through row dimensions - foreach ($this->_rowDimensions as $dimension) { - $highestRow = max($highestRow,$dimension->getRowIndex()); - } + // Loop through row dimensions + foreach ($this->_rowDimensions as $dimension) { + $highestRow = max($highestRow,$dimension->getRowIndex()); + } - // Cache values - if ($highestColumn < 0) { - $this->_cachedHighestColumn = 'A'; - } else { - $this->_cachedHighestColumn = PHPExcel_Cell::stringFromColumnIndex(--$highestColumn); - } - $this->_cachedHighestRow = $highestRow; + // Cache values + if ($highestColumn < 0) { + $this->_cachedHighestColumn = 'A'; + } else { + $this->_cachedHighestColumn = PHPExcel_Cell::stringFromColumnIndex(--$highestColumn); + } + $this->_cachedHighestRow = $highestRow; - // Return - return $this; - } + // Return + return $this; + } - /** - * Get hash code - * - * @return string Hash code - */ - public function getHashCode() { - if ($this->_dirty) { - $this->_hash = md5( $this->_title . - $this->_autoFilter . - ($this->_protection->isProtectionEnabled() ? 't' : 'f') . - __CLASS__ - ); - $this->_dirty = false; - } - return $this->_hash; - } + /** + * Get hash code + * + * @return string Hash code + */ + public function getHashCode() + { + if ($this->_dirty) { + $this->_hash = md5( $this->_title . + $this->_autoFilter . + ($this->_protection->isProtectionEnabled() ? 't' : 'f') . + __CLASS__ + ); + $this->_dirty = false; + } + return $this->_hash; + } - /** - * Extract worksheet title from range. - * - * Example: extractSheetTitle("testSheet!A1") ==> 'A1' - * Example: extractSheetTitle("'testSheet 1'!A1", true) ==> array('testSheet 1', 'A1'); - * - * @param string $pRange Range to extract title from - * @param bool $returnRange Return range? (see example) - * @return mixed - */ - public static function extractSheetTitle($pRange, $returnRange = false) { - // Sheet title included? - if (($sep = strpos($pRange, '!')) === false) { - return ''; - } + /** + * Extract worksheet title from range. + * + * Example: extractSheetTitle("testSheet!A1") ==> 'A1' + * Example: extractSheetTitle("'testSheet 1'!A1", true) ==> array('testSheet 1', 'A1'); + * + * @param string $pRange Range to extract title from + * @param bool $returnRange Return range? (see example) + * @return mixed + */ + public static function extractSheetTitle($pRange, $returnRange = false) + { + // Sheet title included? + if (($sep = strpos($pRange, '!')) === false) { + return ''; + } - if ($returnRange) { - return array( trim(substr($pRange, 0, $sep),"'"), - substr($pRange, $sep + 1) - ); - } + if ($returnRange) { + return array( trim(substr($pRange, 0, $sep),"'"), + substr($pRange, $sep + 1) + ); + } - return substr($pRange, $sep + 1); - } + return substr($pRange, $sep + 1); + } - /** - * Get hyperlink - * - * @param string $pCellCoordinate Cell coordinate to get hyperlink for - */ - public function getHyperlink($pCellCoordinate = 'A1') - { - // return hyperlink if we already have one - if (isset($this->_hyperlinkCollection[$pCellCoordinate])) { - return $this->_hyperlinkCollection[$pCellCoordinate]; - } + /** + * Get hyperlink + * + * @param string $pCellCoordinate Cell coordinate to get hyperlink for + */ + public function getHyperlink($pCellCoordinate = 'A1') + { + // return hyperlink if we already have one + if (isset($this->_hyperlinkCollection[$pCellCoordinate])) { + return $this->_hyperlinkCollection[$pCellCoordinate]; + } - // else create hyperlink - $this->_hyperlinkCollection[$pCellCoordinate] = new PHPExcel_Cell_Hyperlink(); - return $this->_hyperlinkCollection[$pCellCoordinate]; - } + // else create hyperlink + $this->_hyperlinkCollection[$pCellCoordinate] = new PHPExcel_Cell_Hyperlink(); + return $this->_hyperlinkCollection[$pCellCoordinate]; + } - /** - * Set hyperlnk - * - * @param string $pCellCoordinate Cell coordinate to insert hyperlink - * @param PHPExcel_Cell_Hyperlink $pHyperlink - * @return PHPExcel_Worksheet - */ - public function setHyperlink($pCellCoordinate = 'A1', PHPExcel_Cell_Hyperlink $pHyperlink = null) - { - if ($pHyperlink === null) { - unset($this->_hyperlinkCollection[$pCellCoordinate]); - } else { - $this->_hyperlinkCollection[$pCellCoordinate] = $pHyperlink; - } - return $this; - } + /** + * Set hyperlnk + * + * @param string $pCellCoordinate Cell coordinate to insert hyperlink + * @param PHPExcel_Cell_Hyperlink $pHyperlink + * @return PHPExcel_Worksheet + */ + public function setHyperlink($pCellCoordinate = 'A1', PHPExcel_Cell_Hyperlink $pHyperlink = null) + { + if ($pHyperlink === null) { + unset($this->_hyperlinkCollection[$pCellCoordinate]); + } else { + $this->_hyperlinkCollection[$pCellCoordinate] = $pHyperlink; + } + return $this; + } - /** - * Hyperlink at a specific coordinate exists? - * - * @param string $pCoordinate - * @return boolean - */ - public function hyperlinkExists($pCoordinate = 'A1') - { - return isset($this->_hyperlinkCollection[$pCoordinate]); - } + /** + * Hyperlink at a specific coordinate exists? + * + * @param string $pCoordinate + * @return boolean + */ + public function hyperlinkExists($pCoordinate = 'A1') + { + return isset($this->_hyperlinkCollection[$pCoordinate]); + } - /** - * Get collection of hyperlinks - * - * @return PHPExcel_Cell_Hyperlink[] - */ - public function getHyperlinkCollection() - { - return $this->_hyperlinkCollection; - } + /** + * Get collection of hyperlinks + * + * @return PHPExcel_Cell_Hyperlink[] + */ + public function getHyperlinkCollection() + { + return $this->_hyperlinkCollection; + } - /** - * Get data validation - * - * @param string $pCellCoordinate Cell coordinate to get data validation for - */ - public function getDataValidation($pCellCoordinate = 'A1') - { - // return data validation if we already have one - if (isset($this->_dataValidationCollection[$pCellCoordinate])) { - return $this->_dataValidationCollection[$pCellCoordinate]; - } + /** + * Get data validation + * + * @param string $pCellCoordinate Cell coordinate to get data validation for + */ + public function getDataValidation($pCellCoordinate = 'A1') + { + // return data validation if we already have one + if (isset($this->_dataValidationCollection[$pCellCoordinate])) { + return $this->_dataValidationCollection[$pCellCoordinate]; + } - // else create data validation - $this->_dataValidationCollection[$pCellCoordinate] = new PHPExcel_Cell_DataValidation(); - return $this->_dataValidationCollection[$pCellCoordinate]; - } + // else create data validation + $this->_dataValidationCollection[$pCellCoordinate] = new PHPExcel_Cell_DataValidation(); + return $this->_dataValidationCollection[$pCellCoordinate]; + } - /** - * Set data validation - * - * @param string $pCellCoordinate Cell coordinate to insert data validation - * @param PHPExcel_Cell_DataValidation $pDataValidation - * @return PHPExcel_Worksheet - */ - public function setDataValidation($pCellCoordinate = 'A1', PHPExcel_Cell_DataValidation $pDataValidation = null) - { - if ($pDataValidation === null) { - unset($this->_dataValidationCollection[$pCellCoordinate]); - } else { - $this->_dataValidationCollection[$pCellCoordinate] = $pDataValidation; - } - return $this; - } + /** + * Set data validation + * + * @param string $pCellCoordinate Cell coordinate to insert data validation + * @param PHPExcel_Cell_DataValidation $pDataValidation + * @return PHPExcel_Worksheet + */ + public function setDataValidation($pCellCoordinate = 'A1', PHPExcel_Cell_DataValidation $pDataValidation = null) + { + if ($pDataValidation === null) { + unset($this->_dataValidationCollection[$pCellCoordinate]); + } else { + $this->_dataValidationCollection[$pCellCoordinate] = $pDataValidation; + } + return $this; + } - /** - * Data validation at a specific coordinate exists? - * - * @param string $pCoordinate - * @return boolean - */ - public function dataValidationExists($pCoordinate = 'A1') - { - return isset($this->_dataValidationCollection[$pCoordinate]); - } + /** + * Data validation at a specific coordinate exists? + * + * @param string $pCoordinate + * @return boolean + */ + public function dataValidationExists($pCoordinate = 'A1') + { + return isset($this->_dataValidationCollection[$pCoordinate]); + } - /** - * Get collection of data validations - * - * @return PHPExcel_Cell_DataValidation[] - */ - public function getDataValidationCollection() - { - return $this->_dataValidationCollection; - } + /** + * Get collection of data validations + * + * @return PHPExcel_Cell_DataValidation[] + */ + public function getDataValidationCollection() + { + return $this->_dataValidationCollection; + } - /** - * Accepts a range, returning it as a range that falls within the current highest row and column of the worksheet - * - * @param string $range - * @return string Adjusted range value - */ - public function shrinkRangeToFit($range) { - $maxCol = $this->getHighestColumn(); - $maxRow = $this->getHighestRow(); - $maxCol = PHPExcel_Cell::columnIndexFromString($maxCol); + /** + * Accepts a range, returning it as a range that falls within the current highest row and column of the worksheet + * + * @param string $range + * @return string Adjusted range value + */ + public function shrinkRangeToFit($range) + { + $maxCol = $this->getHighestColumn(); + $maxRow = $this->getHighestRow(); + $maxCol = PHPExcel_Cell::columnIndexFromString($maxCol); - $rangeBlocks = explode(' ',$range); - foreach ($rangeBlocks as &$rangeSet) { - $rangeBoundaries = PHPExcel_Cell::getRangeBoundaries($rangeSet); + $rangeBlocks = explode(' ',$range); + foreach ($rangeBlocks as &$rangeSet) { + $rangeBoundaries = PHPExcel_Cell::getRangeBoundaries($rangeSet); - if (PHPExcel_Cell::columnIndexFromString($rangeBoundaries[0][0]) > $maxCol) { $rangeBoundaries[0][0] = PHPExcel_Cell::stringFromColumnIndex($maxCol); } - if ($rangeBoundaries[0][1] > $maxRow) { $rangeBoundaries[0][1] = $maxRow; } - if (PHPExcel_Cell::columnIndexFromString($rangeBoundaries[1][0]) > $maxCol) { $rangeBoundaries[1][0] = PHPExcel_Cell::stringFromColumnIndex($maxCol); } - if ($rangeBoundaries[1][1] > $maxRow) { $rangeBoundaries[1][1] = $maxRow; } - $rangeSet = $rangeBoundaries[0][0].$rangeBoundaries[0][1].':'.$rangeBoundaries[1][0].$rangeBoundaries[1][1]; - } - unset($rangeSet); - $stRange = implode(' ',$rangeBlocks); + if (PHPExcel_Cell::columnIndexFromString($rangeBoundaries[0][0]) > $maxCol) { $rangeBoundaries[0][0] = PHPExcel_Cell::stringFromColumnIndex($maxCol); } + if ($rangeBoundaries[0][1] > $maxRow) { $rangeBoundaries[0][1] = $maxRow; } + if (PHPExcel_Cell::columnIndexFromString($rangeBoundaries[1][0]) > $maxCol) { $rangeBoundaries[1][0] = PHPExcel_Cell::stringFromColumnIndex($maxCol); } + if ($rangeBoundaries[1][1] > $maxRow) { $rangeBoundaries[1][1] = $maxRow; } + $rangeSet = $rangeBoundaries[0][0].$rangeBoundaries[0][1].':'.$rangeBoundaries[1][0].$rangeBoundaries[1][1]; + } + unset($rangeSet); + $stRange = implode(' ',$rangeBlocks); - return $stRange; - } + return $stRange; + } - /** - * Get tab color - * - * @return PHPExcel_Style_Color - */ - public function getTabColor() - { - if ($this->_tabColor === NULL) - $this->_tabColor = new PHPExcel_Style_Color(); + /** + * Get tab color + * + * @return PHPExcel_Style_Color + */ + public function getTabColor() + { + if ($this->_tabColor === NULL) + $this->_tabColor = new PHPExcel_Style_Color(); - return $this->_tabColor; - } + return $this->_tabColor; + } - /** - * Reset tab color - * - * @return PHPExcel_Worksheet - */ - public function resetTabColor() - { - $this->_tabColor = null; - unset($this->_tabColor); + /** + * Reset tab color + * + * @return PHPExcel_Worksheet + */ + public function resetTabColor() + { + $this->_tabColor = null; + unset($this->_tabColor); - return $this; - } + return $this; + } - /** - * Tab color set? - * - * @return boolean - */ - public function isTabColorSet() - { - return ($this->_tabColor !== NULL); - } + /** + * Tab color set? + * + * @return boolean + */ + public function isTabColorSet() + { + return ($this->_tabColor !== NULL); + } - /** - * Copy worksheet (!= clone!) - * - * @return PHPExcel_Worksheet - */ - public function copy() { - $copied = clone $this; + /** + * Copy worksheet (!= clone!) + * + * @return PHPExcel_Worksheet + */ + public function copy() + { + $copied = clone $this; - return $copied; - } + return $copied; + } - /** - * Implement PHP __clone to create a deep clone, not just a shallow copy. - */ - public function __clone() { - foreach ($this as $key => $val) { - if ($key == '_parent') { - continue; - } + /** + * Implement PHP __clone to create a deep clone, not just a shallow copy. + */ + public function __clone() + { + foreach ($this as $key => $val) { + if ($key == '_parent') { + continue; + } - if (is_object($val) || (is_array($val))) { - if ($key == '_cellCollection') { - $newCollection = clone $this->_cellCollection; - $newCollection->copyCellCollection($this); - $this->_cellCollection = $newCollection; - } elseif ($key == '_drawingCollection') { - $newCollection = clone $this->_drawingCollection; - $this->_drawingCollection = $newCollection; - } elseif (($key == '_autoFilter') && ($this->_autoFilter instanceof PHPExcel_Worksheet_AutoFilter)) { - $newAutoFilter = clone $this->_autoFilter; - $this->_autoFilter = $newAutoFilter; - $this->_autoFilter->setParent($this); - } else { - $this->{$key} = unserialize(serialize($val)); - } - } - } - } + if (is_object($val) || (is_array($val))) { + if ($key == '_cellCollection') { + $newCollection = clone $this->_cellCollection; + $newCollection->copyCellCollection($this); + $this->_cellCollection = $newCollection; + } elseif ($key == '_drawingCollection') { + $newCollection = clone $this->_drawingCollection; + $this->_drawingCollection = $newCollection; + } elseif (($key == '_autoFilter') && ($this->_autoFilter instanceof PHPExcel_Worksheet_AutoFilter)) { + $newAutoFilter = clone $this->_autoFilter; + $this->_autoFilter = $newAutoFilter; + $this->_autoFilter->setParent($this); + } else { + $this->{$key} = unserialize(serialize($val)); + } + } + } + } } From 4771c30ef15802123e51091d9f26bdacdc3fae1e Mon Sep 17 00:00:00 2001 From: Dominik Bonsch Date: Sat, 9 Feb 2013 12:17:58 +0100 Subject: [PATCH 13/17] PSR-2 --- Classes/PHPExcel/Style.php | 878 +++++++++++++++++++------------------ 1 file changed, 444 insertions(+), 434 deletions(-) diff --git a/Classes/PHPExcel/Style.php b/Classes/PHPExcel/Style.php index 15004a58..f57332e0 100644 --- a/Classes/PHPExcel/Style.php +++ b/Classes/PHPExcel/Style.php @@ -21,7 +21,7 @@ * @category PHPExcel * @package PHPExcel_Style * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version ##VERSION##, ##DATE## */ @@ -35,447 +35,449 @@ */ class PHPExcel_Style extends PHPExcel_Style_Supervisor implements PHPExcel_IComparable { - /** - * Font - * - * @var PHPExcel_Style_Font - */ - protected $_font; + /** + * Font + * + * @var PHPExcel_Style_Font + */ + protected $_font; - /** - * Fill - * - * @var PHPExcel_Style_Fill - */ - protected $_fill; + /** + * Fill + * + * @var PHPExcel_Style_Fill + */ + protected $_fill; - /** - * Borders - * - * @var PHPExcel_Style_Borders - */ - protected $_borders; + /** + * Borders + * + * @var PHPExcel_Style_Borders + */ + protected $_borders; - /** - * Alignment - * - * @var PHPExcel_Style_Alignment - */ - protected $_alignment; + /** + * Alignment + * + * @var PHPExcel_Style_Alignment + */ + protected $_alignment; - /** - * Number Format - * - * @var PHPExcel_Style_NumberFormat - */ - protected $_numberFormat; + /** + * Number Format + * + * @var PHPExcel_Style_NumberFormat + */ + protected $_numberFormat; - /** - * Conditional styles - * - * @var PHPExcel_Style_Conditional[] - */ - protected $_conditionalStyles; + /** + * Conditional styles + * + * @var PHPExcel_Style_Conditional[] + */ + protected $_conditionalStyles; - /** - * Protection - * - * @var PHPExcel_Style_Protection - */ - protected $_protection; + /** + * Protection + * + * @var PHPExcel_Style_Protection + */ + protected $_protection; - /** - * Index of style in collection. Only used for real style. - * - * @var int - */ - protected $_index; + /** + * Index of style in collection. Only used for real style. + * + * @var int + */ + protected $_index; /** * Create a new PHPExcel_Style - * - * @param boolean $isSupervisor Flag indicating if this is a supervisor or not - * 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 + * + * @param boolean $isSupervisor Flag indicating if this is a supervisor or not + * 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 */ public function __construct($isSupervisor = false, $isConditional = false) { - // Supervisor? - $this->_isSupervisor = $isSupervisor; + // Supervisor? + $this->_isSupervisor = $isSupervisor; - // Initialise values - $this->_conditionalStyles = array(); - $this->_font = new PHPExcel_Style_Font($isSupervisor, $isConditional); - $this->_fill = new PHPExcel_Style_Fill($isSupervisor, $isConditional); - $this->_borders = new PHPExcel_Style_Borders($isSupervisor, $isConditional); - $this->_alignment = new PHPExcel_Style_Alignment($isSupervisor, $isConditional); - $this->_numberFormat = new PHPExcel_Style_NumberFormat($isSupervisor, $isConditional); - $this->_protection = new PHPExcel_Style_Protection($isSupervisor, $isConditional); + // Initialise values + $this->_conditionalStyles = array(); + $this->_font = new PHPExcel_Style_Font($isSupervisor, $isConditional); + $this->_fill = new PHPExcel_Style_Fill($isSupervisor, $isConditional); + $this->_borders = new PHPExcel_Style_Borders($isSupervisor, $isConditional); + $this->_alignment = new PHPExcel_Style_Alignment($isSupervisor, $isConditional); + $this->_numberFormat = new PHPExcel_Style_NumberFormat($isSupervisor, $isConditional); + $this->_protection = new PHPExcel_Style_Protection($isSupervisor, $isConditional); - // bind parent if we are a supervisor - if ($isSupervisor) { - $this->_font->bindParent($this); - $this->_fill->bindParent($this); - $this->_borders->bindParent($this); - $this->_alignment->bindParent($this); - $this->_numberFormat->bindParent($this); - $this->_protection->bindParent($this); - } + // bind parent if we are a supervisor + if ($isSupervisor) { + $this->_font->bindParent($this); + $this->_fill->bindParent($this); + $this->_borders->bindParent($this); + $this->_alignment->bindParent($this); + $this->_numberFormat->bindParent($this); + $this->_protection->bindParent($this); + } } - /** - * Get the shared style component for the currently active cell in currently active sheet. - * Only used for style supervisor - * - * @return PHPExcel_Style - */ - public function getSharedComponent() - { - $activeSheet = $this->getActiveSheet(); - $selectedCell = $this->getActiveCell(); // e.g. 'A1' + /** + * Get the shared style component for the currently active cell in currently active sheet. + * Only used for style supervisor + * + * @return PHPExcel_Style + */ + public function getSharedComponent() + { + $activeSheet = $this->getActiveSheet(); + $selectedCell = $this->getActiveCell(); // e.g. 'A1' - if ($activeSheet->cellExists($selectedCell)) { - $xfIndex = $activeSheet->getCell($selectedCell)->getXfIndex(); - } else { - $xfIndex = 0; - } + if ($activeSheet->cellExists($selectedCell)) { + $xfIndex = $activeSheet->getCell($selectedCell)->getXfIndex(); + } else { + $xfIndex = 0; + } - return $this->_parent->getCellXfByIndex($xfIndex); - } + return $this->_parent->getCellXfByIndex($xfIndex); + } - /** - * Get parent. Only used for style supervisor - * - * @return PHPExcel - */ - public function getParent() - { - return $this->_parent; - } + /** + * Get parent. Only used for style supervisor + * + * @return PHPExcel + */ + public function getParent() + { + return $this->_parent; + } /** * Apply styles from array * * * $objPHPExcel->getActiveSheet()->getStyle('B2')->applyFromArray( - * array( - * 'font' => array( - * 'name' => 'Arial', - * 'bold' => true, - * 'italic' => false, - * 'underline' => PHPExcel_Style_Font::UNDERLINE_DOUBLE, - * 'strike' => false, - * 'color' => array( - * 'rgb' => '808080' - * ) - * ), - * 'borders' => array( - * 'bottom' => array( - * 'style' => PHPExcel_Style_Border::BORDER_DASHDOT, - * 'color' => array( - * 'rgb' => '808080' - * ) - * ), - * 'top' => array( - * 'style' => PHPExcel_Style_Border::BORDER_DASHDOT, - * 'color' => array( - * 'rgb' => '808080' - * ) - * ) - * ) - * ) + * array( + * 'font' => array( + * 'name' => 'Arial', + * 'bold' => true, + * 'italic' => false, + * 'underline' => PHPExcel_Style_Font::UNDERLINE_DOUBLE, + * 'strike' => false, + * 'color' => array( + * 'rgb' => '808080' + * ) + * ), + * 'borders' => array( + * 'bottom' => array( + * 'style' => PHPExcel_Style_Border::BORDER_DASHDOT, + * 'color' => array( + * 'rgb' => '808080' + * ) + * ), + * 'top' => array( + * 'style' => PHPExcel_Style_Border::BORDER_DASHDOT, + * 'color' => array( + * 'rgb' => '808080' + * ) + * ) + * ) + * ) * ); * * - * @param array $pStyles Array containing style information - * @param boolean $pAdvanced Advanced mode for setting borders. - * @throws PHPExcel_Exception + * @param array $pStyles Array containing style information + * @param boolean $pAdvanced Advanced mode for setting borders. + * @throws PHPExcel_Exception * @return PHPExcel_Style */ - public function applyFromArray($pStyles = null, $pAdvanced = true) { - if (is_array($pStyles)) { - if ($this->_isSupervisor) { + public function applyFromArray($pStyles = null, $pAdvanced = true) + { + if (is_array($pStyles)) { + if ($this->_isSupervisor) { - $pRange = $this->getSelectedCells(); + $pRange = $this->getSelectedCells(); - // Uppercase coordinate - $pRange = strtoupper($pRange); + // Uppercase coordinate + $pRange = strtoupper($pRange); - // Is it a cell range or a single cell? - if (strpos($pRange, ':') === false) { - $rangeA = $pRange; - $rangeB = $pRange; - } else { - list($rangeA, $rangeB) = explode(':', $pRange); - } + // Is it a cell range or a single cell? + if (strpos($pRange, ':') === false) { + $rangeA = $pRange; + $rangeB = $pRange; + } else { + list($rangeA, $rangeB) = explode(':', $pRange); + } - // Calculate range outer borders - $rangeStart = PHPExcel_Cell::coordinateFromString($rangeA); - $rangeEnd = PHPExcel_Cell::coordinateFromString($rangeB); + // Calculate range outer borders + $rangeStart = PHPExcel_Cell::coordinateFromString($rangeA); + $rangeEnd = PHPExcel_Cell::coordinateFromString($rangeB); - // Translate column into index - $rangeStart[0] = PHPExcel_Cell::columnIndexFromString($rangeStart[0]) - 1; - $rangeEnd[0] = PHPExcel_Cell::columnIndexFromString($rangeEnd[0]) - 1; + // Translate column into index + $rangeStart[0] = PHPExcel_Cell::columnIndexFromString($rangeStart[0]) - 1; + $rangeEnd[0] = PHPExcel_Cell::columnIndexFromString($rangeEnd[0]) - 1; - // Make sure we can loop upwards on rows and columns - if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) { - $tmp = $rangeStart; - $rangeStart = $rangeEnd; - $rangeEnd = $tmp; - } + // Make sure we can loop upwards on rows and columns + if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) { + $tmp = $rangeStart; + $rangeStart = $rangeEnd; + $rangeEnd = $tmp; + } - // ADVANCED MODE: + // ADVANCED MODE: - if ($pAdvanced && isset($pStyles['borders'])) { + if ($pAdvanced && isset($pStyles['borders'])) { - // 'allborders' is a shorthand property for 'outline' and 'inside' and - // it applies to components that have not been set explicitly - if (isset($pStyles['borders']['allborders'])) { - foreach (array('outline', 'inside') as $component) { - if (!isset($pStyles['borders'][$component])) { - $pStyles['borders'][$component] = $pStyles['borders']['allborders']; - } - } - unset($pStyles['borders']['allborders']); // not needed any more - } + // 'allborders' is a shorthand property for 'outline' and 'inside' and + // it applies to components that have not been set explicitly + if (isset($pStyles['borders']['allborders'])) { + foreach (array('outline', 'inside') as $component) { + if (!isset($pStyles['borders'][$component])) { + $pStyles['borders'][$component] = $pStyles['borders']['allborders']; + } + } + unset($pStyles['borders']['allborders']); // not needed any more + } - // 'outline' is a shorthand property for 'top', 'right', 'bottom', 'left' - // it applies to components that have not been set explicitly - if (isset($pStyles['borders']['outline'])) { - foreach (array('top', 'right', 'bottom', 'left') as $component) { - if (!isset($pStyles['borders'][$component])) { - $pStyles['borders'][$component] = $pStyles['borders']['outline']; - } - } - unset($pStyles['borders']['outline']); // not needed any more - } + // 'outline' is a shorthand property for 'top', 'right', 'bottom', 'left' + // it applies to components that have not been set explicitly + if (isset($pStyles['borders']['outline'])) { + foreach (array('top', 'right', 'bottom', 'left') as $component) { + if (!isset($pStyles['borders'][$component])) { + $pStyles['borders'][$component] = $pStyles['borders']['outline']; + } + } + unset($pStyles['borders']['outline']); // not needed any more + } - // 'inside' is a shorthand property for 'vertical' and 'horizontal' - // it applies to components that have not been set explicitly - if (isset($pStyles['borders']['inside'])) { - foreach (array('vertical', 'horizontal') as $component) { - if (!isset($pStyles['borders'][$component])) { - $pStyles['borders'][$component] = $pStyles['borders']['inside']; - } - } - unset($pStyles['borders']['inside']); // not needed any more - } + // 'inside' is a shorthand property for 'vertical' and 'horizontal' + // it applies to components that have not been set explicitly + if (isset($pStyles['borders']['inside'])) { + foreach (array('vertical', 'horizontal') as $component) { + if (!isset($pStyles['borders'][$component])) { + $pStyles['borders'][$component] = $pStyles['borders']['inside']; + } + } + unset($pStyles['borders']['inside']); // not needed any more + } - // width and height characteristics of selection, 1, 2, or 3 (for 3 or more) - $xMax = min($rangeEnd[0] - $rangeStart[0] + 1, 3); - $yMax = min($rangeEnd[1] - $rangeStart[1] + 1, 3); + // width and height characteristics of selection, 1, 2, or 3 (for 3 or more) + $xMax = min($rangeEnd[0] - $rangeStart[0] + 1, 3); + $yMax = min($rangeEnd[1] - $rangeStart[1] + 1, 3); - // loop through up to 3 x 3 = 9 regions - for ($x = 1; $x <= $xMax; ++$x) { - // start column index for region - $colStart = ($x == 3) ? - PHPExcel_Cell::stringFromColumnIndex($rangeEnd[0]) - : PHPExcel_Cell::stringFromColumnIndex($rangeStart[0] + $x - 1); + // loop through up to 3 x 3 = 9 regions + for ($x = 1; $x <= $xMax; ++$x) { + // start column index for region + $colStart = ($x == 3) ? + PHPExcel_Cell::stringFromColumnIndex($rangeEnd[0]) + : PHPExcel_Cell::stringFromColumnIndex($rangeStart[0] + $x - 1); - // end column index for region - $colEnd = ($x == 1) ? - PHPExcel_Cell::stringFromColumnIndex($rangeStart[0]) - : PHPExcel_Cell::stringFromColumnIndex($rangeEnd[0] - $xMax + $x); + // end column index for region + $colEnd = ($x == 1) ? + PHPExcel_Cell::stringFromColumnIndex($rangeStart[0]) + : PHPExcel_Cell::stringFromColumnIndex($rangeEnd[0] - $xMax + $x); - for ($y = 1; $y <= $yMax; ++$y) { + for ($y = 1; $y <= $yMax; ++$y) { - // which edges are touching the region - $edges = array(); + // which edges are touching the region + $edges = array(); - // are we at left edge - if ($x == 1) { - $edges[] = 'left'; - } + // are we at left edge + if ($x == 1) { + $edges[] = 'left'; + } - // are we at right edge - if ($x == $xMax) { - $edges[] = 'right'; - } + // are we at right edge + if ($x == $xMax) { + $edges[] = 'right'; + } - // are we at top edge? - if ($y == 1) { - $edges[] = 'top'; - } + // are we at top edge? + if ($y == 1) { + $edges[] = 'top'; + } - // are we at bottom edge? - if ($y == $yMax) { - $edges[] = 'bottom'; - } + // are we at bottom edge? + if ($y == $yMax) { + $edges[] = 'bottom'; + } - // start row index for region - $rowStart = ($y == 3) ? - $rangeEnd[1] : $rangeStart[1] + $y - 1; + // start row index for region + $rowStart = ($y == 3) ? + $rangeEnd[1] : $rangeStart[1] + $y - 1; - // end row index for region - $rowEnd = ($y == 1) ? - $rangeStart[1] : $rangeEnd[1] - $yMax + $y; + // end row index for region + $rowEnd = ($y == 1) ? + $rangeStart[1] : $rangeEnd[1] - $yMax + $y; - // build range for region - $range = $colStart . $rowStart . ':' . $colEnd . $rowEnd; + // build range for region + $range = $colStart . $rowStart . ':' . $colEnd . $rowEnd; - // retrieve relevant style array for region - $regionStyles = $pStyles; - unset($regionStyles['borders']['inside']); + // retrieve relevant style array for region + $regionStyles = $pStyles; + unset($regionStyles['borders']['inside']); - // what are the inner edges of the region when looking at the selection - $innerEdges = array_diff( array('top', 'right', 'bottom', 'left'), $edges ); + // what are the inner edges of the region when looking at the selection + $innerEdges = array_diff( array('top', 'right', 'bottom', 'left'), $edges ); - // inner edges that are not touching the region should take the 'inside' border properties if they have been set - foreach ($innerEdges as $innerEdge) { - switch ($innerEdge) { - case 'top': - case 'bottom': - // should pick up 'horizontal' border property if set - if (isset($pStyles['borders']['horizontal'])) { - $regionStyles['borders'][$innerEdge] = $pStyles['borders']['horizontal']; - } else { - unset($regionStyles['borders'][$innerEdge]); - } - break; - case 'left': - case 'right': - // should pick up 'vertical' border property if set - if (isset($pStyles['borders']['vertical'])) { - $regionStyles['borders'][$innerEdge] = $pStyles['borders']['vertical']; - } else { - unset($regionStyles['borders'][$innerEdge]); - } - break; - } - } + // inner edges that are not touching the region should take the 'inside' border properties if they have been set + foreach ($innerEdges as $innerEdge) { + switch ($innerEdge) { + case 'top': + case 'bottom': + // should pick up 'horizontal' border property if set + if (isset($pStyles['borders']['horizontal'])) { + $regionStyles['borders'][$innerEdge] = $pStyles['borders']['horizontal']; + } else { + unset($regionStyles['borders'][$innerEdge]); + } + break; + case 'left': + case 'right': + // should pick up 'vertical' border property if set + if (isset($pStyles['borders']['vertical'])) { + $regionStyles['borders'][$innerEdge] = $pStyles['borders']['vertical']; + } else { + unset($regionStyles['borders'][$innerEdge]); + } + break; + } + } - // apply region style to region by calling applyFromArray() in simple mode - $this->getActiveSheet()->getStyle($range)->applyFromArray($regionStyles, false); - } - } - return $this; - } + // apply region style to region by calling applyFromArray() in simple mode + $this->getActiveSheet()->getStyle($range)->applyFromArray($regionStyles, false); + } + } + return $this; + } - // SIMPLE MODE: + // SIMPLE MODE: - // Selection type, inspect - if (preg_match('/^[A-Z]+1:[A-Z]+1048576$/', $pRange)) { - $selectionType = 'COLUMN'; - } else if (preg_match('/^A[0-9]+:XFD[0-9]+$/', $pRange)) { - $selectionType = 'ROW'; - } else { - $selectionType = 'CELL'; - } + // Selection type, inspect + if (preg_match('/^[A-Z]+1:[A-Z]+1048576$/', $pRange)) { + $selectionType = 'COLUMN'; + } else if (preg_match('/^A[0-9]+:XFD[0-9]+$/', $pRange)) { + $selectionType = 'ROW'; + } else { + $selectionType = 'CELL'; + } - // First loop through columns, rows, or cells to find out which styles are affected by this operation - switch ($selectionType) { - case 'COLUMN': - $oldXfIndexes = array(); - for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) { - $oldXfIndexes[$this->getActiveSheet()->getColumnDimensionByColumn($col)->getXfIndex()] = true; - } - break; + // First loop through columns, rows, or cells to find out which styles are affected by this operation + switch ($selectionType) { + case 'COLUMN': + $oldXfIndexes = array(); + for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) { + $oldXfIndexes[$this->getActiveSheet()->getColumnDimensionByColumn($col)->getXfIndex()] = true; + } + break; - case 'ROW': - $oldXfIndexes = array(); - for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) { - if ($this->getActiveSheet()->getRowDimension($row)->getXfIndex() == null) { - $oldXfIndexes[0] = true; // row without explicit style should be formatted based on default style - } else { - $oldXfIndexes[$this->getActiveSheet()->getRowDimension($row)->getXfIndex()] = true; - } - } - break; + case 'ROW': + $oldXfIndexes = array(); + for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) { + if ($this->getActiveSheet()->getRowDimension($row)->getXfIndex() == null) { + $oldXfIndexes[0] = true; // row without explicit style should be formatted based on default style + } else { + $oldXfIndexes[$this->getActiveSheet()->getRowDimension($row)->getXfIndex()] = true; + } + } + break; - case 'CELL': - $oldXfIndexes = array(); - for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) { - for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) { - $oldXfIndexes[$this->getActiveSheet()->getCellByColumnAndRow($col, $row)->getXfIndex()] = true; - } - } - break; - } + case 'CELL': + $oldXfIndexes = array(); + for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) { + for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) { + $oldXfIndexes[$this->getActiveSheet()->getCellByColumnAndRow($col, $row)->getXfIndex()] = true; + } + } + break; + } - // clone each of the affected styles, apply the style array, and add the new styles to the workbook - $workbook = $this->getActiveSheet()->getParent(); - foreach ($oldXfIndexes as $oldXfIndex => $dummy) { - $style = $workbook->getCellXfByIndex($oldXfIndex); - $newStyle = clone $style; - $newStyle->applyFromArray($pStyles); + // clone each of the affected styles, apply the style array, and add the new styles to the workbook + $workbook = $this->getActiveSheet()->getParent(); + foreach ($oldXfIndexes as $oldXfIndex => $dummy) { + $style = $workbook->getCellXfByIndex($oldXfIndex); + $newStyle = clone $style; + $newStyle->applyFromArray($pStyles); - if ($workbook->cellXfExists($newStyle)) { - // there is already such cell Xf in our collection - $newXfIndexes[$oldXfIndex] = $existingStyle->getIndex(); - } else { - // we don't have such a cell Xf, need to add - $workbook->addCellXf($newStyle); - $newXfIndexes[$oldXfIndex] = $newStyle->getIndex(); - } - } + if ($workbook->cellXfExists($newStyle)) { + // there is already such cell Xf in our collection + $newXfIndexes[$oldXfIndex] = $existingStyle->getIndex(); + } else { + // we don't have such a cell Xf, need to add + $workbook->addCellXf($newStyle); + $newXfIndexes[$oldXfIndex] = $newStyle->getIndex(); + } + } - // Loop through columns, rows, or cells again and update the XF index - switch ($selectionType) { - case 'COLUMN': - for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) { - $columnDimension = $this->getActiveSheet()->getColumnDimensionByColumn($col); - $oldXfIndex = $columnDimension->getXfIndex(); - $columnDimension->setXfIndex($newXfIndexes[$oldXfIndex]); - } - break; + // Loop through columns, rows, or cells again and update the XF index + switch ($selectionType) { + case 'COLUMN': + for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) { + $columnDimension = $this->getActiveSheet()->getColumnDimensionByColumn($col); + $oldXfIndex = $columnDimension->getXfIndex(); + $columnDimension->setXfIndex($newXfIndexes[$oldXfIndex]); + } + break; - case 'ROW': - for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) { - $rowDimension = $this->getActiveSheet()->getRowDimension($row); - $oldXfIndex = $rowDimension->getXfIndex() === null ? - 0 : $rowDimension->getXfIndex(); // row without explicit style should be formatted based on default style - $rowDimension->setXfIndex($newXfIndexes[$oldXfIndex]); - } - break; + case 'ROW': + for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) { + $rowDimension = $this->getActiveSheet()->getRowDimension($row); + $oldXfIndex = $rowDimension->getXfIndex() === null ? + 0 : $rowDimension->getXfIndex(); // row without explicit style should be formatted based on default style + $rowDimension->setXfIndex($newXfIndexes[$oldXfIndex]); + } + break; - case 'CELL': - for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) { - for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) { - $cell = $this->getActiveSheet()->getCellByColumnAndRow($col, $row); - $oldXfIndex = $cell->getXfIndex(); - $cell->setXfIndex($newXfIndexes[$oldXfIndex]); - } - } - break; - } + case 'CELL': + for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++$col) { + for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++$row) { + $cell = $this->getActiveSheet()->getCellByColumnAndRow($col, $row); + $oldXfIndex = $cell->getXfIndex(); + $cell->setXfIndex($newXfIndexes[$oldXfIndex]); + } + } + break; + } - } else { - // not a supervisor, just apply the style array directly on style object - if (array_key_exists('fill', $pStyles)) { - $this->getFill()->applyFromArray($pStyles['fill']); - } - if (array_key_exists('font', $pStyles)) { - $this->getFont()->applyFromArray($pStyles['font']); - } - if (array_key_exists('borders', $pStyles)) { - $this->getBorders()->applyFromArray($pStyles['borders']); - } - if (array_key_exists('alignment', $pStyles)) { - $this->getAlignment()->applyFromArray($pStyles['alignment']); - } - if (array_key_exists('numberformat', $pStyles)) { - $this->getNumberFormat()->applyFromArray($pStyles['numberformat']); - } - if (array_key_exists('protection', $pStyles)) { - $this->getProtection()->applyFromArray($pStyles['protection']); - } - } - } else { - throw new PHPExcel_Exception("Invalid style array passed."); - } - return $this; - } + } else { + // not a supervisor, just apply the style array directly on style object + if (array_key_exists('fill', $pStyles)) { + $this->getFill()->applyFromArray($pStyles['fill']); + } + if (array_key_exists('font', $pStyles)) { + $this->getFont()->applyFromArray($pStyles['font']); + } + if (array_key_exists('borders', $pStyles)) { + $this->getBorders()->applyFromArray($pStyles['borders']); + } + if (array_key_exists('alignment', $pStyles)) { + $this->getAlignment()->applyFromArray($pStyles['alignment']); + } + if (array_key_exists('numberformat', $pStyles)) { + $this->getNumberFormat()->applyFromArray($pStyles['numberformat']); + } + if (array_key_exists('protection', $pStyles)) { + $this->getProtection()->applyFromArray($pStyles['protection']); + } + } + } else { + throw new PHPExcel_Exception("Invalid style array passed."); + } + return $this; + } /** * Get Fill * * @return PHPExcel_Style_Fill */ - public function getFill() { - return $this->_fill; + public function getFill() + { + return $this->_fill; } /** @@ -483,29 +485,31 @@ class PHPExcel_Style extends PHPExcel_Style_Supervisor implements PHPExcel_IComp * * @return PHPExcel_Style_Font */ - public function getFont() { - return $this->_font; + public function getFont() + { + return $this->_font; } - /** - * Set font - * - * @param PHPExcel_Style_Font $font - * @return PHPExcel_Style - */ - public function setFont(PHPExcel_Style_Font $font) - { - $this->_font = $font; - return $this; - } + /** + * Set font + * + * @param PHPExcel_Style_Font $font + * @return PHPExcel_Style + */ + public function setFont(PHPExcel_Style_Font $font) + { + $this->_font = $font; + return $this; + } /** * Get Borders * * @return PHPExcel_Style_Borders */ - public function getBorders() { - return $this->_borders; + public function getBorders() + { + return $this->_borders; } /** @@ -513,8 +517,9 @@ class PHPExcel_Style extends PHPExcel_Style_Supervisor implements PHPExcel_IComp * * @return PHPExcel_Style_Alignment */ - public function getAlignment() { - return $this->_alignment; + public function getAlignment() + { + return $this->_alignment; } /** @@ -522,8 +527,9 @@ class PHPExcel_Style extends PHPExcel_Style_Supervisor implements PHPExcel_IComp * * @return PHPExcel_Style_NumberFormat */ - public function getNumberFormat() { - return $this->_numberFormat; + public function getNumberFormat() + { + return $this->_numberFormat; } /** @@ -531,21 +537,23 @@ class PHPExcel_Style extends PHPExcel_Style_Supervisor implements PHPExcel_IComp * * @return PHPExcel_Style_Conditional[] */ - public function getConditionalStyles() { - return $this->getActiveSheet()->getConditionalStyles($this->getActiveCell()); + public function getConditionalStyles() + { + return $this->getActiveSheet()->getConditionalStyles($this->getActiveCell()); } /** * Set Conditional Styles. Only used on supervisor. * - * @param PHPExcel_Style_Conditional[] $pValue Array of condtional styles + * @param PHPExcel_Style_Conditional[] $pValue Array of condtional styles * @return PHPExcel_Style */ - public function setConditionalStyles($pValue = null) { - if (is_array($pValue)) { - $this->getActiveSheet()->setConditionalStyles($this->getSelectedCells(), $pValue); - } - return $this; + public function setConditionalStyles($pValue = null) + { + if (is_array($pValue)) { + $this->getActiveSheet()->setConditionalStyles($this->getSelectedCells(), $pValue); + } + return $this; } /** @@ -553,51 +561,53 @@ class PHPExcel_Style extends PHPExcel_Style_Supervisor implements PHPExcel_IComp * * @return PHPExcel_Style_Protection */ - public function getProtection() { - return $this->_protection; + public function getProtection() + { + return $this->_protection; } - /** - * Get hash code - * - * @return string Hash code - */ - public function getHashCode() { - $hashConditionals = ''; - foreach ($this->_conditionalStyles as $conditional) { - $hashConditionals .= $conditional->getHashCode(); - } + /** + * Get hash code + * + * @return string Hash code + */ + public function getHashCode() + { + $hashConditionals = ''; + foreach ($this->_conditionalStyles as $conditional) { + $hashConditionals .= $conditional->getHashCode(); + } - return md5( - $this->_fill->getHashCode() - . $this->_font->getHashCode() - . $this->_borders->getHashCode() - . $this->_alignment->getHashCode() - . $this->_numberFormat->getHashCode() - . $hashConditionals - . $this->_protection->getHashCode() - . __CLASS__ - ); + return md5( + $this->_fill->getHashCode() + . $this->_font->getHashCode() + . $this->_borders->getHashCode() + . $this->_alignment->getHashCode() + . $this->_numberFormat->getHashCode() + . $hashConditionals + . $this->_protection->getHashCode() + . __CLASS__ + ); } - /** - * Get own index in style collection - * - * @return int - */ - public function getIndex() - { - return $this->_index; - } + /** + * Get own index in style collection + * + * @return int + */ + public function getIndex() + { + return $this->_index; + } - /** - * Set own index in style collection - * - * @param int $pValue - */ - public function setIndex($pValue) - { - $this->_index = $pValue; - } + /** + * Set own index in style collection + * + * @param int $pValue + */ + public function setIndex($pValue) + { + $this->_index = $pValue; + } } From 94967a7cf904c2fefd337b87a889f1d78f35afbd Mon Sep 17 00:00:00 2001 From: Dominik Bonsch Date: Sat, 9 Feb 2013 12:18:30 +0100 Subject: [PATCH 14/17] PSR-2 --- Classes/PHPExcel/Style.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Classes/PHPExcel/Style.php b/Classes/PHPExcel/Style.php index f57332e0..03777d91 100644 --- a/Classes/PHPExcel/Style.php +++ b/Classes/PHPExcel/Style.php @@ -545,7 +545,7 @@ class PHPExcel_Style extends PHPExcel_Style_Supervisor implements PHPExcel_IComp /** * Set Conditional Styles. Only used on supervisor. * - * @param PHPExcel_Style_Conditional[] $pValue Array of condtional styles + * @param PHPExcel_Style_Conditional[] $pValue Array of condtional styles * @return PHPExcel_Style */ public function setConditionalStyles($pValue = null) @@ -569,7 +569,7 @@ class PHPExcel_Style extends PHPExcel_Style_Supervisor implements PHPExcel_IComp /** * Get hash code * - * @return string Hash code + * @return string Hash code */ public function getHashCode() { From b9970417c30c200212c97f471ae32f2fadabf6d9 Mon Sep 17 00:00:00 2001 From: Dominik Bonsch Date: Sat, 9 Feb 2013 12:24:19 +0100 Subject: [PATCH 15/17] PSR-2 --- Classes/PHPExcel/Settings.php | 510 ++++++++++++++++++---------------- 1 file changed, 266 insertions(+), 244 deletions(-) diff --git a/Classes/PHPExcel/Settings.php b/Classes/PHPExcel/Settings.php index e6162313..eed460c3 100644 --- a/Classes/PHPExcel/Settings.php +++ b/Classes/PHPExcel/Settings.php @@ -21,312 +21,334 @@ * @category PHPExcel * @package PHPExcel_Settings * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version ##VERSION##, ##DATE## */ /** PHPExcel root directory */ if (!defined('PHPEXCEL_ROOT')) { - /** - * @ignore - */ - define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../'); - require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); + /** + * @ignore + */ + define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../'); + require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); } class PHPExcel_Settings { - /** constants */ - /** Available Zip library classes */ - const PCLZIP = 'PHPExcel_Shared_ZipArchive'; - const ZIPARCHIVE = 'ZipArchive'; + /** constants */ + /** Available Zip library classes */ + const PCLZIP = 'PHPExcel_Shared_ZipArchive'; + const ZIPARCHIVE = 'ZipArchive'; - /** Optional Chart Rendering libraries */ - const CHART_RENDERER_JPGRAPH = 'jpgraph'; + /** Optional Chart Rendering libraries */ + const CHART_RENDERER_JPGRAPH = 'jpgraph'; - /** Optional PDF Rendering libraries */ + /** Optional PDF Rendering libraries */ const PDF_RENDERER_TCPDF = 'tcPDF'; const PDF_RENDERER_DOMPDF = 'DomPDF'; - const PDF_RENDERER_MPDF = 'mPDF'; + const PDF_RENDERER_MPDF = 'mPDF'; - private static $_chartRenderers = array( - self::CHART_RENDERER_JPGRAPH, - ); + private static $_chartRenderers = array( + self::CHART_RENDERER_JPGRAPH, + ); - private static $_pdfRenderers = array( - self::PDF_RENDERER_TCPDF, - self::PDF_RENDERER_DOMPDF, - self::PDF_RENDERER_MPDF, - ); + private static $_pdfRenderers = array( + self::PDF_RENDERER_TCPDF, + self::PDF_RENDERER_DOMPDF, + self::PDF_RENDERER_MPDF, + ); - /** - * Name of the class used for Zip file management - * e.g. - * ZipArchive - * - * @var string - */ - private static $_zipClass = self::ZIPARCHIVE; + /** + * Name of the class used for Zip file management + * e.g. + * ZipArchive + * + * @var string + */ + private static $_zipClass = self::ZIPARCHIVE; - /** - * Name of the external Library used for rendering charts - * e.g. - * jpgraph - * - * @var string - */ - private static $_chartRendererName = NULL; + /** + * Name of the external Library used for rendering charts + * e.g. + * jpgraph + * + * @var string + */ + private static $_chartRendererName = NULL; - /** - * Directory Path to the external Library used for rendering charts - * - * @var string - */ - private static $_chartRendererPath = NULL; + /** + * Directory Path to the external Library used for rendering charts + * + * @var string + */ + private static $_chartRendererPath = NULL; - /** - * Name of the external Library used for rendering PDF files - * e.g. - * mPDF - * - * @var string - */ - private static $_pdfRendererName = NULL; + /** + * Name of the external Library used for rendering PDF files + * e.g. + * mPDF + * + * @var string + */ + private static $_pdfRendererName = NULL; - /** - * Directory Path to the external Library used for rendering PDF files - * - * @var string - */ - private static $_pdfRendererPath = NULL; + /** + * Directory Path to the external Library used for rendering PDF files + * + * @var string + */ + private static $_pdfRendererPath = NULL; - /** - * Set the Zip handler Class that PHPExcel should use for Zip file management (PCLZip or ZipArchive) - * - * @param string $zipClass The Zip handler class that PHPExcel should use for Zip file management - * e.g. PHPExcel_Settings::PCLZip or PHPExcel_Settings::ZipArchive - * @return boolean Success or failure - */ - public static function setZipClass($zipClass) { - if (($zipClass === self::PCLZIP) || - ($zipClass === self::ZIPARCHIVE)) { - self::$_zipClass = $zipClass; - return TRUE; - } - return FALSE; - } // function setZipClass() + /** + * Set the Zip handler Class that PHPExcel should use for Zip file management (PCLZip or ZipArchive) + * + * @param string $zipClass The Zip handler class that PHPExcel should use for Zip file management + * e.g. PHPExcel_Settings::PCLZip or PHPExcel_Settings::ZipArchive + * @return boolean Success or failure + */ + public static function setZipClass($zipClass) + { + if (($zipClass === self::PCLZIP) || + ($zipClass === self::ZIPARCHIVE)) { + self::$_zipClass = $zipClass; + return TRUE; + } + return FALSE; + } // function setZipClass() - /** - * Return the name of the Zip handler Class that PHPExcel is configured to use (PCLZip or ZipArchive) - * for Zip file management - * - * @return string Name of the Zip handler Class that PHPExcel is configured to use - * for Zip file management - * e.g. PHPExcel_Settings::PCLZip or PHPExcel_Settings::ZipArchive - */ - public static function getZipClass() { - return self::$_zipClass; - } // function getZipClass() + /** + * Return the name of the Zip handler Class that PHPExcel is configured to use (PCLZip or ZipArchive) + * or Zip file management + * + * @return string Name of the Zip handler Class that PHPExcel is configured to use + * for Zip file management + * e.g. PHPExcel_Settings::PCLZip or PHPExcel_Settings::ZipArchive + */ + public static function getZipClass() + { + return self::$_zipClass; + } // function getZipClass() - /** - * Return the name of the method that is currently configured for cell cacheing - * - * @return string Name of the cacheing method - */ - public static function getCacheStorageMethod() { - return PHPExcel_CachedObjectStorageFactory::getCacheStorageMethod(); - } // function getCacheStorageMethod() + /** + * Return the name of the method that is currently configured for cell cacheing + * + * @return string Name of the cacheing method + */ + public static function getCacheStorageMethod() + { + return PHPExcel_CachedObjectStorageFactory::getCacheStorageMethod(); + } // function getCacheStorageMethod() - /** - * Return the name of the class that is currently being used for cell cacheing - * - * @return string Name of the class currently being used for cacheing - */ - public static function getCacheStorageClass() { - return PHPExcel_CachedObjectStorageFactory::getCacheStorageClass(); - } // function getCacheStorageClass() + /** + * Return the name of the class that is currently being used for cell cacheing + * + * @return string Name of the class currently being used for cacheing + */ + public static function getCacheStorageClass() + { + return PHPExcel_CachedObjectStorageFactory::getCacheStorageClass(); + } // function getCacheStorageClass() - /** - * Set the method that should be used for cell cacheing - * - * @param string $method Name of the cacheing method - * @param array $arguments Optional configuration arguments for the cacheing method - * @return boolean Success or failure - */ - public static function setCacheStorageMethod($method = PHPExcel_CachedObjectStorageFactory::cache_in_memory, - $arguments = array()) { - return PHPExcel_CachedObjectStorageFactory::initialize($method, $arguments); - } // function setCacheStorageMethod() + /** + * Set the method that should be used for cell cacheing + * + * @param string $method Name of the cacheing method + * @param array $arguments Optional configuration arguments for the cacheing method + * @return boolean Success or failure + */ + public static function setCacheStorageMethod( + $method = PHPExcel_CachedObjectStorageFactory::cache_in_memory, + $arguments = array() + ) + { + return PHPExcel_CachedObjectStorageFactory::initialize($method, $arguments); + } // function setCacheStorageMethod() - /** - * Set the locale code to use for formula translations and any special formatting - * - * @param string $locale The locale code to use (e.g. "fr" or "pt_br" or "en_uk") - * @return boolean Success or failure - */ - public static function setLocale($locale='en_us') { - return PHPExcel_Calculation::getInstance()->setLocale($locale); - } // function setLocale() + /** + * Set the locale code to use for formula translations and any special formatting + * + * @param string $locale The locale code to use (e.g. "fr" or "pt_br" or "en_uk") + * @return boolean Success or failure + */ + public static function setLocale($locale='en_us') + { + return PHPExcel_Calculation::getInstance()->setLocale($locale); + } // function setLocale() - /** - * Set details of the external library that PHPExcel should use for rendering charts - * - * @param string $libraryName Internal reference name of the library - * e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH - * @param string $libraryBaseDir Directory path to the library's base folder - * @return boolean Success or failure - */ - public static function setChartRenderer($libraryName, $libraryBaseDir) { - if (!self::setChartRendererName($libraryName)) - return FALSE; - return self::setChartRendererPath($libraryBaseDir); - } // function setChartRenderer() + /** + * Set details of the external library that PHPExcel should use for rendering charts + * + * @param string $libraryName Internal reference name of the library + * e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH + * @param string $libraryBaseDir Directory path to the library's base folder + * + * @return boolean Success or failure + */ + public static function setChartRenderer($libraryName, $libraryBaseDir) + { + if (!self::setChartRendererName($libraryName)) + return FALSE; + return self::setChartRendererPath($libraryBaseDir); + } // function setChartRenderer() - /** - * Identify to PHPExcel the external library to use for rendering charts - * - * @param string $libraryName Internal reference name of the library - * e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH - * @return boolean Success or failure - */ - public static function setChartRendererName($libraryName) { - if (!in_array($libraryName,self::$_chartRenderers)) { - return FALSE; - } + /** + * Identify to PHPExcel the external library to use for rendering charts + * + * @param string $libraryName Internal reference name of the library + * e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH + * + * @return boolean Success or failure + */ + public static function setChartRendererName($libraryName) + { + if (!in_array($libraryName,self::$_chartRenderers)) { + return FALSE; + } - self::$_chartRendererName = $libraryName; + self::$_chartRendererName = $libraryName; - return TRUE; - } // function setChartRendererName() + return TRUE; + } // function setChartRendererName() - /** - * Tell PHPExcel where to find the external library to use for rendering charts - * - * @param string $libraryBaseDir Directory path to the library's base folder - * @return boolean Success or failure - */ - public static function setChartRendererPath($libraryBaseDir) { - if ((file_exists($libraryBaseDir) === false) || (is_readable($libraryBaseDir) === false)) { - return FALSE; - } - self::$_chartRendererPath = $libraryBaseDir; + /** + * Tell PHPExcel where to find the external library to use for rendering charts + * + * @param string $libraryBaseDir Directory path to the library's base folder + * @return boolean Success or failure + */ + public static function setChartRendererPath($libraryBaseDir) + { + if ((file_exists($libraryBaseDir) === false) || (is_readable($libraryBaseDir) === false)) { + return FALSE; + } + self::$_chartRendererPath = $libraryBaseDir; - return TRUE; - } // function setChartRendererPath() + return TRUE; + } // function setChartRendererPath() - /** - * Return the Chart Rendering Library that PHPExcel is currently configured to use (e.g. jpgraph) - * - * @return string|NULL Internal reference name of the Chart Rendering Library that PHPExcel is - * currently configured to use - * e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH - */ - public static function getChartRendererName() { - return self::$_chartRendererName; - } // function getChartRendererName() + /** + * Return the Chart Rendering Library that PHPExcel is currently configured to use (e.g. jpgraph) + * + * @return string|NULL Internal reference name of the Chart Rendering Library that PHPExcel is + * currently configured to use + * e.g. PHPExcel_Settings::CHART_RENDERER_JPGRAPH + */ + public static function getChartRendererName() + { + return self::$_chartRendererName; + } // function getChartRendererName() - /** - * Return the directory path to the Chart Rendering Library that PHPExcel is currently configured to use - * - * @return string|NULL Directory Path to the Chart Rendering Library that PHPExcel is - * currently configured to use - */ - public static function getChartRendererPath() { - return self::$_chartRendererPath; - } // function getChartRendererPath() + /** + * Return the directory path to the Chart Rendering Library that PHPExcel is currently configured to use + * + * @return string|NULL Directory Path to the Chart Rendering Library that PHPExcel is + * currently configured to use + */ + public static function getChartRendererPath() + { + return self::$_chartRendererPath; + } // function getChartRendererPath() - /** - * Set details of the external library that PHPExcel should use for rendering PDF files - * - * @param string $libraryName Internal reference name of the library - * e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF, - * PHPExcel_Settings::PDF_RENDERER_DOMPDF - * or PHPExcel_Settings::PDF_RENDERER_MPDF - * @param string $libraryBaseDir Directory path to the library's base folder - * @return boolean Success or failure - */ - public static function setPdfRenderer($libraryName, $libraryBaseDir) { - if (!self::setPdfRendererName($libraryName)) - return FALSE; - return self::setPdfRendererPath($libraryBaseDir); - } // function setPdfRenderer() + /** + * Set details of the external library that PHPExcel should use for rendering PDF files + * + * @param string $libraryName Internal reference name of the library + * e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF, + * PHPExcel_Settings::PDF_RENDERER_DOMPDF + * or PHPExcel_Settings::PDF_RENDERER_MPDF + * @param string $libraryBaseDir Directory path to the library's base folder + * + * @return boolean Success or failure + */ + public static function setPdfRenderer($libraryName, $libraryBaseDir) + { + if (!self::setPdfRendererName($libraryName)) + return FALSE; + return self::setPdfRendererPath($libraryBaseDir); + } // function setPdfRenderer() - /** - * Identify to PHPExcel the external library to use for rendering PDF files - * - * @param string $libraryName Internal reference name of the library - * e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF, - * PHPExcel_Settings::PDF_RENDERER_DOMPDF - * or PHPExcel_Settings::PDF_RENDERER_MPDF - * @return boolean Success or failure - */ - public static function setPdfRendererName($libraryName) { - if (!in_array($libraryName,self::$_pdfRenderers)) { - return FALSE; - } + /** + * Identify to PHPExcel the external library to use for rendering PDF files + * + * @param string $libraryName Internal reference name of the library + * e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF, + * PHPExcel_Settings::PDF_RENDERER_DOMPDF + * or PHPExcel_Settings::PDF_RENDERER_MPDF + * + * @return boolean Success or failure + */ + public static function setPdfRendererName($libraryName) + { + if (!in_array($libraryName,self::$_pdfRenderers)) { + return FALSE; + } - self::$_pdfRendererName = $libraryName; + self::$_pdfRendererName = $libraryName; - return TRUE; - } // function setPdfRendererName() + return TRUE; + } // function setPdfRendererName() - /** - * Tell PHPExcel where to find the external library to use for rendering PDF files - * - * @param string $libraryBaseDir Directory path to the library's base folder - * @return boolean Success or failure - */ - public static function setPdfRendererPath($libraryBaseDir) { - if ((file_exists($libraryBaseDir) === false) || (is_readable($libraryBaseDir) === false)) { - return FALSE; - } - self::$_pdfRendererPath = $libraryBaseDir; + /** + * Tell PHPExcel where to find the external library to use for rendering PDF files + * + * @param string $libraryBaseDir Directory path to the library's base folder + * @return boolean Success or failure + */ + public static function setPdfRendererPath($libraryBaseDir) + { + if ((file_exists($libraryBaseDir) === false) || (is_readable($libraryBaseDir) === false)) { + return FALSE; + } + self::$_pdfRendererPath = $libraryBaseDir; - return TRUE; - } // function setPdfRendererPath() + return TRUE; + } // function setPdfRendererPath() - /** - * Return the PDF Rendering Library that PHPExcel is currently configured to use (e.g. dompdf) - * - * @return string|NULL Internal reference name of the PDF Rendering Library that PHPExcel is - * currently configured to use - * e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF, - * PHPExcel_Settings::PDF_RENDERER_DOMPDF - * or PHPExcel_Settings::PDF_RENDERER_MPDF - */ - public static function getPdfRendererName() { - return self::$_pdfRendererName; - } // function getPdfRendererName() + /** + * Return the PDF Rendering Library that PHPExcel is currently configured to use (e.g. dompdf) + * + * @return string|NULL Internal reference name of the PDF Rendering Library that PHPExcel is + * currently configured to use + * e.g. PHPExcel_Settings::PDF_RENDERER_TCPDF, + * PHPExcel_Settings::PDF_RENDERER_DOMPDF + * or PHPExcel_Settings::PDF_RENDERER_MPDF + */ + public static function getPdfRendererName() + { + return self::$_pdfRendererName; + } // function getPdfRendererName() - /** - * Return the directory path to the PDF Rendering Library that PHPExcel is currently configured to use - * - * @return string|NULL Directory Path to the PDF Rendering Library that PHPExcel is - * currently configured to use - */ - public static function getPdfRendererPath() { - return self::$_pdfRendererPath; - } // function getPdfRendererPath() + /** + * Return the directory path to the PDF Rendering Library that PHPExcel is currently configured to use + * + * @return string|NULL Directory Path to the PDF Rendering Library that PHPExcel is + * currently configured to use + */ + public static function getPdfRendererPath() + { + return self::$_pdfRendererPath; + } // function getPdfRendererPath() } \ No newline at end of file From 49783efbd20ce423121d3e013f2b4a1a1f21df96 Mon Sep 17 00:00:00 2001 From: Dominik Bonsch Date: Sat, 9 Feb 2013 12:26:15 +0100 Subject: [PATCH 16/17] PSR-2 --- Classes/PHPExcel/RichText.php | 171 +++++++++++++++++----------------- 1 file changed, 87 insertions(+), 84 deletions(-) diff --git a/Classes/PHPExcel/RichText.php b/Classes/PHPExcel/RichText.php index b53bb486..09004901 100644 --- a/Classes/PHPExcel/RichText.php +++ b/Classes/PHPExcel/RichText.php @@ -21,7 +21,7 @@ * @category PHPExcel * @package PHPExcel_RichText * @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel) - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @version ##VERSION##, ##DATE## */ @@ -35,77 +35,77 @@ */ class PHPExcel_RichText implements PHPExcel_IComparable { - /** - * Rich text elements - * - * @var PHPExcel_RichText_ITextElement[] - */ - private $_richTextElements; + /** + * Rich text elements + * + * @var PHPExcel_RichText_ITextElement[] + */ + private $_richTextElements; /** * Create a new PHPExcel_RichText instance * - * @param PHPExcel_Cell $pParent - * @throws PHPExcel_Exception + * @param PHPExcel_Cell $pParent + * @throws PHPExcel_Exception */ public function __construct(PHPExcel_Cell $pCell = null) { - // Initialise variables - $this->_richTextElements = array(); + // Initialise variables + $this->_richTextElements = array(); - // Rich-Text string attached to cell? - if ($pCell !== NULL) { - // Add cell text and style - if ($pCell->getValue() != "") { - $objRun = new PHPExcel_RichText_Run($pCell->getValue()); - $objRun->setFont(clone $pCell->getParent()->getStyle($pCell->getCoordinate())->getFont()); - $this->addText($objRun); - } + // Rich-Text string attached to cell? + if ($pCell !== NULL) { + // Add cell text and style + if ($pCell->getValue() != "") { + $objRun = new PHPExcel_RichText_Run($pCell->getValue()); + $objRun->setFont(clone $pCell->getParent()->getStyle($pCell->getCoordinate())->getFont()); + $this->addText($objRun); + } - // Set parent value - $pCell->setValueExplicit($this, PHPExcel_Cell_DataType::TYPE_STRING); - } + // Set parent value + $pCell->setValueExplicit($this, PHPExcel_Cell_DataType::TYPE_STRING); + } } /** * Add text * - * @param PHPExcel_RichText_ITextElement $pText Rich text element - * @throws PHPExcel_Exception + * @param PHPExcel_RichText_ITextElement $pText Rich text element + * @throws PHPExcel_Exception * @return PHPExcel_RichText */ public function addText(PHPExcel_RichText_ITextElement $pText = null) { - $this->_richTextElements[] = $pText; - return $this; + $this->_richTextElements[] = $pText; + return $this; } /** * Create text * - * @param string $pText Text - * @return PHPExcel_RichText_TextElement - * @throws PHPExcel_Exception + * @param string $pText Text + * @return PHPExcel_RichText_TextElement + * @throws PHPExcel_Exception */ public function createText($pText = '') { - $objText = new PHPExcel_RichText_TextElement($pText); - $this->addText($objText); - return $objText; + $objText = new PHPExcel_RichText_TextElement($pText); + $this->addText($objText); + return $objText; } /** * Create text run * - * @param string $pText Text - * @return PHPExcel_RichText_Run - * @throws PHPExcel_Exception + * @param string $pText Text + * @return PHPExcel_RichText_Run + * @throws PHPExcel_Exception */ public function createTextRun($pText = '') { - $objText = new PHPExcel_RichText_Run($pText); - $this->addText($objText); - return $objText; + $objText = new PHPExcel_RichText_Run($pText); + $this->addText($objText); + return $objText; } /** @@ -115,16 +115,16 @@ class PHPExcel_RichText implements PHPExcel_IComparable */ public function getPlainText() { - // Return value - $returnValue = ''; + // Return value + $returnValue = ''; - // Loop through all PHPExcel_RichText_ITextElement - foreach ($this->_richTextElements as $text) { - $returnValue .= $text->getText(); - } + // Loop through all PHPExcel_RichText_ITextElement + foreach ($this->_richTextElements as $text) { + $returnValue .= $text->getText(); + } - // Return - return $returnValue; + // Return + return $returnValue; } /** @@ -132,8 +132,9 @@ class PHPExcel_RichText implements PHPExcel_IComparable * * @return string */ - public function __toString() { - return $this->getPlainText(); + public function __toString() + { + return $this->getPlainText(); } /** @@ -143,54 +144,56 @@ class PHPExcel_RichText implements PHPExcel_IComparable */ public function getRichTextElements() { - return $this->_richTextElements; + return $this->_richTextElements; } /** * Set Rich Text elements * - * @param PHPExcel_RichText_ITextElement[] $pElements Array of elements - * @throws PHPExcel_Exception + * @param PHPExcel_RichText_ITextElement[] $pElements Array of elements + * @throws PHPExcel_Exception * @return PHPExcel_RichText */ public function setRichTextElements($pElements = null) { - if (is_array($pElements)) { - $this->_richTextElements = $pElements; - } else { - throw new PHPExcel_Exception("Invalid PHPExcel_RichText_ITextElement[] array passed."); - } - return $this; + if (is_array($pElements)) { + $this->_richTextElements = $pElements; + } else { + throw new PHPExcel_Exception("Invalid PHPExcel_RichText_ITextElement[] array passed."); + } + return $this; } - /** - * Get hash code - * - * @return string Hash code - */ - public function getHashCode() { - $hashElements = ''; - foreach ($this->_richTextElements as $element) { - $hashElements .= $element->getHashCode(); - } + /** + * Get hash code + * + * @return string Hash code + */ + public function getHashCode() + { + $hashElements = ''; + foreach ($this->_richTextElements as $element) { + $hashElements .= $element->getHashCode(); + } - return md5( - $hashElements - . __CLASS__ - ); + return md5( + $hashElements + . __CLASS__ + ); } - /** - * Implement PHP __clone to create a deep clone, not just a shallow copy. - */ - public function __clone() { - $vars = get_object_vars($this); - foreach ($vars as $key => $value) { - if (is_object($value)) { - $this->$key = clone $value; - } else { - $this->$key = $value; - } - } - } + /** + * Implement PHP __clone to create a deep clone, not just a shallow copy. + */ + public function __clone() + { + $vars = get_object_vars($this); + foreach ($vars as $key => $value) { + if (is_object($value)) { + $this->$key = clone $value; + } else { + $this->$key = $value; + } + } + } } From 245a1dc8323af98c0a44926db6c78f06083eb8e5 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Wed, 13 Feb 2013 09:01:36 +0000 Subject: [PATCH 17/17] __destroy methods for Excel and Worksheet objects --- Classes/PHPExcel.php | 9 +++++++++ Classes/PHPExcel/Worksheet.php | 12 +++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Classes/PHPExcel.php b/Classes/PHPExcel.php index 5c66cf45..2a450c4c 100644 --- a/Classes/PHPExcel.php +++ b/Classes/PHPExcel.php @@ -133,6 +133,7 @@ class PHPExcel * */ public function disconnectWorksheets() { + $worksheet = NULL; foreach($this->_workSheetCollection as $k => &$worksheet) { $worksheet->disconnectCells(); $this->_workSheetCollection[$k] = null; @@ -141,6 +142,14 @@ class PHPExcel $this->_workSheetCollection = array(); } + /** + * Code to execute when this worksheet is unset() + * + */ + function __destruct() { + $this->disconnectWorksheets(); + } + /** * Get properties * diff --git a/Classes/PHPExcel/Worksheet.php b/Classes/PHPExcel/Worksheet.php index 2cdaca75..c8b70fe1 100644 --- a/Classes/PHPExcel/Worksheet.php +++ b/Classes/PHPExcel/Worksheet.php @@ -379,13 +379,23 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable public function disconnectCells() { $this->_cellCollection->unsetWorksheetCells(); - $this->_cellCollection = null; + $this->_cellCollection = NULL; // detach ourself from the workbook, so that it can then delete this worksheet successfully $this->_parent = null; } /** + * Code to execute when this worksheet is unset() + * + */ + function __destruct() { + if ($this->_cellCollection !== NULL) { + $this->disconnectCells(); + } + } + + /** * Return the cache controller for the cell collection * * @return PHPExcel_CachedObjectStorage_xxx