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

Documentation generated on Mon, 17 May 2010 08:10:29 +0200 by phpDocumentor 1.4.3