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

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