PHPExcel_Worksheet
[ class tree: PHPExcel_Worksheet ] [ index: PHPExcel_Worksheet ] [ all elements ]

Source for file Worksheet.php

Documentation is available at Worksheet.php

  1. <?php
  2. /**
  3.  * PHPExcel
  4.  *
  5.  * Copyright (c) 2006 - 2010 PHPExcel
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  *
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20.  *
  21.  * @category   PHPExcel
  22.  * @package    PHPExcel_Worksheet
  23.  * @copyright  Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.7.2, 2010-01-11
  26.  */
  27.  
  28.  
  29. /** PHPExcel root */
  30. if (!defined('PHPEXCEL_ROOT')) {
  31.     /**
  32.      * @ignore
  33.      */
  34.     define('PHPEXCEL_ROOT'dirname(__FILE__'/../');
  35. }
  36.  
  37. /** PHPExcel */
  38. require_once PHPEXCEL_ROOT 'PHPExcel.php';
  39.  
  40. /** PHPExcel_Cell */
  41. require_once PHPEXCEL_ROOT 'PHPExcel/Cell.php';
  42.  
  43. /** PHPExcel_Cell_DataType */
  44. require_once PHPEXCEL_ROOT 'PHPExcel/Cell/DataType.php';
  45.  
  46. /** PHPExcel_Worksheet_RowDimension */
  47. require_once PHPEXCEL_ROOT 'PHPExcel/Worksheet/RowDimension.php';
  48.  
  49. /** PHPExcel_Worksheet_ColumnDimension */
  50. require_once PHPEXCEL_ROOT 'PHPExcel/Worksheet/ColumnDimension.php';
  51.  
  52. /** PHPExcel_Worksheet_PageSetup */
  53. require_once PHPEXCEL_ROOT 'PHPExcel/Worksheet/PageSetup.php';
  54.  
  55. /** PHPExcel_Worksheet_PageMargins */
  56. require_once PHPEXCEL_ROOT 'PHPExcel/Worksheet/PageMargins.php';
  57.  
  58. /** PHPExcel_Worksheet_HeaderFooter */
  59. require_once PHPEXCEL_ROOT 'PHPExcel/Worksheet/HeaderFooter.php';
  60.  
  61. /** PHPExcel_Worksheet_BaseDrawing */
  62. require_once PHPEXCEL_ROOT 'PHPExcel/Worksheet/BaseDrawing.php';
  63.  
  64. /** PHPExcel_Worksheet_Drawing */
  65. require_once PHPEXCEL_ROOT 'PHPExcel/Worksheet/Drawing.php';
  66.  
  67. /** PHPExcel_Worksheet_MemoryDrawing */
  68. require_once PHPEXCEL_ROOT 'PHPExcel/Worksheet/MemoryDrawing.php';
  69.  
  70. /** PHPExcel_Worksheet_HeaderFooterDrawing */
  71. require_once PHPEXCEL_ROOT 'PHPExcel/Worksheet/HeaderFooterDrawing.php';
  72.  
  73. /** PHPExcel_Worksheet_SheetView */
  74. require_once PHPEXCEL_ROOT 'PHPExcel/Worksheet/SheetView.php';
  75.  
  76. /** PHPExcel_Worksheet_Protection */
  77. require_once PHPEXCEL_ROOT 'PHPExcel/Worksheet/Protection.php';
  78.  
  79. /** PHPExcel_Worksheet_RowIterator */
  80. require_once PHPEXCEL_ROOT 'PHPExcel/Worksheet/RowIterator.php';
  81.  
  82. /** PHPExcel_Comment */
  83. require_once PHPEXCEL_ROOT 'PHPExcel/Comment.php';
  84.  
  85. /** PHPExcel_Style */
  86. require_once PHPEXCEL_ROOT 'PHPExcel/Style.php';
  87.  
  88. /** PHPExcel_Style_Fill */
  89. require_once PHPEXCEL_ROOT 'PHPExcel/Style/Fill.php';
  90.  
  91. /** PHPExcel_Style_Color */
  92. require_once PHPEXCEL_ROOT 'PHPExcel/Style/Color.php';
  93.  
  94. /** PHPExcel_Style_NumberFormat */
  95. require_once PHPEXCEL_ROOT 'PHPExcel/Style/NumberFormat.php';
  96.  
  97. /** PHPExcel_IComparable */
  98. require_once PHPEXCEL_ROOT 'PHPExcel/IComparable.php';
  99.  
  100. /** PHPExcel_Shared_Font */
  101. require_once PHPEXCEL_ROOT 'PHPExcel/Shared/Font.php';
  102.  
  103. /** PHPExcel_Shared_String */
  104. require_once PHPEXCEL_ROOT 'PHPExcel/Shared/String.php';
  105.  
  106. /** PHPExcel_Shared_PasswordHasher */
  107. require_once PHPEXCEL_ROOT 'PHPExcel/Shared/PasswordHasher.php';
  108.  
  109. /** PHPExcel_ReferenceHelper */
  110. require_once PHPEXCEL_ROOT 'PHPExcel/ReferenceHelper.php';
  111.  
  112.  
  113. /**
  114.  * PHPExcel_Worksheet
  115.  *
  116.  * @category   PHPExcel
  117.  * @package    PHPExcel_Worksheet
  118.  * @copyright  Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  119.  */
  120. class PHPExcel_Worksheet implements PHPExcel_IComparable
  121. {
  122.     /* Break types */
  123.     const BREAK_NONE    0;
  124.     const BREAK_ROW        1;
  125.     const BREAK_COLUMN    2;
  126.     
  127.     /* Sheet state */
  128.     const SHEETSTATE_VISIBLE     'visible';
  129.     const SHEETSTATE_HIDDEN     'hidden';
  130.     const SHEETSTATE_VERYHIDDEN 'veryHidden';
  131.  
  132.     /**
  133.      * Parent spreadsheet
  134.      *
  135.      * @var PHPExcel 
  136.      */
  137.     private $_parent;
  138.  
  139.     /**
  140.      * Collection of cells
  141.      *
  142.      * @var PHPExcel_Cell[] 
  143.      */
  144.     private $_cellCollection = array();
  145.  
  146.     /**
  147.      * Collection of row dimensions
  148.      *
  149.      * @var PHPExcel_Worksheet_RowDimension[] 
  150.      */
  151.     private $_rowDimensions = array();
  152.  
  153.     /**
  154.      * Default row dimension
  155.      *
  156.      * @var PHPExcel_Worksheet_RowDimension 
  157.      */
  158.     private $_defaultRowDimension = null;
  159.  
  160.     /**
  161.      * Collection of column dimensions
  162.      *
  163.      * @var PHPExcel_Worksheet_ColumnDimension[] 
  164.      */
  165.     private $_columnDimensions = array();
  166.  
  167.     /**
  168.      * Default column dimension
  169.      *
  170.      * @var PHPExcel_Worksheet_ColumnDimension 
  171.      */
  172.     private $_defaultColumnDimension = null;
  173.  
  174.     /**
  175.      * Collection of drawings
  176.      *
  177.      * @var PHPExcel_Worksheet_BaseDrawing[] 
  178.      */
  179.     private $_drawingCollection = null;
  180.  
  181.     /**
  182.      * Worksheet title
  183.      *
  184.      * @var string 
  185.      */
  186.     private $_title;
  187.     
  188.     /**
  189.      * Sheet state
  190.      *
  191.      * @var string 
  192.      */
  193.     private $_sheetState;
  194.  
  195.     /**
  196.      * Page setup
  197.      *
  198.      * @var PHPExcel_Worksheet_PageSetup 
  199.      */
  200.     private $_pageSetup;
  201.  
  202.     /**
  203.      * Page margins
  204.      *
  205.      * @var PHPExcel_Worksheet_PageMargins 
  206.      */
  207.     private $_pageMargins;
  208.  
  209.     /**
  210.      * Page header/footer
  211.      *
  212.      * @var PHPExcel_Worksheet_HeaderFooter 
  213.      */
  214.     private $_headerFooter;
  215.  
  216.     /**
  217.      * Sheet view
  218.      *
  219.      * @var PHPExcel_Worksheet_SheetView 
  220.      */
  221.     private $_sheetView;
  222.  
  223.     /**
  224.      * Protection
  225.      *
  226.      * @var PHPExcel_Worksheet_Protection 
  227.      */
  228.     private $_protection;
  229.  
  230.     /**
  231.      * Collection of styles
  232.      *
  233.      * @var PHPExcel_Style[] 
  234.      */
  235.     private $_styles = array();
  236.  
  237.     /**
  238.      * Conditional styles. Indexed by cell coordinate, e.g. 'A1'
  239.      *
  240.      * @var array 
  241.      */
  242.     private $_conditionalStylesCollection = array();
  243.  
  244.     /**
  245.      * Is the current cell collection sorted already?
  246.      *
  247.      * @var boolean 
  248.      */
  249.     private $_cellCollectionIsSorted = false;
  250.  
  251.     /**
  252.      * Collection of breaks
  253.      *
  254.      * @var array 
  255.      */
  256.     private $_breaks = array();
  257.  
  258.     /**
  259.      * Collection of merged cell ranges
  260.      *
  261.      * @var array 
  262.      */
  263.     private $_mergeCells = array();
  264.  
  265.     /**
  266.      * Collection of protected cell ranges
  267.      *
  268.      * @var array 
  269.      */
  270.     private $_protectedCells = array();
  271.  
  272.     /**
  273.      * Autofilter Range
  274.      *
  275.      * @var string 
  276.      */
  277.     private $_autoFilter = '';
  278.  
  279.     /**
  280.      * Freeze pane
  281.      *
  282.      * @var string 
  283.      */
  284.     private $_freezePane = '';
  285.  
  286.     /**
  287.      * Show gridlines?
  288.      *
  289.      * @var boolean 
  290.      */
  291.     private $_showGridlines = true;
  292.  
  293.     /**
  294.     * Print gridlines?
  295.     *
  296.     * @var boolean 
  297.     */
  298.     private $_printGridlines = false;
  299.  
  300.     /**
  301.      * Show summary below? (Row/Column outline)
  302.      *
  303.      * @var boolean 
  304.      */
  305.     private $_showSummaryBelow = true;
  306.  
  307.     /**
  308.      * Show summary right? (Row/Column outline)
  309.      *
  310.      * @var boolean 
  311.      */
  312.     private $_showSummaryRight = true;
  313.  
  314.     /**
  315.      * Collection of comments
  316.      *
  317.      * @var PHPExcel_Comment[] 
  318.      */
  319.     private $_comments = array();
  320.  
  321.     /**
  322.      * Active cell. (Only one!)
  323.      *
  324.      * @var string 
  325.      */
  326.     private $_activeCell = 'A1';
  327.  
  328.     /**
  329.      * Selected cells
  330.      *
  331.      * @var string 
  332.      */
  333.     private $_selectedCells = 'A1';
  334.  
  335.     /**
  336.      * Cached highest column
  337.      *
  338.      * @var string 
  339.      */
  340.     private $_cachedHighestColumn = 'A';
  341.  
  342.     /**
  343.      * Cached highest row
  344.      *
  345.      * @var int 
  346.      */
  347.     private $_cachedHighestRow = 1;
  348.  
  349.     /**
  350.      * Right-to-left?
  351.      *
  352.      * @var boolean 
  353.      */
  354.     private $_rightToLeft = false;
  355.  
  356.     /**
  357.      * Hyperlinks. Indexed by cell coordinate, e.g. 'A1'
  358.      *
  359.      * @var array 
  360.      */
  361.     private $_hyperlinkCollection = array();
  362.  
  363.     /**
  364.      * Data validation objects. Indexed by cell coordinate, e.g. 'A1'
  365.      *
  366.      * @var array 
  367.      */
  368.     private $_dataValidationCollection = array();
  369.  
  370.     /**
  371.      * Tab color
  372.      *
  373.      * @var PHPExcel_Style_Color 
  374.      */
  375.     private $_tabColor;
  376.  
  377.     /**
  378.      * Create a new worksheet
  379.      *
  380.      * @param PHPExcel         $pParent 
  381.      * @param string         $pTitle 
  382.      */
  383.     public function __construct(PHPExcel $pParent null$pTitle 'Worksheet')
  384.     {
  385.         // Set parent and title
  386.         $this->_parent = $pParent;
  387.         $this->setTitle($pTitle);
  388.         $this->setSheetState(PHPExcel_Worksheet::SHEETSTATE_VISIBLE);
  389.  
  390.         // Set page setup
  391.         $this->_pageSetup             = new PHPExcel_Worksheet_PageSetup();
  392.  
  393.         // Set page margins
  394.         $this->_pageMargins         = new PHPExcel_Worksheet_PageMargins();
  395.  
  396.         // Set page header/footer
  397.         $this->_headerFooter         = new PHPExcel_Worksheet_HeaderFooter();
  398.  
  399.         // Set sheet view
  400.         $this->_sheetView           = new PHPExcel_Worksheet_SheetView();
  401.  
  402.         // Drawing collection
  403.         $this->_drawingCollection     = new ArrayObject();
  404.  
  405.         // Protection
  406.         $this->_protection            = new PHPExcel_Worksheet_Protection();
  407.  
  408.         // Gridlines
  409.         $this->_showGridlines        = true;
  410.         $this->_printGridlines        = false;
  411.  
  412.         // Outline summary
  413.         $this->_showSummaryBelow    = true;
  414.         $this->_showSummaryRight    = true;
  415.  
  416.         // Default row dimension
  417.         $this->_defaultRowDimension = new PHPExcel_Worksheet_RowDimension(null);
  418.  
  419.         // Default column dimension
  420.         $this->_defaultColumnDimension = new PHPExcel_Worksheet_ColumnDimension(null);
  421.     }
  422.  
  423.     /**
  424.      * Check sheet title for valid Excel syntax
  425.      *
  426.      * @param string $pValue The string to check
  427.      * @return string The valid string
  428.      * @throws Exception
  429.      */
  430.     private static function _checkSheetTitle($pValue)
  431.     {
  432.         // Some of the printable ASCII characters are invalid:  * : / \ ? [ ]
  433.         if (preg_match('/(\\*|\\:|\\/|\\\\|\\?|\\[|\\])/'$pValue)) {
  434.             throw new Exception('Invalid character found in sheet title');
  435.         }
  436.  
  437.         // Maximum 31 characters allowed for sheet title
  438.         if (PHPExcel_Shared_String::CountCharacters($pValue31{
  439.             throw new Exception('Maximum 31 characters allowed in sheet title.');
  440.         }
  441.  
  442.         return $pValue;
  443.     }
  444.  
  445.     /**
  446.      * Get collection of cells
  447.      *
  448.      * @param boolean $pSorted Also sort the cell collection?
  449.      * @return PHPExcel_Cell[] 
  450.      */
  451.     public function getCellCollection($pSorted true)
  452.     {
  453.         if ($pSorted{
  454.             // Re-order cell collection
  455.             $this->sortCellCollection();
  456.         }
  457.  
  458.         return $this->_cellCollection;
  459.     }
  460.  
  461.     /**
  462.      * Sort collection of cells
  463.      *
  464.      * @return PHPExcel_Worksheet 
  465.      */
  466.     public function sortCellCollection()
  467.     {
  468.         if (!$this->_cellCollectionIsSorted{
  469.             // Re-order cell collection
  470.             // uasort($this->_cellCollection, array('PHPExcel_Cell', 'compareCells')); <-- slow
  471.  
  472.             $indexed array();
  473.             foreach (array_keys($this->_cellCollectionas $index{
  474.                 $rowNum $this->_cellCollection[$index]->getRow();
  475.                 $colNum PHPExcel_Cell::columnIndexFromString($this->_cellCollection[$index]->getColumn());
  476.  
  477.                 // Columns are limited to ZZZ (18278), so 20000 is plenty to assure no conflicts
  478.                 $key =  $rowNum 20000 $colNum;
  479.  
  480.                 $indexed[$key$index// &$this->_cellCollection[$index];
  481.             }
  482.             ksort($indexed);
  483.  
  484.             // Rebuild cellCollection from the sorted index
  485.             $newCellCollection array();
  486.             foreach ($indexed as $index{
  487.                 $newCellCollection[$index$this->_cellCollection[$index];
  488.             }
  489.  
  490.             $this->_cellCollection = $newCellCollection;
  491.  
  492.             $this->_cellCollectionIsSorted = true;
  493.         }
  494.         return $this;
  495.     }
  496.  
  497.     /**
  498.      * Get collection of row dimensions
  499.      *
  500.      * @return PHPExcel_Worksheet_RowDimension[] 
  501.      */
  502.     public function getRowDimensions()
  503.     {
  504.         return $this->_rowDimensions;
  505.     }
  506.  
  507.     /**
  508.      * Get default row dimension
  509.      *
  510.      * @return PHPExcel_Worksheet_RowDimension 
  511.      */
  512.     public function getDefaultRowDimension()
  513.     {
  514.         return $this->_defaultRowDimension;
  515.     }
  516.  
  517.     /**
  518.      * Get collection of column dimensions
  519.      *
  520.      * @return PHPExcel_Worksheet_ColumnDimension[] 
  521.      */
  522.     public function getColumnDimensions()
  523.     {
  524.         return $this->_columnDimensions;
  525.     }
  526.  
  527.     /**
  528.      * Get default column dimension
  529.      *
  530.      * @return PHPExcel_Worksheet_ColumnDimension 
  531.      */
  532.     public function getDefaultColumnDimension()
  533.     {
  534.         return $this->_defaultColumnDimension;
  535.     }
  536.  
  537.     /**
  538.      * Get collection of drawings
  539.      *
  540.      * @return PHPExcel_Worksheet_BaseDrawing[] 
  541.      */
  542.     public function getDrawingCollection()
  543.     {
  544.         return $this->_drawingCollection;
  545.     }
  546.  
  547.     /**
  548.      * Refresh column dimensions
  549.      *
  550.      * @return PHPExcel_Worksheet 
  551.      */
  552.     public function refreshColumnDimensions()
  553.     {
  554.         $currentColumnDimensions $this->getColumnDimensions();
  555.         $newColumnDimensions array();
  556.  
  557.         foreach ($currentColumnDimensions as $objColumnDimension{
  558.             $newColumnDimensions[$objColumnDimension->getColumnIndex()$objColumnDimension;
  559.         }
  560.  
  561.         $this->_columnDimensions = $newColumnDimensions;
  562.  
  563.         return $this;
  564.     }
  565.  
  566.     /**
  567.      * Refresh row dimensions
  568.      *
  569.      * @return PHPExcel_Worksheet 
  570.      */
  571.     public function refreshRowDimensions()
  572.     {
  573.         $currentRowDimensions $this->getRowDimensions();
  574.         $newRowDimensions array();
  575.  
  576.         foreach ($currentRowDimensions as $objRowDimension{
  577.             $newRowDimensions[$objRowDimension->getRowIndex()$objRowDimension;
  578.         }
  579.  
  580.         $this->_rowDimensions = $newRowDimensions;
  581.  
  582.         return $this;
  583.     }
  584.  
  585.     /**
  586.      * Calculate worksheet dimension
  587.      *
  588.      * @return string  String containing the dimension of this worksheet
  589.      */
  590.     public function calculateWorksheetDimension()
  591.     {
  592.         // Return
  593.         return 'A1' ':' .  $this->getHighestColumn($this->getHighestRow();
  594.     }
  595.  
  596.     /**
  597.      * Calculate widths for auto-size columns
  598.      *
  599.      * @param  boolean  $calculateMergeCells  Calculate merge cell width
  600.      * @return PHPExcel_Worksheet; 
  601.      */
  602.     public function calculateColumnWidths($calculateMergeCells false)
  603.     {
  604.         // initialize $autoSizes array
  605.         $autoSizes array();
  606.         foreach ($this->getColumnDimensions(as $colDimension{
  607.             if ($colDimension->getAutoSize()) {
  608.                 $autoSizes[$colDimension->getColumnIndex()= -1;
  609.             }
  610.         }
  611.  
  612.         // There is only something to do if there are some auto-size columns
  613.         if (count($autoSizes0{
  614.             // loop though all cells in sheet expand $autoSizes
  615.             foreach ($this->getCellCollection(falseas $cell{
  616.                 if (isset($autoSizes[$cell->getColumn()])) {
  617.                     // Calculated value
  618.                     $cellValue $cell->getCalculatedValue();
  619.  
  620.                     // To formatted string
  621.                     $cellValue PHPExcel_Style_NumberFormat::toFormattedString($cellValue$this->getParent()->getCellXfByIndex($cell->getXfIndex())->getNumberFormat()->getFormatCode());
  622.  
  623.                     foreach ($this->getMergeCells(as $cells{
  624.                         if ($cell->isInRange($cells&& !$calculateMergeCells{
  625.                             $cellValue ''// do not calculate merge cells
  626.                         }
  627.                     }
  628.  
  629.                     $autoSizes[$cell->getColumn()max(
  630.                         (float)$autoSizes[$cell->getColumn()],
  631.                         (float)PHPExcel_Shared_Font::calculateColumnWidth(
  632.                             $this->getParent()->getCellXfByIndex($cell->getXfIndex())->getFont(),
  633.                             $cellValue,
  634.                             $this->getParent()->getCellXfByIndex($cell->getXfIndex())->getAlignment()->getTextRotation(),
  635.                             $this->getDefaultStyle()->getFont()
  636.                         )
  637.                     );
  638.                 }
  639.             }
  640.  
  641.             // adjust column widths
  642.             foreach ($autoSizes as $columnIndex => $width{
  643.                 if ($width == -1$width $this->getDefaultColumnDimension()->getWidth();
  644.                 $this->getColumnDimension($columnIndex)->setWidth($width);
  645.             }
  646.         }
  647.  
  648.         return $this;
  649.     }
  650.  
  651.     /**
  652.      * Get parent
  653.      *
  654.      * @return PHPExcel 
  655.      */
  656.     public function getParent({
  657.         return $this->_parent;
  658.     }
  659.  
  660.     /**
  661.      * Re-bind parent
  662.      *
  663.      * @param PHPExcel $parent 
  664.      * @return PHPExcel_Worksheet 
  665.      */
  666.     public function rebindParent(PHPExcel $parent{
  667.         $namedRanges $this->_parent->getNamedRanges();
  668.         foreach ($namedRanges as $namedRange{
  669.             $parent->addNamedRange($namedRange);
  670.         }
  671.  
  672.         $this->_parent->removeSheetByIndex(
  673.             $this->_parent->getIndex($this)
  674.         );
  675.         $this->_parent = $parent;
  676.  
  677.         return $this;
  678.     }
  679.  
  680.     /**
  681.      * Get title
  682.      *
  683.      * @return string 
  684.      */
  685.     public function getTitle()
  686.     {
  687.         return $this->_title;
  688.     }
  689.  
  690.     /**
  691.      * Set title
  692.      *
  693.      * @param string $pValue String containing the dimension of this worksheet
  694.      * @return PHPExcel_Worksheet 
  695.      */
  696.     public function setTitle($pValue 'Worksheet')
  697.     {
  698.         // Is this a 'rename' or not?
  699.         if ($this->getTitle(== $pValue{
  700.             return;
  701.         }
  702.  
  703.         // Syntax check
  704.         self::_checkSheetTitle($pValue);
  705.  
  706.         // Old title
  707.         $oldTitle $this->getTitle();
  708.  
  709.         // Is there already such sheet name?
  710.         if ($this->getParent()->getSheetByName($pValue)) {
  711.             // Use name, but append with lowest possible integer
  712.  
  713.             $i 1;
  714.             while ($this->getParent()->getSheetByName($pValue ' ' $i)) {
  715.                 ++$i;
  716.             }
  717.  
  718.             $altTitle $pValue ' ' $i;
  719.             $this->setTitle($altTitle);
  720.  
  721.             return;
  722.         }
  723.  
  724.         // Set title
  725.         $this->_title = $pValue;
  726.  
  727.         // New title
  728.         $newTitle $this->getTitle();
  729.         PHPExcel_ReferenceHelper::getInstance()->updateNamedFormulas($this->getParent()$oldTitle$newTitle);
  730.  
  731.         return $this;
  732.     }
  733.     
  734.     /**
  735.      * Get sheet state
  736.      *
  737.      * @return string Sheet state (visible, hidden, veryHidden)
  738.      */
  739.     public function getSheetState({
  740.         return $this->_sheetState;
  741.     }
  742.     
  743.     /**
  744.      * Set sheet state
  745.      *
  746.      * @param string $value Sheet state (visible, hidden, veryHidden)
  747.      * @return PHPExcel_Worksheet 
  748.      */
  749.     public function setSheetState($value PHPExcel_Worksheet::SHEETSTATE_VISIBLE{
  750.         $this->_sheetState = $value;
  751.         return $this;
  752.     }
  753.     
  754.     /**
  755.      * Get page setup
  756.      *
  757.      * @return PHPExcel_Worksheet_PageSetup 
  758.      */
  759.     public function getPageSetup()
  760.     {
  761.         return $this->_pageSetup;
  762.     }
  763.  
  764.     /**
  765.      * Set page setup
  766.      *
  767.      * @param PHPExcel_Worksheet_PageSetup    $pValue 
  768.      * @return PHPExcel_Worksheet 
  769.      */
  770.     public function setPageSetup(PHPExcel_Worksheet_PageSetup $pValue)
  771.     {
  772.            $this->_pageSetup = $pValue;
  773.            return $this;
  774.     }
  775.  
  776.     /**
  777.      * Get page margins
  778.      *
  779.      * @return PHPExcel_Worksheet_PageMargins 
  780.      */
  781.     public function getPageMargins()
  782.     {
  783.         return $this->_pageMargins;
  784.     }
  785.  
  786.     /**
  787.      * Set page margins
  788.      *
  789.      * @param PHPExcel_Worksheet_PageMargins    $pValue 
  790.      * @return PHPExcel_Worksheet 
  791.      */
  792.     public function setPageMargins(PHPExcel_Worksheet_PageMargins $pValue)
  793.     {
  794.            $this->_pageMargins = $pValue;
  795.            return $this;
  796.     }
  797.  
  798.     /**
  799.      * Get page header/footer
  800.      *
  801.      * @return PHPExcel_Worksheet_HeaderFooter 
  802.      */
  803.     public function getHeaderFooter()
  804.     {
  805.         return $this->_headerFooter;
  806.     }
  807.  
  808.     /**
  809.      * Set page header/footer
  810.      *
  811.      * @param PHPExcel_Worksheet_HeaderFooter    $pValue 
  812.      * @return PHPExcel_Worksheet 
  813.      */
  814.     public function setHeaderFooter(PHPExcel_Worksheet_HeaderFooter $pValue)
  815.     {
  816.         $this->_headerFooter = $pValue;
  817.         return $this;
  818.     }
  819.  
  820.     /**
  821.      * Get sheet view
  822.      *
  823.      * @return PHPExcel_Worksheet_HeaderFooter 
  824.      */
  825.     public function getSheetView()
  826.     {
  827.         return $this->_sheetView;
  828.     }
  829.  
  830.     /**
  831.      * Set sheet view
  832.      *
  833.      * @param PHPExcel_Worksheet_SheetView    $pValue 
  834.      * @return PHPExcel_Worksheet 
  835.      */
  836.     public function setSheetView(PHPExcel_Worksheet_SheetView $pValue)
  837.     {
  838.         $this->_sheetView = $pValue;
  839.         return $this;
  840.     }
  841.  
  842.     /**
  843.      * Get Protection
  844.      *
  845.      * @return PHPExcel_Worksheet_Protection 
  846.      */
  847.     public function getProtection()
  848.     {
  849.         return $this->_protection;
  850.     }
  851.  
  852.     /**
  853.      * Set Protection
  854.      *
  855.      * @param PHPExcel_Worksheet_Protection    $pValue 
  856.      * @return PHPExcel_Worksheet 
  857.      */
  858.     public function setProtection(PHPExcel_Worksheet_Protection $pValue)
  859.     {
  860.            $this->_protection = $pValue;
  861.            return $this;
  862.     }
  863.  
  864.     /**
  865.      * Get highest worksheet column
  866.      *
  867.      * @return string Highest column name
  868.      */
  869.     public function getHighestColumn()
  870.     {
  871.         return $this->_cachedHighestColumn;
  872.     }
  873.  
  874.     /**
  875.      * Get highest worksheet row
  876.      *
  877.      * @return int Highest row number
  878.      */
  879.     public function getHighestRow()
  880.     {
  881.         return $this->_cachedHighestRow;
  882.     }
  883.  
  884.     /**
  885.      * Set a cell value
  886.      *
  887.      * @param string     $pCoordinate    Coordinate of the cell
  888.      * @param mixed     $pValue            Value of the cell
  889.      * @return PHPExcel_Worksheet 
  890.      */
  891.     public function setCellValue($pCoordinate 'A1'$pValue null)
  892.     {
  893.         // Set value
  894.         $this->getCell($pCoordinate)->setValue($pValue);
  895.  
  896.         return $this;
  897.     }
  898.  
  899.     /**
  900.      * Set a cell value by using numeric cell coordinates
  901.      *
  902.      * @param string     $pColumn        Numeric column coordinate of the cell
  903.      * @param string     $pRow            Numeric row coordinate of the cell
  904.      * @param mixed     $pValue            Value of the cell
  905.      * @return PHPExcel_Worksheet 
  906.      */
  907.     public function setCellValueByColumnAndRow($pColumn 0$pRow 0$pValue null)
  908.     {
  909.         return $this->setCellValue(PHPExcel_Cell::stringFromColumnIndex($pColumn$pRow$pValue);
  910.     }
  911.  
  912.     /**
  913.      * Set a cell value
  914.      *
  915.      * @param string     $pCoordinate    Coordinate of the cell
  916.      * @param mixed     $pValue            Value of the cell
  917.      * @param string    $pDataType        Explicit data type
  918.      * @return PHPExcel_Worksheet 
  919.      */
  920.     public function setCellValueExplicit($pCoordinate 'A1'$pValue null$pDataType PHPExcel_Cell_DataType::TYPE_STRING)
  921.     {
  922.         // Set value
  923.         $this->getCell($pCoordinate)->setValueExplicit($pValue$pDataType);
  924.         return $this;
  925.     }
  926.  
  927.     /**
  928.      * Set a cell value by using numeric cell coordinates
  929.      *
  930.      * @param string     $pColumn        Numeric column coordinate of the cell
  931.      * @param string     $pRow            Numeric row coordinate of the cell
  932.      * @param mixed     $pValue            Value of the cell
  933.      * @param string    $pDataType        Explicit data type
  934.      * @return PHPExcel_Worksheet 
  935.      */
  936.     public function setCellValueExplicitByColumnAndRow($pColumn 0$pRow 0$pValue null$pDataType PHPExcel_Cell_DataType::TYPE_STRING)
  937.     {
  938.         return $this->setCellValueExplicit(PHPExcel_Cell::stringFromColumnIndex($pColumn$pRow$pValue$pDataType);
  939.     }
  940.  
  941.     /**
  942.      * Get cell at a specific coordinate
  943.      *
  944.      * @param     string             $pCoordinate    Coordinate of the cell
  945.      * @throws     Exception
  946.      * @return     PHPExcel_Cell     Cell that was found
  947.      */
  948.     public function getCell($pCoordinate 'A1')
  949.     {
  950.         // Check cell collection
  951.         if (isset($this->_cellCollection[$pCoordinate])) {
  952.             return $this->_cellCollection[$pCoordinate];
  953.         }
  954.  
  955.         // Worksheet reference?
  956.         if (strpos($pCoordinate'!'!== false{
  957.             $worksheetReference PHPExcel_Worksheet::extractSheetTitle($pCoordinatetrue);
  958.             return $this->getParent()->getSheetByName($worksheetReference[0])->getCell($worksheetReference[1]);
  959.         }
  960.  
  961.         // Named range?
  962.         if ((!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i'$pCoordinate$matches)) &&
  963.             (preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_NAMEDRANGE.'$/i'$pCoordinate$matches))) {
  964.             $namedRange PHPExcel_NamedRange::resolveRange($pCoordinate$this);
  965.             if (!is_null($namedRange)) {
  966.                 $pCoordinate $namedRange->getRange();
  967.                 if ($this->getHashCode(!= $namedRange->getWorksheet()->getHashCode()) {
  968.                     if (!$namedRange->getLocalOnly()) {
  969.                         return $namedRange->getWorksheet()->getCell($pCoordinate);
  970.                     else {
  971.                         throw new Exception('Named range ' $namedRange->getName(' is not accessible from within sheet ' $this->getTitle());
  972.                     }
  973.                 else {
  974.                     //Allow named ranges within the same sheet.
  975.                     return $this->getCell($pCoordinate);
  976.                 }
  977.             }
  978.         }
  979.  
  980.         // Uppercase coordinate
  981.         $pCoordinate strtoupper($pCoordinate);
  982.  
  983.         if (strpos($pCoordinate,':'!== false || strpos($pCoordinate,','!== false{
  984.             throw new Exception('Cell coordinate can not be a range of cells.');
  985.         elseif (strpos($pCoordinate,'$'!== false{
  986.             throw new Exception('Cell coordinate must not be absolute.');
  987.         else {
  988.             // Create new cell object
  989.  
  990.             // Coordinates
  991.             $aCoordinates PHPExcel_Cell::coordinateFromString($pCoordinate);
  992.  
  993.             $this->_cellCollection[$pCoordinatenew PHPExcel_Cell($aCoordinates[0]$aCoordinates[1]nullPHPExcel_Cell_DataType::TYPE_NULL$this);
  994.             $this->_cellCollectionIsSorted = false;
  995.  
  996.             if (PHPExcel_Cell::columnIndexFromString($this->_cachedHighestColumnPHPExcel_Cell::columnIndexFromString($aCoordinates[0]))
  997.                 $this->_cachedHighestColumn = $aCoordinates[0];
  998.  
  999.             if ($this->_cachedHighestRow < $aCoordinates[1])
  1000.                 $this->_cachedHighestRow = $aCoordinates[1];
  1001.  
  1002.             // Cell needs appropriate xfIndex
  1003.             $rowDimensions    $this->getRowDimensions();
  1004.             $columnDimensions $this->getColumnDimensions();
  1005.  
  1006.             if isset($rowDimensions[$aCoordinates[1]]&& $rowDimensions[$aCoordinates[1]]->getXfIndex(!== null {
  1007.                 // then there is a row dimension with explicit style, assign it to the cell
  1008.                 $this->_cellCollection[$pCoordinate]->setXfIndex($rowDimensions[$aCoordinates[1]]->getXfIndex());
  1009.  
  1010.             else if isset($columnDimensions[$aCoordinates[0]]) ) {
  1011.                 // then there is a column dimension, assign it to the cell
  1012.                 $this->_cellCollection[$pCoordinate]->setXfIndex($columnDimensions[$aCoordinates[0]]->getXfIndex());
  1013.  
  1014.             else {
  1015.                 // set to default index
  1016.                 $this->_cellCollection[$pCoordinate]->setXfIndex(0);
  1017.             }
  1018.  
  1019.             return $this->_cellCollection[$pCoordinate];
  1020.         }
  1021.     }
  1022.  
  1023.     /**
  1024.      * Get cell at a specific coordinate by using numeric cell coordinates
  1025.      *
  1026.      * @param     string $pColumn        Numeric column coordinate of the cell
  1027.      * @param     string $pRow        Numeric row coordinate of the cell
  1028.      * @return     PHPExcel_Cell         Cell that was found
  1029.      */
  1030.     public function getCellByColumnAndRow($pColumn 0$pRow 0)
  1031.     {
  1032.         $coordinate PHPExcel_Cell::stringFromColumnIndex($pColumn$pRow;
  1033.  
  1034.         if (!isset($this->_cellCollection[$coordinate])) {
  1035.             $columnLetter PHPExcel_Cell::stringFromColumnIndex($pColumn);
  1036.  
  1037.             $this->_cellCollection[$coordinatenew PHPExcel_Cell($columnLetter$pRownullPHPExcel_Cell_DataType::TYPE_NULL$this);
  1038.             $this->_cellCollectionIsSorted = false;
  1039.  
  1040.             if (PHPExcel_Cell::columnIndexFromString($this->_cachedHighestColumn$pColumn)
  1041.                 $this->_cachedHighestColumn = $pColumn;
  1042.  
  1043.             if ($this->_cachedHighestRow < $pRow)
  1044.                 $this->_cachedHighestRow = $pRow;
  1045.         }
  1046.  
  1047.         return $this->_cellCollection[$coordinate];
  1048.     }
  1049.  
  1050.     /**
  1051.      * Cell at a specific coordinate exists?
  1052.      *
  1053.      * @param     string             $pCoordinate    Coordinate of the cell
  1054.      * @throws     Exception
  1055.      * @return     boolean 
  1056.      */
  1057.     public function cellExists($pCoordinate 'A1')
  1058.     {
  1059.         // Worksheet reference?
  1060.         if (strpos($pCoordinate'!'!== false{
  1061.             $worksheetReference PHPExcel_Worksheet::extractSheetTitle($pCoordinatetrue);
  1062.             return $this->getParent()->getSheetByName($worksheetReference[0])->cellExists($worksheetReference[1]);
  1063.         }
  1064.  
  1065.         // Named range?
  1066.         if ((!preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_CELLREF.'$/i'$pCoordinate$matches)) &&
  1067.             (preg_match('/^'.PHPExcel_Calculation::CALCULATION_REGEXP_NAMEDRANGE.'$/i'$pCoordinate$matches))) {
  1068.             $namedRange PHPExcel_NamedRange::resolveRange($pCoordinate$this);
  1069.             if (!is_null($namedRange)) {
  1070.                 $pCoordinate $namedRange->getRange();
  1071.                 if ($this->getHashCode(!= $namedRange->getWorksheet()->getHashCode()) {
  1072.                     if (!$namedRange->getLocalOnly()) {
  1073.                         return $namedRange->getWorksheet()->cellExists($pCoordinate);
  1074.                     else {
  1075.                         throw new Exception('Named range ' $namedRange->getName(' is not accessible from within sheet ' $this->getTitle());
  1076.                     }
  1077.                 }
  1078.             }
  1079.         }
  1080.  
  1081.         // Uppercase coordinate
  1082.         $pCoordinate strtoupper($pCoordinate);
  1083.  
  1084.         if (strpos($pCoordinate,':'!== false || strpos($pCoordinate,','!== false{
  1085.             throw new Exception('Cell coordinate can not be a range of cells.');
  1086.         elseif (strpos($pCoordinate,'$'!== false{
  1087.             throw new Exception('Cell coordinate must not be absolute.');
  1088.         else {
  1089.             // Coordinates
  1090.             $aCoordinates PHPExcel_Cell::coordinateFromString($pCoordinate);
  1091.  
  1092.             // Cell exists?
  1093.             return isset($this->_cellCollection[$pCoordinate]);
  1094.         }
  1095.     }
  1096.  
  1097.     /**
  1098.      * Cell at a specific coordinate by using numeric cell coordinates exists?
  1099.      *
  1100.      * @param     string $pColumn        Numeric column coordinate of the cell
  1101.      * @param     string $pRow        Numeric row coordinate of the cell
  1102.      * @return     boolean 
  1103.      */
  1104.     public function cellExistsByColumnAndRow($pColumn 0$pRow 0)
  1105.     {
  1106.         return $this->cellExists(PHPExcel_Cell::stringFromColumnIndex($pColumn$pRow);
  1107.     }
  1108.  
  1109.     /**
  1110.      * Get row dimension at a specific row
  1111.      *
  1112.      * @param int $pRow    Numeric index of the row
  1113.      * @return PHPExcel_Worksheet_RowDimension 
  1114.      */
  1115.     public function getRowDimension($pRow 0)
  1116.     {
  1117.         // Found
  1118.         $found null;
  1119.  
  1120.         // Get row dimension
  1121.         if (!isset($this->_rowDimensions[$pRow])) {
  1122.             $this->_rowDimensions[$pRownew PHPExcel_Worksheet_RowDimension($pRow);
  1123.  
  1124.             if ($this->_cachedHighestRow < $pRow)
  1125.                 $this->_cachedHighestRow = $pRow;
  1126.         }
  1127.         return $this->_rowDimensions[$pRow];
  1128.     }
  1129.  
  1130.     /**
  1131.      * Get column dimension at a specific column
  1132.      *
  1133.      * @param string $pColumn    String index of the column
  1134.      * @return PHPExcel_Worksheet_ColumnDimension 
  1135.      */
  1136.     public function getColumnDimension($pColumn 'A')
  1137.     {
  1138.         // Uppercase coordinate
  1139.         $pColumn strtoupper($pColumn);
  1140.  
  1141.         // Fetch dimensions
  1142.         if (!isset($this->_columnDimensions[$pColumn])) {
  1143.             $this->_columnDimensions[$pColumnnew PHPExcel_Worksheet_ColumnDimension($pColumn);
  1144.  
  1145.                 $this->_cachedHighestColumn = $pColumn;
  1146.         }
  1147.         return $this->_columnDimensions[$pColumn];
  1148.     }
  1149.  
  1150.     /**
  1151.      * Get column dimension at a specific column by using numeric cell coordinates
  1152.      *
  1153.      * @param     string $pColumn        Numeric column coordinate of the cell
  1154.      * @param     string $pRow        Numeric row coordinate of the cell
  1155.      * @return     PHPExcel_Worksheet_ColumnDimension 
  1156.      */
  1157.     public function getColumnDimensionByColumn($pColumn 0)
  1158.     {
  1159.         return $this->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($pColumn));
  1160.     }
  1161.  
  1162.     /**
  1163.      * Get styles
  1164.      *
  1165.      * @return PHPExcel_Style[] 
  1166.      */
  1167.     public function getStyles()
  1168.     {
  1169.         return $this->_styles;
  1170.     }
  1171.  
  1172.     /**
  1173.      * Get default style of workbork.
  1174.      *
  1175.      * @deprecated
  1176.      * @return     PHPExcel_Style 
  1177.      * @throws     Exception
  1178.      */
  1179.     public function getDefaultStyle()
  1180.     {
  1181.         return $this->_parent->getDefaultStyle();
  1182.     }
  1183.  
  1184.     /**
  1185.      * Set default style - should only be used by PHPExcel_IReader implementations!
  1186.      *
  1187.      * @deprecated
  1188.      * @param     PHPExcel_Style $value 
  1189.      * @throws     Exception
  1190.      * @return PHPExcel_Worksheet 
  1191.      */
  1192.     public function setDefaultStyle(PHPExcel_Style $pValue)
  1193.     {
  1194.         $this->_parent->getDefaultStyle()->applyFromArray(array(
  1195.             'font' => array(
  1196.                 'name' => $pValue->getFont()->getName(),
  1197.                 'size' => $pValue->getFont()->getSize(),
  1198.             ),
  1199.         ));
  1200.         return $this;
  1201.     }
  1202.  
  1203.     /**
  1204.      * Get style for cell
  1205.      *
  1206.      * @param     string     $pCellCoordinate    Cell coordinate to get style for
  1207.      * @return     PHPExcel_Style 
  1208.      * @throws     Exception
  1209.      */
  1210.     public function getStyle($pCellCoordinate 'A1')
  1211.     {
  1212.         // set this sheet as active
  1213.         $this->_parent->setActiveSheetIndex($this->_parent->getIndex($this));
  1214.  
  1215.         // set cell coordinate as active
  1216.         $this->setSelectedCells($pCellCoordinate);
  1217.  
  1218.         return $this->_parent->getCellXfSupervisor();
  1219.     }
  1220.  
  1221.     /**
  1222.      * Get conditional styles for a cell
  1223.      *
  1224.      * @param string $pCoordinate 
  1225.      * @return PHPExcel_Style_Conditional[] 
  1226.      */
  1227.     public function getConditionalStyles($pCoordinate 'A1')
  1228.     {
  1229.         if (!isset($this->_conditionalStylesCollection[$pCoordinate])) {
  1230.             $this->_conditionalStylesCollection[$pCoordinatearray();
  1231.         }
  1232.         return $this->_conditionalStylesCollection[$pCoordinate];
  1233.     }
  1234.  
  1235.     /**
  1236.      * Do conditional styles exist for this cell?
  1237.      *
  1238.      * @param string $pCoordinate 
  1239.      * @return boolean 
  1240.      */
  1241.     public function conditionalStylesExists($pCoordinate 'A1')
  1242.     {
  1243.         if (isset($this->_conditionalStylesCollection[$pCoordinate])) {
  1244.             return true;
  1245.         }
  1246.         return false;
  1247.     }
  1248.  
  1249.     /**
  1250.      * Removes conditional styles for a cell
  1251.      *
  1252.      * @param string $pCoordinate 
  1253.      * @return PHPExcel_Worksheet 
  1254.      */
  1255.     public function removeConditionalStyles($pCoordinate 'A1')
  1256.     {
  1257.         unset($this->_conditionalStylesCollection[$pCoordinate]);
  1258.         return $this;
  1259.     }
  1260.  
  1261.     /**
  1262.      * Get collection of conditional styles
  1263.      *
  1264.      * @return array 
  1265.      */
  1266.     public function getConditionalStylesCollection()
  1267.     {
  1268.         return $this->_conditionalStylesCollection;
  1269.     }
  1270.  
  1271.     /**
  1272.      * Set conditional styles
  1273.      *
  1274.      * @param $pCoordinate string E.g. 'A1'
  1275.      * @param $pValue PHPExcel_Style_Conditional[]
  1276.      * @return PHPExcel_Worksheet 
  1277.      */
  1278.     public function setConditionalStyles($pCoordinate 'A1'$pValue)
  1279.     {
  1280.         $this->_conditionalStylesCollection[$pCoordinate$pValue;
  1281.         return $this;
  1282.     }
  1283.  
  1284.     /**
  1285.      * Get style for cell by using numeric cell coordinates
  1286.      *
  1287.      * @param     int $pColumn    Numeric column coordinate of the cell
  1288.      * @param     int $pRow        Numeric row coordinate of the cell
  1289.      * @return     PHPExcel_Style 
  1290.      */
  1291.     public function getStyleByColumnAndRow($pColumn 0$pRow 0)
  1292.     {
  1293.         return $this->getStyle(PHPExcel_Cell::stringFromColumnIndex($pColumn$pRow);
  1294.     }
  1295.  
  1296.     /**
  1297.      * Set shared cell style to a range of cells
  1298.      *
  1299.      * Please note that this will overwrite existing cell styles for cells in range!
  1300.      *
  1301.      * @deprecated
  1302.      * @param     PHPExcel_Style    $pSharedCellStyle    Cell style to share
  1303.      * @param     string            $pRange                Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1")
  1304.      * @throws    Exception
  1305.      * @return PHPExcel_Worksheet 
  1306.      */
  1307.      public function setSharedStyle(PHPExcel_Style $pSharedCellStyle null$pRange '')
  1308.     {
  1309.         $this->duplicateStyle($pSharedCellStyle$pRange);
  1310.         return $this;
  1311.     }
  1312.  
  1313.     /**
  1314.      * Duplicate cell style to a range of cells
  1315.      *
  1316.      * Please note that this will overwrite existing cell styles for cells in range!
  1317.      *
  1318.      * @param     PHPExcel_Style    $pCellStyle    Cell style to duplicate
  1319.      * @param     string            $pRange        Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1")
  1320.      * @throws    Exception
  1321.      * @return PHPExcel_Worksheet 
  1322.      */
  1323.     public function duplicateStyle(PHPExcel_Style $pCellStyle null$pRange '')
  1324.     {
  1325.         // make sure we have a real style and not supervisor
  1326.         $style $pCellStyle->getIsSupervisor($pCellStyle->getSharedComponent($pCellStyle;
  1327.  
  1328.         // Add the style to the workbook if necessary
  1329.         $workbook $this->_parent;
  1330.         if ($existingStyle $this->_parent->getCellXfByHashCode($pCellStyle->getHashCode())) {
  1331.             // there is already such cell Xf in our collection
  1332.             $xfIndex $existingStyle->getIndex();
  1333.         else {
  1334.             // we don't have such a cell Xf, need to add
  1335.             $workbook->addCellXf($pCellStyle);
  1336.             $xfIndex $pCellStyle->getIndex();
  1337.         }
  1338.  
  1339.         // Uppercase coordinate
  1340.         $pRange strtoupper($pRange);
  1341.  
  1342.            // Is it a cell range or a single cell?
  1343.            $rangeA     '';
  1344.            $rangeB     '';
  1345.            if (strpos($pRange':'=== false{
  1346.                $rangeA $pRange;
  1347.                $rangeB $pRange;
  1348.            else {
  1349.                list($rangeA$rangeBexplode(':'$pRange);
  1350.            }
  1351.  
  1352.            // Calculate range outer borders
  1353.            $rangeStart PHPExcel_Cell::coordinateFromString($rangeA);
  1354.            $rangeEnd     PHPExcel_Cell::coordinateFromString($rangeB);
  1355.  
  1356.            // Translate column into index
  1357.            $rangeStart[0]    PHPExcel_Cell::columnIndexFromString($rangeStart[0]1;
  1358.            $rangeEnd[0]    PHPExcel_Cell::columnIndexFromString($rangeEnd[0]1;
  1359.  
  1360.            // Make sure we can loop upwards on rows and columns
  1361.            if ($rangeStart[0$rangeEnd[0&& $rangeStart[1$rangeEnd[1]{
  1362.                $tmp $rangeStart;
  1363.                $rangeStart $rangeEnd;
  1364.                $rangeEnd $tmp;
  1365.            }
  1366.  
  1367.            // Loop through cells and apply styles
  1368.            for ($col $rangeStart[0]$col <= $rangeEnd[0]++$col{
  1369.                for ($row $rangeStart[1]$row <= $rangeEnd[1]++$row{
  1370.                    $this->getCell(PHPExcel_Cell::stringFromColumnIndex($col$row)->setXfIndex($xfIndex);
  1371.                }
  1372.            }
  1373.  
  1374.            return $this;
  1375.     }
  1376.  
  1377.     /**
  1378.      * Duplicate cell style array to a range of cells
  1379.      *
  1380.      * Please note that this will overwrite existing cell styles for cells in range,
  1381.      * if they are in the styles array. For example, if you decide to set a range of
  1382.      * cells to font bold, only include font bold in the styles array.
  1383.      *
  1384.      * @deprecated
  1385.      * @param    array            $pStyles    Array containing style information
  1386.      * @param     string            $pRange        Range of cells (i.e. "A1:B10"), or just one cell (i.e. "A1")
  1387.      * @param     boolean            $pAdvanced    Advanced mode for setting borders.
  1388.      * @throws    Exception
  1389.      * @return PHPExcel_Worksheet 
  1390.      */
  1391.     public function duplicateStyleArray($pStyles null$pRange ''$pAdvanced true)
  1392.     {
  1393.         $this->getStyle($pRange)->applyFromArray($pStyles$pAdvanced);
  1394.         return $this;
  1395.     }
  1396.  
  1397.     /**
  1398.      * Set break on a cell
  1399.      *
  1400.      * @param     string            $pCell        Cell coordinate (e.g. A1)
  1401.      * @param     int                $pBreak        Break type (type of PHPExcel_Worksheet::BREAK_*)
  1402.      * @throws    Exception
  1403.      * @return PHPExcel_Worksheet 
  1404.      */
  1405.     public function setBreak($pCell 'A1'$pBreak PHPExcel_Worksheet::BREAK_NONE)
  1406.     {
  1407.         // Uppercase coordinate
  1408.         $pCell strtoupper($pCell);
  1409.  
  1410.         if ($pCell != ''{
  1411.             $this->_breaks[$pCell$pBreak;
  1412.         else {
  1413.             throw new Exception('No cell coordinate specified.');
  1414.         }
  1415.  
  1416.         return $this;
  1417.     }
  1418.  
  1419.     /**
  1420.      * Set break on a cell by using numeric cell coordinates
  1421.      *
  1422.      * @param     int     $pColumn    Numeric column coordinate of the cell
  1423.      * @param     int     $pRow        Numeric row coordinate of the cell
  1424.      * @param     int        $pBreak        Break type (type of PHPExcel_Worksheet::BREAK_*)
  1425.      * @throws    Exception
  1426.      * @return PHPExcel_Worksheet 
  1427.      */
  1428.     public function setBreakByColumnAndRow($pColumn 0$pRow 0$pBreak PHPExcel_Worksheet::BREAK_NONE)
  1429.     {
  1430.         return $this->setBreak(PHPExcel_Cell::stringFromColumnIndex($pColumn$pRow$pBreak);
  1431.     }
  1432.  
  1433.     /**
  1434.      * Get breaks
  1435.      *
  1436.      * @return array[] 
  1437.      */
  1438.     public function getBreaks()
  1439.     {
  1440.         return $this->_breaks;
  1441.     }
  1442.  
  1443.     /**
  1444.      * Set merge on a cell range
  1445.      *
  1446.      * @param     string            $pRange        Cell range (e.g. A1:E1)
  1447.      * @throws    Exception
  1448.      * @return PHPExcel_Worksheet 
  1449.      */
  1450.     public function mergeCells($pRange 'A1:A1')
  1451.     {
  1452.         // Uppercase coordinate
  1453.         $pRange strtoupper($pRange);
  1454.  
  1455.         if (strpos($pRange,':'!== false{
  1456.             $this->_mergeCells[$pRange$pRange;
  1457.         else {
  1458.             throw new Exception('Merge must be set on a range of cells.');
  1459.         }
  1460.  
  1461.         return $this;
  1462.     }
  1463.  
  1464.     /**
  1465.      * Set merge on a cell range by using numeric cell coordinates
  1466.      *
  1467.      * @param     int $pColumn1    Numeric column coordinate of the first cell
  1468.      * @param     int $pRow1        Numeric row coordinate of the first cell
  1469.      * @param     int $pColumn2    Numeric column coordinate of the last cell
  1470.      * @param     int $pRow2        Numeric row coordinate of the last cell
  1471.      * @throws    Exception
  1472.      * @return PHPExcel_Worksheet 
  1473.      */
  1474.     public function mergeCellsByColumnAndRow($pColumn1 0$pRow1 0$pColumn2 0$pRow2 0)
  1475.     {
  1476.         $cellRange PHPExcel_Cell::stringFromColumnIndex($pColumn1$pRow1 ':' PHPExcel_Cell::stringFromColumnIndex($pColumn2$pRow2;
  1477.         return $this->mergeCells($cellRange);
  1478.     }
  1479.  
  1480.     /**
  1481.      * Remove merge on a cell range
  1482.      *
  1483.      * @param     string            $pRange        Cell range (e.g. A1:E1)
  1484.      * @throws    Exception
  1485.      * @return PHPExcel_Worksheet 
  1486.      */
  1487.     public function unmergeCells($pRange 'A1:A1')
  1488.     {
  1489.         // Uppercase coordinate
  1490.         $pRange strtoupper($pRange);
  1491.  
  1492.         if (strpos($pRange,':'!== false{
  1493.             if (isset($this->_mergeCells[$pRange])) {
  1494.                 unset($this->_mergeCells[$pRange]);
  1495.             else {
  1496.                 throw new Exception('Cell range ' $pRange ' not known as merged.');
  1497.             }
  1498.         else {
  1499.             throw new Exception('Merge can only be removed from a range of cells.');
  1500.         }
  1501.  
  1502.         return $this;
  1503.     }
  1504.  
  1505.     /**
  1506.      * Remove merge on a cell range by using numeric cell coordinates
  1507.      *
  1508.      * @param     int $pColumn1    Numeric column coordinate of the first cell
  1509.      * @param     int $pRow1        Numeric row coordinate of the first cell
  1510.      * @param     int $pColumn2    Numeric column coordinate of the last cell
  1511.      * @param     int $pRow2        Numeric row coordinate of the last cell
  1512.      * @throws    Exception
  1513.      * @return PHPExcel_Worksheet 
  1514.      */
  1515.     public function unmergeCellsByColumnAndRow($pColumn1 0$pRow1 0$pColumn2 0$pRow2 0)
  1516.     {
  1517.         $cellRange PHPExcel_Cell::stringFromColumnIndex($pColumn1$pRow1 ':' PHPExcel_Cell::stringFromColumnIndex($pColumn2$pRow2;
  1518.         return $this->unmergeCells($cellRange);
  1519.     }
  1520.  
  1521.     /**
  1522.      * Get merge cells array.
  1523.      *
  1524.      * @return array[] 
  1525.      */
  1526.     public function getMergeCells()
  1527.     {
  1528.         return $this->_mergeCells;
  1529.     }
  1530.  
  1531.     /**
  1532.      * Set merge cells array for the entire sheet. Use instead mergeCells() to merge
  1533.      * a single cell range.
  1534.      *
  1535.      * @param array 
  1536.      */
  1537.     public function setMergeCells($pValue array())
  1538.     {
  1539.         $this->_mergeCells = $pValue;
  1540.  
  1541.         return $this;
  1542.     }
  1543.  
  1544.     /**
  1545.      * Set protection on a cell range
  1546.      *
  1547.      * @param     string            $pRange                Cell (e.g. A1) or cell range (e.g. A1:E1)
  1548.      * @param     string            $pPassword            Password to unlock the protection
  1549.      * @param     boolean         $pAlreadyHashed     If the password has already been hashed, set this to true
  1550.      * @throws    Exception
  1551.      * @return PHPExcel_Worksheet 
  1552.      */
  1553.     public function protectCells($pRange 'A1'$pPassword ''$pAlreadyHashed false)
  1554.     {
  1555.         // Uppercase coordinate
  1556.         $pRange strtoupper($pRange);
  1557.  
  1558.         if (!$pAlreadyHashed{
  1559.             $pPassword PHPExcel_Shared_PasswordHasher::hashPassword($pPassword);
  1560.         }
  1561.         $this->_protectedCells[$pRange$pPassword;
  1562.  
  1563.         return $this;
  1564.     }
  1565.  
  1566.     /**
  1567.      * Set protection on a cell range by using numeric cell coordinates
  1568.      *
  1569.      * @param     int     $pColumn1            Numeric column coordinate of the first cell
  1570.      * @param     int     $pRow1                Numeric row coordinate of the first cell
  1571.      * @param     int     $pColumn2            Numeric column coordinate of the last cell
  1572.      * @param     int     $pRow2                Numeric row coordinate of the last cell
  1573.      * @param     string    $pPassword            Password to unlock the protection
  1574.      * @param     boolean $pAlreadyHashed     If the password has already been hashed, set this to true
  1575.      * @throws    Exception
  1576.      * @return PHPExcel_Worksheet 
  1577.      */
  1578.     public function protectCellsByColumnAndRow($pColumn1 0$pRow1 0$pColumn2 0$pRow2 0$pPassword ''$pAlreadyHashed false)
  1579.     {
  1580.         $cellRange PHPExcel_Cell::stringFromColumnIndex($pColumn1$pRow1 ':' PHPExcel_Cell::stringFromColumnIndex($pColumn2$pRow2;
  1581.         return $this->protectCells($cellRange$pPassword$pAlreadyHashed);
  1582.     }
  1583.  
  1584.     /**
  1585.      * Remove protection on a cell range
  1586.      *
  1587.      * @param     string            $pRange        Cell (e.g. A1) or cell range (e.g. A1:E1)
  1588.      * @throws    Exception
  1589.      * @return PHPExcel_Worksheet 
  1590.      */
  1591.     public function unprotectCells($pRange 'A1')
  1592.     {
  1593.         // Uppercase coordinate
  1594.         $pRange strtoupper($pRange);
  1595.  
  1596.         if (isset($this->_protectedCells[$pRange])) {
  1597.             unset($this->_protectedCells[$pRange]);
  1598.         else {
  1599.             throw new Exception('Cell range ' $pRange ' not known as protected.');
  1600.         }
  1601.         return $this;
  1602.     }
  1603.  
  1604.     /**
  1605.      * Remove protection on a cell range by using numeric cell coordinates
  1606.      *
  1607.      * @param     int     $pColumn1            Numeric column coordinate of the first cell
  1608.      * @param     int     $pRow1                Numeric row coordinate of the first cell
  1609.      * @param     int     $pColumn2            Numeric column coordinate of the last cell
  1610.      * @param     int     $pRow2                Numeric row coordinate of the last cell
  1611.      * @param     string    $pPassword            Password to unlock the protection
  1612.      * @param     boolean $pAlreadyHashed     If the password has already been hashed, set this to true
  1613.      * @throws    Exception
  1614.      * @return PHPExcel_Worksheet 
  1615.      */
  1616.     public function unprotectCellsByColumnAndRow($pColumn1 0$pRow1 0$pColumn2 0$pRow2 0$pPassword ''$pAlreadyHashed false)
  1617.     {
  1618.         $cellRange PHPExcel_Cell::stringFromColumnIndex($pColumn1$pRow1 ':' PHPExcel_Cell::stringFromColumnIndex($pColumn2$pRow2;
  1619.         return $this->unprotectCells($cellRange$pPassword$pAlreadyHashed);
  1620.     }
  1621.  
  1622.     /**
  1623.      * Get protected cells
  1624.      *
  1625.      * @return array[] 
  1626.      */
  1627.     public function getProtectedCells()
  1628.     {
  1629.         return $this->_protectedCells;
  1630.     }
  1631.  
  1632.     /**
  1633.      * Get Autofilter Range
  1634.      *
  1635.      * @return string 
  1636.      */
  1637.     public function getAutoFilter()
  1638.     {
  1639.         return $this->_autoFilter;
  1640.     }
  1641.  
  1642.     /**
  1643.      * Set Autofilter Range
  1644.      *
  1645.      * @param     string        $pRange        Cell range (i.e. A1:E10)
  1646.      * @throws     Exception
  1647.      * @return PHPExcel_Worksheet 
  1648.      */
  1649.     public function setAutoFilter($pRange '')
  1650.     {
  1651.         // Uppercase coordinate
  1652.         $pRange strtoupper($pRange);
  1653.  
  1654.         if (strpos($pRange,':'!== false{
  1655.             $this->_autoFilter = $pRange;
  1656.         else {
  1657.             throw new Exception('Autofilter must be set on a range of cells.');
  1658.         }
  1659.         return $this;
  1660.     }
  1661.  
  1662.     /**
  1663.      * Set Autofilter Range by using numeric cell coordinates
  1664.      *
  1665.      * @param     int     $pColumn1    Numeric column coordinate of the first cell
  1666.      * @param     int     $pRow1        Numeric row coordinate of the first cell
  1667.      * @param     int     $pColumn2    Numeric column coordinate of the second cell
  1668.      * @param     int     $pRow2        Numeric row coordinate of the second cell
  1669.      * @throws     Exception
  1670.      * @return PHPExcel_Worksheet 
  1671.      */
  1672.     public function setAutoFilterByColumnAndRow($pColumn1 0$pRow1 0$pColumn2 0$pRow2 0)
  1673.     {
  1674.         return $this->setAutoFilter(
  1675.             PHPExcel_Cell::stringFromColumnIndex($pColumn1$pRow1
  1676.             . ':' .
  1677.             PHPExcel_Cell::stringFromColumnIndex($pColumn2$pRow2
  1678.         );
  1679.     }
  1680.  
  1681.     /**
  1682.      * Get Freeze Pane
  1683.      *
  1684.      * @return string 
  1685.      */
  1686.     public function getFreezePane()
  1687.     {
  1688.         return $this->_freezePane;
  1689.     }
  1690.  
  1691.     /**
  1692.      * Freeze Pane
  1693.      *
  1694.      * @param     string        $pCell        Cell (i.e. A1)
  1695.      * @throws     Exception
  1696.      * @return PHPExcel_Worksheet 
  1697.      */
  1698.     public function freezePane($pCell '')
  1699.     {
  1700.         // Uppercase coordinate
  1701.         $pCell strtoupper($pCell);
  1702.  
  1703.         if (strpos($pCell,':'=== false && strpos($pCell,','=== false{
  1704.             $this->_freezePane = $pCell;
  1705.         else {
  1706.             throw new Exception('Freeze pane can not be set on a range of cells.');
  1707.         }
  1708.         return $this;
  1709.     }
  1710.  
  1711.     /**
  1712.      * Freeze Pane by using numeric cell coordinates
  1713.      *
  1714.      * @param     int     $pColumn    Numeric column coordinate of the cell
  1715.      * @param     int     $pRow        Numeric row coordinate of the cell
  1716.      * @throws     Exception
  1717.      * @return PHPExcel_Worksheet 
  1718.      */
  1719.     public function freezePaneByColumnAndRow($pColumn 0$pRow 0)
  1720.     {
  1721.         return $this->freezePane(PHPExcel_Cell::stringFromColumnIndex($pColumn$pRow);
  1722.     }
  1723.  
  1724.     /**
  1725.      * Unfreeze Pane
  1726.      *
  1727.      * @return PHPExcel_Worksheet 
  1728.      */
  1729.     public function unfreezePane()
  1730.     {
  1731.         return $this->freezePane('');
  1732.     }
  1733.  
  1734.     /**
  1735.      * Insert a new row, updating all possible related data
  1736.      *
  1737.      * @param     int    $pBefore    Insert before this one
  1738.      * @param     int    $pNumRows    Number of rows to insert
  1739.      * @throws     Exception
  1740.      * @return PHPExcel_Worksheet 
  1741.      */
  1742.     public function insertNewRowBefore($pBefore 1$pNumRows 1{
  1743.         if ($pBefore >= 1{
  1744.             $objReferenceHelper PHPExcel_ReferenceHelper::getInstance();
  1745.             $objReferenceHelper->insertNewBefore('A' $pBefore0$pNumRows$this);
  1746.         else {
  1747.             throw new Exception("Rows can only be inserted before at least row 1.");
  1748.         }
  1749.         return $this;
  1750.     }
  1751.  
  1752.     /**
  1753.      * Insert a new column, updating all possible related data
  1754.      *
  1755.      * @param     int    $pBefore    Insert before this one
  1756.      * @param     int    $pNumCols    Number of columns to insert
  1757.      * @throws     Exception
  1758.      * @return PHPExcel_Worksheet 
  1759.      */
  1760.     public function insertNewColumnBefore($pBefore 'A'$pNumCols 1{
  1761.         if (!is_numeric($pBefore)) {
  1762.             $objReferenceHelper PHPExcel_ReferenceHelper::getInstance();
  1763.             $objReferenceHelper->insertNewBefore($pBefore '1'$pNumCols0$this);
  1764.         else {
  1765.             throw new Exception("Column references should not be numeric.");
  1766.         }
  1767.         return $this;
  1768.     }
  1769.  
  1770.     /**
  1771.      * Insert a new column, updating all possible related data
  1772.      *
  1773.      * @param     int    $pBefore    Insert before this one (numeric column coordinate of the cell)
  1774.      * @param     int    $pNumCols    Number of columns to insert
  1775.      * @throws     Exception
  1776.      * @return PHPExcel_Worksheet 
  1777.      */
  1778.     public function insertNewColumnBeforeByIndex($pBefore 0$pNumCols 1{
  1779.         if ($pBefore >= 0{
  1780.             return $this->insertNewColumnBefore(PHPExcel_Cell::stringFromColumnIndex($pBefore)$pNumCols);
  1781.         else {
  1782.             throw new Exception("Columns can only be inserted before at least column A (0).");
  1783.         }
  1784.     }
  1785.  
  1786.     /**
  1787.      * Delete a row, updating all possible related data
  1788.      *
  1789.      * @param     int    $pRow        Remove starting with this one
  1790.      * @param     int    $pNumRows    Number of rows to remove
  1791.      * @throws     Exception
  1792.      * @return PHPExcel_Worksheet 
  1793.      */
  1794.     public function removeRow($pRow 1$pNumRows 1{
  1795.         if ($pRow >= 1{
  1796.             $objReferenceHelper PHPExcel_ReferenceHelper::getInstance();
  1797.             $objReferenceHelper->insertNewBefore('A' ($pRow $pNumRows)0-$pNumRows$this);
  1798.         else {
  1799.             throw new Exception("Rows to be deleted should at least start from row 1.");
  1800.         }
  1801.         return $this;
  1802.     }
  1803.  
  1804.     /**
  1805.      * Remove a column, updating all possible related data
  1806.      *
  1807.      * @param     int    $pColumn    Remove starting with this one
  1808.      * @param     int    $pNumCols    Number of columns to remove
  1809.      * @throws     Exception
  1810.      * @return PHPExcel_Worksheet 
  1811.      */
  1812.     public function removeColumn($pColumn 'A'$pNumCols 1{
  1813.         if (!is_numeric($pColumn)) {
  1814.             $pColumn PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($pColumn$pNumCols);
  1815.             $objReferenceHelper PHPExcel_ReferenceHelper::getInstance();
  1816.             $objReferenceHelper->insertNewBefore($pColumn '1'-$pNumCols0$this);
  1817.         else {
  1818.             throw new Exception("Column references should not be numeric.");
  1819.         }
  1820.         return $this;
  1821.     }
  1822.  
  1823.     /**
  1824.      * Remove a column, updating all possible related data
  1825.      *
  1826.      * @param     int    $pColumn    Remove starting with this one (numeric column coordinate of the cell)
  1827.      * @param     int    $pNumCols    Number of columns to remove
  1828.      * @throws     Exception
  1829.      * @return PHPExcel_Worksheet 
  1830.      */
  1831.     public function removeColumnByIndex($pColumn 0$pNumCols 1{
  1832.         if ($pColumn >= 0{
  1833.             return $this->removeColumn(PHPExcel_Cell::stringFromColumnIndex($pColumn)$pNumCols);
  1834.         else {
  1835.             throw new Exception("Columns can only be inserted before at least column A (0).");
  1836.         }
  1837.     }
  1838.  
  1839.     /**
  1840.      * Show gridlines?
  1841.      *
  1842.      * @return boolean 
  1843.      */
  1844.     public function getShowGridlines({
  1845.         return $this->_showGridlines;
  1846.     }
  1847.  
  1848.     /**
  1849.      * Set show gridlines
  1850.      *
  1851.      * @param boolean $pValue    Show gridlines (true/false)
  1852.      * @return PHPExcel_Worksheet 
  1853.      */
  1854.     public function setShowGridlines($pValue false{
  1855.         $this->_showGridlines = $pValue;
  1856.         return $this;
  1857.     }
  1858.  
  1859.     /**
  1860.     * Print gridlines?
  1861.     *
  1862.     * @return boolean 
  1863.     */
  1864.     public function getPrintGridlines({
  1865.         return $this->_printGridlines;
  1866.     }
  1867.  
  1868.     /**
  1869.     * Set print gridlines
  1870.     *
  1871.     * @param boolean $pValue Print gridlines (true/false)
  1872.     * @return PHPExcel_Worksheet 
  1873.     */
  1874.     public function setPrintGridlines($pValue false{
  1875.         $this->_printGridlines = $pValue;
  1876.         return $this;
  1877.     }
  1878.  
  1879.     /**
  1880.      * Show summary below? (Row/Column outlining)
  1881.      *
  1882.      * @return boolean 
  1883.      */
  1884.     public function getShowSummaryBelow({
  1885.         return $this->_showSummaryBelow;
  1886.     }
  1887.  
  1888.     /**
  1889.      * Set show summary below
  1890.      *
  1891.      * @param boolean $pValue    Show summary below (true/false)
  1892.      * @return PHPExcel_Worksheet 
  1893.      */
  1894.     public function setShowSummaryBelow($pValue true{
  1895.         $this->_showSummaryBelow = $pValue;
  1896.         return $this;
  1897.     }
  1898.  
  1899.     /**
  1900.      * Show summary right? (Row/Column outlining)
  1901.      *
  1902.      * @return boolean 
  1903.      */
  1904.     public function getShowSummaryRight({
  1905.         return $this->_showSummaryRight;
  1906.     }
  1907.  
  1908.     /**
  1909.      * Set show summary right
  1910.      *
  1911.      * @param boolean $pValue    Show summary right (true/false)
  1912.      * @return PHPExcel_Worksheet 
  1913.      */
  1914.     public function setShowSummaryRight($pValue true{
  1915.         $this->_showSummaryRight = $pValue;
  1916.         return $this;
  1917.     }
  1918.  
  1919.     /**
  1920.      * Get comments
  1921.      *
  1922.      * @return PHPExcel_Comment[] 
  1923.      */
  1924.     public function getComments()
  1925.     {
  1926.         return $this->_comments;
  1927.     }
  1928.  
  1929.     /**
  1930.      * Get comment for cell
  1931.      *
  1932.      * @param     string     $pCellCoordinate    Cell coordinate to get comment for
  1933.      * @return     PHPExcel_Comment 
  1934.      * @throws     Exception
  1935.      */
  1936.     public function getComment($pCellCoordinate 'A1')
  1937.     {
  1938.         // Uppercase coordinate
  1939.         $pCellCoordinate strtoupper($pCellCoordinate);
  1940.  
  1941.         if (strpos($pCellCoordinate,':'!== false || strpos($pCellCoordinate,','!== false{
  1942.             throw new Exception('Cell coordinate string can not be a range of cells.');
  1943.         else if (strpos($pCellCoordinate,'$'!== false{
  1944.             throw new Exception('Cell coordinate string must not be absolute.');
  1945.         else if ($pCellCoordinate == ''{
  1946.             throw new Exception('Cell coordinate can not be zero-length string.');
  1947.         else {
  1948.             // Check if we already have a comment for this cell.
  1949.             // If not, create a new comment.
  1950.             if (isset($this->_comments[$pCellCoordinate])) {
  1951.                 return $this->_comments[$pCellCoordinate];
  1952.             else {
  1953.                 $newComment new PHPExcel_Comment();
  1954.                 $this->_comments[$pCellCoordinate$newComment;
  1955.                 return $newComment;
  1956.             }
  1957.         }
  1958.     }
  1959.  
  1960.     /**
  1961.      * Get comment for cell by using numeric cell coordinates
  1962.      *
  1963.      * @param     int $pColumn    Numeric column coordinate of the cell
  1964.      * @param     int $pRow        Numeric row coordinate of the cell
  1965.      * @return     PHPExcel_Comment 
  1966.      */
  1967.     public function getCommentByColumnAndRow($pColumn 0$pRow 0)
  1968.     {
  1969.         return $this->getComment(PHPExcel_Cell::stringFromColumnIndex($pColumn$pRow);
  1970.     }
  1971.  
  1972.     /**
  1973.      * Get selected cell
  1974.      *
  1975.      * @deprecated
  1976.      * @return string 
  1977.      */
  1978.     public function getSelectedCell()
  1979.     {
  1980.         return $this->getSelectedCells();
  1981.     }
  1982.  
  1983.     /**
  1984.      * Get active cell
  1985.      *
  1986.      * @return string Example: 'A1'
  1987.      */
  1988.     public function getActiveCell()
  1989.     {
  1990.         return $this->_activeCell;
  1991.     }
  1992.  
  1993.     /**
  1994.      * Get selected cells
  1995.      *
  1996.      * @return string 
  1997.      */
  1998.     public function getSelectedCells()
  1999.     {
  2000.         return $this->_selectedCells;
  2001.     }
  2002.  
  2003.     /**
  2004.      * Selected cell
  2005.      *
  2006.      * @param     string        $pCell        Cell (i.e. A1)
  2007.      * @return PHPExcel_Worksheet 
  2008.      */
  2009.     public function setSelectedCell($pCoordinate 'A1')
  2010.     {
  2011.         return $this->setSelectedCells($pCoordinate);
  2012.     }
  2013.  
  2014.     /**
  2015.      * Select a range of cells.
  2016.      *
  2017.      * @param     string        $pCoordinate    Cell range, examples: 'A1', 'B2:G5', 'A:C', '3:6'
  2018.      * @throws     Exception
  2019.      * @return PHPExcel_Worksheet 
  2020.      */
  2021.     public function setSelectedCells($pCoordinate 'A1')
  2022.     {
  2023.         // Uppercase coordinate
  2024.         $pCoordinate strtoupper($pCoordinate);
  2025.  
  2026.         // Convert 'A' to 'A:A'
  2027.         $pCoordinate preg_replace('/^([A-Z]+)$/''${1}:${1}'$pCoordinate);
  2028.  
  2029.         // Convert '1' to '1:1'
  2030.         $pCoordinate preg_replace('/^([0-9]+)$/''${1}:${1}'$pCoordinate);
  2031.  
  2032.         // Convert 'A:C' to 'A1:C1048576'
  2033.         $pCoordinate preg_replace('/^([A-Z]+):([A-Z]+)$/''${1}1:${2}1048576'$pCoordinate);
  2034.  
  2035.         // Convert '1:3' to 'A1:XFD3'
  2036.         $pCoordinate preg_replace('/^([0-9]+):([0-9]+)$/''A${1}:XFD${2}'$pCoordinate);
  2037.  
  2038.         if (strpos($pCoordinate,':'!== false || strpos($pCoordinate,','!== false{
  2039.             list($firstPHPExcel_Cell::splitRange($pCoordinate);
  2040.             $this->_activeCell = $first[0];
  2041.         else {
  2042.             $this->_activeCell = $pCoordinate;
  2043.         }
  2044.         $this->_selectedCells = $pCoordinate;
  2045.         return $this;
  2046.     }
  2047.  
  2048.     /**
  2049.      * Selected cell by using numeric cell coordinates
  2050.      *
  2051.      * @param     int     $pColumn    Numeric column coordinate of the cell
  2052.      * @param     int     $pRow        Numeric row coordinate of the cell
  2053.      * @throws     Exception
  2054.      * @return PHPExcel_Worksheet 
  2055.      */
  2056.     public function setSelectedCellByColumnAndRow($pColumn 0$pRow 0)
  2057.     {
  2058.         return $this->setSelectedCells(PHPExcel_Cell::stringFromColumnIndex($pColumn$pRow);
  2059.     }
  2060.  
  2061.     /**
  2062.      * Get right-to-left
  2063.      *
  2064.      * @return boolean 
  2065.      */
  2066.     public function getRightToLeft({
  2067.         return $this->_rightToLeft;
  2068.     }
  2069.  
  2070.     /**
  2071.      * Set right-to-left
  2072.      *
  2073.      * @param boolean $value Right-to-left true/false
  2074.      * @return PHPExcel_Worksheet 
  2075.      */
  2076.     public function setRightToLeft($value false{
  2077.         $this->_rightToLeft = $value;
  2078.         return $this;
  2079.     }
  2080.  
  2081.     /**
  2082.      * Fill worksheet from values in array
  2083.      *
  2084.      * @param array $source    Source array
  2085.      * @param mixed $nullValue Value treated as "null"
  2086.      * @throws Exception
  2087.      * @return PHPExcel_Worksheet 
  2088.      */
  2089.     public function fromArray($source null$nullValue null$pCell 'A1'{
  2090.         if (is_array($source)) {
  2091.             // start coordinate
  2092.             list ($startColumn$startRowPHPExcel_Cell::coordinateFromString($pCell);
  2093.             $startColumn PHPExcel_Cell::columnIndexFromString($startColumn1;
  2094.  
  2095.             // Loop through $source
  2096.             $currentRow $startRow 1;
  2097.             $rowData null;
  2098.             foreach ($source as $rowData{
  2099.                 ++$currentRow;
  2100.  
  2101.                 $rowCount count($rowData);
  2102.                 for ($i 0$i $rowCount++$i{
  2103.                     if ($rowData[$i!= $nullValue{
  2104.                         // Set cell value
  2105.                         $this->setCellValue(
  2106.                             PHPExcel_Cell::stringFromColumnIndex($i $startColumn$currentRow$rowData[$i]
  2107.                         );
  2108.                     }
  2109.                 }
  2110.             }
  2111.         else {
  2112.             throw new Exception("Parameter \$source should be an array.");
  2113.         }
  2114.         return $this;
  2115.     }
  2116.  
  2117.     /**
  2118.      * Create array from worksheet
  2119.      *
  2120.      * @param mixed $nullValue Value treated as "null"
  2121.      * @param boolean $calculateFormulas Should formulas be calculated?
  2122.      * @return array 
  2123.      */
  2124.     public function toArray($nullValue null$calculateFormulas true{
  2125.         // Returnvalue
  2126.         $returnValue array();
  2127.  
  2128.         // Garbage collect...
  2129.         $this->garbageCollect();
  2130.  
  2131.         // Get worksheet dimension
  2132.         $dimension explode(':'$this->calculateWorksheetDimension());
  2133.         $dimension[0PHPExcel_Cell::coordinateFromString($dimension[0]);
  2134.         $dimension[0][0PHPExcel_Cell::columnIndexFromString($dimension[0][0]1;
  2135.         $dimension[1PHPExcel_Cell::coordinateFromString($dimension[1]);
  2136.         $dimension[1][0PHPExcel_Cell::columnIndexFromString($dimension[1][0]1;
  2137.  
  2138.         // Loop through cells
  2139.         for ($row $dimension[0][1]$row <= $dimension[1][1]++$row{
  2140.             for ($column $dimension[0][0]$column <= $dimension[1][0]++$column{
  2141.                 // Cell exists?
  2142.                 if ($this->cellExistsByColumnAndRow($column$row)) {
  2143.                     $cell $this->getCellByColumnAndRow($column$row);
  2144.  
  2145.                     if ($cell->getValue(instanceof PHPExcel_RichText{
  2146.                         $returnValue[$row][$column$cell->getValue()->getPlainText();
  2147.                     else {
  2148.                         if ($calculateFormulas{
  2149.                             $returnValue[$row][$column$cell->getCalculatedValue();
  2150.                         else {
  2151.                             $returnValue[$row][$column$cell->getValue();
  2152.                         }
  2153.                     }
  2154.  
  2155.                     $style $this->_parent->getCellXfByIndex($cell->getXfIndex());
  2156.  
  2157.                     $returnValue[$row][$columnPHPExcel_Style_NumberFormat::toFormattedString($returnValue[$row][$column]$style->getNumberFormat()->getFormatCode());
  2158.                 else {
  2159.                     $returnValue[$row][$column$nullValue;
  2160.                 }
  2161.             }
  2162.         }
  2163.  
  2164.         // Return
  2165.         return $returnValue;
  2166.     }
  2167.  
  2168.     /**
  2169.      * Get row iterator
  2170.      *
  2171.      * @return PHPExcel_Worksheet_RowIterator 
  2172.      */
  2173.     public function getRowIterator({
  2174.         return new PHPExcel_Worksheet_RowIterator($this);
  2175.     }
  2176.  
  2177.     /**
  2178.      * Run PHPExcel garabage collector.
  2179.      *
  2180.      * @return PHPExcel_Worksheet 
  2181.      */
  2182.     public function garbageCollect({
  2183.         // Build a reference table from images
  2184.         $imageCoordinates array();
  2185.           $iterator $this->getDrawingCollection()->getIterator();
  2186.            while ($iterator->valid()) {
  2187.                $imageCoordinates[$iterator->current()->getCoordinates()true;
  2188.  
  2189.                $iterator->next();
  2190.            }
  2191.  
  2192.         // Lookup highest column and highest row if cells are cleaned
  2193.         $highestColumn = -1;
  2194.         $highestRow    1;
  2195.  
  2196.         // Find cells that can be cleaned
  2197.         foreach ($this->_cellCollection as $coordinate => $cell{
  2198.             // Can be cleaned?
  2199.             $canBeCleaned false;
  2200.  
  2201.             // Empty value?
  2202.             if (is_null($cell->getValue()) || (!is_object($cell->getValue()) && $cell->getValue(=== '' && !$cell->hasHyperlink())) {
  2203.                 // default style ?
  2204.                 if ($cell->getXfIndex(== 0{
  2205.                     $canBeCleaned true;
  2206.                 }
  2207.             }
  2208.  
  2209.             // Referenced in image?
  2210.             if (isset($imageCoordinates[$coordinate]&& $imageCoordinates[$coordinate=== true{
  2211.                 $canBeCleaned false;
  2212.             }
  2213.  
  2214.             // Clean?
  2215.             if ($canBeCleaned{
  2216.                 // Remove the cell
  2217.                 unset($this->_cellCollection[$coordinate]);
  2218.             else {
  2219.                 // Determine highest column and row
  2220.                 if ($highestColumn PHPExcel_Cell::columnIndexFromString($cell->getColumn())) {
  2221.                     $highestColumn PHPExcel_Cell::columnIndexFromString($cell->getColumn());
  2222.                 }
  2223.                 if ($cell->getRow($highestRow{
  2224.                     $highestRow $cell->getRow();
  2225.                 }
  2226.             }
  2227.         }
  2228.  
  2229.         // Loop through column dimensions
  2230.         foreach ($this->_columnDimensions as $dimension{
  2231.             if ($highestColumn PHPExcel_Cell::columnIndexFromString($dimension->getColumnIndex())) {
  2232.                 $highestColumn PHPExcel_Cell::columnIndexFromString($dimension->getColumnIndex());
  2233.             }
  2234.         }
  2235.  
  2236.         // Loop through row dimensions
  2237.         foreach ($this->_rowDimensions as $dimension{
  2238.             if ($highestRow $dimension->getRowIndex()) {
  2239.                 $highestRow $dimension->getRowIndex();
  2240.             }
  2241.         }
  2242.  
  2243.         // Cache values
  2244.         if ($highestColumn 0{
  2245.             $this->_cachedHighestColumn = 'A';
  2246.         else {
  2247.             $this->_cachedHighestColumn = PHPExcel_Cell::stringFromColumnIndex(--$highestColumn);
  2248.         }
  2249.         $this->_cachedHighestRow = $highestRow;
  2250.  
  2251.         // Return
  2252.         return $this;
  2253.     }
  2254.  
  2255.     /**
  2256.      * Get hash code
  2257.      *
  2258.      * @return string    Hash code
  2259.      */
  2260.     public function getHashCode({
  2261.         return md5(
  2262.               $this->_title
  2263.             . $this->_autoFilter
  2264.             . ($this->_protection->isProtectionEnabled('t' 'f')
  2265.             //. $this->calculateWorksheetDimension()
  2266.             . __CLASS__
  2267.         );
  2268.     }
  2269.  
  2270.     /**
  2271.      * Extract worksheet title from range.
  2272.      *
  2273.      * Example: extractSheetTitle('test!A1') ==> 'A1'
  2274.      * Example: extractSheetTitle('test!A1', true) ==> array('test', 'A1');
  2275.      *
  2276.      * @param string $pRange    Range to extract title from
  2277.      * @param bool $returnRange    Return range? (see example)
  2278.      * @return mixed 
  2279.      */
  2280.     public static function extractSheetTitle($pRange$returnRange false{
  2281.         // Sheet title included?
  2282.         if (strpos($pRange'!'=== false{
  2283.             return '';
  2284.         }
  2285.  
  2286.         // Position of separator exclamation mark
  2287.         $sep strrpos($pRange'!');
  2288.  
  2289.         // Extract sheet title
  2290.         $reference[0substr($pRange0$sep);
  2291.         $reference[1substr($pRange$sep 1);
  2292.  
  2293.         // Strip possible enclosing single quotes
  2294.         if (strpos($reference[0]'\''=== 0{
  2295.             $reference[0substr($reference[0]1);
  2296.         }
  2297.         if (strrpos($reference[0]'\''=== strlen($reference[0]1{
  2298.             $reference[0substr($reference[0]0strlen($reference[0]1);
  2299.         }
  2300.  
  2301.         if ($returnRange{
  2302.             return $reference;
  2303.         else {
  2304.             return $reference[1];
  2305.         }
  2306.     }
  2307.  
  2308.     /**
  2309.      * Get hyperlink
  2310.      *
  2311.      * @param string $pCellCoordinate    Cell coordinate to get hyperlink for
  2312.      */
  2313.     public function getHyperlink($pCellCoordinate 'A1')
  2314.     {
  2315.         // return hyperlink if we already have one
  2316.         if (isset($this->_hyperlinkCollection[$pCellCoordinate])) {
  2317.             return $this->_hyperlinkCollection[$pCellCoordinate];
  2318.         }
  2319.  
  2320.         // else create hyperlink
  2321.         $cell $this->getCell($pCellCoordinate);
  2322.         $this->_hyperlinkCollection[$pCellCoordinatenew PHPExcel_Cell_Hyperlink($cell);
  2323.         return $this->_hyperlinkCollection[$pCellCoordinate];
  2324.     }
  2325.  
  2326.     /**
  2327.      * Set hyperlnk
  2328.      *
  2329.      * @param string $pCellCoordinate    Cell coordinate to insert hyperlink
  2330.      * @param     PHPExcel_Cell_Hyperlink    $pHyperlink 
  2331.      * @return PHPExcel_Worksheet 
  2332.      */
  2333.     public function setHyperlink($pCellCoordinate 'A1'PHPExcel_Cell_Hyperlink $pHyperlink null)
  2334.     {
  2335.         if ($pHyperlink === null{
  2336.             unset($this->_hyperlinkCollection[$pCellCoordinate]);
  2337.         else {
  2338.             $this->_hyperlinkCollection[$pCellCoordinate$pHyperlink;
  2339.             $pHyperlink->setParent($this->getCell($pCellCoordinate));
  2340.         }
  2341.         return $this;
  2342.     }
  2343.  
  2344.     /**
  2345.      * Hyperlink at a specific coordinate exists?
  2346.      *
  2347.      * @param string $pCellCoordinate 
  2348.      * @return boolean 
  2349.      */
  2350.     public function hyperlinkExists($pCoordinate 'A1')
  2351.     {
  2352.         return isset($this->_hyperlinkCollection[$pCoordinate]);
  2353.     }
  2354.  
  2355.     /**
  2356.      * Get collection of hyperlinks
  2357.      *
  2358.      * @return PHPExcel_Cell_Hyperlink[] 
  2359.      */
  2360.     public function getHyperlinkCollection()
  2361.     {
  2362.         return $this->_hyperlinkCollection;
  2363.     }
  2364.  
  2365.     /**
  2366.      * Get data validation
  2367.      *
  2368.      * @param string $pCellCoordinate    Cell coordinate to get data validation for
  2369.      */
  2370.     public function getDataValidation($pCellCoordinate 'A1')
  2371.     {
  2372.         // return data validation if we already have one
  2373.         if (isset($this->_dataValidationCollection[$pCellCoordinate])) {
  2374.             return $this->_dataValidationCollection[$pCellCoordinate];
  2375.         }
  2376.  
  2377.         // else create data validation
  2378.         $cell $this->getCell($pCellCoordinate);
  2379.         $this->_dataValidationCollection[$pCellCoordinatenew PHPExcel_Cell_DataValidation($cell);
  2380.         return $this->_dataValidationCollection[$pCellCoordinate];
  2381.     }
  2382.  
  2383.     /**
  2384.      * Set data validation
  2385.      *
  2386.      * @param string $pCellCoordinate    Cell coordinate to insert data validation
  2387.      * @param     PHPExcel_Cell_DataValidation    $pDataValidation 
  2388.      * @return PHPExcel_Worksheet 
  2389.      */
  2390.     public function setDataValidation($pCellCoordinate 'A1'PHPExcel_Cell_DataValidation $pDataValidation null)
  2391.     {
  2392.         if ($pDataValidation === null{
  2393.             unset($this->_dataValidationCollection[$pCellCoordinate]);
  2394.         else {
  2395.             $this->_dataValidationCollection[$pCellCoordinate$pDataValidation;
  2396.             $pDataValidation->setParent($this->getCell($pCellCoordinate));
  2397.         }
  2398.         return $this;
  2399.     }
  2400.  
  2401.     /**
  2402.      * Data validation at a specific coordinate exists?
  2403.      *
  2404.      * @param string $pCellCoordinate 
  2405.      * @return boolean 
  2406.      */
  2407.     public function dataValidationExists($pCoordinate 'A1')
  2408.     {
  2409.         return isset($this->_dataValidationCollection[$pCoordinate]);
  2410.     }
  2411.  
  2412.     /**
  2413.      * Get collection of data validations
  2414.      *
  2415.      * @return PHPExcel_Cell_DataValidation[] 
  2416.      */
  2417.     public function getDataValidationCollection()
  2418.     {
  2419.         return $this->_dataValidationCollection;
  2420.     }
  2421.  
  2422.     /**
  2423.      * Get tab color
  2424.      *
  2425.      * @return PHPExcel_Style_Color 
  2426.      */
  2427.     public function getTabColor()
  2428.     {
  2429.         if (is_null($this->_tabColor))
  2430.             $this->_tabColor = new PHPExcel_Style_Color();
  2431.  
  2432.         return $this->_tabColor;
  2433.     }
  2434.  
  2435.     /**
  2436.      * Reset tab color
  2437.      *
  2438.      * @return PHPExcel_Worksheet 
  2439.      */
  2440.     public function resetTabColor()
  2441.     {
  2442.         $this->_tabColor = null;
  2443.         unset($this->_tabColor);
  2444.  
  2445.         return $this;
  2446.     }
  2447.  
  2448.     /**
  2449.      * Tab color set?
  2450.      *
  2451.      * @return boolean 
  2452.      */
  2453.     public function isTabColorSet()
  2454.     {
  2455.         return !is_null($this->_tabColor);
  2456.     }
  2457.  
  2458.     /**
  2459.      * Copy worksheet (!= clone!)
  2460.      *
  2461.      * @return PHPExcel_Worksheet 
  2462.      */
  2463.     public function copy({
  2464.         $copied clone $this;
  2465.  
  2466.         return $copied;
  2467.     }
  2468.  
  2469.     /**
  2470.      * Implement PHP __clone to create a deep clone, not just a shallow copy.
  2471.      */
  2472.     public function __clone({
  2473.         foreach ($this as $key => $val{
  2474.             if ($key == '_parent'{
  2475.                 continue;
  2476.             }
  2477.  
  2478.             if (is_object($val|| (is_array($val))) {
  2479.                 $this->{$keyunserialize(serialize($val));
  2480.             }
  2481.         }
  2482.     }
  2483. }

Documentation generated on Mon, 11 Jan 2010 08:19:00 +0100 by phpDocumentor 1.4.1