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

Source for file Excel2007.php

Documentation is available at Excel2007.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.4, 2010-08-26
  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_Excel2007
  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_Excel2007 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.      * PHPExcel_Reader_IReadFilter instance
  67.      *
  68.      * @var PHPExcel_Reader_IReadFilter 
  69.      */
  70.     private $_readFilter null;
  71.  
  72.  
  73.     private $_referenceHelper null;
  74.  
  75.     /**
  76.      * Read data only?
  77.      *
  78.      * @return boolean 
  79.      */
  80.     public function getReadDataOnly({
  81.         return $this->_readDataOnly;
  82.     }
  83.  
  84.     /**
  85.      * Set read data only
  86.      *
  87.      * @param boolean $pValue 
  88.      * @return PHPExcel_Reader_Excel2007 
  89.      */
  90.     public function setReadDataOnly($pValue false{
  91.         $this->_readDataOnly $pValue;
  92.         return $this;
  93.     }
  94.  
  95.     /**
  96.      * Get which sheets to load
  97.      *
  98.      * @return mixed 
  99.      */
  100.     public function getLoadSheetsOnly()
  101.     {
  102.         return $this->_loadSheetsOnly;
  103.     }
  104.  
  105.     /**
  106.      * Set which sheets to load
  107.      *
  108.      * @param mixed $value 
  109.      * @return PHPExcel_Reader_Excel2007 
  110.      */
  111.     public function setLoadSheetsOnly($value null)
  112.     {
  113.         $this->_loadSheetsOnly is_array($value?
  114.             $value array($value);
  115.         return $this;
  116.     }
  117.  
  118.     /**
  119.      * Set all sheets to load
  120.      *
  121.      * @return PHPExcel_Reader_Excel2007 
  122.      */
  123.     public function setLoadAllSheets()
  124.     {
  125.         $this->_loadSheetsOnly null;
  126.         return $this;
  127.     }
  128.  
  129.     /**
  130.      * Read filter
  131.      *
  132.      * @return PHPExcel_Reader_IReadFilter 
  133.      */
  134.     public function getReadFilter({
  135.         return $this->_readFilter;
  136.     }
  137.  
  138.     /**
  139.      * Set read filter
  140.      *
  141.      * @param PHPExcel_Reader_IReadFilter $pValue 
  142.      * @return PHPExcel_Reader_Excel2007 
  143.      */
  144.     public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue{
  145.         $this->_readFilter $pValue;
  146.         return $this;
  147.     }
  148.  
  149.     /**
  150.      * Create a new PHPExcel_Reader_Excel2007 instance
  151.      */
  152.     public function __construct({
  153.         $this->_readFilter new PHPExcel_Reader_DefaultReadFilter();
  154.         $this->_referenceHelper PHPExcel_ReferenceHelper::getInstance();
  155.     }
  156.  
  157.     /**
  158.      * Can the current PHPExcel_Reader_IReader read the file?
  159.      *
  160.      * @param     string         $pFileName 
  161.      * @return     boolean 
  162.      */
  163.     public function canRead($pFilename)
  164.     {
  165.         // Check if zip class exists
  166.         if (!class_exists('ZipArchive')) {
  167.             return false;
  168.         }
  169.  
  170.         // Check if file exists
  171.         if (!file_exists($pFilename)) {
  172.             throw new Exception("Could not open " $pFilename " for reading! File does not exist.");
  173.         }
  174.  
  175.         // Load file
  176.         $zip new ZipArchive;
  177.         if ($zip->open($pFilename=== true{
  178.             // check if it is an OOXML archive
  179.             $rels simplexml_load_string($this->_getFromZipArchive($zip"_rels/.rels"));
  180.  
  181.             $zip->close();
  182.  
  183.             return ($rels !== false);
  184.         }
  185.  
  186.         return false;
  187.     }
  188.  
  189.     private function _castToBool($c{
  190. //        echo 'Initial Cast to Boolean<br />';
  191.         $value = isset($c->v? (string) $c->null;
  192.         if ($value == '0'{
  193.             $value false;
  194.         elseif ($value == '1'{
  195.             $value true;
  196.         else {
  197.             $value = (bool)$c->v;
  198.         }
  199.         return $value;
  200.     }    //    function _castToBool()
  201.  
  202.     private function _castToError($c{
  203. //        echo 'Initial Cast to Error<br />';
  204.         return isset($c->v? (string) $c->null;;
  205.     }    //    function _castToError()
  206.  
  207.     private function _castToString($c{
  208. //        echo 'Initial Cast to String<br />';
  209.         return isset($c->v? (string) $c->null;;
  210.     }    //    function _castToString()
  211.  
  212.     private function _castToFormula($c,$r,&$cellDataType,&$value,&$calculatedValue,&$sharedFormulas,$castBaseType{
  213. //        echo '<font color="darkgreen">Formula</font><br />';
  214. //        echo '$c->f is '.$c->f.'<br />';
  215.         $cellDataType         'f';
  216.         $value                 "={$c->f}";
  217.         $calculatedValue     $this->$castBaseType($c);
  218.  
  219.         // Shared formula?
  220.         if (isset($c->f['t']&& strtolower((string)$c->f['t']== 'shared'{
  221. //            echo '<font color="darkgreen">SHARED FORMULA</font><br />';
  222.             $instance = (string)$c->f['si'];
  223.  
  224. //            echo 'Instance ID = '.$instance.'<br />';
  225. //
  226. //            echo 'Shared Formula Array:<pre>';
  227. //            print_r($sharedFormulas);
  228. //            echo '</pre>';
  229.             if (!isset($sharedFormulas[(string)$c->f['si']])) {
  230. //                echo '<font color="darkgreen">SETTING NEW SHARED FORMULA</font><br />';
  231. //                echo 'Master is '.$r.'<br />';
  232. //                echo 'Formula is '.$value.'<br />';
  233.                 $sharedFormulas[$instancearray(    'master' => $r,
  234.                                                     'formula' => $value
  235.                                                   );
  236. //                echo 'New Shared Formula Array:<pre>';
  237. //                print_r($sharedFormulas);
  238. //                echo '</pre>';
  239.             else {
  240. //                echo '<font color="darkgreen">GETTING SHARED FORMULA</font><br />';
  241. //                echo 'Master is '.$sharedFormulas[$instance]['master'].'<br />';
  242. //                echo 'Formula is '.$sharedFormulas[$instance]['formula'].'<br />';
  243.                 $master PHPExcel_Cell::coordinateFromString($sharedFormulas[$instance]['master']);
  244.                 $current PHPExcel_Cell::coordinateFromString($r);
  245.  
  246.                 $difference array(00);
  247.                 $difference[0PHPExcel_Cell::columnIndexFromString($current[0]PHPExcel_Cell::columnIndexFromString($master[0]);
  248.                 $difference[1$current[1$master[1];
  249.  
  250.                 $value $this->_referenceHelper->updateFormulaReferences(    $sharedFormulas[$instance]['formula'],
  251.                                                                             'A1',
  252.                                                                             $difference[0],
  253.                                                                             $difference[1]
  254.                                                                          );
  255. //                echo 'Adjusted Formula is '.$value.'<br />';
  256.             }
  257.         }
  258.     }
  259.  
  260.     public function _getFromZipArchive(ZipArchive $archive$fileName '')
  261.     {
  262.         // Root-relative paths
  263.         if (strpos($fileName'//'!== false)
  264.         {
  265.             $fileName substr($fileNamestrpos($fileName'//'1);
  266.         }
  267.         $fileName PHPExcel_Shared_File::realpath($fileName);
  268.  
  269.         // Apache POI fixes
  270.         $contents $archive->getFromName($fileName);
  271.         if ($contents === false)
  272.         {
  273.             $contents $archive->getFromName(substr($fileName1));
  274.         }
  275.  
  276.         /*
  277.         if (strpos($contents, '<?xml') !== false && strpos($contents, '<?xml') !== 0)
  278.         {
  279.             $contents = substr($contents, strpos($contents, '<?xml'));
  280.         }
  281.         var_dump($fileName);
  282.         var_dump($contents);
  283.         */
  284.         return $contents;
  285.     }
  286.  
  287.     /**
  288.      * Loads PHPExcel from file
  289.      *
  290.      * @param     string         $pFilename 
  291.      * @throws     Exception
  292.      */
  293.     public function load($pFilename)
  294.     {
  295.         // Check if file exists
  296.         if (!file_exists($pFilename)) {
  297.             throw new Exception("Could not open " $pFilename " for reading! File does not exist.");
  298.         }
  299.  
  300.         // Initialisations
  301.         $excel new PHPExcel;
  302.         $excel->removeSheetByIndex(0);
  303.         if (!$this->_readDataOnly{
  304.             $excel->removeCellStyleXfByIndex(0)// remove the default style
  305.             $excel->removeCellXfByIndex(0)// remove the default style
  306.         }
  307.         $zip new ZipArchive;
  308.         $zip->open($pFilename);
  309.  
  310.         $rels simplexml_load_string($this->_getFromZipArchive($zip"_rels/.rels"))//~ http://schemas.openxmlformats.org/package/2006/relationships");
  311.         foreach ($rels->Relationship as $rel{
  312.             switch ($rel["Type"]{
  313.                 case "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties":
  314.                     $xmlCore simplexml_load_string($this->_getFromZipArchive($zip"{$rel['Target']}"));
  315.                     if (is_object($xmlCore)) {
  316.                         $xmlCore->registerXPathNamespace("dc""http://purl.org/dc/elements/1.1/");
  317.                         $xmlCore->registerXPathNamespace("dcterms""http://purl.org/dc/terms/");
  318.                         $xmlCore->registerXPathNamespace("cp""http://schemas.openxmlformats.org/package/2006/metadata/core-properties");
  319.                         $docProps $excel->getProperties();
  320.                         $docProps->setCreator((string) self::array_item($xmlCore->xpath("dc:creator")));
  321.                         $docProps->setLastModifiedBy((string) self::array_item($xmlCore->xpath("cp:lastModifiedBy")));
  322.                         $docProps->setCreated(strtotime(self::array_item($xmlCore->xpath("dcterms:created"))))//! respect xsi:type
  323.                         $docProps->setModified(strtotime(self::array_item($xmlCore->xpath("dcterms:modified"))))//! respect xsi:type
  324.                         $docProps->setTitle((string) self::array_item($xmlCore->xpath("dc:title")));
  325.                         $docProps->setDescription((string) self::array_item($xmlCore->xpath("dc:description")));
  326.                         $docProps->setSubject((string) self::array_item($xmlCore->xpath("dc:subject")));
  327.                         $docProps->setKeywords((string) self::array_item($xmlCore->xpath("cp:keywords")));
  328.                         $docProps->setCategory((string) self::array_item($xmlCore->xpath("cp:category")));
  329.                     }
  330.                 break;
  331.  
  332.                 case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties":
  333.                     $xmlCore simplexml_load_string($this->_getFromZipArchive($zip"{$rel['Target']}"));
  334.                     if (is_object($xmlCore)) {
  335.                         $docProps $excel->getProperties();
  336.                         if (isset($xmlCore->Company))
  337.                             $docProps->setCompany((string) $xmlCore->Company);
  338.                         if (isset($xmlCore->Manager))
  339.                             $docProps->setManager((string) $xmlCore->Manager);
  340.                     }
  341.                 break;
  342.  
  343.                 case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties":
  344.                     $xmlCore simplexml_load_string($this->_getFromZipArchive($zip"{$rel['Target']}"));
  345.                     if (is_object($xmlCore)) {
  346.                         $xmlCore->registerXPathNamespace("vt""http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes");
  347.                         $docProps $excel->getProperties();
  348.                     }
  349.                 break;
  350.  
  351.                 case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument":
  352.                     $dir dirname($rel["Target"]);
  353.                     $relsWorkbook simplexml_load_string($this->_getFromZipArchive($zip"$dir/_rels/basename($rel["Target"]".rels"));  //~ http://schemas.openxmlformats.org/package/2006/relationships");
  354.                     $relsWorkbook->registerXPathNamespace("rel""http://schemas.openxmlformats.org/package/2006/relationships");
  355.  
  356.                     $sharedStrings array();
  357.                     $xpath self::array_item($relsWorkbook->xpath("rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings']"));
  358.                     $xmlStrings simplexml_load_string($this->_getFromZipArchive($zip"$dir/$xpath[Target]"));  //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
  359.                     if (isset($xmlStrings&& isset($xmlStrings->si)) {
  360.                         foreach ($xmlStrings->si as $val{
  361.                             if (isset($val->t)) {
  362.                                 $sharedStrings[PHPExcel_Shared_String::ControlCharacterOOXML2PHP(string) $val->);
  363.                             elseif (isset($val->r)) {
  364.                                 $sharedStrings[$this->_parseRichText($val);
  365.                             }
  366.                         }
  367.                     }
  368.  
  369.                     $worksheets array();
  370.                     foreach ($relsWorkbook->Relationship as $ele{
  371.                         if ($ele["Type"== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"{
  372.                             $worksheets[(string) $ele["Id"]] $ele["Target"];
  373.                         }
  374.                     }
  375.  
  376.                     $styles     array();
  377.                     $cellStyles array();
  378.                     $xpath self::array_item($relsWorkbook->xpath("rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles']"));
  379.                     $xmlStyles simplexml_load_string($this->_getFromZipArchive($zip"$dir/$xpath[Target]"))//~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
  380.                     $numFmts null;
  381.                     if ($xmlStyles && $xmlStyles->numFmts[0]{
  382.                         $numFmts $xmlStyles->numFmts[0];
  383.                     }
  384.                     if (isset($numFmts&& !is_null($numFmts)) {
  385.                         $numFmts->registerXPathNamespace("sml""http://schemas.openxmlformats.org/spreadsheetml/2006/main");
  386.                     }
  387.                     if (!$this->_readDataOnly && $xmlStyles{
  388.                         foreach ($xmlStyles->cellXfs->xf as $xf{
  389.                             $numFmt PHPExcel_Style_NumberFormat::FORMAT_GENERAL;
  390.  
  391.                             if ($xf["numFmtId"]{
  392.                                 if (isset($numFmts)) {
  393.                                     $tmpNumFmt self::array_item($numFmts->xpath("sml:numFmt[@numFmtId=$xf[numFmtId]]"));
  394.  
  395.                                     if (isset($tmpNumFmt["formatCode"])) {
  396.                                         $numFmt = (string) $tmpNumFmt["formatCode"];
  397.                                     }
  398.                                 }
  399.  
  400.                                 if ((int)$xf["numFmtId"164{
  401.                                     $numFmt PHPExcel_Style_NumberFormat::builtInFormatCode((int)$xf["numFmtId"]);
  402.                                 }
  403.                             }
  404.                             //$numFmt = str_replace('mm', 'i', $numFmt);
  405.                             //$numFmt = str_replace('h', 'H', $numFmt);
  406.  
  407.                             $style = (object) array(
  408.                                 "numFmt" => $numFmt,
  409.                                 "font" => $xmlStyles->fonts->font[intval($xf["fontId"])],
  410.                                 "fill" => $xmlStyles->fills->fill[intval($xf["fillId"])],
  411.                                 "border" => $xmlStyles->borders->border[intval($xf["borderId"])],
  412.                                 "alignment" => $xf->alignment,
  413.                                 "protection" => $xf->protection,
  414.                             );
  415.                             $styles[$style;
  416.  
  417.                             // add style to cellXf collection
  418.                             $objStyle new PHPExcel_Style;
  419.                             $this->_readStyle($objStyle$style);
  420.                             $excel->addCellXf($objStyle);
  421.                         }
  422.  
  423.                         foreach ($xmlStyles->cellStyleXfs->xf as $xf{
  424.                             $numFmt PHPExcel_Style_NumberFormat::FORMAT_GENERAL;
  425.                             if ($numFmts && $xf["numFmtId"]{
  426.                                 $tmpNumFmt self::array_item($numFmts->xpath("sml:numFmt[@numFmtId=$xf[numFmtId]]"));
  427.                                 if (isset($tmpNumFmt["formatCode"])) {
  428.                                     $numFmt = (string) $tmpNumFmt["formatCode"];
  429.                                 else if ((int)$xf["numFmtId"165{
  430.                                     $numFmt PHPExcel_Style_NumberFormat::builtInFormatCode((int)$xf["numFmtId"]);
  431.                                 }
  432.                             }
  433.  
  434.                             $cellStyle = (object) array(
  435.                                 "numFmt" => $numFmt,
  436.                                 "font" => $xmlStyles->fonts->font[intval($xf["fontId"])],
  437.                                 "fill" => $xmlStyles->fills->fill[intval($xf["fillId"])],
  438.                                 "border" => $xmlStyles->borders->border[intval($xf["borderId"])],
  439.                                 "alignment" => $xf->alignment,
  440.                                 "protection" => $xf->protection,
  441.                             );
  442.                             $cellStyles[$cellStyle;
  443.  
  444.                             // add style to cellStyleXf collection
  445.                             $objStyle new PHPExcel_Style;
  446.                             $this->_readStyle($objStyle$cellStyle);
  447.                             $excel->addCellStyleXf($objStyle);
  448.                         }
  449.                     }
  450.  
  451.                     $dxfs array();
  452.                     if (!$this->_readDataOnly && $xmlStyles{
  453.                         if ($xmlStyles->dxfs{
  454.                             foreach ($xmlStyles->dxfs->dxf as $dxf{
  455.                                 $style new PHPExcel_Style;
  456.                                 $this->_readStyle($style$dxf);
  457.                                 $dxfs[$style;
  458.                             }
  459.                         }
  460.  
  461.                         if ($xmlStyles->cellStyles)
  462.                         {
  463.                             foreach ($xmlStyles->cellStyles->cellStyle as $cellStyle{
  464.                                 if (intval($cellStyle['builtinId']== 0{
  465.                                     if (isset($cellStyles[intval($cellStyle['xfId'])])) {
  466.                                         // Set default style
  467.                                         $style new PHPExcel_Style;
  468.                                         $this->_readStyle($style$cellStyles[intval($cellStyle['xfId'])]);
  469.  
  470.                                         // normal style, currently not using it for anything
  471.                                     }
  472.                                 }
  473.                             }
  474.                         }
  475.                     }
  476.  
  477.                     $xmlWorkbook simplexml_load_string($this->_getFromZipArchive($zip"{$rel['Target']}"));  //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
  478.  
  479.                     // Set base date
  480.                     if ($xmlWorkbook->workbookPr{
  481.                         PHPExcel_Shared_Date::setExcelCalendar(PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900);
  482.                         if (isset($xmlWorkbook->workbookPr['date1904'])) {
  483.                             $date1904 = (string)$xmlWorkbook->workbookPr['date1904'];
  484.                             if ($date1904 == "true" || $date1904 == "1"{
  485.                                 PHPExcel_Shared_Date::setExcelCalendar(PHPExcel_Shared_Date::CALENDAR_MAC_1904);
  486.                             }
  487.                         }
  488.                     }
  489.  
  490.                     $sheetId 0// keep track of new sheet id in final workbook
  491.                     $oldSheetId = -1// keep track of old sheet id in final workbook
  492.                     $countSkippedSheets 0// keep track of number of skipped sheets
  493.                     $mapSheetId array()// mapping of sheet ids from old to new
  494.  
  495.                     if ($xmlWorkbook->sheets)
  496.                     {
  497.                         foreach ($xmlWorkbook->sheets->sheet as $eleSheet{
  498.                             ++$oldSheetId;
  499.  
  500.                             // Check if sheet should be skipped
  501.                             if (isset($this->_loadSheetsOnly&& !in_array((string) $eleSheet["name"]$this->_loadSheetsOnly)) {
  502.                                 ++$countSkippedSheets;
  503.                                 $mapSheetId[$oldSheetIdnull;
  504.                                 continue;
  505.                             }
  506.  
  507.                             // Map old sheet id in original workbook to new sheet id.
  508.                             // They will differ if loadSheetsOnly() is being used
  509.                             $mapSheetId[$oldSheetId$oldSheetId $countSkippedSheets;
  510.  
  511.                             // Load sheet
  512.                             $docSheet $excel->createSheet();
  513.                             $docSheet->setTitle((string) $eleSheet["name"]);
  514.                             $fileWorksheet $worksheets[(string) self::array_item($eleSheet->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships")"id")];
  515.                             $xmlSheet simplexml_load_string($this->_getFromZipArchive($zip"$dir/$fileWorksheet"));  //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
  516.  
  517.                             $sharedFormulas array();
  518.  
  519.                             if (isset($eleSheet["state"]&& (string) $eleSheet["state"!= ''{
  520.                                 $docSheet->setSheetState(string) $eleSheet["state");
  521.                             }
  522.  
  523.                             if (isset($xmlSheet->sheetViews&& isset($xmlSheet->sheetViews->sheetView)) {
  524.                                 if (isset($xmlSheet->sheetViews->sheetView['zoomScale'])) {
  525.                                     $docSheet->getSheetView()->setZoomScaleintval($xmlSheet->sheetViews->sheetView['zoomScale']) );
  526.                                 }
  527.  
  528.                                 if (isset($xmlSheet->sheetViews->sheetView['zoomScaleNormal'])) {
  529.                                     $docSheet->getSheetView()->setZoomScaleNormalintval($xmlSheet->sheetViews->sheetView['zoomScaleNormal']) );
  530.                                 }
  531.  
  532.                                 if (isset($xmlSheet->sheetViews->sheetView['showGridLines'])) {
  533.                                     $docSheet->setShowGridLines((string)$xmlSheet->sheetViews->sheetView['showGridLines'true false);
  534.                                 }
  535.  
  536.                                 if (isset($xmlSheet->sheetViews->sheetView['showRowColHeaders'])) {
  537.                                     $docSheet->setShowRowColHeaders((string)$xmlSheet->sheetViews->sheetView['showRowColHeaders'true false);
  538.                                 }
  539.  
  540.                                 if (isset($xmlSheet->sheetViews->sheetView['rightToLeft'])) {
  541.                                     $docSheet->setRightToLeft((string)$xmlSheet->sheetViews->sheetView['rightToLeft'true false);
  542.                                 }
  543.  
  544.                                 if (isset($xmlSheet->sheetViews->sheetView->pane)) {
  545.                                     if (isset($xmlSheet->sheetViews->sheetView->pane['topLeftCell'])) {
  546.                                         $docSheet->freezePane(string)$xmlSheet->sheetViews->sheetView->pane['topLeftCell');
  547.                                     else {
  548.                                         $xSplit 0;
  549.                                         $ySplit 0;
  550.  
  551.                                         if (isset($xmlSheet->sheetViews->sheetView->pane['xSplit'])) {
  552.                                             $xSplit intval($xmlSheet->sheetViews->sheetView->pane['xSplit']);
  553.                                         }
  554.  
  555.                                         if (isset($xmlSheet->sheetViews->sheetView->pane['ySplit'])) {
  556.                                             $ySplit intval($xmlSheet->sheetViews->sheetView->pane['ySplit']);
  557.                                         }
  558.  
  559.                                         $docSheet->freezePaneByColumnAndRow($xSplit$ySplit);
  560.                                     }
  561.                                 }
  562.  
  563.                                 if (isset($xmlSheet->sheetViews->sheetView->selection)) {
  564.                                     if (isset($xmlSheet->sheetViews->sheetView->selection['sqref'])) {
  565.                                         $sqref = (string)$xmlSheet->sheetViews->sheetView->selection['sqref'];
  566.                                         $sqref explode(' '$sqref);
  567.                                         $sqref $sqref[0];
  568.                                         $docSheet->setSelectedCells($sqref);
  569.                                     }
  570.                                 }
  571.  
  572.                             }
  573.  
  574.                             if (isset($xmlSheet->sheetPr&& isset($xmlSheet->sheetPr->tabColor)) {
  575.                                 if (isset($xmlSheet->sheetPr->tabColor['rgb'])) {
  576.                                     $docSheet->getTabColor()->setARGB(string)$xmlSheet->sheetPr->tabColor['rgb');
  577.                                 }
  578.                             }
  579.  
  580.                             if (isset($xmlSheet->sheetPr&& isset($xmlSheet->sheetPr->outlinePr)) {
  581.                                 if (isset($xmlSheet->sheetPr->outlinePr['summaryRight']&& $xmlSheet->sheetPr->outlinePr['summaryRight'== false{
  582.                                     $docSheet->setShowSummaryRight(false);
  583.                                 else {
  584.                                     $docSheet->setShowSummaryRight(true);
  585.                                 }
  586.  
  587.                                 if (isset($xmlSheet->sheetPr->outlinePr['summaryBelow']&& $xmlSheet->sheetPr->outlinePr['summaryBelow'== false{
  588.                                     $docSheet->setShowSummaryBelow(false);
  589.                                 else {
  590.                                     $docSheet->setShowSummaryBelow(true);
  591.                                 }
  592.                             }
  593.  
  594.                             if (isset($xmlSheet->sheetPr&& isset($xmlSheet->sheetPr->pageSetUpPr)) {
  595.                                 if (isset($xmlSheet->sheetPr->pageSetUpPr['fitToPage']&& $xmlSheet->sheetPr->pageSetUpPr['fitToPage'== false{
  596.                                     $docSheet->getPageSetup()->setFitToPage(false);
  597.                                 else {
  598.                                     $docSheet->getPageSetup()->setFitToPage(true);
  599.                                 }
  600.                             }
  601.  
  602.                             if (isset($xmlSheet->sheetFormatPr)) {
  603.                                 if (isset($xmlSheet->sheetFormatPr['customHeight']&& ((string)$xmlSheet->sheetFormatPr['customHeight'== '1' || strtolower((string)$xmlSheet->sheetFormatPr['customHeight']== 'true'&& isset($xmlSheet->sheetFormatPr['defaultRowHeight'])) {
  604.                                     $docSheet->getDefaultRowDimension()->setRowHeight(float)$xmlSheet->sheetFormatPr['defaultRowHeight');
  605.                                 }
  606.                                 if (isset($xmlSheet->sheetFormatPr['defaultColWidth'])) {
  607.                                     $docSheet->getDefaultColumnDimension()->setWidth(float)$xmlSheet->sheetFormatPr['defaultColWidth');
  608.                                 }
  609.                             }
  610.  
  611.                             if (isset($xmlSheet->cols&& !$this->_readDataOnly{
  612.                                 foreach ($xmlSheet->cols->col as $col{
  613.                                     for ($i intval($col["min"]1$i intval($col["max"])++$i{
  614.                                         if ($col["style"&& !$this->_readDataOnly{
  615.                                             $docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setXfIndex(intval($col["style"]));
  616.                                         }
  617.                                         if ($col["bestFit"]{
  618.                                             //$docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setAutoSize(true);
  619.                                         }
  620.                                         if ($col["hidden"]{
  621.                                             $docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setVisible(false);
  622.                                         }
  623.                                         if ($col["collapsed"]{
  624.                                             $docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setCollapsed(true);
  625.                                         }
  626.                                         if ($col["outlineLevel"0{
  627.                                             $docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setOutlineLevel(intval($col["outlineLevel"]));
  628.                                         }
  629.                                         $docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setWidth(floatval($col["width"]));
  630.  
  631.                                         if (intval($col["max"]== 16384{
  632.                                             break;
  633.                                         }
  634.                                     }
  635.                                 }
  636.                             }
  637.  
  638.                             if (isset($xmlSheet->printOptions&& !$this->_readDataOnly{
  639.                                 if ($xmlSheet->printOptions['gridLinesSet'== 'true' && $xmlSheet->printOptions['gridLinesSet'== '1'{
  640.                                     $docSheet->setShowGridlines(true);
  641.                                 }
  642.  
  643.                                 if ($xmlSheet->printOptions['gridLines'== 'true' || $xmlSheet->printOptions['gridLines'== '1'{
  644.                                     $docSheet->setPrintGridlines(true);
  645.                                 }
  646.  
  647.                                 if ($xmlSheet->printOptions['horizontalCentered']{
  648.                                     $docSheet->getPageSetup()->setHorizontalCentered(true);
  649.                                 }
  650.                                 if ($xmlSheet->printOptions['verticalCentered']{
  651.                                     $docSheet->getPageSetup()->setVerticalCentered(true);
  652.                                 }
  653.                             }
  654.  
  655.                             if ($xmlSheet && $xmlSheet->sheetData && $xmlSheet->sheetData->row{
  656.                                 foreach ($xmlSheet->sheetData->row as $row{
  657.                                     if ($row["ht"&& !$this->_readDataOnly{
  658.                                         $docSheet->getRowDimension(intval($row["r"]))->setRowHeight(floatval($row["ht"]));
  659.                                     }
  660.                                     if ($row["hidden"&& !$this->_readDataOnly{
  661.                                         $docSheet->getRowDimension(intval($row["r"]))->setVisible(false);
  662.                                     }
  663.                                     if ($row["collapsed"]{
  664.                                         $docSheet->getRowDimension(intval($row["r"]))->setCollapsed(true);
  665.                                     }
  666.                                     if ($row["outlineLevel"0{
  667.                                         $docSheet->getRowDimension(intval($row["r"]))->setOutlineLevel(intval($row["outlineLevel"]));
  668.                                     }
  669.                                     if ($row["s"&& !$this->_readDataOnly{
  670.                                         $docSheet->getRowDimension(intval($row["r"]))->setXfIndex(intval($row["s"]));
  671.                                     }
  672.  
  673.                                     foreach ($row->as $c{
  674.                                         $r                     = (string) $c["r"];
  675.                                         $cellDataType         = (string) $c["t"];
  676.                                         $value                null;
  677.                                         $calculatedValue     null;
  678.  
  679.                                         // Read cell?
  680.                                         if (!is_null($this->getReadFilter())) {
  681.                                             $coordinates PHPExcel_Cell::coordinateFromString($r);
  682.  
  683.                                             if (!$this->getReadFilter()->readCell($coordinates[0]$coordinates[1]$docSheet->getTitle())) {
  684.                                                 continue;
  685.                                             }
  686.                                         }
  687.  
  688.     //                                    echo '<b>Reading cell '.$coordinates[0].$coordinates[1].'</b><br />';
  689.     //                                    print_r($c);
  690.     //                                    echo '<br />';
  691.     //                                    echo 'Cell Data Type is '.$cellDataType.': ';
  692.     //
  693.                                         // Read cell!
  694.                                         switch ($cellDataType{
  695.                                             case "s":
  696.     //                                            echo 'String<br />';
  697.                                                 if ((string)$c->!= ''{
  698.                                                     $value $sharedStrings[intval($c->v)];
  699.  
  700.                                                     if ($value instanceof PHPExcel_RichText{
  701.                                                         $value clone $value;
  702.                                                     }
  703.                                                 else {
  704.                                                     $value '';
  705.                                                 }
  706.  
  707.                                                 break;
  708.                                             case "b":
  709.     //                                            echo 'Boolean<br />';
  710.                                                 if (!isset($c->f)) {
  711.                                                     $value $this->_castToBool($c);
  712.                                                 else {
  713.                                                     // Formula
  714.                                                     $this->_castToFormula($c,$r,$cellDataType,$value,$calculatedValue,$sharedFormulas,'_castToBool');
  715.                                                     if (isset($c->f['t'])) {
  716.                                                         $att array();
  717.                                                         $att $c->f;
  718.                                                         $docSheet->getCell($r)->setFormulaAttributes($att);
  719.                                                     }
  720.     //                                                echo '$calculatedValue = '.$calculatedValue.'<br />';
  721.                                                 }
  722.                                                 break;
  723.                                             case "inlineStr":
  724.     //                                            echo 'Inline String<br />';
  725.                                                 $value $this->_parseRichText($c->is);
  726.  
  727.                                                 break;
  728.                                             case "e":
  729.     //                                            echo 'Error<br />';
  730.                                                 if (!isset($c->f)) {
  731.                                                     $value $this->_castToError($c);
  732.                                                 else {
  733.                                                     // Formula
  734.                                                     $this->_castToFormula($c,$r,$cellDataType,$value,$calculatedValue,$sharedFormulas,'_castToError');
  735.     //                                                echo '$calculatedValue = '.$calculatedValue.'<br />';
  736.                                                 }
  737.  
  738.                                                 break;
  739.  
  740.                                             default:
  741.     //                                            echo 'Default<br />';
  742.                                                 if (!isset($c->f)) {
  743.     //                                                echo 'Not a Formula<br />';
  744.                                                     $value $this->_castToString($c);
  745.                                                 else {
  746.     //                                                echo 'Treat as Formula<br />';
  747.                                                     // Formula
  748.                                                     $this->_castToFormula($c,$r,$cellDataType,$value,$calculatedValue,$sharedFormulas,'_castToString');
  749.     //                                                echo '$calculatedValue = '.$calculatedValue.'<br />';
  750.                                                 }
  751.  
  752.                                                 break;
  753.                                         }
  754.     //                                    echo 'Value is '.$value.'<br />';
  755.  
  756.                                         // Check for numeric values
  757.                                         if (is_numeric($value&& $cellDataType != 's'{
  758.                                             if ($value == (int)$value$value = (int)$value;
  759.                                             elseif ($value == (float)$value$value = (float)$value;
  760.                                             elseif ($value == (double)$value$value = (double)$value;
  761.                                         }
  762.  
  763.                                         // Rich text?
  764.                                         if ($value instanceof PHPExcel_RichText && $this->_readDataOnly{
  765.                                             $value $value->getPlainText();
  766.                                         }
  767.  
  768.                                         $cell $docSheet->getCell($r);
  769.                                         // Assign value
  770.                                         if ($cellDataType != ''{
  771.                                             $cell->setValueExplicit($value$cellDataType);
  772.                                         else {
  773.                                             $cell->setValue($value);
  774.                                         }
  775.                                         if (!is_null($calculatedValue)) {
  776.                                             $cell->setCalculatedValue($calculatedValue);
  777.                                         }
  778.  
  779.                                         // Style information?
  780.                                         if ($c["s"&& !$this->_readDataOnly{
  781.                                             // no style index means 0, it seems
  782.                                             $cell->setXfIndex(isset($styles[intval($c["s"])]?
  783.                                                 intval($c["s"]0);
  784.                                         }
  785.                                     }
  786.                                 }
  787.                             }
  788.  
  789.                             $conditionals array();
  790.                             if (!$this->_readDataOnly && $xmlSheet && $xmlSheet->conditionalFormatting{
  791.                                 foreach ($xmlSheet->conditionalFormatting as $conditional{
  792.                                     foreach ($conditional->cfRule as $cfRule{
  793.                                         if (
  794.                                             (
  795.                                                 (string)$cfRule["type"== PHPExcel_Style_Conditional::CONDITION_NONE ||
  796.                                                 (string)$cfRule["type"== PHPExcel_Style_Conditional::CONDITION_CELLIS ||
  797.                                                 (string)$cfRule["type"== PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT ||
  798.                                                 (string)$cfRule["type"== PHPExcel_Style_Conditional::CONDITION_EXPRESSION
  799.                                             && isset($dxfs[intval($cfRule["dxfId"])])
  800.                                         {
  801.                                             $conditionals[(string) $conditional["sqref"]][intval($cfRule["priority"])$cfRule;
  802.                                         }
  803.                                     }
  804.                                 }
  805.  
  806.                                 foreach ($conditionals as $ref => $cfRules{
  807.                                     ksort($cfRules);
  808.                                     $conditionalStyles array();
  809.                                     foreach ($cfRules as $cfRule{
  810.                                         $objConditional new PHPExcel_Style_Conditional();
  811.                                         $objConditional->setConditionType((string)$cfRule["type"]);
  812.                                         $objConditional->setOperatorType((string)$cfRule["operator"]);
  813.  
  814.                                         if ((string)$cfRule["text"!= ''{
  815.                                             $objConditional->setText((string)$cfRule["text"]);
  816.                                         }
  817.  
  818.                                         if (count($cfRule->formula1{
  819.                                             foreach ($cfRule->formula as $formula{
  820.                                                 $objConditional->addCondition((string)$formula);
  821.                                             }
  822.                                         else {
  823.                                             $objConditional->addCondition((string)$cfRule->formula);
  824.                                         }
  825.                                         $objConditional->setStyle(clone $dxfs[intval($cfRule["dxfId"])]);
  826.                                         $conditionalStyles[$objConditional;
  827.                                     }
  828.  
  829.                                     // Extract all cell references in $ref
  830.                                     $aReferences PHPExcel_Cell::extractAllCellReferencesInRange($ref);
  831.                                     foreach ($aReferences as $reference{
  832.                                         $docSheet->getStyle($reference)->setConditionalStyles($conditionalStyles);
  833.                                     }
  834.                                 }
  835.                             }
  836.  
  837.                             $aKeys array("sheet""objects""scenarios""formatCells""formatColumns""formatRows""insertColumns""insertRows""insertHyperlinks""deleteColumns""deleteRows""selectLockedCells""sort""autoFilter""pivotTables""selectUnlockedCells");
  838.                             if (!$this->_readDataOnly && $xmlSheet && $xmlSheet->sheetProtection{
  839.                                 foreach ($aKeys as $key{
  840.                                     $method "set" ucfirst($key);
  841.                                     $docSheet->getProtection()->$method($xmlSheet->sheetProtection[$key== "true");
  842.                                 }
  843.                             }
  844.  
  845.                             if (!$this->_readDataOnly && $xmlSheet && $xmlSheet->sheetProtection{
  846.                                 $docSheet->getProtection()->setPassword((string) $xmlSheet->sheetProtection["password"]true);
  847.                                 if ($xmlSheet->protectedRanges->protectedRange{
  848.                                     foreach ($xmlSheet->protectedRanges->protectedRange as $protectedRange{
  849.                                         $docSheet->protectCells((string) $protectedRange["sqref"](string) $protectedRange["password"]true);
  850.                                     }
  851.                                 }
  852.                             }
  853.  
  854.                             if ($xmlSheet && $xmlSheet->autoFilter && !$this->_readDataOnly{
  855.                                 $docSheet->setAutoFilter((string) $xmlSheet->autoFilter["ref"]);
  856.                             }
  857.  
  858.                             if ($xmlSheet && $xmlSheet->mergeCells && $xmlSheet->mergeCells->mergeCell && !$this->_readDataOnly{
  859.                                 foreach ($xmlSheet->mergeCells->mergeCell as $mergeCell{
  860.                                     $docSheet->mergeCells((string) $mergeCell["ref"]);
  861.                                 }
  862.                             }
  863.  
  864.                             if ($xmlSheet && $xmlSheet->pageMargins && !$this->_readDataOnly{
  865.                                 $docPageMargins $docSheet->getPageMargins();
  866.                                 $docPageMargins->setLeft(floatval($xmlSheet->pageMargins["left"]));
  867.                                 $docPageMargins->setRight(floatval($xmlSheet->pageMargins["right"]));
  868.                                 $docPageMargins->setTop(floatval($xmlSheet->pageMargins["top"]));
  869.                                 $docPageMargins->setBottom(floatval($xmlSheet->pageMargins["bottom"]));
  870.                                 $docPageMargins->setHeader(floatval($xmlSheet->pageMargins["header"]));
  871.                                 $docPageMargins->setFooter(floatval($xmlSheet->pageMargins["footer"]));
  872.                             }
  873.  
  874.                             if ($xmlSheet && $xmlSheet->pageSetup && !$this->_readDataOnly{
  875.                                 $docPageSetup $docSheet->getPageSetup();
  876.  
  877.                                 if (isset($xmlSheet->pageSetup["orientation"])) {
  878.                                     $docPageSetup->setOrientation((string) $xmlSheet->pageSetup["orientation"]);
  879.                                 }
  880.                                 if (isset($xmlSheet->pageSetup["paperSize"])) {
  881.                                     $docPageSetup->setPaperSize(intval($xmlSheet->pageSetup["paperSize"]));
  882.                                 }
  883.                                 if (isset($xmlSheet->pageSetup["scale"])) {
  884.                                     $docPageSetup->setScale(intval($xmlSheet->pageSetup["scale"])false);
  885.                                 }
  886.                                 if (isset($xmlSheet->pageSetup["fitToHeight"]&& intval($xmlSheet->pageSetup["fitToHeight"]>= 0{
  887.                                     $docPageSetup->setFitToHeight(intval($xmlSheet->pageSetup["fitToHeight"])false);
  888.                                 }
  889.                                 if (isset($xmlSheet->pageSetup["fitToWidth"]&& intval($xmlSheet->pageSetup["fitToWidth"]>= 0{
  890.                                     $docPageSetup->setFitToWidth(intval($xmlSheet->pageSetup["fitToWidth"])false);
  891.                                 }
  892.                                 if (isset($xmlSheet->pageSetup["firstPageNumber"]&& isset($xmlSheet->pageSetup["useFirstPageNumber"]&&
  893.                                     ((string)$xmlSheet->pageSetup["useFirstPageNumber"== 'true' || (string)$xmlSheet->pageSetup["useFirstPageNumber"== '1')) {
  894.                                     $docPageSetup->setFirstPageNumber(intval($xmlSheet->pageSetup["firstPageNumber"]));
  895.                                 }
  896.                             }
  897.  
  898.                             if ($xmlSheet && $xmlSheet->headerFooter && !$this->_readDataOnly{
  899.                                 $docHeaderFooter $docSheet->getHeaderFooter();
  900.  
  901.                                 if (isset($xmlSheet->headerFooter["differentOddEven"]&&
  902.                                     ((string)$xmlSheet->headerFooter["differentOddEven"== 'true' || (string)$xmlSheet->headerFooter["differentOddEven"== '1')) {
  903.                                     $docHeaderFooter->setDifferentOddEven(true);
  904.                                 else {
  905.                                     $docHeaderFooter->setDifferentOddEven(false);
  906.                                 }
  907.                                 if (isset($xmlSheet->headerFooter["differentFirst"]&&
  908.                                     ((string)$xmlSheet->headerFooter["differentFirst"== 'true' || (string)$xmlSheet->headerFooter["differentFirst"== '1')) {
  909.                                     $docHeaderFooter->setDifferentFirst(true);
  910.                                 else {
  911.                                     $docHeaderFooter->setDifferentFirst(false);
  912.                                 }
  913.                                 if (isset($xmlSheet->headerFooter["scaleWithDoc"]&&
  914.                                     ((string)$xmlSheet->headerFooter["scaleWithDoc"== 'false' || (string)$xmlSheet->headerFooter["scaleWithDoc"== '0')) {
  915.                                     $docHeaderFooter->setScaleWithDocument(false);
  916.                                 else {
  917.                                     $docHeaderFooter->setScaleWithDocument(true);
  918.                                 }
  919.                                 if (isset($xmlSheet->headerFooter["alignWithMargins"]&&
  920.                                     ((string)$xmlSheet->headerFooter["alignWithMargins"== 'false' || (string)$xmlSheet->headerFooter["alignWithMargins"== '0')) {
  921.                                     $docHeaderFooter->setAlignWithMargins(false);
  922.                                 else {
  923.                                     $docHeaderFooter->setAlignWithMargins(true);
  924.                                 }
  925.  
  926.                                 $docHeaderFooter->setOddHeader((string) $xmlSheet->headerFooter->oddHeader);
  927.                                 $docHeaderFooter->setOddFooter((string) $xmlSheet->headerFooter->oddFooter);
  928.                                 $docHeaderFooter->setEvenHeader((string) $xmlSheet->headerFooter->evenHeader);
  929.                                 $docHeaderFooter->setEvenFooter((string) $xmlSheet->headerFooter->evenFooter);
  930.                                 $docHeaderFooter->setFirstHeader((string) $xmlSheet->headerFooter->firstHeader);
  931.                                 $docHeaderFooter->setFirstFooter((string) $xmlSheet->headerFooter->firstFooter);
  932.                             }
  933.  
  934.                             if ($xmlSheet && $xmlSheet->rowBreaks && $xmlSheet->rowBreaks->brk && !$this->_readDataOnly{
  935.                                 foreach ($xmlSheet->rowBreaks->brk as $brk{
  936.                                     if ($brk["man"]{
  937.                                         $docSheet->setBreak("A$brk[id]"PHPExcel_Worksheet::BREAK_ROW);
  938.                                     }
  939.                                 }
  940.                             }
  941.                             if ($xmlSheet && $xmlSheet->colBreaks && $xmlSheet->colBreaks->brk && !$this->_readDataOnly{
  942.                                 foreach ($xmlSheet->colBreaks->brk as $brk{
  943.                                     if ($brk["man"]{
  944.                                         $docSheet->setBreak(PHPExcel_Cell::stringFromColumnIndex($brk["id"]"1"PHPExcel_Worksheet::BREAK_COLUMN);
  945.                                     }
  946.                                 }
  947.                             }
  948.  
  949.                             if ($xmlSheet && $xmlSheet->dataValidations && !$this->_readDataOnly{
  950.                                 foreach ($xmlSheet->dataValidations->dataValidation as $dataValidation{
  951.                                     // Uppercase coordinate
  952.                                     $range strtoupper($dataValidation["sqref"]);
  953.                                     $rangeSet explode(' ',$range);
  954.                                     foreach($rangeSet as $range{
  955.                                         $stRange $docSheet->shrinkRangeToFit($range);
  956.  
  957.                                         // Extract all cell references in $range
  958.                                         $aReferences PHPExcel_Cell::extractAllCellReferencesInRange($stRange);
  959.                                         foreach ($aReferences as $reference{
  960.                                             // Create validation
  961.                                             $docValidation $docSheet->getCell($reference)->getDataValidation();
  962.                                             $docValidation->setType((string) $dataValidation["type"]);
  963.                                             $docValidation->setErrorStyle((string) $dataValidation["errorStyle"]);
  964.                                             $docValidation->setOperator((string) $dataValidation["operator"]);
  965.                                             $docValidation->setAllowBlank($dataValidation["allowBlank"!= 0);
  966.                                             $docValidation->setShowDropDown($dataValidation["showDropDown"== 0);
  967.                                             $docValidation->setShowInputMessage($dataValidation["showInputMessage"!= 0);
  968.                                             $docValidation->setShowErrorMessage($dataValidation["showErrorMessage"!= 0);
  969.                                             $docValidation->setErrorTitle((string) $dataValidation["errorTitle"]);
  970.                                             $docValidation->setError((string) $dataValidation["error"]);
  971.                                             $docValidation->setPromptTitle((string) $dataValidation["promptTitle"]);
  972.                                             $docValidation->setPrompt((string) $dataValidation["prompt"]);
  973.                                             $docValidation->setFormula1((string) $dataValidation->formula1);
  974.                                             $docValidation->setFormula2((string) $dataValidation->formula2);
  975.                                         }
  976.                                     }
  977.                                 }
  978.                             }
  979.  
  980.                             // Add hyperlinks
  981.                             $hyperlinks array();
  982.                             if (!$this->_readDataOnly{
  983.                                 // Locate hyperlink relations
  984.                                 if ($zip->locateName(dirname("$dir/$fileWorksheet""/_rels/" basename($fileWorksheet".rels")) {
  985.                                     $relsWorksheet simplexml_load_string($this->_getFromZipArchive($zip,  dirname("$dir/$fileWorksheet""/_rels/" basename($fileWorksheet".rels") )//~ http://schemas.openxmlformats.org/package/2006/relationships");
  986.                                     foreach ($relsWorksheet->Relationship as $ele{
  987.                                         if ($ele["Type"== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"{
  988.                                             $hyperlinks[(string)$ele["Id"]] = (string)$ele["Target"];
  989.                                         }
  990.                                     }
  991.                                 }
  992.  
  993.                                 // Loop through hyperlinks
  994.                                 if ($xmlSheet && $xmlSheet->hyperlinks{
  995.                                     foreach ($xmlSheet->hyperlinks->hyperlink as $hyperlink{
  996.                                         // Link url
  997.                                         $linkRel $hyperlink->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships');
  998.  
  999.                                         foreach (PHPExcel_Cell::extractAllCellReferencesInRange($hyperlink['ref']as $cellReference{
  1000.                                             $cell $docSheet->getCell$cellReference );
  1001.                                             if (isset($linkRel['id'])) {
  1002.                                                 $cell->getHyperlink()->setUrl$hyperlinks(string)$linkRel['id'] ] );
  1003.                                             }
  1004.                                             if (isset($hyperlink['location'])) {
  1005.                                                 $cell->getHyperlink()->setUrl'sheet://' . (string)$hyperlink['location');
  1006.                                             }
  1007.  
  1008.                                             // Tooltip
  1009.                                             if (isset($hyperlink['tooltip'])) {
  1010.                                                 $cell->getHyperlink()->setTooltip(string)$hyperlink['tooltip');
  1011.                                             }
  1012.                                         }
  1013.                                     }
  1014.                                 }
  1015.                             }
  1016.  
  1017.                             // Add comments
  1018.                             $comments array();
  1019.                             $vmlComments array();
  1020.                             if (!$this->_readDataOnly{
  1021.                                 // Locate comment relations
  1022.                                 if ($zip->locateName(dirname("$dir/$fileWorksheet""/_rels/" basename($fileWorksheet".rels")) {
  1023.                                     $relsWorksheet simplexml_load_string($this->_getFromZipArchive($zip,  dirname("$dir/$fileWorksheet""/_rels/" basename($fileWorksheet".rels") )//~ http://schemas.openxmlformats.org/package/2006/relationships");
  1024.                                     foreach ($relsWorksheet->Relationship as $ele{
  1025.                                         if ($ele["Type"== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"{
  1026.                                             $comments[(string)$ele["Id"]] = (string)$ele["Target"];
  1027.                                         }
  1028.                                         if ($ele["Type"== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing"{
  1029.                                             $vmlComments[(string)$ele["Id"]] = (string)$ele["Target"];
  1030.                                         }
  1031.                                     }
  1032.                                 }
  1033.  
  1034.                                 // Loop through comments
  1035.                                 foreach ($comments as $relName => $relPath{
  1036.                                     // Load comments file
  1037.                                     $relPath PHPExcel_Shared_File::realpath(dirname("$dir/$fileWorksheet""/" $relPath);
  1038.                                     $commentsFile simplexml_load_string($this->_getFromZipArchive($zip$relPath) );
  1039.  
  1040.                                     // Utility variables
  1041.                                     $authors array();
  1042.  
  1043.                                     // Loop through authors
  1044.                                     foreach ($commentsFile->authors->author as $author{
  1045.                                         $authors[= (string)$author;
  1046.                                     }
  1047.  
  1048.                                     // Loop through contents
  1049.                                     foreach ($commentsFile->commentList->comment as $comment{
  1050.                                         $docSheet->getComment(string)$comment['ref')->setAuthor$authors[(string)$comment['authorId']] );
  1051.                                         $docSheet->getComment(string)$comment['ref')->setText$this->_parseRichText($comment->text) );
  1052.                                     }
  1053.                                 }
  1054.  
  1055.                                 // Loop through VML comments
  1056.                                 foreach ($vmlComments as $relName => $relPath{
  1057.                                     // Load VML comments file
  1058.                                     $relPath PHPExcel_Shared_File::realpath(dirname("$dir/$fileWorksheet""/" $relPath);
  1059.                                     $vmlCommentsFile simplexml_load_string$this->_getFromZipArchive($zip$relPath) );
  1060.                                     $vmlCommentsFile->registerXPathNamespace('v''urn:schemas-microsoft-com:vml');
  1061.  
  1062.                                     $shapes $vmlCommentsFile->xpath('//v:shape');
  1063.                                     foreach ($shapes as $shape{
  1064.                                         $shape->registerXPathNamespace('v''urn:schemas-microsoft-com:vml');
  1065.  
  1066.                                         if (isset($shape['style'])) {
  1067.                                             $style        = (string)$shape['style'];
  1068.                                             $fillColor    strtouppersubstr(string)$shape['fillcolor']) );
  1069.                                             $column       null;
  1070.                                             $row          null;
  1071.  
  1072.                                             $clientData   $shape->xpath('.//x:ClientData');
  1073.                                             if (is_array($clientData&& count($clientData0{
  1074.                                                 $clientData   $clientData[0];
  1075.  
  1076.                                                 if isset($clientData['ObjectType']&& (string)$clientData['ObjectType'== 'Note' {
  1077.                                                     $temp $clientData->xpath('.//x:Row');
  1078.                                                     if (is_array($temp)) $row $temp[0];
  1079.  
  1080.                                                     $temp $clientData->xpath('.//x:Column');
  1081.                                                     if (is_array($temp)) $column $temp[0];
  1082.                                                 }
  1083.                                             }
  1084.  
  1085.                                             if (!is_null($column&& !is_null($row)) {
  1086.                                                 // Set comment properties
  1087.                                                 $comment $docSheet->getCommentByColumnAndRow($column$row 1);
  1088.                                                 $comment->getFillColor()->setRGB$fillColor );
  1089.  
  1090.                                                 // Parse style
  1091.                                                 $styleArray explode(';'str_replace(' '''$style));
  1092.                                                 foreach ($styleArray as $stylePair{
  1093.                                                     $stylePair explode(':'$stylePair);
  1094.  
  1095.                                                     if ($stylePair[0== 'margin-left')     $comment->setMarginLeft($stylePair[1]);
  1096.                                                     if ($stylePair[0== 'margin-top')      $comment->setMarginTop($stylePair[1]);
  1097.                                                     if ($stylePair[0== 'width')           $comment->setWidth($stylePair[1]);
  1098.                                                     if ($stylePair[0== 'height')          $comment->setHeight($stylePair[1]);
  1099.                                                     if ($stylePair[0== 'visibility')      $comment->setVisible$stylePair[1== 'visible' );
  1100.  
  1101.                                                 }
  1102.                                             }
  1103.                                         }
  1104.                                     }
  1105.                                 }
  1106.  
  1107.                                 // Header/footer images
  1108.                                 if ($xmlSheet && $xmlSheet->legacyDrawingHF && !$this->_readDataOnly{
  1109.                                     if ($zip->locateName(dirname("$dir/$fileWorksheet""/_rels/" basename($fileWorksheet".rels")) {
  1110.                                         $relsWorksheet simplexml_load_string($this->_getFromZipArchive($zip,  dirname("$dir/$fileWorksheet""/_rels/" basename($fileWorksheet".rels") )//~ http://schemas.openxmlformats.org/package/2006/relationships");
  1111.                                         $vmlRelationship '';
  1112.  
  1113.                                         foreach ($relsWorksheet->Relationship as $ele{
  1114.                                             if ($ele["Type"== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing"{
  1115.                                                 $vmlRelationship self::dir_add("$dir/$fileWorksheet"$ele["Target"]);
  1116.                                             }
  1117.                                         }
  1118.  
  1119.                                         if ($vmlRelationship != ''{
  1120.                                             // Fetch linked images
  1121.                                             $relsVML simplexml_load_string($this->_getFromZipArchive($zip,  dirname($vmlRelationship'/_rels/' basename($vmlRelationship'.rels' ))//~ http://schemas.openxmlformats.org/package/2006/relationships");
  1122.                                             $drawings array();
  1123.                                             foreach ($relsVML->Relationship as $ele{
  1124.                                                 if ($ele["Type"== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"{
  1125.                                                     $drawings[(string) $ele["Id"]] self::dir_add($vmlRelationship$ele["Target"]);
  1126.                                                 }
  1127.                                             }
  1128.  
  1129.                                             // Fetch VML document
  1130.                                             $vmlDrawing simplexml_load_string($this->_getFromZipArchive($zip$vmlRelationship));
  1131.                                             $vmlDrawing->registerXPathNamespace('v''urn:schemas-microsoft-com:vml');
  1132.  
  1133.                                             $hfImages array();
  1134.  
  1135.                                             $shapes $vmlDrawing->xpath('//v:shape');
  1136.                                             foreach ($shapes as $shape{
  1137.                                                 $shape->registerXPathNamespace('v''urn:schemas-microsoft-com:vml');
  1138.                                                 $imageData $shape->xpath('//v:imagedata');
  1139.                                                 $imageData $imageData[0];
  1140.  
  1141.                                                 $imageData $imageData->attributes('urn:schemas-microsoft-com:office:office');
  1142.                                                 $style self::toCSSArray(string)$shape['style');
  1143.  
  1144.                                                 $hfImages(string)$shape['id'] ] new PHPExcel_Worksheet_HeaderFooterDrawing();
  1145.                                                 if (isset($imageData['title'])) {
  1146.                                                     $hfImages(string)$shape['id'] ]->setName(string)$imageData['title');
  1147.                                                 }
  1148.  
  1149.                                                 $hfImages(string)$shape['id'] ]->setPath("zip://$pFilename#$drawings[(string)$imageData['relid']]false);
  1150.                                                 $hfImages(string)$shape['id'] ]->setResizeProportional(false);
  1151.                                                 $hfImages(string)$shape['id'] ]->setWidth($style['width']);
  1152.                                                 $hfImages(string)$shape['id'] ]->setHeight($style['height']);
  1153.                                                 $hfImages(string)$shape['id'] ]->setOffsetX($style['margin-left']);
  1154.                                                 $hfImages(string)$shape['id'] ]->setOffsetY($style['margin-top']);
  1155.                                                 $hfImages(string)$shape['id'] ]->setResizeProportional(true);
  1156.                                             }
  1157.  
  1158.                                             $docSheet->getHeaderFooter()->setImages($hfImages);
  1159.                                         }
  1160.                                     }
  1161.                                 }
  1162.  
  1163.                             }
  1164.  
  1165.     // TODO: Make sure drawings and graph are loaded differently!
  1166.                             if ($zip->locateName(dirname("$dir/$fileWorksheet""/_rels/" basename($fileWorksheet".rels")) {
  1167.                                 $relsWorksheet simplexml_load_string($this->_getFromZipArchive($zip,  dirname("$dir/$fileWorksheet""/_rels/" basename($fileWorksheet".rels") )//~ http://schemas.openxmlformats.org/package/2006/relationships");
  1168.                                 $drawings array();
  1169.                                 foreach ($relsWorksheet->Relationship as $ele{
  1170.                                     if ($ele["Type"== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing"{
  1171.                                         $drawings[(string) $ele["Id"]] self::dir_add("$dir/$fileWorksheet"$ele["Target"]);
  1172.                                     }
  1173.                                 }
  1174.                                 if ($xmlSheet->drawing && !$this->_readDataOnly{
  1175.                                     foreach ($xmlSheet->drawing as $drawing{
  1176.                                         $fileDrawing $drawings[(string) self::array_item($drawing->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships")"id")];
  1177.                                         $relsDrawing simplexml_load_string($this->_getFromZipArchive($zip,  dirname($fileDrawing"/_rels/" basename($fileDrawing".rels") )//~ http://schemas.openxmlformats.org/package/2006/relationships");
  1178.                                         $images array();
  1179.  
  1180.                                         if ($relsDrawing && $relsDrawing->Relationship{
  1181.                                             foreach ($relsDrawing->Relationship as $ele{
  1182.                                                 if ($ele["Type"== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"{
  1183.                                                     $images[(string) $ele["Id"]] self::dir_add($fileDrawing$ele["Target"]);
  1184.                                                 }
  1185.                                             }
  1186.                                         }
  1187.                                         $xmlDrawing simplexml_load_string($this->_getFromZipArchive($zip$fileDrawing))->children("http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing");
  1188.  
  1189.                                         if ($xmlDrawing->oneCellAnchor{
  1190.                                             foreach ($xmlDrawing->oneCellAnchor as $oneCellAnchor{
  1191.                                                 if ($oneCellAnchor->pic->blipFill{
  1192.                                                     $blip $oneCellAnchor->pic->blipFill->children("http://schemas.openxmlformats.org/drawingml/2006/main")->blip;
  1193.                                                     $xfrm $oneCellAnchor->pic->spPr->children("http://schemas.openxmlformats.org/drawingml/2006/main")->xfrm;
  1194.                                                     $outerShdw $oneCellAnchor->pic->spPr->children("http://schemas.openxmlformats.org/drawingml/2006/main")->effectLst->outerShdw;
  1195.                                                     $objDrawing new PHPExcel_Worksheet_Drawing;
  1196.                                                     $objDrawing->setName((string) self::array_item($oneCellAnchor->pic->nvPicPr->cNvPr->attributes()"name"));
  1197.                                                     $objDrawing->setDescription((string) self::array_item($oneCellAnchor->pic->nvPicPr->cNvPr->attributes()"descr"));
  1198.                                                     $objDrawing->setPath("zip://$pFilename#$images[(string) self::array_item($blip->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships")"embed")]false);
  1199.                                                     $objDrawing->setCoordinates(PHPExcel_Cell::stringFromColumnIndex($oneCellAnchor->from->col($oneCellAnchor->from->row 1));
  1200.                                                     $objDrawing->setOffsetX(PHPExcel_Shared_Drawing::EMUToPixels($oneCellAnchor->from->colOff));
  1201.                                                     $objDrawing->setOffsetY(PHPExcel_Shared_Drawing::EMUToPixels($oneCellAnchor->from->rowOff));
  1202.                                                     $objDrawing->setResizeProportional(false);
  1203.                                                     $objDrawing->setWidth(PHPExcel_Shared_Drawing::EMUToPixels(self::array_item($oneCellAnchor->ext->attributes()"cx")));
  1204.                                                     $objDrawing->setHeight(PHPExcel_Shared_Drawing::EMUToPixels(self::array_item($oneCellAnchor->ext->attributes()"cy")));
  1205.                                                     if ($xfrm{
  1206.                                                         $objDrawing->setRotation(PHPExcel_Shared_Drawing::angleToDegrees(self::array_item($xfrm->attributes()"rot")));
  1207.                                                     }
  1208.                                                     if ($outerShdw{
  1209.                                                         $shadow $objDrawing->getShadow();
  1210.                                                         $shadow->setVisible(true);
  1211.                                                         $shadow->setBlurRadius(PHPExcel_Shared_Drawing::EMUTopixels(self::array_item($outerShdw->attributes()"blurRad")));
  1212.                                                         $shadow->setDistance(PHPExcel_Shared_Drawing::EMUTopixels(self::array_item($outerShdw->attributes()"dist")));
  1213.                                                         $shadow->setDirection(PHPExcel_Shared_Drawing::angleToDegrees(self::array_item($outerShdw->attributes()"dir")));
  1214.                                                         $shadow->setAlignment((string) self::array_item($outerShdw->attributes()"algn"));
  1215.                                                         $shadow->getColor()->setRGB(self::array_item($outerShdw->srgbClr->attributes()"val"));
  1216.                                                         $shadow->setAlpha(self::array_item($outerShdw->srgbClr->alpha->attributes()"val"1000);
  1217.                                                     }
  1218.                                                     $objDrawing->setWorksheet($docSheet);
  1219.                                                 }
  1220.                                             }
  1221.                                         }
  1222.                                         if ($xmlDrawing->twoCellAnchor{
  1223.                                             foreach ($xmlDrawing->twoCellAnchor as $twoCellAnchor{
  1224.                                                 if ($twoCellAnchor->pic->blipFill{
  1225.                                                     $blip $twoCellAnchor->pic->blipFill->children("http://schemas.openxmlformats.org/drawingml/2006/main")->blip;
  1226.                                                     $xfrm $twoCellAnchor->pic->spPr->children("http://schemas.openxmlformats.org/drawingml/2006/main")->xfrm;
  1227.                                                     $outerShdw $twoCellAnchor->pic->spPr->children("http://schemas.openxmlformats.org/drawingml/2006/main")->effectLst->outerShdw;
  1228.                                                     $objDrawing new PHPExcel_Worksheet_Drawing;
  1229.                                                     $objDrawing->setName((string) self::array_item($twoCellAnchor->pic->nvPicPr->cNvPr->attributes()"name"));
  1230.                                                     $objDrawing->setDescription((string) self::array_item($twoCellAnchor->pic->nvPicPr->cNvPr->attributes()"descr"));
  1231.                                                     $objDrawing->setPath("zip://$pFilename#$images[(string) self::array_item($blip->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships")"embed")]false);
  1232.                                                     $objDrawing->setCoordinates(PHPExcel_Cell::stringFromColumnIndex($twoCellAnchor->from->col($twoCellAnchor->from->row 1));
  1233.                                                     $objDrawing->setOffsetX(PHPExcel_Shared_Drawing::EMUToPixels($twoCellAnchor->from->colOff));
  1234.                                                     $objDrawing->setOffsetY(PHPExcel_Shared_Drawing::EMUToPixels($twoCellAnchor->from->rowOff));
  1235.                                                     $objDrawing->setResizeProportional(false);
  1236.  
  1237.                                                     $objDrawing->setWidth(PHPExcel_Shared_Drawing::EMUToPixels(self::array_item($xfrm->ext->attributes()"cx")));
  1238.                                                     $objDrawing->setHeight(PHPExcel_Shared_Drawing::EMUToPixels(self::array_item($xfrm->ext->attributes()"cy")));
  1239.  
  1240.                                                     if ($xfrm{
  1241.                                                         $objDrawing->setRotation(PHPExcel_Shared_Drawing::angleToDegrees(self::array_item($xfrm->attributes()"rot")));
  1242.                                                     }
  1243.                                                     if ($outerShdw{
  1244.                                                         $shadow $objDrawing->getShadow();
  1245.                                                         $shadow->setVisible(true);
  1246.                                                         $shadow->setBlurRadius(PHPExcel_Shared_Drawing::EMUTopixels(self::array_item($outerShdw->attributes()"blurRad")));
  1247.                                                         $shadow->setDistance(PHPExcel_Shared_Drawing::EMUTopixels(self::array_item($outerShdw->attributes()"dist")));
  1248.                                                         $shadow->setDirection(PHPExcel_Shared_Drawing::angleToDegrees(self::array_item($outerShdw->attributes()"dir")));
  1249.                                                         $shadow->setAlignment((string) self::array_item($outerShdw->attributes()"algn"));
  1250.                                                         $shadow->getColor()->setRGB(self::array_item($outerShdw->srgbClr->attributes()"val"));
  1251.                                                         $shadow->setAlpha(self::array_item($outerShdw->srgbClr->alpha->attributes()"val"1000);
  1252.                                                     }
  1253.                                                     $objDrawing->setWorksheet($docSheet);
  1254.                                                 }
  1255.                                             }
  1256.                                         }
  1257.  
  1258.                                     }
  1259.                                 }
  1260.                             }
  1261.  
  1262.                             // Loop through definedNames
  1263.                             if ($xmlWorkbook->definedNames{
  1264.                                 foreach ($xmlWorkbook->definedNames->definedName as $definedName{
  1265.                                     // Extract range
  1266.                                     $extractedRange = (string)$definedName;
  1267.                                     $extractedRange preg_replace('/\'(\w+)\'\!/'''$extractedRange);
  1268.                                     $extractedRange str_replace('$'''$extractedRange);
  1269.  
  1270.                                     // Valid range?
  1271.                                     if (stripos((string)$definedName'#REF!'!== false || $extractedRange == ''{
  1272.                                         continue;
  1273.                                     }
  1274.  
  1275.                                     // Some definedNames are only applicable if we are on the same sheet...
  1276.                                     if ((string)$definedName['localSheetId'!= '' && (string)$definedName['localSheetId'== $sheetId{
  1277.                                         // Switch on type
  1278.                                         switch ((string)$definedName['name']{
  1279.  
  1280.                                             case '_xlnm._FilterDatabase':
  1281.                                                 $docSheet->setAutoFilter($extractedRange);
  1282.                                                 break;
  1283.  
  1284.                                             case '_xlnm.Print_Titles':
  1285.                                                 // Split $extractedRange
  1286.                                                 $extractedRange explode(','$extractedRange);
  1287.  
  1288.                                                 // Set print titles
  1289.                                                 foreach ($extractedRange as $range{
  1290.                                                     $matches array();
  1291.  
  1292.                                                     // check for repeating columns, e g. 'A:A' or 'A:D'
  1293.                                                     if (preg_match('/^([A-Z]+)\:([A-Z]+)$/'$range$matches)) {
  1294.                                                         $docSheet->getPageSetup()->setColumnsToRepeatAtLeft(array($matches[1]$matches[2]));
  1295.                                                     }
  1296.                                                     // check for repeating rows, e.g. '1:1' or '1:5'
  1297.                                                     elseif (preg_match('/^(\d+)\:(\d+)$/'$range$matches)) {
  1298.                                                         $docSheet->getPageSetup()->setRowsToRepeatAtTop(array($matches[1]$matches[2]));
  1299.                                                     }
  1300.                                                 }
  1301.                                                 break;
  1302.  
  1303.                                             case '_xlnm.Print_Area':
  1304.                                                 $rangeSets explode(','$extractedRange);        // FIXME: what if sheetname contains comma?
  1305.                                                 $newRangeSets array();
  1306.                                                 foreach($rangeSets as $rangeSet{
  1307.                                                     $range explode('!'$rangeSet);    // FIXME: what if sheetname contains exclamation mark?
  1308.                                                     $rangeSet = isset($range[1]$range[1$range[0];
  1309.                                                     $newRangeSets[str_replace('$'''$rangeSet);
  1310.                                                 }
  1311.                                                 $docSheet->getPageSetup()->setPrintArea(implode(',',$newRangeSets));
  1312.                                                 break;
  1313.  
  1314.                                             default:
  1315.                                                 break;
  1316.                                         }
  1317.                                     }
  1318.                                 }
  1319.                             }
  1320.  
  1321.                             // Next sheet id
  1322.                             ++$sheetId;
  1323.                         }
  1324.  
  1325.                         // Loop through definedNames
  1326.                         if ($xmlWorkbook->definedNames{
  1327.                             foreach ($xmlWorkbook->definedNames->definedName as $definedName{
  1328.                                 // Extract range
  1329.                                 $extractedRange = (string)$definedName;
  1330.                                 $extractedRange preg_replace('/\'(\w+)\'\!/'''$extractedRange);
  1331.                                 $extractedRange str_replace('$'''$extractedRange);
  1332.  
  1333.                                 // Valid range?
  1334.                                 if (stripos((string)$definedName'#REF!'!== false || $extractedRange == ''{
  1335.                                     continue;
  1336.                                 }
  1337.  
  1338.                                 // Some definedNames are only applicable if we are on the same sheet...
  1339.                                 if ((string)$definedName['localSheetId'!= ''{
  1340.                                     // Local defined name
  1341.                                     // Switch on type
  1342.                                     switch ((string)$definedName['name']{
  1343.  
  1344.                                         case '_xlnm._FilterDatabase':
  1345.                                         case '_xlnm.Print_Titles':
  1346.                                         case '_xlnm.Print_Area':
  1347.                                             break;
  1348.  
  1349.                                         default:
  1350.                                             $range explode('!'(string)$definedName);
  1351.                                             if (count($range== 2{
  1352.                                                 $range[0str_replace("''""'"$range[0]);
  1353.                                                 $range[0str_replace("'"""$range[0]);
  1354.                                                 if ($worksheet $docSheet->getParent()->getSheetByName($range[0])) {
  1355.                                                     $extractedRange str_replace('$'''$range[1]);
  1356.                                                     $scope $docSheet->getParent()->getSheet((string)$definedName['localSheetId']);
  1357.  
  1358.                                                     $excel->addNamedRangenew PHPExcel_NamedRange((string)$definedName['name']$worksheet$extractedRangetrue$scope) );
  1359.                                                 }
  1360.                                             }
  1361.                                             break;
  1362.                                     }
  1363.                                 else if (!isset($definedName['localSheetId'])) {
  1364.                                     // "Global" definedNames
  1365.                                     $locatedSheet null;
  1366.                                     $extractedSheetName '';
  1367.                                     if (strpos(string)$definedName'!' !== false{
  1368.                                         // Extract sheet name
  1369.                                         $extractedSheetName PHPExcel_Worksheet::extractSheetTitle(string)$definedNametrue );
  1370.                                         $extractedSheetName $extractedSheetName[0];
  1371.  
  1372.                                         // Locate sheet
  1373.                                         $locatedSheet $excel->getSheetByName($extractedSheetName);
  1374.  
  1375.                                         // Modify range
  1376.                                         $range explode('!'$extractedRange);
  1377.                                         $extractedRange = isset($range[1]$range[1$range[0];
  1378.                                     }
  1379.  
  1380.                                     if (!is_null($locatedSheet)) {
  1381.                                         $excel->addNamedRangenew PHPExcel_NamedRange((string)$definedName['name']$locatedSheet$extractedRangefalse) );
  1382.                                     }
  1383.                                 }
  1384.                             }
  1385.                         }
  1386.                     }
  1387.  
  1388.                     if (!$this->_readDataOnly{
  1389.                         // active sheet index
  1390.                         $activeTab intval($xmlWorkbook->bookViews->workbookView["activeTab"])// refers to old sheet index
  1391.  
  1392.                         // keep active sheet index if sheet is still loaded, else first sheet is set as the active
  1393.                         if (isset($mapSheetId[$activeTab]&& $mapSheetId[$activeTab!== null{
  1394.                             $excel->setActiveSheetIndex($mapSheetId[$activeTab]);
  1395.                         else {
  1396.                             if ($excel->getSheetCount(== 0)
  1397.                             {
  1398.                                 $excel->createSheet();
  1399.                             }
  1400.                             $excel->setActiveSheetIndex(0);
  1401.                         }
  1402.                     }
  1403.                 break;
  1404.             }
  1405.  
  1406.         }
  1407.  
  1408.         return $excel;
  1409.     }
  1410.  
  1411.     private function _readColor($color{
  1412.         if (isset($color["rgb"])) {
  1413.             return (string)$color["rgb"];
  1414.         else if (isset($color["indexed"])) {
  1415.             return PHPExcel_Style_Color::indexedColor($color["indexed"])->getARGB();
  1416.         }
  1417.     }
  1418.  
  1419.     private function _readStyle($docStyle$style{
  1420.         // format code
  1421.         if (isset($style->numFmt)) {
  1422.             $docStyle->getNumberFormat()->setFormatCode($style->numFmt);
  1423.         }
  1424.  
  1425.         // font
  1426.         if (isset($style->font)) {
  1427.             $docStyle->getFont()->setName((string) $style->font->name["val"]);
  1428.             $docStyle->getFont()->setSize((string) $style->font->sz["val"]);
  1429.             if (isset($style->font->b)) {
  1430.                 $docStyle->getFont()->setBold(!isset($style->font->b["val"]|| $style->font->b["val"== 'true' || $style->font->b["val"== '1');
  1431.             }
  1432.             if (isset($style->font->i)) {
  1433.                 $docStyle->getFont()->setItalic(!isset($style->font->i["val"]|| $style->font->i["val"== 'true' || $style->font->i["val"== '1');
  1434.             }
  1435.             if (isset($style->font->strike)) {
  1436.                 $docStyle->getFont()->setStrikethrough(!isset($style->font->strike["val"]|| $style->font->strike["val"== 'true' || $style->font->strike["val"== '1');
  1437.             }
  1438.             $docStyle->getFont()->getColor()->setARGB($this->_readColor($style->font->color));
  1439.  
  1440.             if (isset($style->font->u&& !isset($style->font->u["val"])) {
  1441.                 $docStyle->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);
  1442.             else if (isset($style->font->u&& isset($style->font->u["val"])) {
  1443.                 $docStyle->getFont()->setUnderline((string)$style->font->u["val"]);
  1444.             }
  1445.  
  1446.             if (isset($style->font->vertAlign&& isset($style->font->vertAlign["val"])) {
  1447.                 $vertAlign strtolower((string)$style->font->vertAlign["val"]);
  1448.                 if ($vertAlign == 'superscript'{
  1449.                     $docStyle->getFont()->setSuperScript(true);
  1450.                 }
  1451.                 if ($vertAlign == 'subscript'{
  1452.                     $docStyle->getFont()->setSubScript(true);
  1453.                 }
  1454.             }
  1455.         }
  1456.  
  1457.         // fill
  1458.         if (isset($style->fill)) {
  1459.             if ($style->fill->gradientFill{
  1460.                 $gradientFill $style->fill->gradientFill[0];
  1461.                 $docStyle->getFill()->setFillType((string) $gradientFill["type"]);
  1462.                 $docStyle->getFill()->setRotation(floatval($gradientFill["degree"]));
  1463.                 $gradientFill->registerXPathNamespace("sml""http://schemas.openxmlformats.org/spreadsheetml/2006/main");
  1464.                 $docStyle->getFill()->getStartColor()->setARGB($this->_readColorself::array_item($gradientFill->xpath("sml:stop[@position=0]"))->color) );
  1465.                 $docStyle->getFill()->getEndColor()->setARGB($this->_readColorself::array_item($gradientFill->xpath("sml:stop[@position=1]"))->color) );
  1466.             elseif ($style->fill->patternFill{
  1467.                 $patternType = (string)$style->fill->patternFill["patternType"!= '' ? (string)$style->fill->patternFill["patternType"'solid';
  1468.                 $docStyle->getFill()->setFillType($patternType);
  1469.                 if ($style->fill->patternFill->fgColor{
  1470.                     $docStyle->getFill()->getStartColor()->setARGB($this->_readColor($style->fill->patternFill->fgColor));
  1471.                 else {
  1472.                     $docStyle->getFill()->getStartColor()->setARGB('FF000000');
  1473.                 }
  1474.                 if ($style->fill->patternFill->bgColor{
  1475.                     $docStyle->getFill()->getEndColor()->setARGB($this->_readColor($style->fill->patternFill->bgColor));
  1476.                 }
  1477.             }
  1478.         }
  1479.  
  1480.         // border
  1481.         if (isset($style->border)) {
  1482.             $diagonalUp   false;
  1483.             $diagonalDown false;
  1484.             if ($style->border["diagonalUp"== 'true' || $style->border["diagonalUp"== 1{
  1485.                 $diagonalUp true;
  1486.             }
  1487.             if ($style->border["diagonalDown"== 'true' || $style->border["diagonalDown"== 1{
  1488.                 $diagonalDown true;
  1489.             }
  1490.             if ($diagonalUp == false && $diagonalDown == false{
  1491.                 $docStyle->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_NONE);
  1492.             elseif ($diagonalUp == true && $diagonalDown == false{
  1493.                 $docStyle->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_UP);
  1494.             elseif ($diagonalUp == false && $diagonalDown == true{
  1495.                 $docStyle->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_DOWN);
  1496.             elseif ($diagonalUp == true && $diagonalDown == true{
  1497.                 $docStyle->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_BOTH);
  1498.             }
  1499.             $this->_readBorder($docStyle->getBorders()->getLeft()$style->border->left);
  1500.             $this->_readBorder($docStyle->getBorders()->getRight()$style->border->right);
  1501.             $this->_readBorder($docStyle->getBorders()->getTop()$style->border->top);
  1502.             $this->_readBorder($docStyle->getBorders()->getBottom()$style->border->bottom);
  1503.             $this->_readBorder($docStyle->getBorders()->getDiagonal()$style->border->diagonal);
  1504.         }
  1505.  
  1506.         // alignment
  1507.         if (isset($style->alignment)) {
  1508.             $docStyle->getAlignment()->setHorizontal((string) $style->alignment["horizontal"]);
  1509.             $docStyle->getAlignment()->setVertical((string) $style->alignment["vertical"]);
  1510.  
  1511.             $textRotation 0;
  1512.             if ((int)$style->alignment["textRotation"<= 90{
  1513.                 $textRotation = (int)$style->alignment["textRotation"];
  1514.             else if ((int)$style->alignment["textRotation"90{
  1515.                 $textRotation 90 - (int)$style->alignment["textRotation"];
  1516.             }
  1517.  
  1518.             $docStyle->getAlignment()->setTextRotation(intval($textRotation));
  1519.             $docStyle->getAlignment()->setWrapText(string)$style->alignment["wrapText"== "true" || (string)$style->alignment["wrapText"== "1" );
  1520.             $docStyle->getAlignment()->setShrinkToFit(string)$style->alignment["shrinkToFit"== "true" || (string)$style->alignment["shrinkToFit"== "1" );
  1521.             $docStyle->getAlignment()->setIndentintval((string)$style->alignment["indent"]intval((string)$style->alignment["indent"]);
  1522.         }
  1523.  
  1524.         // protection
  1525.         if (isset($style->protection)) {
  1526.             if (isset($style->protection['locked'])) {
  1527.                 if ((string)$style->protection['locked'== 'true'{
  1528.                     $docStyle->getProtection()->setLocked(PHPExcel_Style_Protection::PROTECTION_PROTECTED);
  1529.                 else {
  1530.                     $docStyle->getProtection()->setLocked(PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);
  1531.                 }
  1532.             }
  1533.  
  1534.             if (isset($style->protection['hidden'])) {
  1535.                 if ((string)$style->protection['hidden'== 'true'{
  1536.                     $docStyle->getProtection()->setHidden(PHPExcel_Style_Protection::PROTECTION_PROTECTED);
  1537.                 else {
  1538.                     $docStyle->getProtection()->setHidden(PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);
  1539.                 }
  1540.             }
  1541.         }
  1542.     }
  1543.  
  1544.     private function _readBorder($docBorder$eleBorder{
  1545.         if (isset($eleBorder["style"])) {
  1546.             $docBorder->setBorderStyle((string) $eleBorder["style"]);
  1547.         }
  1548.         if (isset($eleBorder->color)) {
  1549.             $docBorder->getColor()->setARGB($this->_readColor($eleBorder->color));
  1550.         }
  1551.     }
  1552.  
  1553.     private function _parseRichText($is null{
  1554.         $value new PHPExcel_RichText();
  1555.  
  1556.         if (isset($is->t)) {
  1557.             $value->createTextPHPExcel_Shared_String::ControlCharacterOOXML2PHP(string) $is->) );
  1558.         else {
  1559.             foreach ($is->as $run{
  1560.                 if (!isset($run->rPr)) {
  1561.                     $objText $value->createTextPHPExcel_Shared_String::ControlCharacterOOXML2PHP(string) $run->) );
  1562.  
  1563.                 else {
  1564.                     $objText $value->createTextRunPHPExcel_Shared_String::ControlCharacterOOXML2PHP(string) $run->) );
  1565.  
  1566.                     if (isset($run->rPr->rFont["val"])) {
  1567.                         $objText->getFont()->setName((string) $run->rPr->rFont["val"]);
  1568.                     }
  1569.  
  1570.                     if (isset($run->rPr->sz["val"])) {
  1571.                         $objText->getFont()->setSize((string) $run->rPr->sz["val"]);
  1572.                     }
  1573.  
  1574.                     if (isset($run->rPr->color)) {
  1575.                         $objText->getFont()->setColornew PHPExcel_Style_Color$this->_readColor($run->rPr->color) ) );
  1576.                     }
  1577.  
  1578.                     if ( (isset($run->rPr->b["val"]&& ((string) $run->rPr->b["val"== 'true' || (string) $run->rPr->b["val"== '1'))
  1579.                          || (isset($run->rPr->b&& !isset($run->rPr->b["val"])) ) {
  1580.                         $objText->getFont()->setBold(true);
  1581.                     }
  1582.  
  1583.                     if ( (isset($run->rPr->i["val"]&& ((string) $run->rPr->i["val"== 'true' || (string) $run->rPr->i["val"== '1'))
  1584.                          || (isset($run->rPr->i&& !isset($run->rPr->i["val"])) ) {
  1585.                         $objText->getFont()->setItalic(true);
  1586.                     }
  1587.  
  1588.                     if (isset($run->rPr->vertAlign&& isset($run->rPr->vertAlign["val"])) {
  1589.                         $vertAlign strtolower((string)$run->rPr->vertAlign["val"]);
  1590.                         if ($vertAlign == 'superscript'{
  1591.                             $objText->getFont()->setSuperScript(true);
  1592.                         }
  1593.                         if ($vertAlign == 'subscript'{
  1594.                             $objText->getFont()->setSubScript(true);
  1595.                         }
  1596.                     }
  1597.  
  1598.                     if (isset($run->rPr->u&& !isset($run->rPr->u["val"])) {
  1599.                         $objText->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);
  1600.                     else if (isset($run->rPr->u&& isset($run->rPr->u["val"])) {
  1601.                         $objText->getFont()->setUnderline((string)$run->rPr->u["val"]);
  1602.                     }
  1603.  
  1604.                     if ( (isset($run->rPr->strike["val"])  && ((string) $run->rPr->strike["val"== 'true' || (string) $run->rPr->strike["val"== '1'))
  1605.                          || (isset($run->rPr->strike&& !isset($run->rPr->strike["val"])) ) {
  1606.                         $objText->getFont()->setStrikethrough(true);
  1607.                     }
  1608.                 }
  1609.             }
  1610.         }
  1611.  
  1612.         return $value;
  1613.     }
  1614.  
  1615.     private static function array_item($array$key 0{
  1616.         return (isset($array[$key]$array[$keynull);
  1617.     }
  1618.  
  1619.     private static function dir_add($base$add{
  1620.         return preg_replace('~[^/]+/\.\./~'''dirname($base"/$add");
  1621.     }
  1622.  
  1623.     private static function toCSSArray($style{
  1624.         $style str_replace("\r"""$style);
  1625.         $style str_replace("\n"""$style);
  1626.  
  1627.         $temp explode(';'$style);
  1628.  
  1629.         $style array();
  1630.         foreach ($temp as $item{
  1631.             $item explode(':'$item);
  1632.  
  1633.             if (strpos($item[1]'px'!== false{
  1634.                 $item[1str_replace('px'''$item[1]);
  1635.             }
  1636.             if (strpos($item[1]'pt'!== false{
  1637.                 $item[1str_replace('pt'''$item[1]);
  1638.                 $item[1PHPExcel_Shared_Font::fontSizeToPixels($item[1]);
  1639.             }
  1640.             if (strpos($item[1]'in'!== false{
  1641.                 $item[1str_replace('in'''$item[1]);
  1642.                 $item[1PHPExcel_Shared_Font::inchSizeToPixels($item[1]);
  1643.             }
  1644.             if (strpos($item[1]'cm'!== false{
  1645.                 $item[1str_replace('cm'''$item[1]);
  1646.                 $item[1PHPExcel_Shared_Font::centimeterSizeToPixels($item[1]);
  1647.             }
  1648.  
  1649.             $style[$item[0]] $item[1];
  1650.         }
  1651.  
  1652.         return $style;
  1653.     }
  1654. }

Documentation generated on Thu, 26 Aug 2010 17:42:06 +0200 by phpDocumentor 1.4.3