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

Source for file Excel2003XML.php

Documentation is available at Excel2003XML.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_Reader
  23.  * @copyright  Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.7.2, 2010-01-11
  26.  */
  27.  
  28.  
  29. /** PHPExcel root directory */
  30. if (!defined('PHPEXCEL_ROOT')) {
  31.     /**
  32.      * @ignore
  33.      */
  34.     define('PHPEXCEL_ROOT'dirname(__FILE__'/../../');
  35. }
  36.  
  37. /** PHPExcel */
  38. require_once PHPEXCEL_ROOT 'PHPExcel.php';
  39.  
  40. /** PHPExcel_Reader_IReader */
  41. require_once PHPEXCEL_ROOT 'PHPExcel/Reader/IReader.php';
  42.  
  43. /** PHPExcel_Worksheet */
  44. require_once PHPEXCEL_ROOT 'PHPExcel/Worksheet.php';
  45.  
  46. /** PHPExcel_Cell */
  47. require_once PHPEXCEL_ROOT 'PHPExcel/Cell.php';
  48.  
  49. /** PHPExcel_Calculation */
  50. require_once PHPEXCEL_ROOT 'PHPExcel/Calculation.php';
  51.  
  52.  /** PHPExcel_Reader_DefaultReadFilter */
  53. require_once PHPEXCEL_ROOT 'PHPExcel/Reader/DefaultReadFilter.php';
  54.  
  55.  
  56. /**
  57.  * PHPExcel_Reader_Excel2003XML
  58.  *
  59.  * @category   PHPExcel
  60.  * @package    PHPExcel_Reader
  61.  * @copyright  Copyright (c) 2006 - 2010 PHPExcel (http://www.codeplex.com/PHPExcel)
  62.  */
  63. class PHPExcel_Reader_Excel2003XML implements PHPExcel_Reader_IReader
  64. {
  65.     /**
  66.      * Read data only?
  67.      *
  68.      * @var boolean 
  69.      */
  70.     private $_readDataOnly = false;
  71.  
  72.     /**
  73.      * Restict which sheets should be loaded?
  74.      *
  75.      * @var array 
  76.      */
  77.     private $_loadSheetsOnly = null;
  78.  
  79.     /**
  80.      * Sheet index to read
  81.      *
  82.      * @var int 
  83.      */
  84.     private $_sheetIndex;
  85.  
  86.     /**
  87.      * Formats
  88.      *
  89.      * @var array 
  90.      */
  91.     private $_styles = array();
  92.  
  93.     /**
  94.      * PHPExcel_Reader_IReadFilter instance
  95.      *
  96.      * @var PHPExcel_Reader_IReadFilter 
  97.      */
  98.     private $_readFilter = null;
  99.  
  100.  
  101.     /**
  102.      * Read data only?
  103.      *
  104.      * @return boolean 
  105.      */
  106.     public function getReadDataOnly({
  107.         return $this->_readDataOnly;
  108.     }
  109.  
  110.     /**
  111.      * Set read data only
  112.      *
  113.      * @param boolean $pValue 
  114.      * @return PHPExcel_Reader_Excel2007 
  115.      */
  116.     public function setReadDataOnly($pValue false{
  117.         $this->_readDataOnly = $pValue;
  118.         return $this;
  119.     }
  120.  
  121.     /**
  122.      * Get which sheets to load
  123.      *
  124.      * @return mixed 
  125.      */
  126.     public function getLoadSheetsOnly()
  127.     {
  128.         return $this->_loadSheetsOnly;
  129.     }
  130.  
  131.     /**
  132.      * Set which sheets to load
  133.      *
  134.      * @param mixed $value 
  135.      * @return PHPExcel_Reader_Excel2007 
  136.      */
  137.     public function setLoadSheetsOnly($value null)
  138.     {
  139.         $this->_loadSheetsOnly = is_array($value?
  140.             $value array($value);
  141.         return $this;
  142.     }
  143.  
  144.     /**
  145.      * Set all sheets to load
  146.      *
  147.      * @return PHPExcel_Reader_Excel2007 
  148.      */
  149.     public function setLoadAllSheets()
  150.     {
  151.         $this->_loadSheetsOnly = null;
  152.         return $this;
  153.     }
  154.  
  155.     /**
  156.      * Read filter
  157.      *
  158.      * @return PHPExcel_Reader_IReadFilter 
  159.      */
  160.     public function getReadFilter({
  161.         return $this->_readFilter;
  162.     }
  163.  
  164.     /**
  165.      * Set read filter
  166.      *
  167.      * @param PHPExcel_Reader_IReadFilter $pValue 
  168.      * @return PHPExcel_Reader_Excel2007 
  169.      */
  170.     public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue{
  171.         $this->_readFilter = $pValue;
  172.         return $this;
  173.     }
  174.  
  175.     /**
  176.      * Create a new PHPExcel_Reader_Excel2003XML
  177.      */
  178.     public function __construct({
  179.         $this->_sheetIndex     = 0;
  180.         $this->_readFilter     = new PHPExcel_Reader_DefaultReadFilter();
  181.     }
  182.  
  183.     /**
  184.      * Can the current PHPExcel_Reader_IReader read the file?
  185.      *
  186.      * @param     string         $pFileName 
  187.      * @return     boolean 
  188.      */
  189.     public function canRead($pFilename)
  190.     {
  191.  
  192. //    Office                    xmlns:o="urn:schemas-microsoft-com:office:office"
  193. //    Excel                    xmlns:x="urn:schemas-microsoft-com:office:excel"
  194. //    XML Spreadsheet            xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
  195. //    Spreadsheet component    xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet"
  196. //    XML schema                 xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
  197. //    XML data type            xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
  198. //    MS-persist recordset    xmlns:rs="urn:schemas-microsoft-com:rowset"
  199. //    Rowset                    xmlns:z="#RowsetSchema"
  200. //
  201.  
  202.         $signature array(
  203.                 '<?xml version="1.0"?>',
  204.                 '<?mso-application progid="Excel.Sheet"?>'
  205.             );
  206.  
  207.         // Check if file exists
  208.         if (!file_exists($pFilename)) {
  209.             throw new Exception("Could not open " $pFilename " for reading! File does not exist.");
  210.         }
  211.  
  212.         // Read sample data (first 2 KB will do)
  213.         $fh fopen($pFilename'r');
  214.         $data fread($fh2048);
  215.         fclose($fh);
  216.  
  217.         $headers explode("\n",$data);
  218.         $valid true;
  219.         foreach($signature as $key => $match{
  220.             if (isset($headers[$key])) {
  221.                 $line trim(rtrim($headers[$key]"\r\n"));
  222.                 if ($line != $match{
  223.                     $valid false;
  224.                     break;
  225.                 }
  226.             else {
  227.                 $valid false;
  228.                 break;
  229.             }
  230.         }
  231.  
  232.         return $valid;
  233.     }
  234.  
  235.     /**
  236.      * Loads PHPExcel from file
  237.      *
  238.      * @param     string         $pFilename 
  239.      * @throws     Exception
  240.      */
  241.     public function load($pFilename)
  242.     {
  243.         // Create new PHPExcel
  244.         $objPHPExcel new PHPExcel();
  245.  
  246.         // Load into this instance
  247.         return $this->loadIntoExisting($pFilename$objPHPExcel);
  248.     }
  249.  
  250.     private static function identifyFixedStyleValue($styleList,&$styleAttributeValue{
  251.         $styleAttributeValue strtolower($styleAttributeValue);
  252.         foreach($styleList as $style{
  253.             if ($styleAttributeValue == strtolower($style)) {
  254.                 $styleAttributeValue $style;
  255.                 return true;
  256.             }
  257.         }
  258.         return false;
  259.     }
  260.  
  261.      /**
  262.       * pixel units to excel width units(units of 1/256th of a character width)
  263.       * @param pxs 
  264.       * @return 
  265.       */
  266.      private static function _pixel2WidthUnits($pxs{
  267.         $UNIT_OFFSET_MAP array(03673109146182219);
  268.  
  269.         $widthUnits 256 ($pxs 7);
  270.         $widthUnits += $UNIT_OFFSET_MAP[($pxs 7)];
  271.         return $widthUnits;
  272.     }
  273.  
  274.     /**
  275.      * excel width units(units of 1/256th of a character width) to pixel units
  276.      * @param widthUnits 
  277.      * @return 
  278.      */
  279.     private static function _widthUnits2Pixel($widthUnits{
  280.         $pixels ($widthUnits 2567;
  281.         $offsetWidthUnits $widthUnits 256;
  282.         $pixels += round($offsetWidthUnits (256 7));
  283.         return $pixels;
  284.     }
  285.  
  286.     /**
  287.      * Loads PHPExcel from file into PHPExcel instance
  288.      *
  289.      * @param     string         $pFilename 
  290.      * @param    PHPExcel    $objPHPExcel 
  291.      * @throws     Exception
  292.      */
  293.     public function loadIntoExisting($pFilenamePHPExcel $objPHPExcel)
  294.     {
  295.         $fromFormats    array('\-',    '\ ');
  296.         $toFormats        array('-',    ' ');
  297.  
  298.         $underlineStyles array (
  299.                 PHPExcel_Style_Font::UNDERLINE_NONE,
  300.                 PHPExcel_Style_Font::UNDERLINE_DOUBLE,
  301.                 PHPExcel_Style_Font::UNDERLINE_DOUBLEACCOUNTING,
  302.                 PHPExcel_Style_Font::UNDERLINE_SINGLE,
  303.                 PHPExcel_Style_Font::UNDERLINE_SINGLEACCOUNTING
  304.             );
  305.         $verticalAlignmentStyles array (
  306.                 PHPExcel_Style_Alignment::VERTICAL_BOTTOM,
  307.                 PHPExcel_Style_Alignment::VERTICAL_TOP,
  308.                 PHPExcel_Style_Alignment::VERTICAL_CENTER,
  309.                 PHPExcel_Style_Alignment::VERTICAL_JUSTIFY
  310.             );
  311.         $horizontalAlignmentStyles array (
  312.                 PHPExcel_Style_Alignment::HORIZONTAL_GENERAL,
  313.                 PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
  314.                 PHPExcel_Style_Alignment::HORIZONTAL_RIGHT,
  315.                 PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
  316.                 PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS,
  317.                 PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY
  318.             );
  319.  
  320.  
  321.         // Check if file exists
  322.         if (!file_exists($pFilename)) {
  323.             throw new Exception("Could not open " $pFilename " for reading! File does not exist.");
  324.         }
  325.  
  326.         $xml simplexml_load_file($pFilename);
  327.         $namespaces $xml->getNamespaces(true);
  328. //        echo '<pre>';
  329. //        print_r($namespaces);
  330. //        echo '</pre><hr />';
  331. //
  332. //        echo '<pre>';
  333. //        print_r($xml);
  334. //        echo '</pre><hr />';
  335. //
  336.         $docProps $objPHPExcel->getProperties();
  337.         foreach($xml->DocumentProperties[0as $propertyName => $propertyValue{
  338.             switch ($propertyName{
  339.                 case 'Title' :
  340.                         $docProps->setTitle($propertyValue);
  341.                         break;
  342.                 case 'Subject' :
  343.                         $docProps->setSubject($propertyValue);
  344.                         break;
  345.                 case 'Author' :
  346.                         $docProps->setCreator($propertyValue);
  347.                         break;
  348.                 case 'Created' :
  349.                         $creationDate strtotime($propertyValue);
  350.                         $docProps->setCreated($creationDate);
  351.                         break;
  352.                 case 'LastAuthor' :
  353.                         $docProps->setLastModifiedBy($propertyValue);
  354.                         break;
  355.                 case 'Company' :
  356.                         $docProps->setCompany($propertyValue);
  357.                         break;
  358.                 case 'Category' :
  359.                         $docProps->setCategory($propertyValue);
  360.                         break;
  361.                 case 'Keywords' :
  362.                         $docProps->setKeywords($propertyValue);
  363.                         break;
  364.                 case 'Description' :
  365.                         $docProps->setDescription($propertyValue);
  366.                         break;
  367.             }
  368.         }
  369.  
  370.  
  371.         foreach($xml->Styles[0as $style{
  372.             $style_ss $style->attributes($namespaces['ss']);
  373.             $styleID = (string) $style_ss['ID'];
  374. //            echo 'Style ID = '.$styleID.'<br />';
  375.             if ($styleID == 'Default'{
  376.                 $this->_styles['Default'array();
  377.             else {
  378.                 $this->_styles[$styleID$this->_styles['Default'];
  379.             }
  380.             foreach ($style as $styleType => $styleData{
  381.                 $styleAttributes $styleData->attributes($namespaces['ss']);
  382. //                echo $styleType.'<br />';
  383.                 switch ($styleType{
  384.                     case 'Alignment' :
  385.                             foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue{
  386. //                                echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
  387.                                 $styleAttributeValue = (string) $styleAttributeValue;
  388.                                 switch ($styleAttributeKey{
  389.                                     case 'Vertical' :
  390.                                             if (self::identifyFixedStyleValue($verticalAlignmentStyles,$styleAttributeValue)) {
  391.                                                 $this->_styles[$styleID]['alignment']['vertical'$styleAttributeValue;
  392.                                             }
  393.                                             break;
  394.                                     case 'Horizontal' :
  395.                                             if (self::identifyFixedStyleValue($horizontalAlignmentStyles,$styleAttributeValue)) {
  396.                                                 $this->_styles[$styleID]['alignment']['horizontal'$styleAttributeValue;
  397.                                             }
  398.                                             break;
  399.                                     case 'WrapText' :
  400.                                             $this->_styles[$styleID]['alignment']['wrap'true;
  401.                                             break;
  402.                                 }
  403.                             }
  404.                             break;
  405.                     case 'Borders' :
  406.                             foreach($styleData->Border as $borderStyle{
  407.                                 $borderAttributes $borderStyle->attributes($namespaces['ss']);
  408.                                 $thisBorder array();
  409.                                 foreach($borderAttributes as $borderStyleKey => $borderStyleValue{
  410. //                                    echo $borderStyleKey.' = '.$borderStyleValue.'<br />';
  411.                                     switch ($borderStyleKey{
  412.                                         case 'LineStyle' :
  413.                                                 $thisBorder['style'PHPExcel_Style_Border::BORDER_MEDIUM;
  414. //                                                $thisBorder['style'] = $borderStyleValue;
  415.                                                 break;
  416.                                         case 'Weight' :
  417. //                                                $thisBorder['style'] = $borderStyleValue;
  418.                                                 break;
  419.                                         case 'Position' :
  420.                                                 $borderPosition strtolower($borderStyleValue);
  421.                                                 break;
  422.                                         case 'Color' :
  423.                                                 $borderColour substr($borderStyleValue,1);
  424.                                                 $thisBorder['color']['rgb'$borderColour;
  425.                                                 break;
  426.                                     }
  427.                                 }
  428.                                 if (count($thisBorder0{
  429.                                     if (($borderPosition == 'left'|| ($borderPosition == 'right'|| ($borderPosition == 'top'|| ($borderPosition == 'bottom')) {
  430.                                         $this->_styles[$styleID]['borders'][$borderPosition$thisBorder;
  431.                                     }
  432.                                 }
  433.                             }
  434.                             break;
  435.                     case 'Font' :
  436.                             foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue{
  437. //                                echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
  438.                                 $styleAttributeValue = (string) $styleAttributeValue;
  439.                                 switch ($styleAttributeKey{
  440.                                     case 'FontName' :
  441.                                             $this->_styles[$styleID]['font']['name'$styleAttributeValue;
  442.                                             break;
  443.                                     case 'Size' :
  444.                                             $this->_styles[$styleID]['font']['size'$styleAttributeValue;
  445.                                             break;
  446.                                     case 'Color' :
  447.                                             $this->_styles[$styleID]['font']['color']['rgb'substr($styleAttributeValue,1);
  448.                                             break;
  449.                                     case 'Bold' :
  450.                                             $this->_styles[$styleID]['font']['bold'true;
  451.                                             break;
  452.                                     case 'Italic' :
  453.                                             $this->_styles[$styleID]['font']['italic'true;
  454.                                             break;
  455.                                     case 'Underline' :
  456.                                             if (self::identifyFixedStyleValue($underlineStyles,$styleAttributeValue)) {
  457.                                                 $this->_styles[$styleID]['font']['underline'$styleAttributeValue;
  458.                                             }
  459.                                             break;
  460.                                 }
  461.                             }
  462.                             break;
  463.                     case 'Interior' :
  464.                             foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue{
  465. //                                echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
  466.                                 switch ($styleAttributeKey{
  467.                                     case 'Color' :
  468.                                             $this->_styles[$styleID]['fill']['color']['rgb'substr($styleAttributeValue,1);
  469.                                             break;
  470.                                 }
  471.                             }
  472.                             break;
  473.                     case 'NumberFormat' :
  474.                             foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue{
  475. //                                echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
  476.                                 $styleAttributeValue str_replace($fromFormats,$toFormats,$styleAttributeValue);
  477.                                 switch ($styleAttributeValue{
  478.                                     case 'Short Date' :
  479.                                             $styleAttributeValue 'dd/mm/yyyy';
  480.                                             break;
  481.                                 }
  482.                                 if ($styleAttributeValue ''{
  483.                                     $this->_styles[$styleID]['numberformat']['code'$styleAttributeValue;
  484.                                 }
  485.                             }
  486.                             break;
  487.                     case 'Protection' :
  488.                             foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue{
  489. //                                echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
  490.                             }
  491.                             break;
  492.                 }
  493.             }
  494. //            print_r($this->_styles[$styleID]);
  495. //            echo '<hr />';
  496.         }
  497. //        echo '<hr />';
  498.  
  499.         $worksheetID 0;
  500.         foreach($xml->Worksheet as $worksheet{
  501.             $worksheet_ss $worksheet->attributes($namespaces['ss']);
  502.             if ((isset($this->_loadSheetsOnly)) && (isset($worksheet_ss['Name'])) &&
  503.                 (!in_array($worksheet_ss['Name']$this->_loadSheetsOnly))) {
  504.                 continue;
  505.             }
  506.  
  507.             // Create new Worksheet
  508.             $objPHPExcel->createSheet();
  509.             $objPHPExcel->setActiveSheetIndex($worksheetID);
  510.             if (isset($worksheet_ss['Name'])) {
  511.                 $worksheetName $worksheet_ss['Name'];
  512.                 $objPHPExcel->getActiveSheet()->setTitle($worksheetName);
  513.             }
  514.  
  515.             $columnID 'A';
  516.             foreach($worksheet->Table->Column as $columnData{
  517.                 $columnData_ss $columnData->attributes($namespaces['ss']);
  518.                 if (isset($columnData_ss['Index'])) {
  519.                     $columnID PHPExcel_Cell::stringFromColumnIndex($columnData_ss['Index']-1);
  520.                 }
  521.                 if (isset($columnData_ss['Width'])) {
  522.                     $columnWidth $columnData_ss['Width'];
  523. //                    echo '<b>Setting column width for '.$columnID.' to '.$columnWidth.'</b><br />';
  524.                     $objPHPExcel->getActiveSheet()->getColumnDimension($columnID)->setWidth($columnWidth 5.4);
  525.                 }
  526.                 ++$columnID;
  527.             }
  528.  
  529.             $rowID 1;
  530.             foreach($worksheet->Table->Row as $rowData{
  531.                 $row_ss $rowData->attributes($namespaces['ss']);
  532.                 if (isset($row_ss['Index'])) {
  533.                     $rowID = (integer) $row_ss['Index'];
  534.                 }
  535. //                echo '<b>Row '.$rowID.'</b><br />';
  536.                 if (isset($row_ss['StyleID'])) {
  537.                     $rowStyle $row_ss['StyleID'];
  538.                 }
  539.                 if (isset($row_ss['Height'])) {
  540.                     $rowHeight $row_ss['Height'];
  541. //                    echo '<b>Setting row height to '.$rowHeight.'</b><br />';
  542.                     $objPHPExcel->getActiveSheet()->getRowDimension($rowID)->setRowHeight($rowHeight);
  543.                 }
  544.                 $columnID 'A';
  545.                 foreach($rowData->Cell as $cell{
  546.  
  547.                     $cell_ss $cell->attributes($namespaces['ss']);
  548.                     if (isset($cell_ss['Index'])) {
  549.                         $columnID PHPExcel_Cell::stringFromColumnIndex($cell_ss['Index']-1);
  550.                     }
  551.                     $cellRange $columnID.$rowID;
  552.  
  553.                     if ((isset($cell_ss['MergeAcross'])) || (isset($cell_ss['MergeDown']))) {
  554.                         $columnTo $columnID;
  555.                         if (isset($cell_ss['MergeAcross'])) {
  556.                             $columnTo PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($columnID$cell_ss['MergeAcross'-1);
  557.                         }
  558.                         $rowTo $rowID;
  559.                         if (isset($cell_ss['MergeDown'])) {
  560.                             $rowTo $rowTo $cell_ss['MergeDown'];
  561.                         }
  562.                         $cellRange .= ':'.$columnTo.$rowTo;
  563.                         $objPHPExcel->getActiveSheet()->mergeCells($cellRange);
  564.                     }
  565.  
  566.                     $hasCalculatedValue false;
  567.                     $cellDataFormula '';
  568.                     if (isset($cell_ss['Formula'])) {
  569.                         $cellDataFormula $cell_ss['Formula'];
  570.                         $hasCalculatedValue true;
  571.                     }
  572.                     if (isset($cell->Data)) {
  573.                         $cellValue $cellData $cell->Data;
  574.                         $type PHPExcel_Cell_DataType::TYPE_NULL;
  575.                         $cellData_ss $cellData->attributes($namespaces['ss']);
  576.                         if (isset($cellData_ss['Type'])) {
  577.                             $cellDataType $cellData_ss['Type'];
  578.                             switch ($cellDataType{
  579.                                 /*
  580.                                 const TYPE_STRING        = 's';
  581.                                 const TYPE_FORMULA        = 'f';
  582.                                 const TYPE_NUMERIC        = 'n';
  583.                                 const TYPE_BOOL            = 'b';
  584.                                 const TYPE_NULL            = 's';
  585.                                 const TYPE_INLINE        = 'inlineStr';
  586.                                 const TYPE_ERROR        = 'e';
  587.                                 */
  588.                                 case 'String' :
  589.                                         $type PHPExcel_Cell_DataType::TYPE_STRING;
  590.                                         break;
  591.                                 case 'Number' :
  592.                                         $type PHPExcel_Cell_DataType::TYPE_NUMERIC;
  593.                                         $cellValue = (float) $cellValue;
  594.                                         if (floor($cellValue== $cellValue{
  595.                                             $cellValue = (integer) $cellValue;
  596.                                         }
  597.                                         break;
  598.                                 case 'Boolean' :
  599.                                         $type PHPExcel_Cell_DataType::TYPE_BOOL;
  600.                                         $cellValue ($cellValue != 0);
  601.                                         break;
  602.                                 case 'DateTime' :
  603.                                         $type PHPExcel_Cell_DataType::TYPE_NUMERIC;
  604.                                         $cellValue PHPExcel_Shared_Date::PHPToExcel(strtotime($cellValue));
  605.                                         break;
  606.                                 case 'Error' :
  607.                                         $type PHPExcel_Cell_DataType::TYPE_ERROR;
  608.                                         break;
  609.                             }
  610.                         }
  611.                         if ($hasCalculatedValue{
  612.                             $type PHPExcel_Cell_DataType::TYPE_FORMULA;
  613.                             $columnNumber PHPExcel_Cell::columnIndexFromString($columnID);
  614.                             //    Convert R1C1 style references to A1 style references (but only when not quoted)
  615.                             $temp explode('"',$cellDataFormula);
  616.                             foreach($temp as $key => &$value{
  617.                                 //    Only replace in alternate array entries (i.e. non-quoted blocks)
  618.                                 if (($key 2== 0{
  619.                                     preg_match_all('/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/',$value$cellReferences,PREG_SET_ORDER+PREG_OFFSET_CAPTURE);
  620.                                     //    Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way
  621.                                     //        through the formula from left to right. Reversing means that we work right to left.through
  622.                                     //        the formula
  623.                                     $cellReferences array_reverse($cellReferences);
  624.                                     //    Loop through each R1C1 style reference in turn, converting it to its A1 style equivalent,
  625.                                     //        then modify the formula to use that new reference
  626.                                     foreach($cellReferences as $cellReference{
  627.                                         $rowReference $cellReference[2][0];
  628.                                         //    Empty R reference is the current row
  629.                                         if ($rowReference == ''$rowReference $rowID;
  630.                                         //    Bracketed R references are relative to the current row
  631.                                         if ($rowReference{0== '['$rowReference $rowID trim($rowReference,'[]');
  632.                                         $columnReference $cellReference[4][0];
  633.                                         //    Empty C reference is the current column
  634.                                         if ($columnReference == ''$columnReference $columnNumber;
  635.                                         //    Bracketed C references are relative to the current column
  636.                                         if ($columnReference{0== '['$columnReference $columnNumber trim($columnReference,'[]');
  637.                                         $A1CellReference PHPExcel_Cell::stringFromColumnIndex($columnReference-1).$rowReference;
  638.                                             $value substr_replace($value,$A1CellReference,$cellReference[0][1],strlen($cellReference[0][0]));
  639.                                     }
  640.                                 }
  641.                             }
  642.                             unset($value);
  643.                             //    Then rebuild the formula string
  644.                             $cellDataFormula implode('"',$temp);
  645.                         }
  646.  
  647. //                        echo 'Cell '.$columnID.$rowID.' is a '.$type.' with a value of '.(($hasCalculatedValue) ? $cellDataFormula : $cellValue).'<br />';
  648. //
  649.                         $objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setValueExplicit((($hasCalculatedValue$cellDataFormula $cellValue),$type);
  650.                         if ($hasCalculatedValue{
  651. //                            echo 'Forumla result is '.$cellValue.'<br />';
  652.                             $objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setCalculatedValue($cellValue);
  653.                         }
  654.                     }
  655.                     if (isset($cell_ss['StyleID'])) {
  656.                         $style = (string) $cell_ss['StyleID'];
  657. //                        echo 'Cell style for '.$columnID.$rowID.' is '.$style.'<br />';
  658.                         if ((isset($this->_styles[$style])) && (count($this->_styles[$style]0)) {
  659. //                            echo 'Cell '.$columnID.$rowID.'<br />';
  660. //                            print_r($this->_styles[$style]);
  661. //                            echo '<br />';
  662.                             if (!$objPHPExcel->getActiveSheet()->cellExists($columnID.$rowID)) {
  663.                                 $objPHPExcel->getActiveSheet()->setCellValue($columnID.$rowID,NULL);
  664.                             }
  665.                             $objPHPExcel->getActiveSheet()->getStyle($cellRange)->applyFromArray($this->_styles[$style]);
  666.                         }
  667.                     }
  668.                     ++$columnID;
  669.                 }
  670.                 ++$rowID;
  671.             }
  672.             ++$worksheetID;
  673.         }
  674.  
  675.         // Return
  676.         return $objPHPExcel;
  677.     }
  678.  
  679.     /**
  680.      * Get sheet index
  681.      *
  682.      * @return int 
  683.      */
  684.     public function getSheetIndex({
  685.         return $this->_sheetIndex;
  686.     }
  687.  
  688.     /**
  689.      * Set sheet index
  690.      *
  691.      * @param    int        $pValue        Sheet index
  692.      * @return PHPExcel_Reader_Excel2003XML 
  693.      */
  694.     public function setSheetIndex($pValue 0{
  695.         $this->_sheetIndex = $pValue;
  696.         return $this;
  697.     }
  698. }

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