Source for file Worksheet.php
Documentation is available at Worksheet.php
* Copyright (c) 2006 - 2009 PHPExcel
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* @package PHPExcel_Worksheet
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.6.5, 2009-01-05
require_once 'PHPExcel.php';
require_once 'PHPExcel/Cell.php';
/** PHPExcel_Cell_DataType */
require_once 'PHPExcel/Cell/DataType.php';
/** PHPExcel_Worksheet_RowDimension */
require_once 'PHPExcel/Worksheet/RowDimension.php';
/** PHPExcel_Worksheet_ColumnDimension */
require_once 'PHPExcel/Worksheet/ColumnDimension.php';
/** PHPExcel_Worksheet_PageSetup */
require_once 'PHPExcel/Worksheet/PageSetup.php';
/** PHPExcel_Worksheet_PageMargins */
require_once 'PHPExcel/Worksheet/PageMargins.php';
/** PHPExcel_Worksheet_HeaderFooter */
require_once 'PHPExcel/Worksheet/HeaderFooter.php';
/** PHPExcel_Worksheet_BaseDrawing */
require_once 'PHPExcel/Worksheet/BaseDrawing.php';
/** PHPExcel_Worksheet_Drawing */
require_once 'PHPExcel/Worksheet/Drawing.php';
/** PHPExcel_Worksheet_MemoryDrawing */
require_once 'PHPExcel/Worksheet/MemoryDrawing.php';
/** PHPExcel_Worksheet_HeaderFooterDrawing */
require_once 'PHPExcel/Worksheet/HeaderFooterDrawing.php';
/** PHPExcel_Worksheet_SheetView */
require_once 'PHPExcel/Worksheet/SheetView.php';
/** PHPExcel_Worksheet_Protection */
require_once 'PHPExcel/Worksheet/Protection.php';
require_once 'PHPExcel/Comment.php';
require_once 'PHPExcel/Style.php';
/** PHPExcel_Style_Fill */
require_once 'PHPExcel/Style/Fill.php';
/** PHPExcel_Style_NumberFormat */
require_once 'PHPExcel/Style/NumberFormat.php';
/** PHPExcel_IComparable */
require_once 'PHPExcel/IComparable.php';
/** PHPExcel_Shared_Font */
require_once 'PHPExcel/Shared/Font.php';
/** PHPExcel_Shared_PasswordHasher */
require_once 'PHPExcel/Shared/PasswordHasher.php';
/** PHPExcel_ReferenceHelper */
require_once 'PHPExcel/ReferenceHelper.php';
* @package PHPExcel_Worksheet
* @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
* Collection of row dimensions
* @var PHPExcel_Worksheet_RowDimension[]
* @var PHPExcel_Worksheet_RowDimension
* Collection of column dimensions
* @var PHPExcel_Worksheet_ColumnDimension[]
* Default column dimension
* @var PHPExcel_Worksheet_ColumnDimension
* @var PHPExcel_Worksheet_BaseDrawing[]
* @var PHPExcel_Worksheet_PageSetup
* @var PHPExcel_Worksheet_PageMargins
* @var PHPExcel_Worksheet_HeaderFooter
* @var PHPExcel_Worksheet_SheetView
* @var PHPExcel_Worksheet_Protection
* Is the current cell collection sorted already?
* Collection of merged cell ranges
* Collection of protected cell ranges
* Show summary below? (Row/Column outline)
* Show summary right? (Row/Column outline)
* @var PHPExcel_Comment[]
* @param PHPExcel $pParent
public function __construct(PHPExcel $pParent = null, $pTitle = 'Worksheet')
// Set page header/footer
// Create a default style and a default gray125 style
// Default column dimension
* Get collection of cells
* @return PHPExcel_Cell[]
// Re-order cell collection
* Sort collection of cells
// Re-order cell collection
// uasort($this->_cellCollection, array('PHPExcel_Cell', 'compareCells')); <-- slow
// Columns are limited to ZZZ (18278), so 20000 is plenty to assure no conflicts
$key = $rowNum * 20000 + $colNum;
$indexed[$key] = $index; // &$this->_cellCollection[$index];
// Rebuild cellCollection from the sorted index
$newCellCollection = array();
foreach ($indexed as $index) {
* Get collection of row dimensions
* @return PHPExcel_Worksheet_RowDimension[]
* Get default row dimension
* @return PHPExcel_Worksheet_RowDimension
* Get collection of column dimensions
* @return PHPExcel_Worksheet_ColumnDimension[]
* Get default column dimension
* @return PHPExcel_Worksheet_ColumnDimension
* Get collection of drawings
* @return PHPExcel_Worksheet_BaseDrawing[]
* Refresh column dimensions
$newColumnDimensions = array();
foreach ($currentColumnDimensions as $objColumnDimension) {
$newColumnDimensions[$objColumnDimension->getColumnIndex()] = $objColumnDimension;
$newRowDimensions = array();
foreach ($currentRowDimensions as $objRowDimension) {
$newRowDimensions[$objRowDimension->getRowIndex()] = $objRowDimension;
* Calculate worksheet dimension
* @return string String containing the dimension of this worksheet
* Calculate widths for auto-size columns
* @param boolean $calculateMergeCells Calculate merge cell width
if ($colDimension->getAutoSize()) {
$autoSizes[$colDimension->getColumnIndex()] = - 1;
if (isset ($autoSizes[$cell->getColumn()])) {
$cellValue = $cell->getCalculatedValue();
if ($cell->isInRange($cells) && !$calculateMergeCells) {
$cellValue = ''; // do not calculate merge cells
$autoSizes[$cell->getColumn()] = max(
(float) $autoSizes[$cell->getColumn()],
$this->getStyle($cell->getCoordinate())->getFont()->getSize(),
foreach ($autoSizes as $columnIndex => $width) {
* @param PHPExcel $parent
$namedRanges = $this->_parent->getNamedRanges();
foreach ($namedRanges as $namedRange) {
$parent->addNamedRange($namedRange);
$this->_parent->removeSheetByIndex(
* @param string $pValue String containing the dimension of this worksheet
public function setTitle($pValue = 'Worksheet')
// Is this a 'rename' or not?
// Loop trough all sheets in parent PHPExcel and verify unique names
$aNames = $this->getParent()->getSheetNames();
foreach ($aNames as $strName) {
if ($strName == $pValue || substr($strName, 0, strrpos($strName, ' ')) == $pValue) {
// Eventually, add a number to the sheet name
$this->setTitle($pValue . ' ' . $titleCount);
* @return PHPExcel_Worksheet_PageSetup
* @param PHPExcel_Worksheet_PageSetup $pValue
public function setPageSetup(PHPExcel_Worksheet_PageSetup $pValue)
* @return PHPExcel_Worksheet_PageMargins
* @param PHPExcel_Worksheet_PageMargins $pValue
public function setPageMargins(PHPExcel_Worksheet_PageMargins $pValue)
* @return PHPExcel_Worksheet_HeaderFooter
* @param PHPExcel_Worksheet_HeaderFooter $pValue
* @return PHPExcel_Worksheet_HeaderFooter
* @param PHPExcel_Worksheet_SheetView $pValue
public function setSheetView(PHPExcel_Worksheet_SheetView $pValue)
* @return PHPExcel_Worksheet_Protection
* @param PHPExcel_Worksheet_Protection $pValue
public function setProtection(PHPExcel_Worksheet_Protection $pValue)
* Get highest worksheet column
* @return string Highest column name
// Loop trough column dimensions
if ($highestColumn < 0) {
* Get highest worksheet row
* @return int Highest row number
if ($cell->getRow() > $highestRow) {
$highestRow = $cell->getRow();
// Loop trough row dimensions
if ($highestRow < $dimension->getRowIndex()) {
$highestRow = $dimension->getRowIndex();
* @param string $pCoordinate Coordinate of the cell
* @param mixed $pValue Value of the cell
public function setCellValue($pCoordinate = 'A1', $pValue = null)
$this->getCell($pCoordinate)->setValue($pValue, true);
* 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 $pCoordinate Coordinate of the cell
* @param mixed $pValue Value of the cell
* @param string $pDataType Explicit data type
public function setCellValueExplicit($pCoordinate = 'A1', $pValue = null, $pDataType = PHPExcel_Cell_DataType::TYPE_STRING)
$this->getCell($pCoordinate)->setValueExplicit($pValue, $pDataType);
* 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
* Get cell at a specific coordinate
* @param string $pCoordinate Coordinate of the cell
* @return PHPExcel_Cell Cell that was found
public function getCell($pCoordinate = 'A1')
if (strpos($pCoordinate, '!') !== false) {
return $this->getParent()->getSheetByName($worksheetReference[0])->getCell($worksheetReference[1]);
$pCoordinate = $namedRange->getRange();
if ($this->getHashCode() != $namedRange->getWorksheet()->getHashCode()) {
if (!$namedRange->getLocalOnly()) {
return $namedRange->getWorksheet()->getCell($pCoordinate);
throw new Exception('Named range ' . $namedRange->getName() . ' is not accessible from within sheet ' . $this->getTitle());
if (strpos($pCoordinate,':') !== false) {
throw new Exception('Cell coordinate can not be a range of cells.');
} elseif (strpos($pCoordinate,'$') !== false) {
throw new Exception('Cell coordinate must not be absolute.');
* 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
* Cell at a specific coordinate exists?
* @param string $pCoordinate Coordinate of the cell
if (strpos($pCoordinate, '!') !== false) {
return $this->getParent()->getSheetByName($worksheetReference[0])->cellExists($worksheetReference[1]);
$pCoordinate = $namedRange->getRange();
if ($this->getHashCode() != $namedRange->getWorksheet()->getHashCode()) {
if (!$namedRange->getLocalOnly()) {
return $namedRange->getWorksheet()->cellExists($pCoordinate);
throw new Exception('Named range ' . $namedRange->getName() . ' is not accessible from within sheet ' . $this->getTitle());
if (strpos($pCoordinate,':') !== false) {
throw new Exception('Cell coordinate can not be a range of cells.');
} elseif (strpos($pCoordinate,'$') !== false) {
throw new Exception('Cell coordinate must not be absolute.');
* 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
* Get row dimension at a specific row
* @param int $pRow Numeric index of the row
* @return PHPExcel_Worksheet_RowDimension
* Get column dimension at a specific column
* @param string $pColumn String index of the column
* @return PHPExcel_Worksheet_ColumnDimension
* Get column dimension at a specific column 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_Worksheet_ColumnDimension
* @return PHPExcel_Style[]
* Set default style - should only be used by PHPExcel_IReader implementations!
* @param PHPExcel_Style $value
$this->_styles['default'] = $value; // just a reference for PHPExcel_IWriter
* @param string $pCellCoordinate Cell coordinate to get style for
public function getStyle($pCellCoordinate = 'A1')
if (strpos($pCellCoordinate, '!') !== false) {
return $this->getParent()->getSheetByName($worksheetReference[0])->getStyle($worksheetReference[1]);
$pCoordinate = $namedRange->getRange();
if ($this->getHashCode() != $namedRange->getWorksheet()->getHashCode()) {
if (!$namedRange->getLocalOnly()) {
return $namedRange->getWorksheet()->getStyle($pCellCoordinate);
throw new Exception('Named range ' . $namedRange->getName() . ' is not accessible from within sheet ' . $this->getTitle());
if (strpos($pCellCoordinate,':') !== false) {
throw new Exception('Cell coordinate string can not be a range of cells.');
} else if (strpos($pCellCoordinate,'$') !== false) {
throw new Exception('Cell coordinate string must not be absolute.');
} else if ($pCellCoordinate == '') {
throw new Exception('Cell coordinate can not be zero-length string.');
// Create a cell for this coordinate.
// Reason: When we have an empty cell that has style information,
// it should exist for our IWriter
// Check if we already have style information for this cell.
// If not, create a new style.
if (isset ($this->_styles[$pCellCoordinate])) {
return $this->_styles[$pCellCoordinate];
$this->_styles[$pCellCoordinate] = $newStyle;
* 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
* Set shared cell style to a range of cells
* Please note that this will overwrite existing cell styles for cells in range!
* @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")
public function setSharedStyle(PHPExcel_Style $pSharedCellStyle = null, $pRange = '')
// Is it a cell range or a single cell?
if (strpos($pRange, ':') === false) {
list ($rangeA, $rangeB) = explode(':', $pRange);
// Calculate range outer borders
// Translate column into index
// Make sure we can loop upwards on rows and columns
if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) {
// Loop trough cells and apply styles
for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++ $col) {
for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++ $row) {
* 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")
public function duplicateStyle(PHPExcel_Style $pCellStyle = null, $pRange = '')
// Is it a cell range or a single cell?
if (strpos($pRange, ':') === false) {
list ($rangeA, $rangeB) = explode(':', $pRange);
// Calculate range outer borders
// Translate column into index
// Make sure we can loop upwards on rows and columns
if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) {
// Loop trough cells and apply styles
for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++ $col) {
for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++ $row) {
* 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.
* @param array $pStyles Array containing style information
* @param string $pRange Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1")
// Is it a cell range or a single cell?
if (strpos($pRange, ':') === false) {
list ($rangeA, $rangeB) = explode(':', $pRange);
// Calculate range outer borders
// Translate column into index
// Make sure we can loop upwards on rows and columns
if ($rangeStart[0] > $rangeEnd[0] && $rangeStart[1] > $rangeEnd[1]) {
// Loop trough cells and apply styles array
for ($col = $rangeStart[0]; $col <= $rangeEnd[0]; ++ $col) {
for ($row = $rangeStart[1]; $row <= $rangeEnd[1]; ++ $row) {
throw new Exception("Invalid style array passed.");
* @param string $pCell Cell coordinate (e.g. A1)
* @param int $pBreak Break type (type of PHPExcel_Worksheet::BREAK_*)
public function setBreak($pCell = 'A1', $pBreak = PHPExcel_Worksheet::BREAK_NONE)
throw new Exception('No cell coordinate specified.');
* Set break on a cell by using numeric cell coordinates
* @param int $pColumn Numeric column coordinate of the cell
* @param int $pRow Numeric row coordinate of the cell
* @param int $pBreak Break type (type of PHPExcel_Worksheet::BREAK_*)
* Set merge on a cell range
* @param string $pRange Cell range (e.g. A1:E1)
if (strpos($pRange,':') !== false) {
throw new Exception('Merge must be set on a range of cells.');
* 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
* Remove merge on a cell range
* @param string $pRange Cell range (e.g. A1:E1)
if (strpos($pRange,':') !== false) {
throw new Exception('Cell range ' . $pRange . ' not known as merged.');
throw new Exception('Merge can only be removed from a range of cells.');
* 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
* 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
public function protectCells($pRange = 'A1', $pPassword = '', $pAlreadyHashed = false)
* 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
public function protectCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 0, $pColumn2 = 0, $pRow2 = 0, $pPassword = '', $pAlreadyHashed = false)
$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)
throw new Exception('Cell range ' . $pRange . ' not known as protected.');
* 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
public function unprotectCellsByColumnAndRow($pColumn1 = 0, $pRow1 = 0, $pColumn2 = 0, $pRow2 = 0, $pPassword = '', $pAlreadyHashed = false)
* @param string $pRange Cell range (i.e. A1:E10)
if (strpos($pRange,':') !== false) {
throw new Exception('Autofilter must be set on a range of cells.');
* 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
* @param string $pCell Cell (i.e. A1)
if (strpos($pCell,':') === false) {
throw new Exception('Freeze pane can not be set on a range of cells.');
* 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
* Insert a new row, updating all possible related data
* @param int $pBefore Insert before this one
* @param int $pNumRows Number of rows to insert
$objReferenceHelper->insertNewBefore('A' . $pBefore, 0, $pNumRows, $this);
throw new Exception("Rows can only be inserted before at least row 1.");
* Insert a new column, updating all possible related data
* @param int $pBefore Insert before this one
* @param int $pNumCols Number of columns to insert
$objReferenceHelper->insertNewBefore($pBefore . '1', $pNumCols, 0, $this);
throw new Exception("Column references should not be numeric.");
* 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
throw new 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
public function removeRow($pRow = 1, $pNumRows = 1) {
$objReferenceHelper->insertNewBefore('A' . ($pRow + $pNumRows), 0, - $pNumRows, $this);
throw new Exception("Rows to be deleted should at least start from row 1.");
* Remove a column, updating all possible related data
* @param int $pColumn Remove starting with this one
* @param int $pNumCols Number of columns to remove
public function removeColumn($pColumn = 'A', $pNumCols = 1) {
$objReferenceHelper->insertNewBefore($pColumn . '1', - $pNumCols, 0, $this);
throw new Exception("Column references should not be numeric.");
* 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
throw new Exception("Columns can only be inserted before at least column A (0).");
* @param boolean $pValue Show gridlines (true/false)
* @param boolean $pValue Print gridlines (true/false)
* Show summary below? (Row/Column outlining)
* @param boolean $pValue Show summary below (true/false)
* Show summary right? (Row/Column outlining)
* @param boolean $pValue Show summary right (true/false)
* @return PHPExcel_Comment[]
* @param string $pCellCoordinate Cell coordinate to get comment for
* @return PHPExcel_Comment
public function getComment($pCellCoordinate = 'A1')
if (strpos($pCellCoordinate,':') !== false) {
throw new Exception('Cell coordinate string can not be a range of cells.');
} else if (strpos($pCellCoordinate,'$') !== false) {
throw new Exception('Cell coordinate string must not be absolute.');
} else if ($pCellCoordinate == '') {
throw new Exception('Cell coordinate can not be zero-length string.');
// Check if we already have a comment for this cell.
// If not, create a new comment.
if (isset ($this->_comments[$pCellCoordinate])) {
$this->_comments[$pCellCoordinate] = $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
* @param string $pCell Cell (i.e. A1)
if (strpos($pCell,':') === false) {
throw new Exception('Selected cell can not be set on a range of cells.');
* 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
* Fill worksheet from values in array
* @param array $source Source array
* @param mixed $nullValue Value treated as "null"
public function fromArray($source = null, $nullValue = null) {
foreach ($source as $rowData) {
$rowCount = count($rowData);
for ($i = 0; $i < $rowCount; ++ $i) {
if ($rowData[$i] != $nullValue) {
throw new Exception("Parameter \$source should be an array.");
* Create array from worksheet
* @param mixed $nullValue Value treated as "null"
* @param boolean $calculateFormulas Should formulas be calculated?
public function toArray($nullValue = null, $calculateFormulas = true) {
// Get worksheet dimension
for ($row = $dimension[0][1]; $row <= $dimension[1][1]; ++ $row) {
for ($column = $dimension[0][0]; $column <= $dimension[1][0]; ++ $column) {
$returnValue[$row][$column] = $cell->getValue()->getPlainText();
if ($calculateFormulas) {
$returnValue[$row][$column] = $cell->getCalculatedValue();
$returnValue[$row][$column] = $cell->getValue();
if (isset ($this->_styles[$cell->getCoordinate()])) {
$returnValue[$row][$column] = $nullValue;
* Run PHPExcel garabage collector.
// Build a reference table from images
$imageCoordinates = array();
while ($iterator->valid()) {
$imageCoordinates[$iterator->current()->getCoordinates()] = true;
// Find cells that can be cleaned
if (is_null($cell->getValue()) || (!is_object($cell->getValue()) && $cell->getValue() === '' && !$cell->hasHyperlink())) {
// Style set? Default style?
if (!isset ($this->_styles[$coordinate]) || $this->_styles[$coordinate]->getHashCode() == $this->_styles['default']->getHashCode()) {
if (isset ($imageCoordinates[$coordinate]) && $imageCoordinates[$coordinate] === true) {
// Does it resemble the default style?
if (isset ($this->_styles[$coordinate]) && $this->_styles[$coordinate]->getHashCode() == $this->_styles['default']->getHashCode()) {
unset ($this->_styles[$coordinate]);
* @return string Hash code
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
* @return string Hash index
* Note that this index may vary during script execution! Only reliable moment is
* while doing a write of a workbook and when changes are not allowed.
* @param string $value Hash index
* Extract worksheet title from range.
* Example: extractSheetTitle('test!A1') ==> 'test'
* Example: extractSheetTitle('test!A1', true) ==> array('test', 'A1');
* @param string $pRange Range to extract title from
* @param bool $returnRange Return range? (see example)
if (strpos($pRange, '!') === false) {
$reference = explode('!', $pRange);
//$reference[0] = str_replace("'", "", $reference[0]);
* Copy worksheet (!= clone!)
* @return PHPExcel_Worksheet
foreach ($copied->_cellCollection as $coordinate => $cell) {
$newCell->rebindParent($copied);
$copied->_cellCollection[$coordinate] = $newCell;
* Implement PHP __clone to create a deep clone, not just a shallow copy.
foreach ($vars as $key => $value) {
$this->$key = clone $value;
|