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 - 2008 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 tshhe 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 - 2008 PHPExcel (http://www.codeplex.com/PHPExcel)
  24.  * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
  25.  * @version    1.6.4, 2008-10-27
  26.  */
  27.  
  28.  
  29. /** PHPExcel */
  30. require_once 'PHPExcel.php';
  31.  
  32. /** PHPExcel_Reader_IReader */
  33. require_once 'PHPExcel/Reader/IReader.php';
  34.  
  35. /** PHPExcel_Worksheet */
  36. require_once 'PHPExcel/Worksheet.php';
  37.  
  38. /** PHPExcel_Cell */
  39. require_once 'PHPExcel/Cell.php';
  40.  
  41. /** PHPExcel_Style */
  42. require_once 'PHPExcel/Style.php';
  43.  
  44. /** PHPExcel_Style_Borders */
  45. require_once 'PHPExcel/Style/Borders.php';
  46.  
  47. /** PHPExcel_Style_Conditional */
  48. require_once 'PHPExcel/Style/Conditional.php';
  49.  
  50. /** PHPExcel_Style_Protection */
  51. require_once 'PHPExcel/Style/Protection.php';
  52.  
  53. /** PHPExcel_Style_NumberFormat */
  54. require_once 'PHPExcel/Style/NumberFormat.php';
  55.  
  56. /** PHPExcel_Worksheet_BaseDrawing */
  57. require_once 'PHPExcel/Worksheet/BaseDrawing.php';
  58.  
  59. /** PHPExcel_Worksheet_Drawing */
  60. require_once 'PHPExcel/Worksheet/Drawing.php';
  61.  
  62. /** PHPExcel_Shared_Drawing */
  63. require_once 'PHPExcel/Shared/Drawing.php';
  64.  
  65. /** PHPExcel_Shared_Date */
  66. require_once 'PHPExcel/Shared/Date.php';
  67.  
  68. /** PHPExcel_Shared_File */
  69. require_once 'PHPExcel/Shared/File.php';
  70.  
  71. /** PHPExcel_Shared_String */
  72. require_once 'PHPExcel/Shared/String.php';
  73.  
  74. /** PHPExcel_ReferenceHelper */
  75. require_once 'PHPExcel/ReferenceHelper.php';
  76.  
  77.  /** PHPExcel_Reader_IReadFilter */
  78. require_once 'PHPExcel/Reader/IReadFilter.php';
  79.  
  80.  /** PHPExcel_Reader_DefaultReadFilter */
  81. require_once 'PHPExcel/Reader/DefaultReadFilter.php';
  82.  
  83.  
  84. /**
  85.  * PHPExcel_Reader_Excel2007
  86.  *
  87.  * @category   PHPExcel
  88.  * @package    PHPExcel_Reader
  89.  * @copyright  Copyright (c) 2006 - 2008 PHPExcel (http://www.codeplex.com/PHPExcel)
  90.  */
  91. class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
  92. {
  93.     /**
  94.      * Read data only?
  95.      *
  96.      * @var boolean 
  97.      */
  98.     private $_readDataOnly = false;
  99.  
  100.     /**
  101.      * Restict which sheets should be loaded?
  102.      *
  103.      * @var array 
  104.      */
  105.     private $_loadSheetsOnly = null;
  106.  
  107.     /**
  108.      * PHPExcel_Reader_IReadFilter instance
  109.      *
  110.      * @var PHPExcel_Reader_IReadFilter 
  111.      */
  112.     private $_readFilter = null;
  113.  
  114.     /**
  115.      * Read data only?
  116.      *
  117.      * @return boolean 
  118.      */
  119.     public function getReadDataOnly({
  120.         return $this->_readDataOnly;
  121.     }
  122.  
  123.     /**
  124.      * Set read data only
  125.      *
  126.      * @param boolean $pValue 
  127.      */
  128.     public function setReadDataOnly($pValue false{
  129.         $this->_readDataOnly = $pValue;
  130.     }
  131.  
  132.     /**
  133.      * Get which sheets to load
  134.      *
  135.      * @return mixed 
  136.      */
  137.     public function getLoadSheetsOnly()
  138.     {
  139.         return $this->_loadSheetsOnly;
  140.     }
  141.  
  142.     /**
  143.      * Set which sheets to load
  144.      *
  145.      * @param mixed $value 
  146.      */
  147.     public function setLoadSheetsOnly($value null)
  148.     {
  149.         $this->_loadSheetsOnly = is_array($value?
  150.             $value array($value);
  151.     }
  152.  
  153.     /**
  154.      * Set all sheets to load
  155.      */
  156.     public function setLoadAllSheets()
  157.     {
  158.         $this->_loadSheetsOnly = null;
  159.     }
  160.  
  161.     /**
  162.      * Read filter
  163.      *
  164.      * @return PHPExcel_Reader_IReadFilter 
  165.      */
  166.     public function getReadFilter({
  167.         return $this->_readFilter;
  168.     }
  169.  
  170.     /**
  171.      * Set read filter
  172.      *
  173.      * @param PHPExcel_Reader_IReadFilter $pValue 
  174.      */
  175.     public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue{
  176.         $this->_readFilter = $pValue;
  177.     }
  178.  
  179.     /**
  180.      * Create a new PHPExcel_Reader_Excel2007 instance
  181.      */
  182.     public function __construct({
  183.         $this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
  184.     }
  185.  
  186.     /**
  187.      * Loads PHPExcel from file
  188.      *
  189.      * @param     string         $pFilename 
  190.      * @throws     Exception
  191.      */
  192.     public function load($pFilename)
  193.     {
  194.         // Check if file exists
  195.         if (!file_exists($pFilename)) {
  196.             throw new Exception("Could not open " $pFilename " for reading! File does not exist.");
  197.         }
  198.  
  199.         // Initialisations
  200.         $excel new PHPExcel;
  201.         $excel->removeSheetByIndex(0);
  202.         $zip new ZipArchive;
  203.         $zip->open($pFilename);
  204.  
  205.         $rels simplexml_load_string($zip->getFromName("_rels/.rels"))//~ http://schemas.openxmlformats.org/package/2006/relationships");
  206.         foreach ($rels->Relationship as $rel{
  207.             switch ($rel["Type"]{
  208.                 case "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties":
  209.                     $xmlCore simplexml_load_string($zip->getFromName("{$rel['Target']}"));
  210.                     $xmlCore->registerXPathNamespace("dc""http://purl.org/dc/elements/1.1/");
  211.                     $xmlCore->registerXPathNamespace("dcterms""http://purl.org/dc/terms/");
  212.                     $xmlCore->registerXPathNamespace("cp""http://schemas.openxmlformats.org/package/2006/metadata/core-properties");
  213.                     $docProps $excel->getProperties();
  214.                     $docProps->setCreator((string) self::array_item($xmlCore->xpath("dc:creator")));
  215.                     $docProps->setLastModifiedBy((string) self::array_item($xmlCore->xpath("cp:lastModifiedBy")));
  216.                     $docProps->setCreated(strtotime(self::array_item($xmlCore->xpath("dcterms:created"))))//! respect xsi:type
  217.                     $docProps->setModified(strtotime(self::array_item($xmlCore->xpath("dcterms:modified"))))//! respect xsi:type
  218.                     $docProps->setTitle((string) self::array_item($xmlCore->xpath("dc:title")));
  219.                     $docProps->setDescription((string) self::array_item($xmlCore->xpath("dc:description")));
  220.                     $docProps->setSubject((string) self::array_item($xmlCore->xpath("dc:subject")));
  221.                     $docProps->setKeywords((string) self::array_item($xmlCore->xpath("cp:keywords")));
  222.                     $docProps->setCategory((string) self::array_item($xmlCore->xpath("cp:category")));
  223.                 break;
  224.  
  225.                 case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument":
  226.                     $dir dirname($rel["Target"]);
  227.                     $relsWorkbook simplexml_load_string($zip->getFromName("$dir/_rels/basename($rel["Target"]".rels"));  //~ http://schemas.openxmlformats.org/package/2006/relationships");
  228.                     $relsWorkbook->registerXPathNamespace("rel""http://schemas.openxmlformats.org/package/2006/relationships");
  229.  
  230.                     $sharedStrings array();
  231.                     $xpath self::array_item($relsWorkbook->xpath("rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings']"));
  232.                     $xmlStrings simplexml_load_string($zip->getFromName("$dir/$xpath[Target]"));  //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
  233.                     if (isset($xmlStrings&& isset($xmlStrings->si)) {
  234.                         foreach ($xmlStrings->si as $val{
  235.                             if (isset($val->t)) {
  236.                                 $sharedStrings[PHPExcel_Shared_String::ControlCharacterOOXML2PHP(string) $val->);
  237.                             elseif (isset($val->r)) {
  238.                                 $sharedStrings[$this->_parseRichText($val);
  239.                             }
  240.                         }
  241.                     }
  242.  
  243.                     $worksheets array();
  244.                     foreach ($relsWorkbook->Relationship as $ele{
  245.                         if ($ele["Type"== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet"{
  246.                             $worksheets[(string) $ele["Id"]] $ele["Target"];
  247.                         }
  248.                     }
  249.  
  250.                     $styles array();
  251.                     $xpath self::array_item($relsWorkbook->xpath("rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles']"));
  252.                     $xmlStyles simplexml_load_string($zip->getFromName("$dir/$xpath[Target]"))//~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
  253.                     $numFmts $xmlStyles->numFmts[0];
  254.                     if ($numFmts{
  255.                         $numFmts->registerXPathNamespace("sml""http://schemas.openxmlformats.org/spreadsheetml/2006/main");
  256.                     }
  257.                     if (!$this->_readDataOnly{
  258.                         foreach ($xmlStyles->cellXfs->xf as $xf{
  259.                             $numFmt PHPExcel_Style_NumberFormat::FORMAT_GENERAL;
  260.                             if ($numFmts && $xf["numFmtId"]{
  261.                                 $tmpNumFmt self::array_item($numFmts->xpath("sml:numFmt[@numFmtId=$xf[numFmtId]]"));
  262.                                 if (isset($tmpNumFmt["formatCode"])) {
  263.                                     $numFmt = (string) $tmpNumFmt["formatCode"];
  264.                                 else if ((int)$xf["numFmtId"165{
  265.                                     $numFmt PHPExcel_Style_NumberFormat::builtInFormatCode((int)$xf["numFmtId"]);
  266.                                 }
  267.                             }
  268.                             //$numFmt = str_replace('mm', 'i', $numFmt);
  269.                             //$numFmt = str_replace('h', 'H', $numFmt);
  270.  
  271.                             $styles[= (object) array(
  272.                                 "numFmt" => $numFmt,
  273.                                 "font" => $xmlStyles->fonts->font[intval($xf["fontId"])],
  274.                                 "fill" => $xmlStyles->fills->fill[intval($xf["fillId"])],
  275.                                 "border" => $xmlStyles->borders->border[intval($xf["borderId"])],
  276.                                 "alignment" => $xf->alignment,
  277.                                 "protection" => $xf->protection,
  278.                                 "applyAlignment" => (isset($xf["applyAlignment"]&& ((string)$xf["applyAlignment"== 'true' || (string)$xf["applyAlignment"== '1')),
  279.                                 "applyBorder" => (isset($xf["applyBorder"]&& ((string)$xf["applyBorder"== 'true' || (string)$xf["applyBorder"== '1')),
  280.                                 "applyFill" => (isset($xf["applyFill"]&& ((string)$xf["applyFill"== 'true' || (string)$xf["applyFill"== '1')),
  281.                                 "applyFont" => (isset($xf["applyFont"]&& ((string)$xf["applyFont"== 'true' || (string)$xf["applyFont"== '1')),
  282.                                 "applyNumberFormat" => (isset($xf["applyNumberFormat"]&& ((string)$xf["applyNumberFormat"== 'true' || (string)$xf["applyNumberFormat"== '1')),
  283.                                 "applyProtection" => (isset($xf["applyProtection"]&& ((string)$xf["applyProtection"== 'true' || (string)$xf["applyProtection"== '1'))
  284.                             );
  285.                         }
  286.                     }
  287.  
  288.                     $dxfs array();
  289.                     if (!$this->_readDataOnly{
  290.                         foreach ($xmlStyles->dxfs->dxf as $dxf{
  291.                             $style new PHPExcel_Style;
  292.                             $this->_readStyle($style$dxf);
  293.                             $dxfs[$style;
  294.                         }
  295.                     }
  296.  
  297.                     $xmlWorkbook simplexml_load_string($zip->getFromName("{$rel['Target']}"));  //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
  298.                     $sheetId 0;
  299.                     foreach ($xmlWorkbook->sheets->sheet as $eleSheet{
  300.                         // Check if sheet should be skipped
  301.                         if (isset($this->_loadSheetsOnly&& !in_array((string) $eleSheet["name"]$this->_loadSheetsOnly)) {
  302.                             continue;
  303.                         }
  304.  
  305.                         // Load sheet
  306.                         $docSheet $excel->createSheet();
  307.                         $docSheet->setTitle((string) $eleSheet["name"]);
  308.                         $fileWorksheet $worksheets[(string) self::array_item($eleSheet->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships")"id")];
  309.                         $xmlSheet simplexml_load_string($zip->getFromName("$dir/$fileWorksheet"));  //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main");
  310.  
  311.                         $sharedFormulas array();
  312.  
  313.                         if (isset($xmlSheet->sheetViews&& isset($xmlSheet->sheetViews->sheetView)) {
  314.                             if (isset($xmlSheet->sheetViews->sheetView['showGridLines'])) {
  315.                                 $docSheet->setShowGridLines($xmlSheet->sheetViews->sheetView['showGridLines'true false);
  316.                             }
  317.                         }
  318.  
  319.                         if (isset($xmlSheet->sheetPr&& isset($xmlSheet->sheetPr->outlinePr)) {
  320.                             if (isset($xmlSheet->sheetPr->outlinePr['summaryRight']&& $xmlSheet->sheetPr->outlinePr['summaryRight'== false{
  321.                                 $docSheet->setShowSummaryRight(false);
  322.                             else {
  323.                                 $docSheet->setShowSummaryRight(true);
  324.                             }
  325.  
  326.                             if (isset($xmlSheet->sheetPr->outlinePr['summaryBelow']&& $xmlSheet->sheetPr->outlinePr['summaryBelow'== false{
  327.                                 $docSheet->setShowSummaryBelow(false);
  328.                             else {
  329.                                 $docSheet->setShowSummaryBelow(true);
  330.                             }
  331.                         }
  332.  
  333.                         if (isset($xmlSheet->sheetFormatPr)) {
  334.                             if (isset($xmlSheet->sheetFormatPr['customHeight']&& ((string)$xmlSheet->sheetFormatPr['customHeight'== '1' || strtolower((string)$xmlSheet->sheetFormatPr['customHeight']== 'true'&& isset($xmlSheet->sheetFormatPr['defaultRowHeight'])) {
  335.                                 $docSheet->getDefaultRowDimension()->setRowHeight(float)$xmlSheet->sheetFormatPr['defaultRowHeight');
  336.                             }
  337.                             if (isset($xmlSheet->sheetFormatPr['defaultColWidth'])) {
  338.                                 $docSheet->getDefaultColumnDimension()->setWidth(float)$xmlSheet->sheetFormatPr['defaultColWidth');
  339.                             }
  340.                         }
  341.  
  342.                         if (isset($xmlSheet->cols&& !$this->_readDataOnly{
  343.                             foreach ($xmlSheet->cols->col as $col{
  344.                                 for ($i intval($col["min"]1$i intval($col["max"])++$i{
  345.                                     if ($col["bestFit"]{
  346.                                         $docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setAutoSize(true);
  347.                                     }
  348.                                     if ($col["hidden"]{
  349.                                         $docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setVisible(false);
  350.                                     }
  351.                                     if ($col["collapsed"]{
  352.                                         $docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setCollapsed(true);
  353.                                     }
  354.                                     if ($col["outlineLevel"0{
  355.                                         $docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setOutlineLevel(intval($col["outlineLevel"]));
  356.                                     }
  357.                                     $docSheet->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($i))->setWidth(floatval($col["width"]));
  358.  
  359.                                     if (intval($col["max"]== 16384{
  360.                                         break;
  361.                                     }
  362.                                 }
  363.                             }
  364.                         }
  365.  
  366.                         if (isset($xmlSheet->printOptions&& !$this->_readDataOnly{
  367.                             if ($xmlSheet->printOptions['gridLinesSet'== 'true' && $xmlSheet->printOptions['gridLinesSet'== '1'{
  368.                                 $docSheet->setShowGridlines(true);
  369.                             }
  370.  
  371.                             if ($xmlSheet->printOptions['gridLines'== 'true' || $xmlSheet->printOptions['gridLines'== '1'{
  372.                                 $docSheet->setPrintGridlines(true);
  373.                             }
  374.  
  375.                             if ($xmlSheet->printOptions['horizontalCentered']{
  376.                                 $docSheet->getPageSetup()->setHorizontalCentered(true);
  377.                             }
  378.                             if ($xmlSheet->printOptions['verticalCentered']{
  379.                                 $docSheet->getPageSetup()->setVerticalCentered(true);
  380.                             }
  381.                         }
  382.  
  383.                         foreach ($xmlSheet->sheetData->row as $row{
  384.                             if ($row["ht"&& !$this->_readDataOnly{
  385.                                 $docSheet->getRowDimension(intval($row["r"]))->setRowHeight(floatval($row["ht"]));
  386.                             }
  387.                             if ($row["hidden"&& !$this->_readDataOnly{
  388.                                 $docSheet->getRowDimension(intval($row["r"]))->setVisible(false);
  389.                             }
  390.                             if ($row["collapsed"]{
  391.                                 $docSheet->getRowDimension(intval($row["r"]))->setCollapsed(true);
  392.                             }
  393.                             if ($row["outlineLevel"0{
  394.                                 $docSheet->getRowDimension(intval($row["r"]))->setOutlineLevel(intval($row["outlineLevel"]));
  395.                             }
  396.  
  397.                             foreach ($row->as $c{
  398.                                 $r = (string) $c["r"];
  399.                                 $cellDataType = (string) $c["t"];
  400.  
  401.                                 // Read cell?
  402.                                 if !is_null($this->getReadFilter()) ) {
  403.                                     $coordinates PHPExcel_Cell::coordinateFromString($r);
  404.  
  405.                                     if !$this->getReadFilter()->readCell($coordinates[0]$coordinates[1]$docSheet->getTitle()) ) {
  406.                                         break;
  407.                                     }
  408.                                 }
  409.  
  410.                                 // Read cell!
  411.                                 switch ($cellDataType{
  412.                                     case "s":
  413.                                         if ((string)$c->!= ''{
  414.                                             $value $sharedStrings[intval($c->v)];
  415.  
  416.                                             if ($value instanceof PHPExcel_RichText{
  417.                                                 $value clone $value;
  418.                                             }
  419.                                         else {
  420.                                             $value '';
  421.                                         }
  422.  
  423.                                         break;
  424.                                     case "b":
  425.                                         $value = (string)$c->v;
  426.                                         if ($value == '0'{
  427.                                             $value false;
  428.                                         else if ($value == '1'{
  429.                                             $value true;
  430.                                         else {
  431.                                             $value = (bool)$c->v;
  432.                                         }
  433.  
  434.                                         break;
  435.                                     case "inlineStr":
  436.                                         $value $this->_parseRichText($c->is);
  437.  
  438.                                         break;
  439.                                     case "e":
  440.                                         if (!isset($c->f)) {
  441.                                             $value = (string)$c->v;
  442.                                         else {
  443.                                             $value "={$c->f}";
  444.                                         }
  445.  
  446.                                         break;
  447.  
  448.                                     default:
  449.                                         if (!isset($c->f)) {
  450.                                             $value = (string) $c->v;
  451.                                         else {
  452.                                             // Formula
  453.                                             $value "={$c->f}";
  454.                                             $cellDataType 'f';
  455.  
  456.                                             // Shared formula?
  457.                                             if (isset($c->f['t']&& strtolower((string)$c->f['t']== 'shared'{
  458.                                                 $instance = (string)$c->f['si'];
  459.  
  460.                                                 if (!isset($sharedFormulas[(string)$c->f['si']])) {
  461.                                                     $sharedFormulas[$instancearray('master' => $r,
  462.                                                                                         'formula' => $value);
  463.                                                 else {
  464.                                                     $master PHPExcel_Cell::coordinateFromString($sharedFormulas[$instance]['master']);
  465.                                                     $current PHPExcel_Cell::coordinateFromString($r);
  466.  
  467.                                                     $difference array(00);
  468.                                                     $difference[0PHPExcel_Cell::columnIndexFromString($current[0]PHPExcel_Cell::columnIndexFromString$master[0]);
  469.                                                     $difference[1$current[1$master[1];
  470.  
  471.                                                     $helper PHPExcel_ReferenceHelper::getInstance();
  472.                                                     $x $helper->updateFormulaReferences(
  473.                                                         $sharedFormulas[$instance]['formula'],
  474.                                                         'A1',
  475.                                                         $difference[0],
  476.                                                         $difference[1]
  477.                                                     );
  478.  
  479.                                                     $value $x;
  480.                                                 }
  481.                                             }
  482.                                         }
  483.  
  484.                                         break;
  485.                                 }
  486.  
  487.                                 // Check for numeric values
  488.                                 if (is_numeric($value&& $cellDataType != 's'{
  489.                                     if ($value == (int)$value$value = (int)$value;
  490.                                     elseif ($value == (float)$value$value = (float)$value;
  491.                                     elseif ($value == (double)$value$value = (double)$value;
  492.                                 }
  493.  
  494.                                 // Rich text?
  495.                                 if ($value instanceof PHPExcel_RichText && $this->_readDataOnly{
  496.                                     $value $value->getPlainText();
  497.                                 }
  498.  
  499.                                 // Assign value
  500.                                 if ($cellDataType != ''{
  501.                                     $docSheet->setCellValueExplicit($r$value$cellDataType);
  502.                                 else {
  503.                                     $docSheet->setCellValue($r$value);
  504.                                 }
  505.  
  506.                                 // Style information?
  507.                                 if ($c["s"&& !$this->_readDataOnly{
  508.                                     if (isset($styles[intval($c["s"])])) {
  509.                                         $this->_readStyle($docSheet->getStyle($r)$styles[intval($c["s"])]);
  510.                                     }
  511.  
  512.                                     if ($cellDataType != 's' && PHPExcel_Shared_Date::isDateTimeFormat($docSheet->getStyle($r)->getNumberFormat())) {
  513.                                         if (preg_match ("/^([0-9.,-]+)$/"$value)) {
  514.                                             $docSheet->setCellValue($rPHPExcel_Shared_Date::ExcelToPHP($value));
  515.                                         }
  516.                                     }
  517.                                 }
  518.  
  519.                                 // Set rich text parent
  520.                                 if ($value instanceof PHPExcel_RichText && !$this->_readDataOnly{
  521.                                     $value->setParent($docSheet->getCell($r));
  522.                                 }
  523.                             }
  524.                         }
  525.  
  526.                         $conditionals array();
  527.                         if (!$this->_readDataOnly{
  528.                             foreach ($xmlSheet->conditionalFormatting as $conditional{
  529.                                 foreach ($conditional->cfRule as $cfRule{
  530.                                     if (
  531.                                         (
  532.                                             (string)$cfRule["type"== PHPExcel_Style_Conditional::CONDITION_NONE ||
  533.                                             (string)$cfRule["type"== PHPExcel_Style_Conditional::CONDITION_CELLIS ||
  534.                                             (string)$cfRule["type"== PHPExcel_Style_Conditional::CONDITION_CONTAINSTEXT
  535.                                         && isset($dxfs[intval($cfRule["dxfId"])])
  536.                                     {
  537.                                         $conditionals[(string) $conditional["sqref"]][intval($cfRule["priority"])$cfRule;
  538.                                     }
  539.                                 }
  540.                             }
  541.  
  542.                             foreach ($conditionals as $ref => $cfRules{
  543.                                 ksort($cfRules);
  544.                                 $conditionalStyles array();
  545.                                 foreach ($cfRules as $cfRule{
  546.                                     $objConditional new PHPExcel_Style_Conditional();
  547.                                     $objConditional->setConditionType((string) $cfRule["type"]);
  548.                                     $objConditional->setOperatorType((string) $cfRule["operator"]);
  549.                                     $objConditional->setCondition((string) $cfRule->formula);
  550.                                     $objConditional->setStyle(clone $dxfs[intval($cfRule["dxfId"])]);
  551.                                     $conditionalStyles[$objConditional;
  552.                                 }
  553.  
  554.                                 // Extract all cell references in $ref
  555.                                 $aReferences PHPExcel_Cell::extractAllCellReferencesInRange($ref);
  556.                                 foreach ($aReferences as $reference{
  557.                                     $docSheet->getStyle($reference)->setConditionalStyles($conditionalStyles);
  558.                                 }
  559.                             }
  560.                         }
  561.  
  562.                         $aKeys array("sheet""objects""scenarios""formatCells""formatColumns""formatRows""insertColumns""insertRows""insertHyperlinks""deleteColumns""deleteRows""selectLockedCells""sort""autoFilter""pivotTables""selectUnlockedCells");
  563.                         if (!$this->_readDataOnly{
  564.                             foreach ($aKeys as $key{
  565.                                 $method "set" ucfirst($key);
  566.                                 $docSheet->getProtection()->$method($xmlSheet->sheetProtection[$key== "true");
  567.                             }
  568.                         }
  569.  
  570.                         if (!$this->_readDataOnly{
  571.                             $docSheet->getProtection()->setPassword((string) $xmlSheet->sheetProtection["password"]true);
  572.                             if ($xmlSheet->protectedRanges->protectedRange{
  573.                                 foreach ($xmlSheet->protectedRanges->protectedRange as $protectedRange{
  574.                                     $docSheet->protectCells((string) $protectedRange["sqref"](string) $protectedRange["password"]true);
  575.                                 }
  576.                             }
  577.                         }
  578.  
  579.                         if ($xmlSheet->autoFilter && !$this->_readDataOnly{
  580.                             $docSheet->setAutoFilter((string) $xmlSheet->autoFilter["ref"]);
  581.                         }
  582.  
  583.                         if ($xmlSheet->mergeCells->mergeCell && !$this->_readDataOnly{
  584.                             foreach ($xmlSheet->mergeCells->mergeCell as $mergeCell{
  585.                                 $docSheet->mergeCells((string) $mergeCell["ref"]);
  586.                             }
  587.                         }
  588.  
  589.                         if (!$this->_readDataOnly{
  590.                             $docPageMargins $docSheet->getPageMargins();
  591.                             $docPageMargins->setLeft(floatval($xmlSheet->pageMargins["left"]));
  592.                             $docPageMargins->setRight(floatval($xmlSheet->pageMargins["right"]));
  593.                             $docPageMargins->setTop(floatval($xmlSheet->pageMargins["top"]));
  594.                             $docPageMargins->setBottom(floatval($xmlSheet->pageMargins["bottom"]));
  595.                             $docPageMargins->setHeader(floatval($xmlSheet->pageMargins["header"]));
  596.                             $docPageMargins->setFooter(floatval($xmlSheet->pageMargins["footer"]));
  597.                         }
  598.  
  599.                         if (!$this->_readDataOnly{
  600.                             $docPageSetup $docSheet->getPageSetup();
  601.  
  602.                             if (isset($xmlSheet->pageSetup["orientation"])) {
  603.                                 $docPageSetup->setOrientation((string) $xmlSheet->pageSetup["orientation"]);
  604.                             }
  605.                             if (isset($xmlSheet->pageSetup["paperSize"])) {
  606.                                 $docPageSetup->setPaperSize(intval($xmlSheet->pageSetup["paperSize"]));
  607.                             }
  608.                             if (isset($xmlSheet->pageSetup["scale"])) {
  609.                                 $docPageSetup->setScale(intval($xmlSheet->pageSetup["scale"]));
  610.                             }
  611.                             if (isset($xmlSheet->pageSetup["fitToHeight"]&& intval($xmlSheet->pageSetup["fitToHeight"]0{
  612.                                 $docPageSetup->setFitToHeight(intval($xmlSheet->pageSetup["fitToHeight"]));
  613.                             }
  614.                             if (isset($xmlSheet->pageSetup["fitToWidth"]&& intval($xmlSheet->pageSetup["fitToWidth"]0{
  615.                                 $docPageSetup->setFitToWidth(intval($xmlSheet->pageSetup["fitToWidth"]));
  616.                             }
  617.                         }
  618.  
  619.                         if (!$this->_readDataOnly{
  620.                             $docHeaderFooter $docSheet->getHeaderFooter();
  621.                             $docHeaderFooter->setDifferentOddEven($xmlSheet->headerFooter["differentOddEven"== 'true');
  622.                             $docHeaderFooter->setDifferentFirst($xmlSheet->headerFooter["differentFirst"== 'true');
  623.                             $docHeaderFooter->setScaleWithDocument($xmlSheet->headerFooter["scaleWithDoc"== 'true');
  624.                             $docHeaderFooter->setAlignWithMargins($xmlSheet->headerFooter["alignWithMargins"== 'true');
  625.                             $docHeaderFooter->setOddHeader((string) $xmlSheet->headerFooter->oddHeader);
  626.                             $docHeaderFooter->setOddFooter((string) $xmlSheet->headerFooter->oddFooter);
  627.                             $docHeaderFooter->setEvenHeader((string) $xmlSheet->headerFooter->evenHeader);
  628.                             $docHeaderFooter->setEvenFooter((string) $xmlSheet->headerFooter->evenFooter);
  629.                             $docHeaderFooter->setFirstHeader((string) $xmlSheet->headerFooter->firstHeader);
  630.                             $docHeaderFooter->setFirstFooter((string) $xmlSheet->headerFooter->firstFooter);
  631.                         }
  632.  
  633.                         if ($xmlSheet->rowBreaks->brk && !$this->_readDataOnly{
  634.                             foreach ($xmlSheet->rowBreaks->brk as $brk{
  635.                                 if ($brk["man"]{
  636.                                     $docSheet->setBreak("A$brk[id]"PHPExcel_Worksheet::BREAK_ROW);
  637.                                 }
  638.                             }
  639.                         }
  640.                         if ($xmlSheet->colBreaks->brk && !$this->_readDataOnly{
  641.                             foreach ($xmlSheet->colBreaks->brk as $brk{
  642.                                 if ($brk["man"]{
  643.                                     $docSheet->setBreak(PHPExcel_Cell::stringFromColumnIndex($brk["id"]"1"PHPExcel_Worksheet::BREAK_COLUMN);
  644.                                 }
  645.                             }
  646.                         }
  647.  
  648.                         if ($xmlSheet->dataValidations && !$this->_readDataOnly{
  649.                             foreach ($xmlSheet->dataValidations->dataValidation as $dataValidation{
  650.                                 // Uppercase coordinate
  651.                                 $range strtoupper($dataValidation["sqref"]);
  652.  
  653.                                 // Extract all cell references in $range
  654.                                 $aReferences PHPExcel_Cell::extractAllCellReferencesInRange($range);
  655.                                 foreach ($aReferences as $reference{
  656.                                     // Create validation
  657.                                     $docValidation $docSheet->getCell($reference)->getDataValidation();
  658.                                     $docValidation->setType((string) $dataValidation["type"]);
  659.                                     $docValidation->setErrorStyle((string) $dataValidation["errorStyle"]);
  660.                                     $docValidation->setOperator((string) $dataValidation["operator"]);
  661.                                     $docValidation->setAllowBlank($dataValidation["allowBlank"!= 0);
  662.                                     $docValidation->setShowDropDown($dataValidation["showDropDown"== 0);
  663.                                     $docValidation->setShowInputMessage($dataValidation["showInputMessage"!= 0);
  664.                                     $docValidation->setShowErrorMessage($dataValidation["showErrorMessage"!= 0);
  665.                                     $docValidation->setErrorTitle((string) $dataValidation["errorTitle"]);
  666.                                     $docValidation->setError((string) $dataValidation["error"]);
  667.                                     $docValidation->setPromptTitle((string) $dataValidation["promptTitle"]);
  668.                                     $docValidation->setPrompt((string) $dataValidation["prompt"]);
  669.                                     $docValidation->setFormula1((string) $dataValidation->formula1);
  670.                                     $docValidation->setFormula2((string) $dataValidation->formula2);
  671.                                 }
  672.                             }
  673.                         }
  674.  
  675.                         // Add hyperlinks
  676.                         $hyperlinks array();
  677.                         if (!$this->_readDataOnly{
  678.                             // Locate hyperlink relations
  679.                             if ($zip->locateName(dirname("$dir/$fileWorksheet""/_rels/" basename($fileWorksheet".rels")) {
  680.                                 $relsWorksheet simplexml_load_string($zip->getFromNamedirname("$dir/$fileWorksheet""/_rels/" basename($fileWorksheet".rels") )//~ http://schemas.openxmlformats.org/package/2006/relationships");
  681.                                 foreach ($relsWorksheet->Relationship as $ele{
  682.                                     if ($ele["Type"== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"{
  683.                                         $hyperlinks[(string)$ele["Id"]] = (string)$ele["Target"];
  684.                                     }
  685.                                 }
  686.                             }
  687.  
  688.                             // Loop trough hyperlinks
  689.                             if ($xmlSheet->hyperlinks{
  690.                                 foreach ($xmlSheet->hyperlinks->hyperlink as $hyperlink{
  691.                                     // Link url
  692.                                     $linkRel $hyperlink->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships');
  693.  
  694.                                     if (isset($linkRel['id'])) {
  695.                                         $docSheet->getCell$hyperlink['ref')->getHyperlink()->setUrl$hyperlinks(string)$linkRel['id'] ] );
  696.                                     }
  697.                                     if (isset($hyperlink['location'])) {
  698.                                         $docSheet->getCell$hyperlink['ref')->getHyperlink()->setUrl'sheet://' . (string)$hyperlink['location');
  699.                                     }
  700.  
  701.                                     // Tooltip
  702.                                     if (isset($hyperlink['tooltip'])) {
  703.                                         $docSheet->getCell$hyperlink['ref')->getHyperlink()->setTooltip(string)$hyperlink['tooltip');
  704.                                     }
  705.                                 }
  706.                             }
  707.                         }
  708.  
  709.                         // Add comments
  710.                         $comments array();
  711.                         if (!$this->_readDataOnly{
  712.                             // Locate comment relations
  713.                             if ($zip->locateName(dirname("$dir/$fileWorksheet""/_rels/" basename($fileWorksheet".rels")) {
  714.                                 $relsWorksheet simplexml_load_string($zip->getFromNamedirname("$dir/$fileWorksheet""/_rels/" basename($fileWorksheet".rels") )//~ http://schemas.openxmlformats.org/package/2006/relationships");
  715.                                 foreach ($relsWorksheet->Relationship as $ele{
  716.                                     if ($ele["Type"== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"{
  717.                                         $comments[(string)$ele["Id"]] = (string)$ele["Target"];
  718.                                     }
  719.                                 }
  720.                             }
  721.  
  722.                             // Loop trough comments
  723.                             foreach ($comments as $relName => $relPath{
  724.                                 // Load comments file
  725.                                 $relPath PHPExcel_Shared_File::realpath(dirname("$dir/$fileWorksheet""/" $relPath);
  726.                                 $commentsFile simplexml_load_string($zip->getFromName($relPath) );
  727.  
  728.                                 // Utility variables
  729.                                 $authors array();
  730.  
  731.                                 // Loop trough authors
  732.                                 foreach ($commentsFile->authors->author as $author{
  733.                                     $authors[= (string)$author;
  734.                                 }
  735.  
  736.                                 // Loop trough contents
  737.                                 foreach ($commentsFile->commentList->comment as $comment{
  738.                                     $docSheet->getComment(string)$comment['ref')->setAuthor$authors[(string)$comment['authorId']] );
  739.                                     $docSheet->getComment(string)$comment['ref')->setText$this->_parseRichText($comment->text) );
  740.                                 }
  741.                             }
  742.  
  743.                             // Header/footer images
  744.                             if ($xmlSheet->legacyDrawingHF && !$this->_readDataOnly{
  745.                                 if ($zip->locateName(dirname("$dir/$fileWorksheet""/_rels/" basename($fileWorksheet".rels")) {
  746.                                     $relsWorksheet simplexml_load_string($zip->getFromNamedirname("$dir/$fileWorksheet""/_rels/" basename($fileWorksheet".rels") )//~ http://schemas.openxmlformats.org/package/2006/relationships");
  747.                                     $vmlRelationship '';
  748.  
  749.                                     foreach ($relsWorksheet->Relationship as $ele{
  750.                                         if ($ele["Type"== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing"{
  751.                                             $vmlRelationship self::dir_add("$dir/$fileWorksheet"$ele["Target"]);
  752.                                         }
  753.                                     }
  754.  
  755.                                     if ($vmlRelationship != ''{
  756.                                         // Fetch linked images
  757.                                         $relsVML simplexml_load_string($zip->getFromNamedirname($vmlRelationship'/_rels/' basename($vmlRelationship'.rels' ))//~ http://schemas.openxmlformats.org/package/2006/relationships");
  758.                                         $drawings array();
  759.                                         foreach ($relsVML->Relationship as $ele{
  760.                                             if ($ele["Type"== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"{
  761.                                                 $drawings[(string) $ele["Id"]] self::dir_add($vmlRelationship$ele["Target"]);
  762.                                             }
  763.                                         }
  764.  
  765.                                         // Fetch VML document
  766.                                         $vmlDrawing simplexml_load_string($zip->getFromName($vmlRelationship));
  767.                                         $vmlDrawing->registerXPathNamespace('v''urn:schemas-microsoft-com:vml');
  768.  
  769.                                         $hfImages array();
  770.  
  771.                                         $shapes $vmlDrawing->xpath('//v:shape');
  772.                                         foreach ($shapes as $shape{
  773.                                             $shape->registerXPathNamespace('v''urn:schemas-microsoft-com:vml');
  774.                                             $imageData $shape->xpath('//v:imagedata');
  775.                                             $imageData $imageData[0];
  776.  
  777.                                             $imageData $imageData->attributes('urn:schemas-microsoft-com:office:office');
  778.                                             $style self::toCSSArray(string)$shape['style');
  779.  
  780.                                             $hfImages(string)$shape['id'] ] new PHPExcel_Worksheet_HeaderFooterDrawing();
  781.                                             if (isset($imageData['title'])) {
  782.                                                 $hfImages(string)$shape['id'] ]->setName(string)$imageData['title');
  783.                                             }
  784.  
  785.                                             $hfImages(string)$shape['id'] ]->setPath("zip://$pFilename#$drawings[(string)$imageData['relid']]false);
  786.                                             $hfImages(string)$shape['id'] ]->setResizeProportional(false);
  787.                                             $hfImages(string)$shape['id'] ]->setWidth($style['width']);
  788.                                             $hfImages(string)$shape['id'] ]->setHeight($style['height']);
  789.                                             $hfImages(string)$shape['id'] ]->setOffsetX($style['margin-left']);
  790.                                             $hfImages(string)$shape['id'] ]->setOffsetY($style['margin-top']);
  791.                                             $hfImages(string)$shape['id'] ]->setResizeProportional(true);
  792.                                         }
  793.  
  794.                                         $docSheet->getHeaderFooter()->setImages($hfImages);
  795.                                     }
  796.                                 }
  797.                             }
  798.  
  799.                         }
  800.  
  801. // TODO: Make sure drawings and graph are loaded differently!
  802.                         if ($zip->locateName(dirname("$dir/$fileWorksheet""/_rels/" basename($fileWorksheet".rels")) {
  803.                             $relsWorksheet simplexml_load_string($zip->getFromNamedirname("$dir/$fileWorksheet""/_rels/" basename($fileWorksheet".rels") )//~ http://schemas.openxmlformats.org/package/2006/relationships");
  804.                             $drawings array();
  805.                             foreach ($relsWorksheet->Relationship as $ele{
  806.                                 if ($ele["Type"== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing"{
  807.                                     $drawings[(string) $ele["Id"]] self::dir_add("$dir/$fileWorksheet"$ele["Target"]);
  808.                                 }
  809.                             }
  810.                             if ($xmlSheet->drawing && !$this->_readDataOnly{
  811.                                 foreach ($xmlSheet->drawing as $drawing{
  812.                                     $fileDrawing $drawings[(string) self::array_item($drawing->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships")"id")];
  813.                                     $relsDrawing simplexml_load_string($zip->getFromNamedirname($fileDrawing"/_rels/" basename($fileDrawing".rels") )//~ http://schemas.openxmlformats.org/package/2006/relationships");
  814.                                     $images array();
  815.  
  816.                                     if ($relsDrawing && $relsDrawing->Relationship{
  817.                                         foreach ($relsDrawing->Relationship as $ele{
  818.                                             if ($ele["Type"== "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image"{
  819.                                                 $images[(string) $ele["Id"]] self::dir_add($fileDrawing$ele["Target"]);
  820.                                             }
  821.                                         }
  822.                                     }
  823.                                     $xmlDrawing simplexml_load_string($zip->getFromName($fileDrawing))->children("http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing");
  824.  
  825.                                     if ($xmlDrawing->oneCellAnchor{
  826.                                         foreach ($xmlDrawing->oneCellAnchor as $oneCellAnchor{
  827.                                             if ($oneCellAnchor->pic->blipFill{
  828.                                                 $blip $oneCellAnchor->pic->blipFill->children("http://schemas.openxmlformats.org/drawingml/2006/main")->blip;
  829.                                                 $xfrm $oneCellAnchor->pic->spPr->children("http://schemas.openxmlformats.org/drawingml/2006/main")->xfrm;
  830.                                                 $outerShdw $oneCellAnchor->pic->spPr->children("http://schemas.openxmlformats.org/drawingml/2006/main")->effectLst->outerShdw;
  831.                                                 $objDrawing new PHPExcel_Worksheet_Drawing;
  832.                                                 $objDrawing->setName((string) self::array_item($oneCellAnchor->pic->nvPicPr->cNvPr->attributes()"name"));
  833.                                                 $objDrawing->setDescription((string) self::array_item($oneCellAnchor->pic->nvPicPr->cNvPr->attributes()"descr"));
  834.                                                 $objDrawing->setPath("zip://$pFilename#$images[(string) self::array_item($blip->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships")"embed")]false);
  835.                                                 $objDrawing->setCoordinates(PHPExcel_Cell::stringFromColumnIndex($oneCellAnchor->from->col($oneCellAnchor->from->row 1));
  836.                                                 $objDrawing->setOffsetX(PHPExcel_Shared_Drawing::EMUToPixels($oneCellAnchor->from->colOff));
  837.                                                 $objDrawing->setOffsetY(PHPExcel_Shared_Drawing::EMUToPixels($oneCellAnchor->from->rowOff));
  838.                                                 $objDrawing->setResizeProportional(false);
  839.                                                 $objDrawing->setWidth(PHPExcel_Shared_Drawing::EMUToPixels(self::array_item($oneCellAnchor->ext->attributes()"cx")));
  840.                                                 $objDrawing->setHeight(PHPExcel_Shared_Drawing::EMUToPixels(self::array_item($oneCellAnchor->ext->attributes()"cy")));
  841.                                                 if ($xfrm{
  842.                                                     $objDrawing->setRotation(PHPExcel_Shared_Drawing::angleToDegrees(self::array_item($xfrm->attributes()"rot")));
  843.                                                 }
  844.                                                 if ($outerShdw{
  845.                                                     $shadow $objDrawing->getShadow();
  846.                                                     $shadow->setVisible(true);
  847.                                                     $shadow->setBlurRadius(PHPExcel_Shared_Drawing::EMUTopixels(self::array_item($outerShdw->attributes()"blurRad")));
  848.                                                     $shadow->setDistance(PHPExcel_Shared_Drawing::EMUTopixels(self::array_item($outerShdw->attributes()"dist")));
  849.                                                     $shadow->setDirection(PHPExcel_Shared_Drawing::angleToDegrees(self::array_item($outerShdw->attributes()"dir")));
  850.                                                     $shadow->setAlignment((string) self::array_item($outerShdw->attributes()"algn"));
  851.                                                     $shadow->getColor()->setRGB(self::array_item($outerShdw->srgbClr->attributes()"val"));
  852.                                                     $shadow->setAlpha(self::array_item($outerShdw->srgbClr->alpha->attributes()"val"1000);
  853.                                                 }
  854.                                                 $objDrawing->setWorksheet($docSheet);
  855.                                             }
  856.                                         }
  857.                                     }
  858.                                     if ($xmlDrawing->twoCellAnchor{
  859.                                         foreach ($xmlDrawing->twoCellAnchor as $twoCellAnchor{
  860.                                             if ($twoCellAnchor->pic->blipFill{
  861.                                                 $blip $twoCellAnchor->pic->blipFill->children("http://schemas.openxmlformats.org/drawingml/2006/main")->blip;
  862.                                                 $xfrm $twoCellAnchor->pic->spPr->children("http://schemas.openxmlformats.org/drawingml/2006/main")->xfrm;
  863.                                                 $outerShdw $twoCellAnchor->pic->spPr->children("http://schemas.openxmlformats.org/drawingml/2006/main")->effectLst->outerShdw;
  864.                                                 $objDrawing new PHPExcel_Worksheet_Drawing;
  865.                                                 $objDrawing->setName((string) self::array_item($twoCellAnchor->pic->nvPicPr->cNvPr->attributes()"name"));
  866.                                                 $objDrawing->setDescription((string) self::array_item($twoCellAnchor->pic->nvPicPr->cNvPr->attributes()"descr"));
  867.                                                 $objDrawing->setPath("zip://$pFilename#$images[(string) self::array_item($blip->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships")"embed")]false);
  868.                                                 $objDrawing->setCoordinates(PHPExcel_Cell::stringFromColumnIndex($twoCellAnchor->from->col($twoCellAnchor->from->row 1));
  869.                                                 $objDrawing->setOffsetX(PHPExcel_Shared_Drawing::EMUToPixels($twoCellAnchor->from->colOff));
  870.                                                 $objDrawing->setOffsetY(PHPExcel_Shared_Drawing::EMUToPixels($twoCellAnchor->from->rowOff));
  871.                                                 $objDrawing->setResizeProportional(false);
  872.  
  873.                                                 $objDrawing->setWidth(PHPExcel_Shared_Drawing::EMUToPixels(self::array_item($xfrm->ext->attributes()"cx")));
  874.                                                 $objDrawing->setHeight(PHPExcel_Shared_Drawing::EMUToPixels(self::array_item($xfrm->ext->attributes()"cy")));
  875.  
  876.                                                 if ($xfrm{
  877.                                                     $objDrawing->setRotation(PHPExcel_Shared_Drawing::angleToDegrees(self::array_item($xfrm->attributes()"rot")));
  878.                                                 }
  879.                                                 if ($outerShdw{
  880.                                                     $shadow $objDrawing->getShadow();
  881.                                                     $shadow->setVisible(true);
  882.                                                     $shadow->setBlurRadius(PHPExcel_Shared_Drawing::EMUTopixels(self::array_item($outerShdw->attributes()"blurRad")));
  883.                                                     $shadow->setDistance(PHPExcel_Shared_Drawing::EMUTopixels(self::array_item($outerShdw->attributes()"dist")));
  884.                                                     $shadow->setDirection(PHPExcel_Shared_Drawing::angleToDegrees(self::array_item($outerShdw->attributes()"dir")));
  885.                                                     $shadow->setAlignment((string) self::array_item($outerShdw->attributes()"algn"));
  886.                                                     $shadow->getColor()->setRGB(self::array_item($outerShdw->srgbClr->attributes()"val"));
  887.                                                     $shadow->setAlpha(self::array_item($outerShdw->srgbClr->alpha->attributes()"val"1000);
  888.                                                 }
  889.                                                 $objDrawing->setWorksheet($docSheet);
  890.                                             }
  891.                                         }
  892.                                     }
  893.  
  894.                                 }
  895.                             }
  896.                         }
  897.  
  898.                         // Loop trough definedNames
  899.                         if ($xmlWorkbook->definedNames{
  900.                             foreach ($xmlWorkbook->definedNames->definedName as $definedName{
  901.                                 // Extract range
  902.                                 $extractedRange = (string)$definedName;
  903.                                 if (strpos($extractedRange'!'!== false{
  904.                                     $extractedRange substr($extractedRangestrpos($extractedRange'!'1);
  905.                                 }
  906.                                 $extractedRange str_replace('$'''$extractedRange);
  907.  
  908.                                 // Valid range?
  909.                                 if (stripos((string)$definedName'#REF!'!== false || $extractedRange == ''{
  910.                                     continue;
  911.                                 }
  912.  
  913.                                 // Some definedNames are only applicable if we are on the same sheet...
  914.                                 if ($definedName['localSheetId'== $sheetId{
  915.                                     // Switch on type
  916.                                     switch ((string)$definedName['name']{
  917.  
  918.                                         case '_xlnm._FilterDatabase':
  919.                                             $docSheet->setAutoFilter($extractedRange);
  920.                                             break;
  921.  
  922.                                         case '_xlnm.Print_Titles':
  923.                                             // Split $extractedRange
  924.                                             $extractedRange explode(','$extractedRange);
  925.  
  926.                                             // Set print titles
  927.                                             if (isset($extractedRange[0])) {
  928.                                                 $range explode(':'$extractedRange[0]);
  929.  
  930.                                                 if (PHPExcel_Worksheet::extractSheetTitle($range[0]!= '')
  931.                                                     $range[0PHPExcel_Worksheet::extractSheetTitle($range[0]);
  932.                                                 $range[0str_replace('$'''$range[0]);
  933.                                                 if (PHPExcel_Worksheet::extractSheetTitle($range[1]!= '')
  934.                                                     $range[1PHPExcel_Worksheet::extractSheetTitle($range[1]);
  935.                                                 $range[1str_replace('$'''$range[1]);
  936.  
  937.                                                 $docSheet->getPageSetup()->setColumnsToRepeatAtLeft$range );
  938.                                             }
  939.                                             if (isset($extractedRange[1])) {
  940.                                                 $range explode(':'$extractedRange[1]);
  941.  
  942.                                                 if (PHPExcel_Worksheet::extractSheetTitle($range[0]!= '')
  943.                                                     $range[0PHPExcel_Worksheet::extractSheetTitle($range[0]);
  944.                                                 $range[0str_replace('$'''$range[0]);
  945.                                                 if (PHPExcel_Worksheet::extractSheetTitle($range[1]!= '')
  946.                                                     $range[1PHPExcel_Worksheet::extractSheetTitle($range[1]);
  947.                                                 $range[1str_replace('$'''$range[1]);
  948.  
  949.                                                 $docSheet->getPageSetup()->setRowsToRepeatAtTop$range );
  950.                                             }
  951.  
  952.                                             break;
  953.  
  954.                                         case '_xlnm.Print_Area':
  955.                                             $docSheet->getPageSetup()->setPrintArea($extractedRange);
  956.                                             break;
  957.  
  958.                                         default:
  959.                                             $excel->addNamedRangenew PHPExcel_NamedRange((string)$definedName['name']$docSheet$extractedRangetrue) );
  960.                                             break;
  961.                                     }
  962.                                 else {
  963.                                     // "Global" definedNames
  964.                                     $locatedSheet null;
  965.                                     $extractedSheetName '';
  966.                                     if (strpos(string)$definedName'!' !== false{
  967.                                         // Extract sheet name
  968.                                         $extractedSheetName PHPExcel_Worksheet::extractSheetTitle(string)$definedName );
  969.  
  970.                                         // Locate sheet
  971.                                         $locatedSheet $excel->getSheetByName($extractedSheetName);
  972.                                     }
  973.  
  974.                                     if (!is_null($locatedSheet)) {
  975.                                         $excel->addNamedRangenew PHPExcel_NamedRange((string)$definedName['name']$locatedSheet$extractedRangefalse) );
  976.                                     }
  977.                                 }
  978.                             }
  979.                         }
  980.  
  981.                         // Garbage collect...
  982.                         $docSheet->garbageCollect();
  983.  
  984.                         // Next sheet id
  985.                         ++$sheetId;
  986.                     }
  987.  
  988.                     if (!$this->_readDataOnly{
  989.                         $excel->setActiveSheetIndex(intval($xmlWorkbook->bookView->workbookView["activeTab"]));
  990.                     }
  991.                 break;
  992.             }
  993.  
  994.         }
  995.  
  996.         return $excel;
  997.     }
  998.  
  999.     private function _readColor($color{
  1000.         if (isset($color["rgb"])) {
  1001.             return $color["rgb"];
  1002.         else if (isset($color["indexed"])) {
  1003.             return PHPExcel_Style_Color::indexedColor($color["indexed"])->getARGB();
  1004.         }
  1005.     }
  1006.  
  1007.     private function _readStyle($docStyle$style{
  1008.         // format code
  1009.         if ($style->applyNumberFormat$docStyle->getNumberFormat()->setFormatCode($style->numFmt);
  1010.  
  1011.         // font
  1012.         if (isset($style->font&& ($style->applyFont || $style instanceof SimpleXMLElement)) {
  1013.             $docStyle->getFont()->setName((string) $style->font->name["val"]);
  1014.             $docStyle->getFont()->setSize((string) $style->font->sz["val"]);
  1015.             if (isset($style->font->b)) {
  1016.                 $docStyle->getFont()->setBold(!isset($style->font->b["val"]|| $style->font->b["val"== 'true');
  1017.             }
  1018.             if (isset($style->font->i)) {
  1019.                 $docStyle->getFont()->setItalic(!isset($style->font->i["val"]|| $style->font->i["val"== 'true');
  1020.             }
  1021.             if (isset($style->font->strike)) {
  1022.                 $docStyle->getFont()->setStriketrough(!isset($style->font->strike["val"]|| $style->font->strike["val"== 'true');
  1023.             }
  1024.             $docStyle->getFont()->getColor()->setARGB($this->_readColor($style->font->color));
  1025.  
  1026.             if (isset($style->font->u&& !isset($style->font->u["val"])) {
  1027.                 $docStyle->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);
  1028.             else if (isset($style->font->u&& isset($style->font->u["val"])) {
  1029.                 $docStyle->getFont()->setUnderline((string)$style->font->u["val"]);
  1030.             }
  1031.  
  1032.             if (isset($style->font->vertAlign&& isset($style->font->vertAlign["val"])) {
  1033.                 $vertAlign strtolower((string)$style->font->vertAlign["val"]);
  1034.                 if ($vertAlign == 'superscript'{
  1035.                     $docStyle->getFont()->setSuperScript(true);
  1036.                 }
  1037.                 if ($vertAlign == 'subscript'{
  1038.                     $docStyle->getFont()->setSubScript(true);
  1039.                 }
  1040.             }
  1041.         }
  1042.  
  1043.         // fill
  1044.         if (isset($style->fill&& ($style->applyFill || $style instanceof SimpleXMLElement)) {
  1045.             if ($style->fill->gradientFill{
  1046.                 $gradientFill $style->fill->gradientFill[0];
  1047.                 $docStyle->getFill()->setFillType((string) $gradientFill["type"]);
  1048.                 $docStyle->getFill()->setRotation(floatval($gradientFill["degree"]));
  1049.                 $gradientFill->registerXPathNamespace("sml""http://schemas.openxmlformats.org/spreadsheetml/2006/main");
  1050.                 $docStyle->getFill()->getStartColor()->setARGB($this->_readColorself::array_item($gradientFill->xpath("sml:stop[@position=0]"))->color) );
  1051.                 $docStyle->getFill()->getEndColor()->setARGB($this->_readColorself::array_item($gradientFill->xpath("sml:stop[@position=1]"))->color) );
  1052.             elseif ($style->fill->patternFill{
  1053.                 $patternType = (string)$style->fill->patternFill["patternType"!= '' ? (string)$style->fill->patternFill["patternType"'solid';
  1054.                 $docStyle->getFill()->setFillType($patternType);
  1055.                 if ($style->fill->patternFill->fgColor{
  1056.                     $docStyle->getFill()->getStartColor()->setARGB($this->_readColor($style->fill->patternFill->fgColor));
  1057.                 }
  1058.                 if ($style->fill->patternFill->bgColor{
  1059.                     $docStyle->getFill()->getEndColor()->setARGB($this->_readColor($style->fill->patternFill->bgColor));
  1060.                 }
  1061.             }
  1062.         }
  1063.  
  1064.         // border
  1065.         if (isset($style->border&& ($style->applyBorder || $style instanceof SimpleXMLElement)) {
  1066.             if ($style->border["diagonalUp"== 'true'{
  1067.                 $docStyle->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_UP);
  1068.             elseif ($style->border["diagonalDown"== 'true'{
  1069.                 $docStyle->getBorders()->setDiagonalDirection(PHPExcel_Style_Borders::DIAGONAL_DOWN);
  1070.             }
  1071.             $docStyle->getBorders()->setOutline($style->border["outline"== 'true');
  1072.             $this->_readBorder($docStyle->getBorders()->getLeft()$style->border->left);
  1073.             $this->_readBorder($docStyle->getBorders()->getRight()$style->border->right);
  1074.             $this->_readBorder($docStyle->getBorders()->getTop()$style->border->top);
  1075.             $this->_readBorder($docStyle->getBorders()->getBottom()$style->border->bottom);
  1076.             $this->_readBorder($docStyle->getBorders()->getDiagonal()$style->border->diagonal);
  1077.             $this->_readBorder($docStyle->getBorders()->getVertical()$style->border->vertical);
  1078.             $this->_readBorder($docStyle->getBorders()->getHorizontal()$style->border->horizontal);
  1079.         }
  1080.  
  1081.         // alignment
  1082.         if (isset($style->alignment&& ($style->applyAlignment || $style instanceof SimpleXMLElement)) {
  1083.             $docStyle->getAlignment()->setHorizontal((string) $style->alignment["horizontal"]);
  1084.             $docStyle->getAlignment()->setVertical((string) $style->alignment["vertical"]);
  1085.  
  1086.             $textRotation 0;
  1087.             if ((int)$style->alignment["textRotation"<= 90{
  1088.                 $textRotation = (int)$style->alignment["textRotation"];
  1089.             else if ((int)$style->alignment["textRotation"90{
  1090.                 $textRotation 90 - (int)$style->alignment["textRotation"];
  1091.             }
  1092.  
  1093.             $docStyle->getAlignment()->setTextRotation(intval($textRotation));
  1094.             $docStyle->getAlignment()->setWrapText(string)$style->alignment["wrapText"== "true" || (string)$style->alignment["wrapText"== "1" );
  1095.             $docStyle->getAlignment()->setShrinkToFit(string)$style->alignment["shrinkToFit"== "true" || (string)$style->alignment["shrinkToFit"== "1" );
  1096.             $docStyle->getAlignment()->setIndentintval((string)$style->alignment["indent"]intval((string)$style->alignment["indent"]);
  1097.         }
  1098.  
  1099.         // protection
  1100.         if (isset($style->protection&& $style->applyProtection{
  1101.             if (isset($style->protection['locked'])) {
  1102.                 if ((string)$style->protection['locked'== 'true'{
  1103.                     $docStyle->getProtection()->setLocked(PHPExcel_Style_Protection::PROTECTION_PROTECTED);
  1104.                 else {
  1105.                     $docStyle->getProtection()->setLocked(PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);
  1106.                 }
  1107.             }
  1108.  
  1109.             if (isset($style->protection['hidden'])) {
  1110.                 if ((string)$style->protection['hidden'== 'true'{
  1111.                     $docStyle->getProtection()->setHidden(PHPExcel_Style_Protection::PROTECTION_PROTECTED);
  1112.                 else {
  1113.                     $docStyle->getProtection()->setHidden(PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);
  1114.                 }
  1115.             }
  1116.         }
  1117.     }
  1118.  
  1119.     private function _readBorder($docBorder$eleBorder{
  1120.         if (isset($eleBorder["style"])) {
  1121.             $docBorder->setBorderStyle((string) $eleBorder["style"]);
  1122.         }
  1123.         if (isset($eleBorder->color)) {
  1124.             $docBorder->getColor()->setARGB($this->_readColor($eleBorder->color));
  1125.         }
  1126.     }
  1127.  
  1128.     private function _parseRichText($is null{
  1129.         $value new PHPExcel_RichText();
  1130.  
  1131.         if (isset($is->t)) {
  1132.             $value->createTextPHPExcel_Shared_String::ControlCharacterOOXML2PHP(string) $is->) );
  1133.         else {
  1134.             foreach ($is->as $run{
  1135.                 $objText $value->createTextRunPHPExcel_Shared_String::ControlCharacterOOXML2PHP(string) $run->) );
  1136.  
  1137.                 if (isset($run->rPr)) {
  1138.                     if (isset($run->rPr->rFont["val"])) {
  1139.                         $objText->getFont()->setName((string) $run->rPr->rFont["val"]);
  1140.                     }
  1141.  
  1142.                     if (isset($run->rPr->sz["val"])) {
  1143.                         $objText->getFont()->setSize((string) $run->rPr->sz["val"]);
  1144.                     }
  1145.  
  1146.                     if (isset($run->rPr->color)) {
  1147.                         $objText->getFont()->setColornew PHPExcel_Style_Color$this->_readColor($run->rPr->color) ) );
  1148.                     }
  1149.  
  1150.                     if ( (isset($run->rPr->b["val"]&& ((string) $run->rPr->b["val"== 'true' || (string) $run->rPr->b["val"== '1'))
  1151.                          || (isset($run->rPr->b&& !isset($run->rPr->b["val"])) ) {
  1152.                         $objText->getFont()->setBold(true);
  1153.                     }
  1154.  
  1155.                     if ( (isset($run->rPr->i["val"]&& ((string) $run->rPr->i["val"== 'true' || (string) $run->rPr->i["val"== '1'))
  1156.                          || (isset($run->rPr->i&& !isset($run->rPr->i["val"])) ) {
  1157.                         $objText->getFont()->setItalic(true);
  1158.                     }
  1159.  
  1160.                     if (isset($run->rPr->vertAlign&& isset($run->rPr->vertAlign["val"])) {
  1161.                         $vertAlign strtolower((string)$run->rPr->vertAlign["val"]);
  1162.                         if ($vertAlign == 'superscript'{
  1163.                             $objText->getFont()->setSuperScript(true);
  1164.                         }
  1165.                         if ($vertAlign == 'subscript'{
  1166.                             $objText->getFont()->setSubScript(true);
  1167.                         }
  1168.                     }
  1169.  
  1170.                     if (isset($run->rPr->u&& !isset($run->rPr->u["val"])) {
  1171.                         $objText->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);
  1172.                     else if (isset($run->rPr->u&& isset($run->rPr->u["val"])) {
  1173.                         $objText->getFont()->setUnderline((string)$run->rPr->u["val"]);
  1174.                     }
  1175.  
  1176.                     if ( (isset($run->rPr->strike["val"])  && ((string) $run->rPr->strike["val"== 'true' || (string) $run->rPr->strike["val"== '1'))
  1177.                          || (isset($run->rPr->strike&& !isset($run->rPr->strike["val"])) ) {
  1178.                         $objText->getFont()->setStriketrough(true);
  1179.                     }
  1180.                 }
  1181.             }
  1182.         }
  1183.  
  1184.         return $value;
  1185.     }
  1186.  
  1187.     private static function array_item($array$key 0{
  1188.         return (isset($array[$key]$array[$keynull);
  1189.     }
  1190.  
  1191.     private static function dir_add($base$add{
  1192.         return preg_replace('~[^/]+/\.\./~'''dirname($base"/$add");
  1193.     }
  1194.  
  1195.     private static function toCSSArray($style{
  1196.         $style str_replace("\r"""$style);
  1197.         $style str_replace("\n"""$style);
  1198.  
  1199.         $temp explode(';'$style);
  1200.  
  1201.         $style array();
  1202.         foreach ($temp as $item{
  1203.             $item explode(':'$item);
  1204.  
  1205.             if (strpos($item[1]'px'!== false{
  1206.                 $item[1str_replace('px'''$item[1]);
  1207.             }
  1208.             if (strpos($item[1]'pt'!== false{
  1209.                 $item[1str_replace('pt'''$item[1]);
  1210.                 $item[1PHPExcel_Shared_Font::fontSizeToPixels($item[1]);
  1211.             }
  1212.  
  1213.             $style[$item[0]] $item[1];
  1214.         }
  1215.  
  1216.         return $style;
  1217.     }
  1218. }

Documentation generated on Mon, 27 Oct 2008 08:38:44 +0100 by phpDocumentor 1.4.1