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

Documentation generated on Tue, 01 Jun 2010 17:08:29 +0200 by phpDocumentor 1.4.3