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

Documentation generated on Mon, 10 Aug 2009 08:11:57 +0200 by phpDocumentor 1.4.1