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

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