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

Documentation generated on Tue, 01 Jun 2010 17:03:36 +0200 by phpDocumentor 1.4.3