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

Documentation generated on Mon, 05 Jan 2009 20:39:00 +0100 by phpDocumentor 1.4.1