30 if (!defined(
'PHPEXCEL_ROOT')) {
34 define(
'PHPEXCEL_ROOT', dirname(__FILE__) .
'/../../');
35 require(PHPEXCEL_ROOT .
'PHPExcel/Autoloader.php');
107 $this->_readDataOnly = $pValue;
134 $this->_loadSheetsOnly = is_array($value) ?
135 $value : array($value);
147 $this->_loadSheetsOnly = null;
167 $this->_readFilter = $pValue;
188 if (!class_exists(
'ZipArchive')) {
193 if (!file_exists($pFilename)) {
194 throw new Exception(
"Could not open " . $pFilename .
" for reading! File does not exist.");
199 $zip =
new ZipArchive;
200 if ($zip->open($pFilename) ===
true) {
203 foreach ($rels->Relationship as $rel) {
204 switch ($rel[
"Type"]) {
205 case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument":
206 if (basename($rel[
"Target"]) ==
'workbook.xml') {
221 $value = isset($c->v) ? (string) $c->v : null;
224 } elseif ($value ==
'1') {
234 return isset($c->v) ? (string) $c->v : null;;
239 return isset($c->v) ? (string) $c->v : null;;
242 private function _castToFormula($c,$r,&$cellDataType,&$value,&$calculatedValue,&$sharedFormulas,$castBaseType) {
247 $calculatedValue = self::$castBaseType($c);
250 if (isset($c->f[
't']) && strtolower((
string)$c->f[
't']) ==
'shared') {
252 $instance = (string)$c->f[
'si'];
259 if (!isset($sharedFormulas[(
string)$c->f[
'si']])) {
263 $sharedFormulas[$instance] = array(
'master' => $r,
276 $difference = array(0, 0);
278 $difference[1] = $current[1] - $master[1];
280 $value = $this->_referenceHelper->updateFormulaReferences( $sharedFormulas[$instance][
'formula'],
293 if (strpos($fileName,
'//') !==
false)
295 $fileName = substr($fileName, strpos($fileName,
'//') + 1);
300 $contents = $archive->getFromName($fileName);
301 if ($contents ===
false)
303 $contents = $archive->getFromName(substr($fileName, 1));
318 if (!file_exists($pFilename)) {
319 throw new Exception(
"Could not open " . $pFilename .
" for reading! File does not exist.");
322 $worksheetNames = array();
324 $zip =
new ZipArchive;
325 $zip->open($pFilename);
328 foreach ($rels->Relationship as $rel) {
329 switch ($rel[
"Type"]) {
330 case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument":
331 $xmlWorkbook = simplexml_load_string($this->
_getFromZipArchive($zip,
"{$rel['Target']}"));
333 if ($xmlWorkbook->sheets) {
334 foreach ($xmlWorkbook->sheets->sheet as $eleSheet) {
336 $worksheetNames[] = (string) $eleSheet[
"name"];
344 return $worksheetNames;
354 public function load($pFilename)
357 if (!file_exists($pFilename)) {
358 throw new Exception(
"Could not open " . $pFilename .
" for reading! File does not exist.");
364 if (!$this->_readDataOnly) {
365 $excel->removeCellStyleXfByIndex(0);
366 $excel->removeCellXfByIndex(0);
368 $zip =
new ZipArchive;
369 $zip->open($pFilename);
372 $wbRels = simplexml_load_string($this->
_getFromZipArchive($zip,
"xl/_rels/workbook.xml.rels"));
373 foreach ($wbRels->Relationship as $rel) {
374 switch ($rel[
"Type"]) {
375 case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme":
376 $themeOrderArray = array(
'lt1',
'dk1',
'lt2',
'dk2');
377 $themeOrderAdditional = count($themeOrderArray);
379 $xmlTheme = simplexml_load_string($this->
_getFromZipArchive($zip,
"xl/{$rel['Target']}"));
380 if (is_object($xmlTheme)) {
381 $xmlThemeName = $xmlTheme->attributes();
382 $xmlTheme = $xmlTheme->children(
"http://schemas.openxmlformats.org/drawingml/2006/main");
383 $themeName = (string)$xmlThemeName[
'name'];
385 $colourScheme = $xmlTheme->themeElements->clrScheme->attributes();
386 $colourSchemeName = (string)$colourScheme[
'name'];
387 $colourScheme = $xmlTheme->themeElements->clrScheme->children(
"http://schemas.openxmlformats.org/drawingml/2006/main");
389 $themeColours = array();
390 foreach ($colourScheme as $k => $xmlColour) {
391 $themePos = array_search($k,$themeOrderArray);
392 if ($themePos ===
false) {
393 $themePos = $themeOrderAdditional++;
395 if (isset($xmlColour->sysClr)) {
396 $xmlColourData = $xmlColour->sysClr->attributes();
397 $themeColours[$themePos] = $xmlColourData[
'lastClr'];
398 } elseif (isset($xmlColour->srgbClr)) {
399 $xmlColourData = $xmlColour->srgbClr->attributes();
400 $themeColours[$themePos] = $xmlColourData[
'val'];
410 foreach ($rels->Relationship as $rel) {
411 switch ($rel[
"Type"]) {
412 case "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties":
413 $xmlCore = simplexml_load_string($this->
_getFromZipArchive($zip,
"{$rel['Target']}"));
414 if (is_object($xmlCore)) {
415 $xmlCore->registerXPathNamespace(
"dc",
"http://purl.org/dc/elements/1.1/");
416 $xmlCore->registerXPathNamespace(
"dcterms",
"http://purl.org/dc/terms/");
417 $xmlCore->registerXPathNamespace(
"cp",
"http://schemas.openxmlformats.org/package/2006/metadata/core-properties");
418 $docProps = $excel->getProperties();
419 $docProps->setCreator((
string) self::array_item($xmlCore->xpath(
"dc:creator")));
420 $docProps->setLastModifiedBy((
string) self::array_item($xmlCore->xpath(
"cp:lastModifiedBy")));
421 $docProps->setCreated(strtotime(self::array_item($xmlCore->xpath(
"dcterms:created"))));
422 $docProps->setModified(strtotime(self::array_item($xmlCore->xpath(
"dcterms:modified"))));
423 $docProps->setTitle((
string) self::array_item($xmlCore->xpath(
"dc:title")));
424 $docProps->setDescription((
string) self::array_item($xmlCore->xpath(
"dc:description")));
425 $docProps->setSubject((
string) self::array_item($xmlCore->xpath(
"dc:subject")));
426 $docProps->setKeywords((
string) self::array_item($xmlCore->xpath(
"cp:keywords")));
427 $docProps->setCategory((
string) self::array_item($xmlCore->xpath(
"cp:category")));
431 case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties":
432 $xmlCore = simplexml_load_string($this->
_getFromZipArchive($zip,
"{$rel['Target']}"));
433 if (is_object($xmlCore)) {
434 $docProps = $excel->getProperties();
435 if (isset($xmlCore->Company))
436 $docProps->setCompany((
string) $xmlCore->Company);
437 if (isset($xmlCore->Manager))
438 $docProps->setManager((
string) $xmlCore->Manager);
442 case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties":
443 $xmlCore = simplexml_load_string($this->
_getFromZipArchive($zip,
"{$rel['Target']}"));
444 if (is_object($xmlCore)) {
445 $docProps = $excel->getProperties();
446 foreach ($xmlCore as $xmlProperty) {
447 $cellDataOfficeAttributes = $xmlProperty->attributes();
448 if (isset($cellDataOfficeAttributes[
'name'])) {
449 $propertyName = (string) $cellDataOfficeAttributes[
'name'];
450 $cellDataOfficeChildren = $xmlProperty->children(
'http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');
451 $attributeType = $cellDataOfficeChildren->getName();
452 $attributeValue = (string) $cellDataOfficeChildren->{$attributeType};
455 $docProps->setCustomProperty($propertyName,$attributeValue,$attributeType);
461 case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument":
462 $dir = dirname($rel[
"Target"]);
463 $relsWorkbook = simplexml_load_string($this->
_getFromZipArchive($zip,
"$dir/_rels/" . basename($rel[
"Target"]) .
".rels"));
464 $relsWorkbook->registerXPathNamespace(
"rel",
"http://schemas.openxmlformats.org/package/2006/relationships");
466 $sharedStrings = array();
467 $xpath =
self::array_item($relsWorkbook->xpath(
"rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings']"));
468 $xmlStrings = simplexml_load_string($this->
_getFromZipArchive($zip,
"$dir/$xpath[Target]"));
469 if (isset($xmlStrings) && isset($xmlStrings->si)) {
470 foreach ($xmlStrings->si as $val) {
471 if (isset($val->t)) {
473 } elseif (isset($val->r)) {
479 $worksheets = array();
480 foreach ($relsWorkbook->Relationship as $ele) {
481 if ($ele[
"Type"] ==
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet") {
482 $worksheets[(string) $ele[
"Id"]] = $ele[
"Target"];
487 $cellStyles = array();
488 $xpath =
self::array_item($relsWorkbook->xpath(
"rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles']"));
489 $xmlStyles = simplexml_load_string($this->
_getFromZipArchive($zip,
"$dir/$xpath[Target]"));
491 if ($xmlStyles && $xmlStyles->numFmts[0]) {
492 $numFmts = $xmlStyles->numFmts[0];
494 if (isset($numFmts) && !is_null($numFmts)) {
495 $numFmts->registerXPathNamespace(
"sml",
"http://schemas.openxmlformats.org/spreadsheetml/2006/main");
497 if (!$this->_readDataOnly && $xmlStyles) {
498 foreach ($xmlStyles->cellXfs->xf as $xf) {
501 if ($xf[
"numFmtId"]) {
502 if (isset($numFmts)) {
503 $tmpNumFmt =
self::array_item($numFmts->xpath(
"sml:numFmt[@numFmtId=$xf[numFmtId]]"));
505 if (isset($tmpNumFmt[
"formatCode"])) {
506 $numFmt = (string) $tmpNumFmt[
"formatCode"];
510 if ((
int)$xf[
"numFmtId"] < 164) {
517 $style = (object) array(
519 "font" => $xmlStyles->fonts->font[intval($xf[
"fontId"])],
520 "fill" => $xmlStyles->fills->fill[intval($xf[
"fillId"])],
521 "border" => $xmlStyles->borders->border[intval($xf[
"borderId"])],
522 "alignment" => $xf->alignment,
523 "protection" => $xf->protection,
530 $excel->addCellXf($objStyle);
533 foreach ($xmlStyles->cellStyleXfs->xf as $xf) {
535 if ($numFmts && $xf[
"numFmtId"]) {
536 $tmpNumFmt =
self::array_item($numFmts->xpath(
"sml:numFmt[@numFmtId=$xf[numFmtId]]"));
537 if (isset($tmpNumFmt[
"formatCode"])) {
538 $numFmt = (string) $tmpNumFmt[
"formatCode"];
539 }
else if ((
int)$xf[
"numFmtId"] < 165) {
544 $cellStyle = (object) array(
546 "font" => $xmlStyles->fonts->font[intval($xf[
"fontId"])],
547 "fill" => $xmlStyles->fills->fill[intval($xf[
"fillId"])],
548 "border" => $xmlStyles->borders->border[intval($xf[
"borderId"])],
549 "alignment" => $xf->alignment,
550 "protection" => $xf->protection,
552 $cellStyles[] = $cellStyle;
557 $excel->addCellStyleXf($objStyle);
562 if (!$this->_readDataOnly && $xmlStyles) {
563 if ($xmlStyles->dxfs) {
564 foreach ($xmlStyles->dxfs->dxf as $dxf) {
571 if ($xmlStyles->cellStyles)
573 foreach ($xmlStyles->cellStyles->cellStyle as $cellStyle) {
574 if (intval($cellStyle[
'builtinId']) == 0) {
575 if (isset($cellStyles[intval($cellStyle[
'xfId'])])) {
587 $xmlWorkbook = simplexml_load_string($this->
_getFromZipArchive($zip,
"{$rel['Target']}"));
590 if ($xmlWorkbook->workbookPr) {
592 if (isset($xmlWorkbook->workbookPr[
'date1904'])) {
593 $date1904 = (string)$xmlWorkbook->workbookPr[
'date1904'];
594 if ($date1904 ==
"true" || $date1904 ==
"1") {
602 $countSkippedSheets = 0;
603 $mapSheetId = array();
605 if ($xmlWorkbook->sheets)
607 foreach ($xmlWorkbook->sheets->sheet as $eleSheet) {
611 if (isset($this->_loadSheetsOnly) && !in_array((
string) $eleSheet[
"name"], $this->_loadSheetsOnly)) {
612 ++$countSkippedSheets;
613 $mapSheetId[$oldSheetId] = null;
619 $mapSheetId[$oldSheetId] = $oldSheetId - $countSkippedSheets;
622 $docSheet = $excel->createSheet();
623 $docSheet->setTitle((
string) $eleSheet[
"name"]);
624 $fileWorksheet = $worksheets[(string) self::array_item($eleSheet->attributes(
"http://schemas.openxmlformats.org/officeDocument/2006/relationships"),
"id")];
625 $xmlSheet = simplexml_load_string($this->
_getFromZipArchive($zip,
"$dir/$fileWorksheet"));
627 $sharedFormulas = array();
629 if (isset($eleSheet[
"state"]) && (
string) $eleSheet[
"state"] !=
'') {
630 $docSheet->setSheetState( (
string) $eleSheet[
"state"] );
633 if (isset($xmlSheet->sheetViews) && isset($xmlSheet->sheetViews->sheetView)) {
634 if (isset($xmlSheet->sheetViews->sheetView[
'zoomScale'])) {
635 $docSheet->getSheetView()->setZoomScale( intval($xmlSheet->sheetViews->sheetView[
'zoomScale']) );
638 if (isset($xmlSheet->sheetViews->sheetView[
'zoomScaleNormal'])) {
639 $docSheet->getSheetView()->setZoomScaleNormal( intval($xmlSheet->sheetViews->sheetView[
'zoomScaleNormal']) );
642 if (isset($xmlSheet->sheetViews->sheetView[
'showGridLines'])) {
643 $docSheet->setShowGridLines((
string)$xmlSheet->sheetViews->sheetView[
'showGridLines'] ?
true :
false);
646 if (isset($xmlSheet->sheetViews->sheetView[
'showRowColHeaders'])) {
647 $docSheet->setShowRowColHeaders((
string)$xmlSheet->sheetViews->sheetView[
'showRowColHeaders'] ?
true :
false);
650 if (isset($xmlSheet->sheetViews->sheetView[
'rightToLeft'])) {
651 $docSheet->setRightToLeft((
string)$xmlSheet->sheetViews->sheetView[
'rightToLeft'] ?
true :
false);
654 if (isset($xmlSheet->sheetViews->sheetView->pane)) {
655 if (isset($xmlSheet->sheetViews->sheetView->pane[
'topLeftCell'])) {
656 $docSheet->freezePane( (
string)$xmlSheet->sheetViews->sheetView->pane[
'topLeftCell'] );
661 if (isset($xmlSheet->sheetViews->sheetView->pane[
'xSplit'])) {
662 $xSplit = 1 + intval($xmlSheet->sheetViews->sheetView->pane[
'xSplit']);
665 if (isset($xmlSheet->sheetViews->sheetView->pane[
'ySplit'])) {
666 $ySplit = 1 + intval($xmlSheet->sheetViews->sheetView->pane[
'ySplit']);
669 $docSheet->freezePaneByColumnAndRow($xSplit, $ySplit);
673 if (isset($xmlSheet->sheetViews->sheetView->selection)) {
674 if (isset($xmlSheet->sheetViews->sheetView->selection[
'sqref'])) {
675 $sqref = (string)$xmlSheet->sheetViews->sheetView->selection[
'sqref'];
676 $sqref = explode(
' ', $sqref);
678 $docSheet->setSelectedCells($sqref);
684 if (isset($xmlSheet->sheetPr) && isset($xmlSheet->sheetPr->tabColor)) {
685 if (isset($xmlSheet->sheetPr->tabColor[
'rgb'])) {
686 $docSheet->getTabColor()->setARGB( (
string)$xmlSheet->sheetPr->tabColor[
'rgb'] );
690 if (isset($xmlSheet->sheetPr) && isset($xmlSheet->sheetPr->outlinePr)) {
691 if (isset($xmlSheet->sheetPr->outlinePr[
'summaryRight']) && $xmlSheet->sheetPr->outlinePr[
'summaryRight'] ==
false) {
692 $docSheet->setShowSummaryRight(
false);
694 $docSheet->setShowSummaryRight(
true);
697 if (isset($xmlSheet->sheetPr->outlinePr[
'summaryBelow']) && $xmlSheet->sheetPr->outlinePr[
'summaryBelow'] ==
false) {
698 $docSheet->setShowSummaryBelow(
false);
700 $docSheet->setShowSummaryBelow(
true);
704 if (isset($xmlSheet->sheetPr) && isset($xmlSheet->sheetPr->pageSetUpPr)) {
705 if (isset($xmlSheet->sheetPr->pageSetUpPr[
'fitToPage']) && $xmlSheet->sheetPr->pageSetUpPr[
'fitToPage'] ==
false) {
706 $docSheet->getPageSetup()->setFitToPage(
false);
708 $docSheet->getPageSetup()->setFitToPage(
true);
712 if (isset($xmlSheet->sheetFormatPr)) {
713 if (isset($xmlSheet->sheetFormatPr[
'customHeight']) && ((
string)$xmlSheet->sheetFormatPr[
'customHeight'] ==
'1' || strtolower((
string)$xmlSheet->sheetFormatPr[
'customHeight']) ==
'true') && isset($xmlSheet->sheetFormatPr[
'defaultRowHeight'])) {
714 $docSheet->getDefaultRowDimension()->setRowHeight( (
float)$xmlSheet->sheetFormatPr[
'defaultRowHeight'] );
716 if (isset($xmlSheet->sheetFormatPr[
'defaultColWidth'])) {
717 $docSheet->getDefaultColumnDimension()->setWidth( (
float)$xmlSheet->sheetFormatPr[
'defaultColWidth'] );
721 if (isset($xmlSheet->cols) && !$this->_readDataOnly) {
722 foreach ($xmlSheet->cols->col as $col) {
723 for ($i = intval($col[
"min"]) - 1; $i < intval($col[
"max"]); ++$i) {
724 if ($col[
"style"] && !$this->_readDataOnly) {
727 if ($col[
"bestFit"]) {
730 if ($col[
"hidden"]) {
733 if ($col[
"collapsed"]) {
736 if ($col[
"outlineLevel"] > 0) {
741 if (intval($col[
"max"]) == 16384) {
748 if (isset($xmlSheet->printOptions) && !$this->_readDataOnly) {
749 if ($xmlSheet->printOptions[
'gridLinesSet'] ==
'true' && $xmlSheet->printOptions[
'gridLinesSet'] ==
'1') {
750 $docSheet->setShowGridlines(
true);
753 if ($xmlSheet->printOptions[
'gridLines'] ==
'true' || $xmlSheet->printOptions[
'gridLines'] ==
'1') {
754 $docSheet->setPrintGridlines(
true);
757 if ($xmlSheet->printOptions[
'horizontalCentered']) {
758 $docSheet->getPageSetup()->setHorizontalCentered(
true);
760 if ($xmlSheet->printOptions[
'verticalCentered']) {
761 $docSheet->getPageSetup()->setVerticalCentered(
true);
765 if ($xmlSheet && $xmlSheet->sheetData && $xmlSheet->sheetData->row) {
766 foreach ($xmlSheet->sheetData->row as
$row) {
767 if ($row[
"ht"] && !$this->_readDataOnly) {
768 $docSheet->getRowDimension(intval($row[
"r"]))->setRowHeight(floatval($row[
"ht"]));
770 if ($row[
"hidden"] && !$this->_readDataOnly) {
771 $docSheet->getRowDimension(intval($row[
"r"]))->setVisible(
false);
773 if ($row[
"collapsed"]) {
774 $docSheet->getRowDimension(intval($row[
"r"]))->setCollapsed(
true);
776 if ($row[
"outlineLevel"] > 0) {
777 $docSheet->getRowDimension(intval($row[
"r"]))->setOutlineLevel(intval($row[
"outlineLevel"]));
779 if ($row[
"s"] && !$this->_readDataOnly) {
780 $docSheet->getRowDimension(intval($row[
"r"]))->setXfIndex(intval($row[
"s"]));
783 foreach ($row->c as $c) {
784 $r = (string) $c[
"r"];
785 $cellDataType = (string) $c[
"t"];
787 $calculatedValue = null;
793 if (!$this->
getReadFilter()->readCell($coordinates[0], $coordinates[1], $docSheet->getTitle())) {
804 switch ($cellDataType) {
807 if ((
string)$c->v !=
'') {
808 $value = $sharedStrings[intval($c->v)];
811 $value = clone $value;
824 $this->
_castToFormula($c,$r,$cellDataType,$value,$calculatedValue,$sharedFormulas,
'_castToBool');
825 if (isset($c->f[
't'])) {
828 $docSheet->getCell($r)->setFormulaAttributes($att);
844 $this->
_castToFormula($c,$r,$cellDataType,$value,$calculatedValue,$sharedFormulas,
'_castToError');
858 $this->
_castToFormula($c,$r,$cellDataType,$value,$calculatedValue,$sharedFormulas,
'_castToString');
867 if (is_numeric($value) && $cellDataType !=
's') {
868 if ($value == (
int)$value) $value = (int)$value;
869 elseif ($value == (
float)$value) $value = (float)$value;
870 elseif ($value == (
double)$value) $value = (double)$value;
875 $value = $value->getPlainText();
878 $cell = $docSheet->getCell($r);
880 if ($cellDataType !=
'') {
881 $cell->setValueExplicit($value, $cellDataType);
883 $cell->setValue($value);
885 if (!is_null($calculatedValue)) {
886 $cell->setCalculatedValue($calculatedValue);
890 if ($c[
"s"] && !$this->_readDataOnly) {
892 $cell->setXfIndex(isset($styles[intval($c[
"s"])]) ?
893 intval($c[
"s"]) : 0);
899 $conditionals = array();
900 if (!$this->_readDataOnly && $xmlSheet && $xmlSheet->conditionalFormatting) {
901 foreach ($xmlSheet->conditionalFormatting as $conditional) {
902 foreach ($conditional->cfRule as $cfRule) {
909 ) && isset($dxfs[intval($cfRule[
"dxfId"])])
911 $conditionals[(string) $conditional[
"sqref"]][intval($cfRule[
"priority"])] = $cfRule;
916 foreach ($conditionals as $ref => $cfRules) {
918 $conditionalStyles = array();
919 foreach ($cfRules as $cfRule) {
921 $objConditional->setConditionType((
string)$cfRule[
"type"]);
922 $objConditional->setOperatorType((
string)$cfRule[
"operator"]);
924 if ((
string)$cfRule[
"text"] !=
'') {
925 $objConditional->setText((
string)$cfRule[
"text"]);
928 if (count($cfRule->formula) > 1) {
929 foreach ($cfRule->formula as $formula) {
930 $objConditional->addCondition((
string)$formula);
933 $objConditional->addCondition((
string)$cfRule->formula);
935 $objConditional->setStyle(clone $dxfs[intval($cfRule[
"dxfId"])]);
936 $conditionalStyles[] = $objConditional;
941 foreach ($aReferences as $reference) {
942 $docSheet->getStyle($reference)->setConditionalStyles($conditionalStyles);
947 $aKeys = array(
"sheet",
"objects",
"scenarios",
"formatCells",
"formatColumns",
"formatRows",
"insertColumns",
"insertRows",
"insertHyperlinks",
"deleteColumns",
"deleteRows",
"selectLockedCells",
"sort",
"autoFilter",
"pivotTables",
"selectUnlockedCells");
948 if (!$this->_readDataOnly && $xmlSheet && $xmlSheet->sheetProtection) {
949 foreach ($aKeys as $key) {
950 $method =
"set" . ucfirst($key);
951 $docSheet->getProtection()->$method($xmlSheet->sheetProtection[$key] ==
"true");
955 if (!$this->_readDataOnly && $xmlSheet && $xmlSheet->sheetProtection) {
956 $docSheet->getProtection()->setPassword((
string) $xmlSheet->sheetProtection[
"password"],
true);
957 if ($xmlSheet->protectedRanges->protectedRange) {
958 foreach ($xmlSheet->protectedRanges->protectedRange as $protectedRange) {
959 $docSheet->protectCells((
string) $protectedRange[
"sqref"], (
string) $protectedRange[
"password"],
true);
964 if ($xmlSheet && $xmlSheet->autoFilter && !$this->_readDataOnly) {
965 $docSheet->setAutoFilter((
string) $xmlSheet->autoFilter[
"ref"]);
968 if ($xmlSheet && $xmlSheet->mergeCells && $xmlSheet->mergeCells->mergeCell && !$this->_readDataOnly) {
969 foreach ($xmlSheet->mergeCells->mergeCell as $mergeCell) {
970 $docSheet->mergeCells((
string) $mergeCell[
"ref"]);
974 if ($xmlSheet && $xmlSheet->pageMargins && !$this->_readDataOnly) {
975 $docPageMargins = $docSheet->getPageMargins();
976 $docPageMargins->setLeft(floatval($xmlSheet->pageMargins[
"left"]));
977 $docPageMargins->setRight(floatval($xmlSheet->pageMargins[
"right"]));
978 $docPageMargins->setTop(floatval($xmlSheet->pageMargins[
"top"]));
979 $docPageMargins->setBottom(floatval($xmlSheet->pageMargins[
"bottom"]));
980 $docPageMargins->setHeader(floatval($xmlSheet->pageMargins[
"header"]));
981 $docPageMargins->setFooter(floatval($xmlSheet->pageMargins[
"footer"]));
984 if ($xmlSheet && $xmlSheet->pageSetup && !$this->_readDataOnly) {
985 $docPageSetup = $docSheet->getPageSetup();
987 if (isset($xmlSheet->pageSetup[
"orientation"])) {
988 $docPageSetup->setOrientation((
string) $xmlSheet->pageSetup[
"orientation"]);
990 if (isset($xmlSheet->pageSetup[
"paperSize"])) {
991 $docPageSetup->setPaperSize(intval($xmlSheet->pageSetup[
"paperSize"]));
993 if (isset($xmlSheet->pageSetup[
"scale"])) {
994 $docPageSetup->setScale(intval($xmlSheet->pageSetup[
"scale"]),
false);
996 if (isset($xmlSheet->pageSetup[
"fitToHeight"]) && intval($xmlSheet->pageSetup[
"fitToHeight"]) >= 0) {
997 $docPageSetup->setFitToHeight(intval($xmlSheet->pageSetup[
"fitToHeight"]),
false);
999 if (isset($xmlSheet->pageSetup[
"fitToWidth"]) && intval($xmlSheet->pageSetup[
"fitToWidth"]) >= 0) {
1000 $docPageSetup->setFitToWidth(intval($xmlSheet->pageSetup[
"fitToWidth"]),
false);
1002 if (isset($xmlSheet->pageSetup[
"firstPageNumber"]) && isset($xmlSheet->pageSetup[
"useFirstPageNumber"]) &&
1003 ((
string)$xmlSheet->pageSetup[
"useFirstPageNumber"] ==
'true' || (
string)$xmlSheet->pageSetup[
"useFirstPageNumber"] ==
'1')) {
1004 $docPageSetup->setFirstPageNumber(intval($xmlSheet->pageSetup[
"firstPageNumber"]));
1008 if ($xmlSheet && $xmlSheet->headerFooter && !$this->_readDataOnly) {
1009 $docHeaderFooter = $docSheet->getHeaderFooter();
1011 if (isset($xmlSheet->headerFooter[
"differentOddEven"]) &&
1012 ((
string)$xmlSheet->headerFooter[
"differentOddEven"] ==
'true' || (
string)$xmlSheet->headerFooter[
"differentOddEven"] ==
'1')) {
1013 $docHeaderFooter->setDifferentOddEven(
true);
1015 $docHeaderFooter->setDifferentOddEven(
false);
1017 if (isset($xmlSheet->headerFooter[
"differentFirst"]) &&
1018 ((
string)$xmlSheet->headerFooter[
"differentFirst"] ==
'true' || (
string)$xmlSheet->headerFooter[
"differentFirst"] ==
'1')) {
1019 $docHeaderFooter->setDifferentFirst(
true);
1021 $docHeaderFooter->setDifferentFirst(
false);
1023 if (isset($xmlSheet->headerFooter[
"scaleWithDoc"]) &&
1024 ((
string)$xmlSheet->headerFooter[
"scaleWithDoc"] ==
'false' || (
string)$xmlSheet->headerFooter[
"scaleWithDoc"] ==
'0')) {
1025 $docHeaderFooter->setScaleWithDocument(
false);
1027 $docHeaderFooter->setScaleWithDocument(
true);
1029 if (isset($xmlSheet->headerFooter[
"alignWithMargins"]) &&
1030 ((
string)$xmlSheet->headerFooter[
"alignWithMargins"] ==
'false' || (
string)$xmlSheet->headerFooter[
"alignWithMargins"] ==
'0')) {
1031 $docHeaderFooter->setAlignWithMargins(
false);
1033 $docHeaderFooter->setAlignWithMargins(
true);
1036 $docHeaderFooter->setOddHeader((
string) $xmlSheet->headerFooter->oddHeader);
1037 $docHeaderFooter->setOddFooter((
string) $xmlSheet->headerFooter->oddFooter);
1038 $docHeaderFooter->setEvenHeader((
string) $xmlSheet->headerFooter->evenHeader);
1039 $docHeaderFooter->setEvenFooter((
string) $xmlSheet->headerFooter->evenFooter);
1040 $docHeaderFooter->setFirstHeader((
string) $xmlSheet->headerFooter->firstHeader);
1041 $docHeaderFooter->setFirstFooter((
string) $xmlSheet->headerFooter->firstFooter);
1044 if ($xmlSheet && $xmlSheet->rowBreaks && $xmlSheet->rowBreaks->brk && !$this->_readDataOnly) {
1045 foreach ($xmlSheet->rowBreaks->brk as $brk) {
1051 if ($xmlSheet && $xmlSheet->colBreaks && $xmlSheet->colBreaks->brk && !$this->_readDataOnly) {
1052 foreach ($xmlSheet->colBreaks->brk as $brk) {
1059 if ($xmlSheet && $xmlSheet->dataValidations && !$this->_readDataOnly) {
1060 foreach ($xmlSheet->dataValidations->dataValidation as $dataValidation) {
1062 $range = strtoupper($dataValidation[
"sqref"]);
1063 $rangeSet = explode(
' ',$range);
1064 foreach($rangeSet as $range) {
1065 $stRange = $docSheet->shrinkRangeToFit($range);
1069 foreach ($aReferences as $reference) {
1071 $docValidation = $docSheet->getCell($reference)->getDataValidation();
1072 $docValidation->setType((
string) $dataValidation[
"type"]);
1073 $docValidation->setErrorStyle((
string) $dataValidation[
"errorStyle"]);
1074 $docValidation->setOperator((
string) $dataValidation[
"operator"]);
1075 $docValidation->setAllowBlank($dataValidation[
"allowBlank"] != 0);
1076 $docValidation->setShowDropDown($dataValidation[
"showDropDown"] == 0);
1077 $docValidation->setShowInputMessage($dataValidation[
"showInputMessage"] != 0);
1078 $docValidation->setShowErrorMessage($dataValidation[
"showErrorMessage"] != 0);
1079 $docValidation->setErrorTitle((
string) $dataValidation[
"errorTitle"]);
1080 $docValidation->setError((
string) $dataValidation[
"error"]);
1081 $docValidation->setPromptTitle((
string) $dataValidation[
"promptTitle"]);
1082 $docValidation->setPrompt((
string) $dataValidation[
"prompt"]);
1083 $docValidation->setFormula1((
string) $dataValidation->formula1);
1084 $docValidation->setFormula2((
string) $dataValidation->formula2);
1091 $hyperlinks = array();
1092 if (!$this->_readDataOnly) {
1094 if ($zip->locateName(dirname(
"$dir/$fileWorksheet") .
"/_rels/" . basename($fileWorksheet) .
".rels")) {
1095 $relsWorksheet = simplexml_load_string($this->
_getFromZipArchive($zip, dirname(
"$dir/$fileWorksheet") .
"/_rels/" . basename($fileWorksheet) .
".rels") );
1096 foreach ($relsWorksheet->Relationship as $ele) {
1097 if ($ele[
"Type"] ==
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink") {
1098 $hyperlinks[(string)$ele[
"Id"]] = (
string)$ele[
"Target"];
1104 if ($xmlSheet && $xmlSheet->hyperlinks) {
1105 foreach ($xmlSheet->hyperlinks->hyperlink as $hyperlink) {
1107 $linkRel = $hyperlink->attributes(
'http://schemas.openxmlformats.org/officeDocument/2006/relationships');
1110 $cell = $docSheet->getCell( $cellReference );
1111 if (isset($linkRel[
'id'])) {
1112 $cell->getHyperlink()->setUrl( $hyperlinks[ (
string)$linkRel[
'id'] ] );
1114 if (isset($hyperlink[
'location'])) {
1115 $cell->getHyperlink()->setUrl(
'sheet://' . (
string)$hyperlink[
'location'] );
1119 if (isset($hyperlink[
'tooltip'])) {
1120 $cell->getHyperlink()->setTooltip( (
string)$hyperlink[
'tooltip'] );
1128 $comments = array();
1129 $vmlComments = array();
1130 if (!$this->_readDataOnly) {
1132 if ($zip->locateName(dirname(
"$dir/$fileWorksheet") .
"/_rels/" . basename($fileWorksheet) .
".rels")) {
1133 $relsWorksheet = simplexml_load_string($this->
_getFromZipArchive($zip, dirname(
"$dir/$fileWorksheet") .
"/_rels/" . basename($fileWorksheet) .
".rels") );
1134 foreach ($relsWorksheet->Relationship as $ele) {
1135 if ($ele[
"Type"] ==
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments") {
1136 $comments[(string)$ele[
"Id"]] = (
string)$ele[
"Target"];
1138 if ($ele[
"Type"] ==
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing") {
1139 $vmlComments[(string)$ele[
"Id"]] = (
string)$ele[
"Target"];
1145 foreach ($comments as $relName => $relPath) {
1154 foreach ($commentsFile->authors->author as $author) {
1155 $authors[] = (string)$author;
1159 foreach ($commentsFile->commentList->comment as
$comment) {
1160 $docSheet->getComment( (
string)$comment[
'ref'] )->setAuthor( $authors[(
string)$comment[
'authorId']] );
1161 $docSheet->getComment( (
string)$comment[
'ref'] )->setText( $this->
_parseRichText($comment->text) );
1166 foreach ($vmlComments as $relName => $relPath) {
1169 $vmlCommentsFile = simplexml_load_string( $this->
_getFromZipArchive($zip, $relPath) );
1170 $vmlCommentsFile->registerXPathNamespace(
'v',
'urn:schemas-microsoft-com:vml');
1172 $shapes = $vmlCommentsFile->xpath(
'//v:shape');
1173 foreach ($shapes as $shape) {
1174 $shape->registerXPathNamespace(
'v',
'urn:schemas-microsoft-com:vml');
1176 if (isset($shape[
'style'])) {
1177 $style = (string)$shape[
'style'];
1178 $fillColor = strtoupper( substr( (
string)$shape[
'fillcolor'], 1 ) );
1182 $clientData = $shape->xpath(
'.//x:ClientData');
1183 if (is_array($clientData) && count($clientData) > 0) {
1184 $clientData = $clientData[0];
1186 if ( isset($clientData[
'ObjectType']) && (
string)$clientData[
'ObjectType'] ==
'Note' ) {
1187 $temp = $clientData->xpath(
'.//x:Row');
1188 if (is_array($temp))
$row = $temp[0];
1190 $temp = $clientData->xpath(
'.//x:Column');
1191 if (is_array($temp)) $column = $temp[0];
1195 if (!is_null($column) && !is_null(
$row)) {
1197 $comment = $docSheet->getCommentByColumnAndRow($column,
$row + 1);
1198 $comment->getFillColor()->setRGB( $fillColor );
1201 $styleArray = explode(
';', str_replace(
' ',
'', $style));
1202 foreach ($styleArray as $stylePair) {
1203 $stylePair = explode(
':', $stylePair);
1205 if ($stylePair[0] ==
'margin-left')
$comment->setMarginLeft($stylePair[1]);
1206 if ($stylePair[0] ==
'margin-top')
$comment->setMarginTop($stylePair[1]);
1207 if ($stylePair[0] ==
'width')
$comment->setWidth($stylePair[1]);
1208 if ($stylePair[0] ==
'height')
$comment->setHeight($stylePair[1]);
1209 if ($stylePair[0] ==
'visibility')
$comment->setVisible( $stylePair[1] ==
'visible' );
1218 if ($xmlSheet && $xmlSheet->legacyDrawingHF && !$this->_readDataOnly) {
1219 if ($zip->locateName(dirname(
"$dir/$fileWorksheet") .
"/_rels/" . basename($fileWorksheet) .
".rels")) {
1220 $relsWorksheet = simplexml_load_string($this->
_getFromZipArchive($zip, dirname(
"$dir/$fileWorksheet") .
"/_rels/" . basename($fileWorksheet) .
".rels") );
1221 $vmlRelationship =
'';
1223 foreach ($relsWorksheet->Relationship as $ele) {
1224 if ($ele[
"Type"] ==
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing") {
1225 $vmlRelationship =
self::dir_add(
"$dir/$fileWorksheet", $ele[
"Target"]);
1229 if ($vmlRelationship !=
'') {
1231 $relsVML = simplexml_load_string($this->
_getFromZipArchive($zip, dirname($vmlRelationship) .
'/_rels/' . basename($vmlRelationship) .
'.rels' ));
1232 $drawings = array();
1233 foreach ($relsVML->Relationship as $ele) {
1234 if ($ele[
"Type"] ==
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image") {
1235 $drawings[(string) $ele[
"Id"]] = self::dir_add($vmlRelationship, $ele[
"Target"]);
1240 $vmlDrawing = simplexml_load_string($this->
_getFromZipArchive($zip, $vmlRelationship));
1241 $vmlDrawing->registerXPathNamespace(
'v',
'urn:schemas-microsoft-com:vml');
1243 $hfImages = array();
1245 $shapes = $vmlDrawing->xpath(
'//v:shape');
1246 foreach ($shapes as $shape) {
1247 $shape->registerXPathNamespace(
'v',
'urn:schemas-microsoft-com:vml');
1248 $imageData = $shape->xpath(
'//v:imagedata');
1249 $imageData = $imageData[0];
1251 $imageData = $imageData->attributes(
'urn:schemas-microsoft-com:office:office');
1255 if (isset($imageData[
'title'])) {
1256 $hfImages[ (string)$shape[
'id'] ]->setName( (
string)$imageData[
'title'] );
1259 $hfImages[ (string)$shape[
'id'] ]->setPath(
"zip://$pFilename#" . $drawings[(
string)$imageData[
'relid']],
false);
1260 $hfImages[ (string)$shape[
'id'] ]->setResizeProportional(
false);
1261 $hfImages[ (string)$shape[
'id'] ]->setWidth($style[
'width']);
1262 $hfImages[ (string)$shape[
'id'] ]->setHeight($style[
'height']);
1263 $hfImages[ (string)$shape[
'id'] ]->setOffsetX($style[
'margin-left']);
1264 $hfImages[ (string)$shape[
'id'] ]->setOffsetY($style[
'margin-top']);
1265 $hfImages[ (string)$shape[
'id'] ]->setResizeProportional(
true);
1268 $docSheet->getHeaderFooter()->setImages($hfImages);
1276 if ($zip->locateName(dirname(
"$dir/$fileWorksheet") .
"/_rels/" . basename($fileWorksheet) .
".rels")) {
1277 $relsWorksheet = simplexml_load_string($this->
_getFromZipArchive($zip, dirname(
"$dir/$fileWorksheet") .
"/_rels/" . basename($fileWorksheet) .
".rels") );
1278 $drawings = array();
1279 foreach ($relsWorksheet->Relationship as $ele) {
1280 if ($ele[
"Type"] ==
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing") {
1281 $drawings[(string) $ele[
"Id"]] = self::dir_add(
"$dir/$fileWorksheet", $ele[
"Target"]);
1284 if ($xmlSheet->drawing && !$this->_readDataOnly) {
1285 foreach ($xmlSheet->drawing as $drawing) {
1286 $fileDrawing = $drawings[(string) self::array_item($drawing->attributes(
"http://schemas.openxmlformats.org/officeDocument/2006/relationships"),
"id")];
1287 $relsDrawing = simplexml_load_string($this->
_getFromZipArchive($zip, dirname($fileDrawing) .
"/_rels/" . basename($fileDrawing) .
".rels") );
1290 if ($relsDrawing && $relsDrawing->Relationship) {
1291 foreach ($relsDrawing->Relationship as $ele) {
1292 if ($ele[
"Type"] ==
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/image") {
1293 $images[(string) $ele[
"Id"]] = self::dir_add($fileDrawing, $ele[
"Target"]);
1297 $xmlDrawing = simplexml_load_string($this->
_getFromZipArchive($zip, $fileDrawing))->children(
"http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing");
1299 if ($xmlDrawing->oneCellAnchor) {
1300 foreach ($xmlDrawing->oneCellAnchor as $oneCellAnchor) {
1301 if ($oneCellAnchor->pic->blipFill) {
1302 $blip = $oneCellAnchor->pic->blipFill->children(
"http://schemas.openxmlformats.org/drawingml/2006/main")->blip;
1303 $xfrm = $oneCellAnchor->pic->spPr->children(
"http://schemas.openxmlformats.org/drawingml/2006/main")->xfrm;
1304 $outerShdw = $oneCellAnchor->pic->spPr->children(
"http://schemas.openxmlformats.org/drawingml/2006/main")->effectLst->outerShdw;
1306 $objDrawing->
setName((
string) self::array_item($oneCellAnchor->pic->nvPicPr->cNvPr->attributes(),
"name"));
1307 $objDrawing->setDescription((
string) self::array_item($oneCellAnchor->pic->nvPicPr->cNvPr->attributes(),
"descr"));
1308 $objDrawing->setPath(
"zip://$pFilename#" . $images[(
string) self::array_item($blip->attributes(
"http://schemas.openxmlformats.org/officeDocument/2006/relationships"),
"embed")],
false);
1312 $objDrawing->setResizeProportional(
false);
1319 $shadow = $objDrawing->getShadow();
1320 $shadow->setVisible(
true);
1321 $shadow->setBlurRadius(PHPExcel_Shared_Drawing::EMUTopixels(self::array_item($outerShdw->attributes(),
"blurRad")));
1322 $shadow->setDistance(PHPExcel_Shared_Drawing::EMUTopixels(self::array_item($outerShdw->attributes(),
"dist")));
1324 $shadow->setAlignment((
string) self::array_item($outerShdw->attributes(),
"algn"));
1325 $shadow->getColor()->setRGB(self::array_item($outerShdw->srgbClr->attributes(),
"val"));
1326 $shadow->setAlpha(self::array_item($outerShdw->srgbClr->alpha->attributes(),
"val") / 1000);
1328 $objDrawing->setWorksheet($docSheet);
1332 if ($xmlDrawing->twoCellAnchor) {
1333 foreach ($xmlDrawing->twoCellAnchor as $twoCellAnchor) {
1334 if ($twoCellAnchor->pic->blipFill) {
1335 $blip = $twoCellAnchor->pic->blipFill->children(
"http://schemas.openxmlformats.org/drawingml/2006/main")->blip;
1336 $xfrm = $twoCellAnchor->pic->spPr->children(
"http://schemas.openxmlformats.org/drawingml/2006/main")->xfrm;
1337 $outerShdw = $twoCellAnchor->pic->spPr->children(
"http://schemas.openxmlformats.org/drawingml/2006/main")->effectLst->outerShdw;
1339 $objDrawing->
setName((
string) self::array_item($twoCellAnchor->pic->nvPicPr->cNvPr->attributes(),
"name"));
1340 $objDrawing->setDescription((
string) self::array_item($twoCellAnchor->pic->nvPicPr->cNvPr->attributes(),
"descr"));
1341 $objDrawing->setPath(
"zip://$pFilename#" . $images[(
string) self::array_item($blip->attributes(
"http://schemas.openxmlformats.org/officeDocument/2006/relationships"),
"embed")],
false);
1345 $objDrawing->setResizeProportional(
false);
1354 $shadow = $objDrawing->getShadow();
1355 $shadow->setVisible(
true);
1356 $shadow->setBlurRadius(PHPExcel_Shared_Drawing::EMUTopixels(self::array_item($outerShdw->attributes(),
"blurRad")));
1357 $shadow->setDistance(PHPExcel_Shared_Drawing::EMUTopixels(self::array_item($outerShdw->attributes(),
"dist")));
1359 $shadow->setAlignment((
string) self::array_item($outerShdw->attributes(),
"algn"));
1360 $shadow->getColor()->setRGB(self::array_item($outerShdw->srgbClr->attributes(),
"val"));
1361 $shadow->setAlpha(self::array_item($outerShdw->srgbClr->alpha->attributes(),
"val") / 1000);
1363 $objDrawing->setWorksheet($docSheet);
1373 if ($xmlWorkbook->definedNames) {
1374 foreach ($xmlWorkbook->definedNames->definedName as $definedName) {
1376 $extractedRange = (string)$definedName;
1377 $extractedRange = preg_replace(
'/\'(\w+)\'\!/',
'', $extractedRange);
1378 if (($spos = strpos($extractedRange,
'!')) !==
false) {
1379 $extractedRange = substr($extractedRange,0,$spos).str_replace(
'$',
'', substr($extractedRange,$spos));
1381 $extractedRange = str_replace(
'$',
'', $extractedRange);
1385 if (stripos((
string)$definedName,
'#REF!') !==
false || $extractedRange ==
'') {
1390 if ((
string)$definedName[
'localSheetId'] !=
'' && (
string)$definedName[
'localSheetId'] == $sheetId) {
1392 switch ((
string)$definedName[
'name']) {
1394 case '_xlnm._FilterDatabase':
1395 $docSheet->setAutoFilter($extractedRange);
1398 case '_xlnm.Print_Titles':
1400 $extractedRange = explode(
',', $extractedRange);
1403 foreach ($extractedRange as $range) {
1407 if (preg_match(
'/^([A-Z]+)\:([A-Z]+)$/', $range, $matches)) {
1408 $docSheet->getPageSetup()->setColumnsToRepeatAtLeft(array($matches[1], $matches[2]));
1411 elseif (preg_match(
'/^(\d+)\:(\d+)$/', $range, $matches)) {
1412 $docSheet->getPageSetup()->setRowsToRepeatAtTop(array($matches[1], $matches[2]));
1417 case '_xlnm.Print_Area':
1418 $rangeSets = explode(
',', $extractedRange);
1419 $newRangeSets = array();
1420 foreach($rangeSets as $rangeSet) {
1421 $range = explode(
'!', $rangeSet);
1422 $rangeSet = isset($range[1]) ? $range[1] : $range[0];
1423 $newRangeSets[] = str_replace(
'$',
'', $rangeSet);
1425 $docSheet->getPageSetup()->setPrintArea(implode(
',',$newRangeSets));
1440 if ($xmlWorkbook->definedNames) {
1441 foreach ($xmlWorkbook->definedNames->definedName as $definedName) {
1443 $extractedRange = (string)$definedName;
1444 $extractedRange = preg_replace(
'/\'(\w+)\'\!/',
'', $extractedRange);
1445 if (($spos = strpos($extractedRange,
'!')) !==
false) {
1446 $extractedRange = substr($extractedRange,0,$spos).str_replace(
'$',
'', substr($extractedRange,$spos));
1448 $extractedRange = str_replace(
'$',
'', $extractedRange);
1452 if (stripos((
string)$definedName,
'#REF!') !==
false || $extractedRange ==
'') {
1457 if ((
string)$definedName[
'localSheetId'] !=
'') {
1460 switch ((
string)$definedName[
'name']) {
1462 case '_xlnm._FilterDatabase':
1463 case '_xlnm.Print_Titles':
1464 case '_xlnm.Print_Area':
1468 $range = explode(
'!', (
string)$definedName);
1469 if (count($range) == 2) {
1470 $range[0] = str_replace(
"''",
"'", $range[0]);
1471 $range[0] = str_replace(
"'",
"", $range[0]);
1472 if ($worksheet = $docSheet->getParent()->getSheetByName($range[0])) {
1473 $extractedRange = str_replace(
'$',
'', $range[1]);
1474 $scope = $docSheet->getParent()->getSheet((
string)$definedName[
'localSheetId']);
1476 $excel->addNamedRange(
new PHPExcel_NamedRange((
string)$definedName[
'name'], $worksheet, $extractedRange,
true, $scope) );
1481 }
else if (!isset($definedName[
'localSheetId'])) {
1483 $locatedSheet = null;
1484 $extractedSheetName =
'';
1485 if (strpos( (
string)$definedName,
'!' ) !==
false) {
1488 $extractedSheetName = $extractedSheetName[0];
1491 $locatedSheet = $excel->getSheetByName($extractedSheetName);
1494 $range = explode(
'!', $extractedRange);
1495 $extractedRange = isset($range[1]) ? $range[1] : $range[0];
1498 if (!is_null($locatedSheet)) {
1499 $excel->addNamedRange(
new PHPExcel_NamedRange((
string)$definedName[
'name'], $locatedSheet, $extractedRange,
false) );
1506 if (!$this->_readDataOnly) {
1508 $activeTab = intval($xmlWorkbook->bookViews->workbookView[
"activeTab"]);
1511 if (isset($mapSheetId[$activeTab]) && $mapSheetId[$activeTab] !== null) {
1512 $excel->setActiveSheetIndex($mapSheetId[$activeTab]);
1514 if ($excel->getSheetCount() == 0)
1516 $excel->createSheet();
1518 $excel->setActiveSheetIndex(0);
1532 if (isset($color[
"rgb"])) {
1533 return (
string)$color[
"rgb"];
1534 }
else if (isset($color[
"indexed"])) {
1536 }
else if (isset($color[
"theme"])) {
1537 if (!is_null(self::$_theme)) {
1538 $returnColour = self::$_theme->getColourByIndex((
int)$color[
"theme"]);
1539 if (isset($color[
"tint"])) {
1540 $tintAdjust = (float) $color[
"tint"];
1543 return 'FF'.$returnColour;
1555 if (isset($style->numFmt)) {
1556 $docStyle->getNumberFormat()->setFormatCode($style->numFmt);
1560 if (isset($style->font)) {
1561 $docStyle->getFont()->setName((
string) $style->font->name[
"val"]);
1562 $docStyle->getFont()->setSize((
string) $style->font->sz[
"val"]);
1563 if (isset($style->font->b)) {
1564 $docStyle->getFont()->setBold(!isset($style->font->b[
"val"]) || $style->font->b[
"val"] ==
'true' || $style->font->b[
"val"] ==
'1');
1566 if (isset($style->font->i)) {
1567 $docStyle->getFont()->setItalic(!isset($style->font->i[
"val"]) || $style->font->i[
"val"] ==
'true' || $style->font->i[
"val"] ==
'1');
1569 if (isset($style->font->strike)) {
1570 $docStyle->getFont()->setStrikethrough(!isset($style->font->strike[
"val"]) || $style->font->strike[
"val"] ==
'true' || $style->font->strike[
"val"] ==
'1');
1572 $docStyle->getFont()->getColor()->setARGB(self::_readColor($style->font->color));
1574 if (isset($style->font->u) && !isset($style->font->u[
"val"])) {
1576 }
else if (isset($style->font->u) && isset($style->font->u[
"val"])) {
1577 $docStyle->getFont()->setUnderline((
string)$style->font->u[
"val"]);
1580 if (isset($style->font->vertAlign) && isset($style->font->vertAlign[
"val"])) {
1581 $vertAlign = strtolower((
string)$style->font->vertAlign[
"val"]);
1582 if ($vertAlign ==
'superscript') {
1583 $docStyle->getFont()->setSuperScript(
true);
1585 if ($vertAlign ==
'subscript') {
1586 $docStyle->getFont()->setSubScript(
true);
1592 if (isset($style->fill)) {
1593 if ($style->fill->gradientFill) {
1594 $gradientFill = $style->fill->gradientFill[0];
1595 if(!empty($gradientFill[
"type"])) {
1596 $docStyle->getFill()->setFillType((
string) $gradientFill[
"type"]);
1598 $docStyle->getFill()->setRotation(floatval($gradientFill[
"degree"]));
1599 $gradientFill->registerXPathNamespace(
"sml",
"http://schemas.openxmlformats.org/spreadsheetml/2006/main");
1600 $docStyle->getFill()->getStartColor()->setARGB(self::_readColor( self::array_item($gradientFill->xpath(
"sml:stop[@position=0]"))->color) );
1601 $docStyle->getFill()->getEndColor()->setARGB(self::_readColor( self::array_item($gradientFill->xpath(
"sml:stop[@position=1]"))->color) );
1602 } elseif ($style->fill->patternFill) {
1603 $patternType = (string)$style->fill->patternFill[
"patternType"] !=
'' ? (
string)$style->fill->patternFill[
"patternType"] :
'solid';
1604 $docStyle->getFill()->setFillType($patternType);
1605 if ($style->fill->patternFill->fgColor) {
1606 $docStyle->getFill()->getStartColor()->setARGB(self::_readColor($style->fill->patternFill->fgColor,
true));
1608 $docStyle->getFill()->getStartColor()->setARGB(
'FF000000');
1610 if ($style->fill->patternFill->bgColor) {
1611 $docStyle->getFill()->getEndColor()->setARGB(self::_readColor($style->fill->patternFill->bgColor,
true));
1617 if (isset($style->border)) {
1618 $diagonalUp =
false;
1619 $diagonalDown =
false;
1620 if ($style->border[
"diagonalUp"] ==
'true' || $style->border[
"diagonalUp"] == 1) {
1623 if ($style->border[
"diagonalDown"] ==
'true' || $style->border[
"diagonalDown"] == 1) {
1624 $diagonalDown =
true;
1626 if ($diagonalUp ==
false && $diagonalDown ==
false) {
1628 } elseif ($diagonalUp ==
true && $diagonalDown ==
false) {
1630 } elseif ($diagonalUp ==
false && $diagonalDown ==
true) {
1632 } elseif ($diagonalUp ==
true && $diagonalDown ==
true) {
1635 self::_readBorder($docStyle->getBorders()->getLeft(), $style->border->left);
1636 self::_readBorder($docStyle->getBorders()->getRight(), $style->border->right);
1637 self::_readBorder($docStyle->getBorders()->getTop(), $style->border->top);
1638 self::_readBorder($docStyle->getBorders()->getBottom(), $style->border->bottom);
1639 self::_readBorder($docStyle->getBorders()->getDiagonal(), $style->border->diagonal);
1643 if (isset($style->alignment)) {
1644 $docStyle->getAlignment()->setHorizontal((
string) $style->alignment[
"horizontal"]);
1645 $docStyle->getAlignment()->setVertical((
string) $style->alignment[
"vertical"]);
1648 if ((
int)$style->alignment[
"textRotation"] <= 90) {
1649 $textRotation = (int)$style->alignment[
"textRotation"];
1650 }
else if ((
int)$style->alignment[
"textRotation"] > 90) {
1651 $textRotation = 90 - (int)$style->alignment[
"textRotation"];
1654 $docStyle->getAlignment()->setTextRotation(intval($textRotation));
1655 $docStyle->getAlignment()->setWrapText( (
string)$style->alignment[
"wrapText"] ==
"true" || (
string)$style->alignment[
"wrapText"] ==
"1" );
1656 $docStyle->getAlignment()->setShrinkToFit( (
string)$style->alignment[
"shrinkToFit"] ==
"true" || (
string)$style->alignment[
"shrinkToFit"] ==
"1" );
1657 $docStyle->getAlignment()->setIndent( intval((
string)$style->alignment[
"indent"]) > 0 ? intval((
string)$style->alignment[
"indent"]) : 0 );
1661 if (isset($style->protection)) {
1662 if (isset($style->protection[
'locked'])) {
1663 if ((
string)$style->protection[
'locked'] ==
'true') {
1670 if (isset($style->protection[
'hidden'])) {
1671 if ((
string)$style->protection[
'hidden'] ==
'true') {
1681 if (isset($eleBorder[
"style"])) {
1682 $docBorder->setBorderStyle((
string) $eleBorder[
"style"]);
1684 if (isset($eleBorder->color)) {
1685 $docBorder->getColor()->setARGB(self::_readColor($eleBorder->color));
1692 if (isset($is->t)) {
1695 foreach ($is->r as $run) {
1696 if (!isset($run->rPr)) {
1702 if (isset($run->rPr->rFont[
"val"])) {
1703 $objText->getFont()->setName((
string) $run->rPr->rFont[
"val"]);
1706 if (isset($run->rPr->sz[
"val"])) {
1707 $objText->getFont()->setSize((
string) $run->rPr->sz[
"val"]);
1710 if (isset($run->rPr->color)) {
1711 $objText->getFont()->setColor(
new PHPExcel_Style_Color( self::_readColor($run->rPr->color) ) );
1714 if ( (isset($run->rPr->b[
"val"]) && ((
string) $run->rPr->b[
"val"] ==
'true' || (
string) $run->rPr->b[
"val"] ==
'1'))
1715 || (isset($run->rPr->b) && !isset($run->rPr->b[
"val"])) ) {
1716 $objText->getFont()->setBold(
true);
1719 if ( (isset($run->rPr->i[
"val"]) && ((
string) $run->rPr->i[
"val"] ==
'true' || (
string) $run->rPr->i[
"val"] ==
'1'))
1720 || (isset($run->rPr->i) && !isset($run->rPr->i[
"val"])) ) {
1721 $objText->getFont()->setItalic(
true);
1724 if (isset($run->rPr->vertAlign) && isset($run->rPr->vertAlign[
"val"])) {
1725 $vertAlign = strtolower((
string)$run->rPr->vertAlign[
"val"]);
1726 if ($vertAlign ==
'superscript') {
1727 $objText->getFont()->setSuperScript(
true);
1729 if ($vertAlign ==
'subscript') {
1730 $objText->getFont()->setSubScript(
true);
1734 if (isset($run->rPr->u) && !isset($run->rPr->u[
"val"])) {
1736 }
else if (isset($run->rPr->u) && isset($run->rPr->u[
"val"])) {
1737 $objText->getFont()->setUnderline((
string)$run->rPr->u[
"val"]);
1740 if ( (isset($run->rPr->strike[
"val"]) && ((
string) $run->rPr->strike[
"val"] ==
'true' || (
string) $run->rPr->strike[
"val"] ==
'1'))
1741 || (isset($run->rPr->strike) && !isset($run->rPr->strike[
"val"])) ) {
1742 $objText->getFont()->setStrikethrough(
true);
1752 return (isset($array[$key]) ? $array[$key] : null);
1756 return preg_replace(
'~[^/]+/\.\./~',
'', dirname($base) .
"/$add");
1760 $style = str_replace(array(
"\r",
"\n"),
"", $style);
1762 $temp = explode(
';', $style);
1764 foreach ($temp as $item) {
1765 $item = explode(
':', $item);
1767 if (strpos($item[1],
'px') !==
false) {
1768 $item[1] = str_replace(
'px',
'', $item[1]);
1770 if (strpos($item[1],
'pt') !==
false) {
1771 $item[1] = str_replace(
'pt',
'', $item[1]);
1774 if (strpos($item[1],
'in') !==
false) {
1775 $item[1] = str_replace(
'in',
'', $item[1]);
1778 if (strpos($item[1],
'cm') !==
false) {
1779 $item[1] = str_replace(
'cm',
'', $item[1]);
1783 $style[$item[0]] = $item[1];