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

Source for file PHPExcel.php

Documentation is available at PHPExcel.php

  1. <?php
  2. /**
  3.  * PHPExcel
  4.  *
  5.  * Copyright (c) 2006 - 2010 PHPExcel
  6.  *
  7.  * This library is free software; you can redistribute it and/or
  8.  * modify it under the terms of the GNU Lesser General Public
  9.  * License as published by the Free Software Foundation; either
  10.  * version 2.1 of the License, or (at your option) any later version.
  11.  *
  12.  * This library is distributed in the hope that it will be useful,
  13.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * Lesser General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU Lesser General Public
  18.  * License along with this library; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20.  *
  21.  * @category   PHPExcel
  22.  * @package    PHPExcel
  23.  * @copyright  Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.7.3c, 2010-06-01
  26.  */
  27.  
  28.  
  29. /** PHPExcel root directory */
  30. if (!defined('PHPEXCEL_ROOT')) {
  31.     define('PHPEXCEL_ROOT'dirname(__FILE__'/');
  32.     require(PHPEXCEL_ROOT 'PHPExcel/Autoloader.php');
  33.     // check mbstring.func_overload
  34.     if (ini_get('mbstring.func_overload'2{
  35.         throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
  36.     }
  37. }
  38.  
  39.  
  40. /**
  41.  * PHPExcel
  42.  *
  43.  * @category   PHPExcel
  44.  * @package    PHPExcel
  45.  * @copyright  Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  46.  */
  47. class PHPExcel
  48. {
  49.     /**
  50.      * Document properties
  51.      *
  52.      * @var PHPExcel_DocumentProperties 
  53.      */
  54.     private $_properties;
  55.  
  56.     /**
  57.      * Document security
  58.      *
  59.      * @var PHPExcel_DocumentSecurity 
  60.      */
  61.     private $_security;
  62.  
  63.     /**
  64.      * Collection of Worksheet objects
  65.      *
  66.      * @var PHPExcel_Worksheet[] 
  67.      */
  68.     private $_workSheetCollection array();
  69.  
  70.     /**
  71.      * Active sheet index
  72.      *
  73.      * @var int 
  74.      */
  75.     private $_activeSheetIndex 0;
  76.  
  77.     /**
  78.      * Named ranges
  79.      *
  80.      * @var PHPExcel_NamedRange[] 
  81.      */
  82.     private $_namedRanges array();
  83.  
  84.     /**
  85.      * CellXf supervisor
  86.      *
  87.      * @var PHPExcel_Style 
  88.      */
  89.     private $_cellXfSupervisor;
  90.  
  91.     /**
  92.      * CellXf collection
  93.      *
  94.      * @var PHPExcel_Style[] 
  95.      */
  96.     private $_cellXfCollection array();
  97.  
  98.     /**
  99.      * CellStyleXf collection
  100.      *
  101.      * @var PHPExcel_Style[] 
  102.      */
  103.     private $_cellStyleXfCollection array();
  104.  
  105.     /**
  106.      * Create a new PHPExcel with one Worksheet
  107.      */
  108.     public function __construct()
  109.     {
  110.         // Initialise worksheet collection and add one worksheet
  111.         $this->_workSheetCollection array();
  112.         $this->_workSheetCollection[new PHPExcel_Worksheet($this);
  113.         $this->_activeSheetIndex 0;
  114.  
  115.         // Create document properties
  116.         $this->_properties new PHPExcel_DocumentProperties();
  117.  
  118.         // Create document security
  119.         $this->_security new PHPExcel_DocumentSecurity();
  120.  
  121.         // Set named ranges
  122.         $this->_namedRanges array();
  123.  
  124.         // Create the cellXf supervisor
  125.         $this->_cellXfSupervisor new PHPExcel_Style(true);
  126.         $this->_cellXfSupervisor->bindParent($this);
  127.  
  128.         // Create the default style
  129.         $this->addCellXf(new PHPExcel_Style);
  130.         $this->addCellStyleXf(new PHPExcel_Style);
  131.     }
  132.  
  133.  
  134.     public function disconnectWorksheets({
  135.         foreach($this->_workSheetCollection as $k => &$worksheet{
  136.             $worksheet->disconnectCells();
  137.             $this->_workSheetCollection[$knull;
  138.         }
  139.         unset($worksheet);
  140.         $this->_workSheetCollection array();
  141.     }
  142.  
  143.     /**
  144.      * Get properties
  145.      *
  146.      * @return PHPExcel_DocumentProperties 
  147.      */
  148.     public function getProperties()
  149.     {
  150.         return $this->_properties;
  151.     }
  152.  
  153.     /**
  154.      * Set properties
  155.      *
  156.      * @param PHPExcel_DocumentProperties    $pValue 
  157.      */
  158.     public function setProperties(PHPExcel_DocumentProperties $pValue)
  159.     {
  160.         $this->_properties $pValue;
  161.     }
  162.  
  163.     /**
  164.      * Get security
  165.      *
  166.      * @return PHPExcel_DocumentSecurity 
  167.      */
  168.     public function getSecurity()
  169.     {
  170.         return $this->_security;
  171.     }
  172.  
  173.     /**
  174.      * Set security
  175.      *
  176.      * @param PHPExcel_DocumentSecurity    $pValue 
  177.      */
  178.     public function setSecurity(PHPExcel_DocumentSecurity $pValue)
  179.     {
  180.         $this->_security $pValue;
  181.     }
  182.  
  183.     /**
  184.      * Get active sheet
  185.      *
  186.      * @return PHPExcel_Worksheet 
  187.      */
  188.     public function getActiveSheet()
  189.     {
  190.         return $this->_workSheetCollection[$this->_activeSheetIndex];
  191.     }
  192.  
  193.     /**
  194.      * Create sheet and add it to this workbook
  195.      *
  196.      * @return PHPExcel_Worksheet 
  197.      */
  198.     public function createSheet($iSheetIndex null)
  199.     {
  200.         $newSheet new PHPExcel_Worksheet($this);
  201.         $this->addSheet($newSheet$iSheetIndex);
  202.         return $newSheet;
  203.     }
  204.  
  205.     /**
  206.      * Add sheet
  207.      *
  208.      * @param PHPExcel_Worksheet $pSheet 
  209.      * @param int|null$iSheetIndex Index where sheet should go (0,1,..., or null for last)
  210.      * @return PHPExcel_Worksheet 
  211.      * @throws Exception
  212.      */
  213.     public function addSheet(PHPExcel_Worksheet $pSheet null$iSheetIndex null)
  214.     {
  215.         if(is_null($iSheetIndex))
  216.         {
  217.             $this->_workSheetCollection[$pSheet;
  218.         }
  219.         else
  220.         {
  221.             // Insert the sheet at the requested index
  222.             array_splice(
  223.                 $this->_workSheetCollection,
  224.                 $iSheetIndex,
  225.                 0,
  226.                 array($pSheet)
  227.                 );
  228.  
  229.             // Adjust active sheet index if necessary
  230.             if ($this->_activeSheetIndex >= $iSheetIndex{
  231.                 ++$this->_activeSheetIndex;
  232.             }
  233.  
  234.         }
  235.         return $pSheet;
  236.     }
  237.  
  238.     /**
  239.      * Remove sheet by index
  240.      *
  241.      * @param int $pIndex Active sheet index
  242.      * @throws Exception
  243.      */
  244.     public function removeSheetByIndex($pIndex 0)
  245.     {
  246.         if ($pIndex count($this->_workSheetCollection1{
  247.             throw new Exception("Sheet index is out of bounds.");
  248.         else {
  249.             array_splice($this->_workSheetCollection$pIndex1);
  250.         }
  251.     }
  252.  
  253.     /**
  254.      * Get sheet by index
  255.      *
  256.      * @param int $pIndex Sheet index
  257.      * @return PHPExcel_Worksheet 
  258.      * @throws Exception
  259.      */
  260.     public function getSheet($pIndex 0)
  261.     {
  262.         if ($pIndex count($this->_workSheetCollection1{
  263.             throw new Exception("Sheet index is out of bounds.");
  264.         else {
  265.             return $this->_workSheetCollection[$pIndex];
  266.         }
  267.     }
  268.  
  269.     /**
  270.      * Get all sheets
  271.      *
  272.      * @return PHPExcel_Worksheet[] 
  273.      */
  274.     public function getAllSheets()
  275.     {
  276.         return $this->_workSheetCollection;
  277.     }
  278.  
  279.     /**
  280.      * Get sheet by name
  281.      *
  282.      * @param string $pName Sheet name
  283.      * @return PHPExcel_Worksheet 
  284.      * @throws Exception
  285.      */
  286.     public function getSheetByName($pName '')
  287.     {
  288.         $worksheetCount count($this->_workSheetCollection);
  289.         for ($i 0$i $worksheetCount++$i{
  290.             if ($this->_workSheetCollection[$i]->getTitle(== $pName{
  291.                 return $this->_workSheetCollection[$i];
  292.             }
  293.         }
  294.  
  295.         return null;
  296.     }
  297.  
  298.     /**
  299.      * Get index for sheet
  300.      *
  301.      * @param PHPExcel_Worksheet $pSheet 
  302.      * @return Sheet index
  303.      * @throws Exception
  304.      */
  305.     public function getIndex(PHPExcel_Worksheet $pSheet)
  306.     {
  307.         foreach ($this->_workSheetCollection as $key => $value{
  308.             if ($value->getHashCode(== $pSheet->getHashCode()) {
  309.                 return $key;
  310.             }
  311.         }
  312.     }
  313.  
  314.     /**
  315.      * Set index for sheet by sheet name.
  316.      *
  317.      * @param string $sheetName Sheet name to modify index for
  318.      * @param int $newIndex New index for the sheet
  319.      * @return New sheet index
  320.      * @throws Exception
  321.      */
  322.     public function setIndexByName($sheetName$newIndex)
  323.     {
  324.         $oldIndex $this->getIndex($this->getSheetByName($sheetName));
  325.         $pSheet array_splice(
  326.             $this->_workSheetCollection,
  327.             $oldIndex,
  328.             1
  329.             );
  330.         array_splice(
  331.             $this->_workSheetCollection,
  332.             $newIndex,
  333.             0,
  334.             $pSheet
  335.             );
  336.         return $newIndex;
  337.     }
  338.  
  339.     /**
  340.      * Get sheet count
  341.      *
  342.      * @return int 
  343.      */
  344.     public function getSheetCount()
  345.     {
  346.         return count($this->_workSheetCollection);
  347.     }
  348.  
  349.     /**
  350.      * Get active sheet index
  351.      *
  352.      * @return int Active sheet index
  353.      */
  354.     public function getActiveSheetIndex()
  355.     {
  356.         return $this->_activeSheetIndex;
  357.     }
  358.  
  359.     /**
  360.      * Set active sheet index
  361.      *
  362.      * @param int $pIndex Active sheet index
  363.      * @throws Exception
  364.      * @return PHPExcel_Worksheet 
  365.      */
  366.     public function setActiveSheetIndex($pIndex 0)
  367.     {
  368.         if ($pIndex count($this->_workSheetCollection1{
  369.             throw new Exception("Active sheet index is out of bounds.");
  370.         else {
  371.             $this->_activeSheetIndex $pIndex;
  372.         }
  373.         return $this->getActiveSheet();
  374.     }
  375.  
  376.     /**
  377.      * Set active sheet index by name
  378.      *
  379.      * @param string $pValue Sheet title
  380.      * @return PHPExcel_Worksheet 
  381.      * @throws Exception
  382.      */
  383.     public function setActiveSheetIndexByName($pValue '')
  384.     {
  385.         if (($worksheet $this->getSheetByName($pValue)) instanceof PHPExcel_Worksheet{
  386.             $this->setActiveSheetIndex($worksheet->getParent()->getIndex($worksheet));
  387.             return $worksheet;
  388.         }
  389.  
  390.         throw new Exception('Workbook does not contain sheet:' $pValue);
  391.     }
  392.  
  393.     /**
  394.      * Get sheet names
  395.      *
  396.      * @return string[] 
  397.      */
  398.     public function getSheetNames()
  399.     {
  400.         $returnValue array();
  401.         $worksheetCount $this->getSheetCount();
  402.         for ($i 0$i $worksheetCount++$i{
  403.             array_push($returnValue$this->getSheet($i)->getTitle());
  404.         }
  405.  
  406.         return $returnValue;
  407.     }
  408.  
  409.     /**
  410.      * Add external sheet
  411.      *
  412.      * @param PHPExcel_Worksheet $pSheet External sheet to add
  413.      * @param int|null$iSheetIndex Index where sheet should go (0,1,..., or null for last)
  414.      * @throws Exception
  415.      * @return PHPExcel_Worksheet 
  416.      */
  417.     public function addExternalSheet(PHPExcel_Worksheet $pSheet$iSheetIndex null{
  418.         if (!is_null($this->getSheetByName($pSheet->getTitle()))) {
  419.             throw new Exception("Workbook already contains a worksheet named '{$pSheet->getTitle()}'. Rename the external sheet first.");
  420.         }
  421.  
  422.         // count how many cellXfs there are in this workbook currently, we will need this below
  423.         $countCellXfs count($this->_cellXfCollection);
  424.  
  425.         // copy all the shared cellXfs from the external workbook and append them to the current
  426.         foreach ($pSheet->getParent()->getCellXfCollection(as $cellXf{
  427.             $this->addCellXf(clone $cellXf);
  428.         }
  429.  
  430.         // move sheet to this workbook
  431.         $pSheet->rebindParent($this);
  432.  
  433.         // update the cellXfs
  434.         foreach ($pSheet->getCellCollection(falseas $cellID{
  435.             $cell $sheet->getCell($cellID);
  436.             $cell->setXfIndex$cell->getXfIndex($countCellXfs );
  437.         }
  438.  
  439.         return $this->addSheet($pSheet$iSheetIndex);
  440.     }
  441.  
  442.     /**
  443.      * Get named ranges
  444.      *
  445.      * @return PHPExcel_NamedRange[] 
  446.      */
  447.     public function getNamedRanges({
  448.         return $this->_namedRanges;
  449.     }
  450.  
  451.     /**
  452.      * Add named range
  453.      *
  454.      * @param PHPExcel_NamedRange $namedRange 
  455.      * @return PHPExcel 
  456.      */
  457.     public function addNamedRange(PHPExcel_NamedRange $namedRange{
  458.         if ($namedRange->getScope(== null{
  459.             // global scope
  460.             $this->_namedRanges[$namedRange->getName()$namedRange;
  461.         else {
  462.             // local scope
  463.             $this->_namedRanges[$namedRange->getScope()->getTitle().'!'.$namedRange->getName()$namedRange;
  464.         }
  465.         return true;
  466.     }
  467.  
  468.     /**
  469.      * Get named range
  470.      *
  471.      * @param string $namedRange 
  472.      * @param PHPExcel_Worksheet|null$pSheet Scope. Use null for global scope
  473.      * @return PHPExcel_NamedRange|null
  474.      */
  475.     public function getNamedRange($namedRangePHPExcel_Worksheet $pSheet null{
  476.         $returnValue null;
  477.  
  478.         if ($namedRange != '' && !is_null($namedRange)) {
  479.             // first look for global defined name
  480.             if (isset($this->_namedRanges[$namedRange])) {
  481.                 $returnValue $this->_namedRanges[$namedRange];
  482.             }
  483.  
  484.             // then look for local defined name (has priority over global defined name if both names exist)
  485.             if (!is_null($pSheet&& isset($this->_namedRanges[$pSheet->getTitle('!' $namedRange])) {
  486.                 $returnValue $this->_namedRanges[$pSheet->getTitle('!' $namedRange];
  487.             }
  488.         }
  489.  
  490.         return $returnValue;
  491.     }
  492.  
  493.     /**
  494.      * Remove named range
  495.      *
  496.      * @param string $namedRange 
  497.      * @param PHPExcel_Worksheet|null$pSheet. Scope. Use null for global scope.
  498.      * @return PHPExcel 
  499.      */
  500.     public function removeNamedRange($namedRangePHPExcel_Worksheet $pSheet null{
  501.         if (is_null($pSheet)) {
  502.             if (isset($this->_namedRanges[$namedRange])) {
  503.                 unset($this->_namedRanges[$namedRange]);
  504.             }
  505.         else {
  506.             if (isset($this->_namedRanges[$pSheet->getTitle('!' $namedRange])) {
  507.                 unset($this->_namedRanges[$pSheet->getTitle('!' $namedRange]);
  508.             }
  509.         }
  510.         return $this;
  511.     }
  512.  
  513.     /**
  514.      * Get worksheet iterator
  515.      *
  516.      * @return PHPExcel_WorksheetIterator 
  517.      */
  518.     public function getWorksheetIterator({
  519.         return new PHPExcel_WorksheetIterator($this);
  520.     }
  521.  
  522.     /**
  523.      * Copy workbook (!= clone!)
  524.      *
  525.      * @return PHPExcel 
  526.      */
  527.     public function copy({
  528.         $copied clone $this;
  529.  
  530.         $worksheetCount count($this->_workSheetCollection);
  531.         for ($i 0$i $worksheetCount++$i{
  532.             $this->_workSheetCollection[$i$this->_workSheetCollection[$i]->copy();
  533.             $this->_workSheetCollection[$i]->rebindParent($this);
  534.         }
  535.  
  536.         return $copied;
  537.     }
  538.  
  539.     /**
  540.      * Implement PHP __clone to create a deep clone, not just a shallow copy.
  541.      */
  542.     public function __clone({
  543.         foreach($this as $key => $val{
  544.             if (is_object($val|| (is_array($val))) {
  545.                 $this->{$keyunserialize(serialize($val));
  546.             }
  547.         }
  548.     }
  549.  
  550.     /**
  551.      * Get the workbook collection of cellXfs
  552.      *
  553.      * @return PHPExcel_Style[] 
  554.      */
  555.     public function getCellXfCollection()
  556.     {
  557.         return $this->_cellXfCollection;
  558.     }
  559.  
  560.     /**
  561.      * Get cellXf by index
  562.      *
  563.      * @param int $index 
  564.      * @return PHPExcel_Style 
  565.      */
  566.     public function getCellXfByIndex($pIndex 0)
  567.     {
  568.         return $this->_cellXfCollection[$pIndex];
  569.     }
  570.  
  571.     /**
  572.      * Get cellXf by hash code
  573.      *
  574.      * @param string $pValue 
  575.      * @return PHPExcel_Style|false
  576.      */
  577.     public function getCellXfByHashCode($pValue '')
  578.     {
  579.         foreach ($this->_cellXfCollection as $cellXf{
  580.             if ($cellXf->getHashCode(== $pValue{
  581.                 return $cellXf;
  582.             }
  583.         }
  584.         return false;
  585.     }
  586.  
  587.     /**
  588.      * Get default style
  589.      *
  590.      * @return PHPExcel_Style 
  591.      * @throws Exception
  592.      */
  593.     public function getDefaultStyle()
  594.     {
  595.         if (isset($this->_cellXfCollection[0])) {
  596.             return $this->_cellXfCollection[0];
  597.         }
  598.         throw new Exception('No default style found for this workbook');
  599.     }
  600.  
  601.     /**
  602.      * Add a cellXf to the workbook
  603.      *
  604.      * @param PHPExcel_Style 
  605.      */
  606.     public function addCellXf(PHPExcel_Style $style)
  607.     {
  608.         $this->_cellXfCollection[$style;
  609.         $style->setIndex(count($this->_cellXfCollection1);
  610.     }
  611.  
  612.     /**
  613.      * Remove cellXf by index. It is ensured that all cells get their xf index updated.
  614.      *
  615.      * @param int $pIndex Index to cellXf
  616.      * @throws Exception
  617.      */
  618.     public function removeCellXfByIndex($pIndex 0)
  619.     {
  620.         if ($pIndex count($this->_cellXfCollection1{
  621.             throw new Exception("CellXf index is out of bounds.");
  622.         else {
  623.             // first remove the cellXf
  624.             array_splice($this->_cellXfCollection$pIndex1);
  625.  
  626.             // then update cellXf indexes for cells
  627.             foreach ($this->_workSheetCollection as $worksheet{
  628.                 foreach ($worksheet->getCellCollection(falseas $cellID{
  629.                     $cell $sheet->getCell($cellID);
  630.                     $xfIndex $cell->getXfIndex();
  631.                     if ($xfIndex $pIndex {
  632.                         // decrease xf index by 1
  633.                         $cell->setXfIndex($xfIndex 1);
  634.                     else if ($xfIndex == $pIndex{
  635.                         // set to default xf index 0
  636.                         $cell->setXfIndex(0);
  637.                     }
  638.                 }
  639.             }
  640.         }
  641.     }
  642.  
  643.     /**
  644.      * Get the cellXf supervisor
  645.      *
  646.      * @return PHPExcel_Style 
  647.      */
  648.     public function getCellXfSupervisor()
  649.     {
  650.         return $this->_cellXfSupervisor;
  651.     }
  652.  
  653.     /**
  654.      * Get the workbook collection of cellStyleXfs
  655.      *
  656.      * @return PHPExcel_Style[] 
  657.      */
  658.     public function getCellStyleXfCollection()
  659.     {
  660.         return $this->_cellStyleXfCollection;
  661.     }
  662.  
  663.     /**
  664.      * Get cellStyleXf by index
  665.      *
  666.      * @param int $pIndex 
  667.      * @return PHPExcel_Style 
  668.      */
  669.     public function getCellStyleXfByIndex($pIndex 0)
  670.     {
  671.         return $this->_cellStyleXfCollection[$pIndex];
  672.     }
  673.  
  674.     /**
  675.      * Get cellStyleXf by hash code
  676.      *
  677.      * @param string $pValue 
  678.      * @return PHPExcel_Style|false
  679.      */
  680.     public function getCellStyleXfByHashCode($pValue '')
  681.     {
  682.         foreach ($this->_cellXfStyleCollection as $cellStyleXf{
  683.             if ($cellStyleXf->getHashCode(== $pValue{
  684.                 return $cellStyleXf;
  685.             }
  686.         }
  687.         return false;
  688.     }
  689.  
  690.     /**
  691.      * Add a cellStyleXf to the workbook
  692.      *
  693.      * @param PHPExcel_Style $pStyle 
  694.      */
  695.     public function addCellStyleXf(PHPExcel_Style $pStyle)
  696.     {
  697.         $this->_cellStyleXfCollection[$pStyle;
  698.         $pStyle->setIndex(count($this->_cellStyleXfCollection1);
  699.     }
  700.  
  701.     /**
  702.      * Remove cellStyleXf by index
  703.      *
  704.      * @param int $pIndex 
  705.      * @throws Exception
  706.      */
  707.     public function removeCellStyleXfByIndex($pIndex 0)
  708.     {
  709.         if ($pIndex count($this->_cellStyleXfCollection1{
  710.             throw new Exception("CellStyleXf index is out of bounds.");
  711.         else {
  712.             array_splice($this->_cellStyleXfCollection$pIndex1);
  713.         }
  714.     }
  715.  
  716.     /**
  717.      * Eliminate all unneeded cellXf and afterwards update the xfIndex for all cells
  718.      * and columns in the workbook
  719.      */
  720.     public function garbageCollect()
  721.     {
  722.         // how many references are there to each cellXf ?
  723.         $countReferencesCellXf array();
  724.         foreach ($this->_cellXfCollection as $index => $cellXf{
  725.             $countReferencesCellXf[$index0;
  726.         }
  727.  
  728.         foreach ($this->getWorksheetIterator(as $sheet{
  729.  
  730.             // from cells
  731.             foreach ($sheet->getCellCollection(falseas $cellID{
  732.                 $cell $sheet->getCell($cellID);
  733.                 ++$countReferencesCellXf[$cell->getXfIndex()];
  734.             }
  735.  
  736.             // from row dimensions
  737.             foreach ($sheet->getRowDimensions(as $rowDimension{
  738.                 if ($rowDimension->getXfIndex(!== null{
  739.                     ++$countReferencesCellXf[$rowDimension->getXfIndex()];
  740.                 }
  741.             }
  742.  
  743.             // from column dimensions
  744.             foreach ($sheet->getColumnDimensions(as $columnDimension{
  745.                 ++$countReferencesCellXf[$columnDimension->getXfIndex()];
  746.             }
  747.         }
  748.  
  749.         // remove cellXfs without references and create mapping so we can update xfIndex
  750.         // for all cells and columns
  751.         $countNeededCellXfs 0;
  752.         foreach ($this->_cellXfCollection as $index => $cellXf{
  753.             if ($countReferencesCellXf[$index|| $index == 0// we must never remove the first cellXf
  754.                 ++$countNeededCellXfs;
  755.             else {
  756.                 unset($this->_cellXfCollection[$index]);
  757.             }
  758.             $map[$index$countNeededCellXfs 1;
  759.         }
  760.         $this->_cellXfCollection array_values($this->_cellXfCollection);
  761.  
  762.         // update the index for all cellXfs
  763.         foreach ($this->_cellXfCollection as $i => $cellXf{
  764.             $cellXf->setIndex($i);
  765.         }
  766.  
  767.         // make sure there is always at least one cellXf (there should be)
  768.         if (count($this->_cellXfCollection== 0{
  769.             $this->_cellXfCollection[new PHPExcel_Style();
  770.         }
  771.  
  772.         // update the xfIndex for all cells, row dimensions, column dimensions
  773.         foreach ($this->getWorksheetIterator(as $sheet{
  774.  
  775.             // for all cells
  776.             foreach ($sheet->getCellCollection(falseas $cellID{
  777.                 $cell $sheet->getCell($cellID);
  778.                 $cell->setXfIndex$map[$cell->getXfIndex());
  779.             }
  780.  
  781.             // for all row dimensions
  782.             foreach ($sheet->getRowDimensions(as $rowDimension{
  783.                 if ($rowDimension->getXfIndex(!== null{
  784.                     $rowDimension->setXfIndex$map[$rowDimension->getXfIndex());
  785.                 }
  786.             }
  787.  
  788.             // for all column dimensions
  789.             foreach ($sheet->getColumnDimensions(as $columnDimension{
  790.                 $columnDimension->setXfIndex$map[$columnDimension->getXfIndex());
  791.             }
  792.         }
  793.  
  794.         // also do garbage collection for all the sheets
  795.         foreach ($this->getWorksheetIterator(as $sheet{
  796.             $sheet->garbageCollect();
  797.         }
  798.     }
  799.  
  800. }

Documentation generated on Tue, 01 Jun 2010 17:05:40 +0200 by phpDocumentor 1.4.3