345 {
346
347 if (!file_exists($pFilename)) {
349 }
350
351
353 $excel->removeSheetByIndex(0);
354 if (!$this->_readDataOnly) {
355 $excel->removeCellStyleXfByIndex(0);
356 $excel->removeCellXfByIndex(0);
357 }
358
360
361 $zip = new $zipClass;
362 $zip->open($pFilename);
363
364
366 foreach ($wbRels->Relationship as $rel) {
367 switch ($rel["Type"]) {
368 case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme":
369 $themeOrderArray = array('lt1','dk1','lt2','dk2');
370 $themeOrderAdditional = count($themeOrderArray);
371
373 if (is_object($xmlTheme)) {
374 $xmlThemeName = $xmlTheme->attributes();
375 $xmlTheme = $xmlTheme->children("http://schemas.openxmlformats.org/drawingml/2006/main");
376 $themeName = (string)$xmlThemeName['name'];
377
378 $colourScheme = $xmlTheme->themeElements->clrScheme->attributes();
379 $colourSchemeName = (string)$colourScheme['name'];
380 $colourScheme = $xmlTheme->themeElements->clrScheme->children("http://schemas.openxmlformats.org/drawingml/2006/main");
381
382 $themeColours = array();
383 foreach ($colourScheme as $k => $xmlColour) {
384 $themePos = array_search($k,$themeOrderArray);
385 if ($themePos === false) {
386 $themePos = $themeOrderAdditional++;
387 }
388 if (isset($xmlColour->sysClr)) {
389 $xmlColourData = $xmlColour->sysClr->attributes();
390 $themeColours[$themePos] = $xmlColourData['lastClr'];
391 } elseif (isset($xmlColour->srgbClr)) {
392 $xmlColourData = $xmlColour->srgbClr->attributes();
393 $themeColours[$themePos] = $xmlColourData['val'];
394 }
395 }
397 }
398 break;
399 }
400 }
401
403 foreach ($rels->Relationship as $rel) {
404 switch ($rel["Type"]) {
405 case "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties":
407 if (is_object($xmlCore)) {
408 $xmlCore->registerXPathNamespace("dc", "http://purl.org/dc/elements/1.1/");
409 $xmlCore->registerXPathNamespace("dcterms", "http://purl.org/dc/terms/");
410 $xmlCore->registerXPathNamespace("cp", "http://schemas.openxmlformats.org/package/2006/metadata/core-properties");
411 $docProps = $excel->getProperties();
412 $docProps->setCreator((string) self::array_item($xmlCore->xpath("dc:creator")));
413 $docProps->setLastModifiedBy((string) self::array_item($xmlCore->xpath("cp:lastModifiedBy")));
414 $docProps->setCreated(strtotime(self::array_item($xmlCore->xpath("dcterms:created"))));
415 $docProps->setModified(strtotime(self::array_item($xmlCore->xpath("dcterms:modified"))));
416 $docProps->setTitle((string) self::array_item($xmlCore->xpath("dc:title")));
417 $docProps->setDescription((string) self::array_item($xmlCore->xpath("dc:description")));
418 $docProps->setSubject((string) self::array_item($xmlCore->xpath("dc:subject")));
419 $docProps->setKeywords((string) self::array_item($xmlCore->xpath("cp:keywords")));
420 $docProps->setCategory((string) self::array_item($xmlCore->xpath("cp:category")));
421 }
422 break;
423
424 case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties":
426 if (is_object($xmlCore)) {
427 $docProps = $excel->getProperties();
428 if (isset($xmlCore->Company))
429 $docProps->setCompany((string) $xmlCore->Company);
430 if (isset($xmlCore->Manager))
431 $docProps->setManager((string) $xmlCore->Manager);
432 }
433 break;
434
435 case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties":
437 if (is_object($xmlCore)) {
438 $docProps = $excel->getProperties();
439 foreach ($xmlCore as $xmlProperty) {
440 $cellDataOfficeAttributes = $xmlProperty->attributes();
441 if (isset($cellDataOfficeAttributes['name'])) {
442 $propertyName = (string) $cellDataOfficeAttributes['name'];
443 $cellDataOfficeChildren = $xmlProperty->children('http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes');
444 $attributeType = $cellDataOfficeChildren->getName();
445 $attributeValue = (string) $cellDataOfficeChildren->{$attributeType};
448 $docProps->setCustomProperty($propertyName,$attributeValue,$attributeType);
449 }
450 }
451 }
452 break;
453
454 case "http://schemas.microsoft.com/office/2006/relationships/ui/extensibility":
455 $customUI = $rel['Target'];
456 if(!is_null($customUI)){
458 }
459 break;
460 case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument":
461 $dir = dirname($rel["Target"]);
463 $relsWorkbook->registerXPathNamespace("rel", "http://schemas.openxmlformats.org/package/2006/relationships");
464
465 $sharedStrings = array();
466 $xpath =
self::array_item($relsWorkbook->xpath(
"rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings']"));
468 if (isset($xmlStrings) && isset($xmlStrings->si)) {
469 foreach ($xmlStrings->si as $val) {
470 if (isset($val->t)) {
472 } elseif (isset($val->r)) {
474 }
475 }
476 }
477
478 $worksheets = array();
479 $macros = $customUI = NULL;
480 foreach ($relsWorkbook->Relationship as $ele) {
481 switch($ele['Type']){
482 case "http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet":
483 $worksheets[(string) $ele["Id"]] = $ele["Target"];
484 break;
485
486 case "http://schemas.microsoft.com/office/2006/relationships/vbaProject":
487 $macros = $ele["Target"];
488 break;
489 }
490 }
491
492 if(!is_null($macros)){
494 if($macrosCode !== false){
495 $excel->setMacrosCode($macrosCode);
496 $excel->setHasMacros(true);
497
499 if($Certificate !== false)
500 $excel->setMacrosCertificate($Certificate);
501 }
502 }
504 $cellStyles = array();
505 $xpath =
self::array_item($relsWorkbook->xpath(
"rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles']"));
507 $numFmts = null;
508 if ($xmlStyles && $xmlStyles->numFmts[0]) {
509 $numFmts = $xmlStyles->numFmts[0];
510 }
511 if (isset($numFmts) && ($numFmts !== NULL)) {
512 $numFmts->registerXPathNamespace("sml", "http://schemas.openxmlformats.org/spreadsheetml/2006/main");
513 }
514 if (!$this->_readDataOnly && $xmlStyles) {
515 foreach ($xmlStyles->cellXfs->xf as $xf) {
517
518 if ($xf["numFmtId"]) {
519 if (isset($numFmts)) {
520 $tmpNumFmt =
self::array_item($numFmts->xpath(
"sml:numFmt[@numFmtId=$xf[numFmtId]]"));
521
522 if (isset($tmpNumFmt["formatCode"])) {
523 $numFmt = (string) $tmpNumFmt["formatCode"];
524 }
525 }
526
527 if ((int)$xf["numFmtId"] < 164) {
529 }
530 }
531 $quotePrefix = false;
532 if (isset($xf["quotePrefix"])) {
533 $quotePrefix = (
boolean) $xf[
"quotePrefix"];
534 }
535
536
537
539 "numFmt" => $numFmt,
540 "font" => $xmlStyles->fonts->font[intval($xf["fontId"])],
541 "fill" => $xmlStyles->fills->fill[intval($xf["fillId"])],
542 "border" => $xmlStyles->borders->border[intval($xf["borderId"])],
543 "alignment" => $xf->alignment,
544 "protection" => $xf->protection,
545 "quotePrefix" => $quotePrefix,
546 );
548
549
552 $excel->addCellXf($objStyle);
553 }
554
555 foreach ($xmlStyles->cellStyleXfs->xf as $xf) {
557 if ($numFmts && $xf["numFmtId"]) {
558 $tmpNumFmt =
self::array_item($numFmts->xpath(
"sml:numFmt[@numFmtId=$xf[numFmtId]]"));
559 if (isset($tmpNumFmt["formatCode"])) {
560 $numFmt = (string) $tmpNumFmt["formatCode"];
561 } else if ((int)$xf["numFmtId"] < 165) {
563 }
564 }
565
566 $cellStyle = (object) array(
567 "numFmt" => $numFmt,
568 "font" => $xmlStyles->fonts->font[intval($xf["fontId"])],
569 "fill" => $xmlStyles->fills->fill[intval($xf["fillId"])],
570 "border" => $xmlStyles->borders->border[intval($xf["borderId"])],
571 "alignment" => $xf->alignment,
572 "protection" => $xf->protection,
573 "quotePrefix" => $quotePrefix,
574 );
575 $cellStyles[] = $cellStyle;
576
577
580 $excel->addCellStyleXf($objStyle);
581 }
582 }
583
584 $dxfs = array();
585 if (!$this->_readDataOnly && $xmlStyles) {
586
587 if ($xmlStyles->dxfs) {
588 foreach ($xmlStyles->dxfs->dxf as $dxf) {
592 }
593 }
594
595 if ($xmlStyles->cellStyles) {
596 foreach ($xmlStyles->cellStyles->cellStyle as $cellStyle) {
597 if (intval($cellStyle['builtinId']) == 0) {
598 if (isset($cellStyles[intval($cellStyle['xfId'])])) {
599
602
603
604 }
605 }
606 }
607 }
608 }
609
611
612
613 if ($xmlWorkbook->workbookPr) {
615 if (isset($xmlWorkbook->workbookPr['date1904'])) {
616 if (self::boolean((string) $xmlWorkbook->workbookPr['date1904'])) {
618 }
619 }
620 }
621
622 $sheetId = 0;
623 $oldSheetId = -1;
624 $countSkippedSheets = 0;
625 $mapSheetId = array();
626
627
628 $charts = $chartDetails = array();
629
630 if ($xmlWorkbook->sheets) {
631 foreach ($xmlWorkbook->sheets->sheet as $eleSheet) {
632 ++$oldSheetId;
633
634
635 if (isset($this->_loadSheetsOnly) && !in_array((string) $eleSheet["name"], $this->_loadSheetsOnly)) {
636 ++$countSkippedSheets;
637 $mapSheetId[$oldSheetId] = null;
638 continue;
639 }
640
641
642
643 $mapSheetId[$oldSheetId] = $oldSheetId - $countSkippedSheets;
644
645
646 $docSheet = $excel->createSheet();
647
648
649
650
651 $docSheet->setTitle((string) $eleSheet["name"],false);
652 $fileWorksheet = $worksheets[(string) self::array_item($eleSheet->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships"), "id")];
654
655 $sharedFormulas = array();
656
657 if (isset($eleSheet["state"]) && (string) $eleSheet["state"] != '') {
658 $docSheet->setSheetState( (string) $eleSheet["state"] );
659 }
660
661 if (isset($xmlSheet->sheetViews) && isset($xmlSheet->sheetViews->sheetView)) {
662 if (isset($xmlSheet->sheetViews->sheetView['zoomScale'])) {
663 $docSheet->getSheetView()->setZoomScale( intval($xmlSheet->sheetViews->sheetView['zoomScale']) );
664 }
665
666 if (isset($xmlSheet->sheetViews->sheetView['zoomScaleNormal'])) {
667 $docSheet->getSheetView()->setZoomScaleNormal( intval($xmlSheet->sheetViews->sheetView['zoomScaleNormal']) );
668 }
669
670 if (isset($xmlSheet->sheetViews->sheetView['view'])) {
671 $docSheet->getSheetView()->setView((string) $xmlSheet->sheetViews->sheetView['view']);
672 }
673
674 if (isset($xmlSheet->sheetViews->sheetView['showGridLines'])) {
675 $docSheet->setShowGridLines(self::boolean((string)$xmlSheet->sheetViews->sheetView['showGridLines']));
676 }
677
678 if (isset($xmlSheet->sheetViews->sheetView['showRowColHeaders'])) {
679 $docSheet->setShowRowColHeaders(self::boolean((string)$xmlSheet->sheetViews->sheetView['showRowColHeaders']));
680 }
681
682 if (isset($xmlSheet->sheetViews->sheetView['rightToLeft'])) {
683 $docSheet->setRightToLeft(self::boolean((string)$xmlSheet->sheetViews->sheetView['rightToLeft']));
684 }
685
686 if (isset($xmlSheet->sheetViews->sheetView->pane)) {
687 if (isset($xmlSheet->sheetViews->sheetView->pane['topLeftCell'])) {
688 $docSheet->freezePane( (string)$xmlSheet->sheetViews->sheetView->pane['topLeftCell'] );
689 } else {
690 $xSplit = 0;
691 $ySplit = 0;
692
693 if (isset($xmlSheet->sheetViews->sheetView->pane['xSplit'])) {
694 $xSplit = 1 + intval($xmlSheet->sheetViews->sheetView->pane['xSplit']);
695 }
696
697 if (isset($xmlSheet->sheetViews->sheetView->pane['ySplit'])) {
698 $ySplit = 1 + intval($xmlSheet->sheetViews->sheetView->pane['ySplit']);
699 }
700
701 $docSheet->freezePaneByColumnAndRow($xSplit, $ySplit);
702 }
703 }
704
705 if (isset($xmlSheet->sheetViews->sheetView->selection)) {
706 if (isset($xmlSheet->sheetViews->sheetView->selection['sqref'])) {
707 $sqref = (string)$xmlSheet->sheetViews->sheetView->selection['sqref'];
708 $sqref = explode(' ', $sqref);
709 $sqref = $sqref[0];
710 $docSheet->setSelectedCells($sqref);
711 }
712 }
713
714 }
715
716 if (isset($xmlSheet->sheetPr) && isset($xmlSheet->sheetPr->tabColor)) {
717 if (isset($xmlSheet->sheetPr->tabColor['rgb'])) {
718 $docSheet->getTabColor()->setARGB( (string)$xmlSheet->sheetPr->tabColor['rgb'] );
719 }
720 }
721 if (isset($xmlSheet->sheetPr) && isset($xmlSheet->sheetPr['codeName'])) {
722 $docSheet->setCodeName((string) $xmlSheet->sheetPr['codeName']);
723 }
724 if (isset($xmlSheet->sheetPr) && isset($xmlSheet->sheetPr->outlinePr)) {
725 if (isset($xmlSheet->sheetPr->outlinePr['summaryRight']) &&
726 !
self::boolean((
string) $xmlSheet->sheetPr->outlinePr[
'summaryRight'])) {
727 $docSheet->setShowSummaryRight(FALSE);
728 } else {
729 $docSheet->setShowSummaryRight(TRUE);
730 }
731
732 if (isset($xmlSheet->sheetPr->outlinePr['summaryBelow']) &&
733 !
self::boolean((
string) $xmlSheet->sheetPr->outlinePr[
'summaryBelow'])) {
734 $docSheet->setShowSummaryBelow(FALSE);
735 } else {
736 $docSheet->setShowSummaryBelow(TRUE);
737 }
738 }
739
740 if (isset($xmlSheet->sheetPr) && isset($xmlSheet->sheetPr->pageSetUpPr)) {
741 if (isset($xmlSheet->sheetPr->pageSetUpPr['fitToPage']) &&
742 !
self::boolean((
string) $xmlSheet->sheetPr->pageSetUpPr[
'fitToPage'])) {
743 $docSheet->getPageSetup()->setFitToPage(FALSE);
744 } else {
745 $docSheet->getPageSetup()->setFitToPage(TRUE);
746 }
747 }
748
749 if (isset($xmlSheet->sheetFormatPr)) {
750 if (isset($xmlSheet->sheetFormatPr['customHeight']) &&
751 self::boolean((
string) $xmlSheet->sheetFormatPr[
'customHeight']) &&
752 isset($xmlSheet->sheetFormatPr['defaultRowHeight'])) {
753 $docSheet->getDefaultRowDimension()->setRowHeight( (float)$xmlSheet->sheetFormatPr['defaultRowHeight'] );
754 }
755 if (isset($xmlSheet->sheetFormatPr['defaultColWidth'])) {
756 $docSheet->getDefaultColumnDimension()->setWidth( (float)$xmlSheet->sheetFormatPr['defaultColWidth'] );
757 }
758 if (isset($xmlSheet->sheetFormatPr['zeroHeight']) &&
759 ((string)$xmlSheet->sheetFormatPr['zeroHeight'] == '1')) {
760 $docSheet->getDefaultRowDimension()->setZeroHeight(true);
761 }
762 }
763
765 foreach ($xmlSheet->cols->col as $col) {
766 for ($i = intval($col["min"]) - 1; $i < intval($col["max"]); ++$i) {
767 if ($col["style"] && !$this->_readDataOnly) {
769 }
770 if (self::boolean($col["bestFit"])) {
771
772 }
773 if (self::boolean($col["hidden"])) {
774
776 }
777 if (self::boolean($col["collapsed"])) {
779 }
780 if ($col["outlineLevel"] > 0) {
782 }
784
785 if (intval($col["max"]) == 16384) {
786 break;
787 }
788 }
789 }
790 }
791
793 if (self::boolean((string) $xmlSheet->printOptions['gridLinesSet'])) {
794 $docSheet->setShowGridlines(TRUE);
795 }
796
797 if (self::boolean((string) $xmlSheet->printOptions['gridLines'])) {
798 $docSheet->setPrintGridlines(TRUE);
799 }
800
801 if (self::boolean((string) $xmlSheet->printOptions['horizontalCentered'])) {
802 $docSheet->getPageSetup()->setHorizontalCentered(TRUE);
803 }
804 if (self::boolean((string) $xmlSheet->printOptions['verticalCentered'])) {
805 $docSheet->getPageSetup()->setVerticalCentered(TRUE);
806 }
807 }
808
809 if ($xmlSheet && $xmlSheet->sheetData && $xmlSheet->sheetData->row) {
810 foreach ($xmlSheet->sheetData->row as
$row) {
811 if (
$row[
"ht"] && !$this->_readDataOnly) {
812 $docSheet->getRowDimension(intval(
$row[
"r"]))->setRowHeight(floatval(
$row[
"ht"]));
813 }
815 $docSheet->getRowDimension(intval(
$row[
"r"]))->setVisible(FALSE);
816 }
817 if (self::boolean(
$row[
"collapsed"])) {
818 $docSheet->getRowDimension(intval(
$row[
"r"]))->setCollapsed(TRUE);
819 }
820 if (
$row[
"outlineLevel"] > 0) {
821 $docSheet->getRowDimension(intval(
$row[
"r"]))->setOutlineLevel(intval(
$row[
"outlineLevel"]));
822 }
823 if (
$row[
"s"] && !$this->_readDataOnly) {
824 $docSheet->getRowDimension(intval(
$row[
"r"]))->setXfIndex(intval(
$row[
"s"]));
825 }
826
827 foreach (
$row->c as $c) {
828 $r = (string) $c[
"r"];
829 $cellDataType = (string) $c["t"];
830 $value = null;
831 $calculatedValue = null;
832
833
836
837 if (!$this->
getReadFilter()->readCell($coordinates[0], $coordinates[1], $docSheet->getTitle())) {
838 continue;
839 }
840 }
841
842
843
844
845
846
847
848 switch ($cellDataType) {
849 case "s":
850
851 if ((string)$c->v != '') {
852 $value = $sharedStrings[intval($c->v)];
853
855 $value = clone $value;
856 }
857 } else {
858 $value = '';
859 }
860
861 break;
862 case "b":
863
864 if (!isset($c->f)) {
866 } else {
867
868 $this->
_castToFormula($c,
$r,$cellDataType,$value,$calculatedValue,$sharedFormulas,
'_castToBool');
869 if (isset($c->f['t'])) {
870 $att = array();
871 $att = $c->f;
872 $docSheet->getCell(
$r)->setFormulaAttributes($att);
873 }
874
875 }
876 break;
877 case "inlineStr":
878
880
881 break;
882 case "e":
883
884 if (!isset($c->f)) {
886 } else {
887
888 $this->
_castToFormula($c,
$r,$cellDataType,$value,$calculatedValue,$sharedFormulas,
'_castToError');
889
890 }
891
892 break;
893
894 default:
895
896 if (!isset($c->f)) {
897
899 } else {
900
901
902 $this->
_castToFormula($c,
$r,$cellDataType,$value,$calculatedValue,$sharedFormulas,
'_castToString');
903
904 }
905
906 break;
907 }
908
909
910
911 if (is_numeric($value) && $cellDataType != 's') {
912 if ($value == (int)$value) $value = (int)$value;
913 elseif ($value == (float)$value) $value = (float)$value;
914 elseif ($value == (double)$value) $value = (double)$value;
915 }
916
917
919 $value = $value->getPlainText();
920 }
921
922 $cell = $docSheet->getCell(
$r);
923
924 if ($cellDataType != '') {
925 $cell->setValueExplicit($value, $cellDataType);
926 } else {
927 $cell->setValue($value);
928 }
929 if ($calculatedValue !== NULL) {
930 $cell->setCalculatedValue($calculatedValue);
931 }
932
933
934 if ($c["s"] && !$this->_readDataOnly) {
935
936 $cell->setXfIndex(isset(
$styles[intval($c[
"s"])]) ?
937 intval($c["s"]) : 0);
938 }
939 }
940 }
941 }
942
943 $conditionals = array();
944 if (!$this->_readDataOnly && $xmlSheet && $xmlSheet->conditionalFormatting) {
945 foreach ($xmlSheet->conditionalFormatting as $conditional) {
946 foreach ($conditional->cfRule as $cfRule) {
947 if (
948 (
953 ) && isset($dxfs[intval($cfRule["dxfId"])])
954 ) {
955 $conditionals[(string) $conditional["sqref"]][intval($cfRule["priority"])] = $cfRule;
956 }
957 }
958 }
959
960 foreach ($conditionals as $ref => $cfRules) {
961 ksort($cfRules);
963 foreach ($cfRules as $cfRule) {
965 $objConditional->setConditionType((string)$cfRule["type"]);
966 $objConditional->setOperatorType((string)$cfRule["operator"]);
967
968 if ((string)$cfRule["text"] != '') {
969 $objConditional->setText((string)$cfRule["text"]);
970 }
971
972 if (count($cfRule->formula) > 1) {
973 foreach ($cfRule->formula as $formula) {
974 $objConditional->addCondition((string)$formula);
975 }
976 } else {
977 $objConditional->addCondition((string)$cfRule->formula);
978 }
979 $objConditional->setStyle(clone $dxfs[intval($cfRule["dxfId"])]);
981 }
982
983
985 foreach ($aReferences as $reference) {
987 }
988 }
989 }
990
991 $aKeys = array("sheet", "objects", "scenarios", "formatCells", "formatColumns", "formatRows", "insertColumns", "insertRows", "insertHyperlinks", "deleteColumns", "deleteRows", "selectLockedCells", "sort", "autoFilter", "pivotTables", "selectUnlockedCells");
992 if (!$this->_readDataOnly && $xmlSheet && $xmlSheet->sheetProtection) {
993 foreach ($aKeys as $key) {
994 $method = "set" . ucfirst($key);
995 $docSheet->getProtection()->$method(self::boolean((string) $xmlSheet->sheetProtection[$key]));
996 }
997 }
998
999 if (!$this->_readDataOnly && $xmlSheet && $xmlSheet->sheetProtection) {
1000 $docSheet->getProtection()->setPassword((string) $xmlSheet->sheetProtection["password"], TRUE);
1001 if ($xmlSheet->protectedRanges->protectedRange) {
1002 foreach ($xmlSheet->protectedRanges->protectedRange as $protectedRange) {
1003 $docSheet->protectCells((string) $protectedRange["sqref"], (string) $protectedRange["password"], true);
1004 }
1005 }
1006 }
1007
1008 if ($xmlSheet && $xmlSheet->autoFilter && !$this->_readDataOnly) {
1009 $autoFilterRange = (string) $xmlSheet->autoFilter["ref"];
1010 if (strpos($autoFilterRange,
':') !==
false) {
1013
1014 foreach ($xmlSheet->autoFilter->filterColumn as $filterColumn) {
1016
1017 if ($filterColumn->filters) {
1019 $filters = $filterColumn->filters;
1020 if ((isset($filters["blank"])) && ($filters["blank"] == 1)) {
1021 $column->createRule()->setRule(
1022 NULL,
1023 ''
1024 )
1026 }
1027
1028
1029 foreach ($filters->filter as $filterRule) {
1030 $column->createRule()->setRule(
1031 NULL,
1032 (string) $filterRule["val"]
1033 )
1035 }
1036
1037 foreach ($filters->dateGroupItem as $dateGroupItem) {
1038 $column->createRule()->setRule(
1039 NULL,
1040 array(
1041 'year' => (string) $dateGroupItem["year"],
1042 'month' => (string) $dateGroupItem["month"],
1043 'day' => (string) $dateGroupItem["day"],
1044 'hour' => (string) $dateGroupItem["hour"],
1045 'minute' => (string) $dateGroupItem["minute"],
1046 'second' => (string) $dateGroupItem["second"],
1047 ),
1048 (string) $dateGroupItem["dateTimeGrouping"]
1049 )
1051 }
1052 }
1053
1054 if ($filterColumn->customFilters) {
1056 $customFilters = $filterColumn->customFilters;
1057
1058
1059 if ((isset($customFilters["and"])) && ($customFilters["and"] == 1)) {
1061 }
1062 foreach ($customFilters->customFilter as $filterRule) {
1063 $column->createRule()->setRule(
1064 (string) $filterRule["operator"],
1065 (string) $filterRule["val"]
1066 )
1068 }
1069 }
1070
1071 if ($filterColumn->dynamicFilter) {
1073
1074 foreach ($filterColumn->dynamicFilter as $filterRule) {
1075 $column->createRule()->setRule(
1076 NULL,
1077 (string) $filterRule["val"],
1078 (string) $filterRule["type"]
1079 )
1081 if (isset($filterRule["val"])) {
1082 $column->setAttribute(
'val',(
string) $filterRule[
"val"]);
1083 }
1084 if (isset($filterRule["maxVal"])) {
1085 $column->setAttribute(
'maxVal',(
string) $filterRule[
"maxVal"]);
1086 }
1087 }
1088 }
1089
1090 if ($filterColumn->top10) {
1092
1093 foreach ($filterColumn->top10 as $filterRule) {
1094 $column->createRule()->setRule(
1095 (((isset($filterRule["percent"])) && ($filterRule["percent"] == 1))
1098 ),
1099 (string) $filterRule["val"],
1100 (((isset($filterRule["top"])) && ($filterRule["top"] == 1))
1103 )
1104 )
1106 }
1107 }
1108 }
1109 }
1110 }
1111
1112 if ($xmlSheet && $xmlSheet->mergeCells && $xmlSheet->mergeCells->mergeCell && !$this->_readDataOnly) {
1113 foreach ($xmlSheet->mergeCells->mergeCell as $mergeCell) {
1114 $mergeRef = (string) $mergeCell["ref"];
1115 if (strpos($mergeRef,':') !== FALSE) {
1116 $docSheet->mergeCells((string) $mergeCell["ref"]);
1117 }
1118 }
1119 }
1120
1121 if ($xmlSheet && $xmlSheet->pageMargins && !$this->_readDataOnly) {
1122 $docPageMargins = $docSheet->getPageMargins();
1123 $docPageMargins->setLeft(floatval($xmlSheet->pageMargins["left"]));
1124 $docPageMargins->setRight(floatval($xmlSheet->pageMargins["right"]));
1125 $docPageMargins->setTop(floatval($xmlSheet->pageMargins["top"]));
1126 $docPageMargins->setBottom(floatval($xmlSheet->pageMargins["bottom"]));
1127 $docPageMargins->setHeader(floatval($xmlSheet->pageMargins["header"]));
1128 $docPageMargins->setFooter(floatval($xmlSheet->pageMargins["footer"]));
1129 }
1130
1131 if ($xmlSheet && $xmlSheet->pageSetup && !$this->_readDataOnly) {
1132 $docPageSetup = $docSheet->getPageSetup();
1133
1134 if (isset($xmlSheet->pageSetup["orientation"])) {
1135 $docPageSetup->setOrientation((string) $xmlSheet->pageSetup["orientation"]);
1136 }
1137 if (isset($xmlSheet->pageSetup["paperSize"])) {
1138 $docPageSetup->setPaperSize(intval($xmlSheet->pageSetup["paperSize"]));
1139 }
1140 if (isset($xmlSheet->pageSetup["scale"])) {
1141 $docPageSetup->setScale(intval($xmlSheet->pageSetup["scale"]), FALSE);
1142 }
1143 if (isset($xmlSheet->pageSetup["fitToHeight"]) && intval($xmlSheet->pageSetup["fitToHeight"]) >= 0) {
1144 $docPageSetup->setFitToHeight(intval($xmlSheet->pageSetup["fitToHeight"]), FALSE);
1145 }
1146 if (isset($xmlSheet->pageSetup["fitToWidth"]) && intval($xmlSheet->pageSetup["fitToWidth"]) >= 0) {
1147 $docPageSetup->setFitToWidth(intval($xmlSheet->pageSetup["fitToWidth"]), FALSE);
1148 }
1149 if (isset($xmlSheet->pageSetup["firstPageNumber"]) && isset($xmlSheet->pageSetup["useFirstPageNumber"]) &&
1150 self::boolean((
string) $xmlSheet->pageSetup[
"useFirstPageNumber"])) {
1151 $docPageSetup->setFirstPageNumber(intval($xmlSheet->pageSetup["firstPageNumber"]));
1152 }
1153 }
1154
1155 if ($xmlSheet && $xmlSheet->headerFooter && !$this->_readDataOnly) {
1156 $docHeaderFooter = $docSheet->getHeaderFooter();
1157
1158 if (isset($xmlSheet->headerFooter["differentOddEven"]) &&
1159 self::boolean((
string)$xmlSheet->headerFooter[
"differentOddEven"])) {
1160 $docHeaderFooter->setDifferentOddEven(TRUE);
1161 } else {
1162 $docHeaderFooter->setDifferentOddEven(FALSE);
1163 }
1164 if (isset($xmlSheet->headerFooter["differentFirst"]) &&
1165 self::boolean((
string)$xmlSheet->headerFooter[
"differentFirst"])) {
1166 $docHeaderFooter->setDifferentFirst(TRUE);
1167 } else {
1168 $docHeaderFooter->setDifferentFirst(FALSE);
1169 }
1170 if (isset($xmlSheet->headerFooter["scaleWithDoc"]) &&
1171 !
self::boolean((
string)$xmlSheet->headerFooter[
"scaleWithDoc"])) {
1172 $docHeaderFooter->setScaleWithDocument(FALSE);
1173 } else {
1174 $docHeaderFooter->setScaleWithDocument(TRUE);
1175 }
1176 if (isset($xmlSheet->headerFooter["alignWithMargins"]) &&
1177 !
self::boolean((
string)$xmlSheet->headerFooter[
"alignWithMargins"])) {
1178 $docHeaderFooter->setAlignWithMargins(FALSE);
1179 } else {
1180 $docHeaderFooter->setAlignWithMargins(TRUE);
1181 }
1182
1183 $docHeaderFooter->setOddHeader((string) $xmlSheet->headerFooter->oddHeader);
1184 $docHeaderFooter->setOddFooter((string) $xmlSheet->headerFooter->oddFooter);
1185 $docHeaderFooter->setEvenHeader((string) $xmlSheet->headerFooter->evenHeader);
1186 $docHeaderFooter->setEvenFooter((string) $xmlSheet->headerFooter->evenFooter);
1187 $docHeaderFooter->setFirstHeader((string) $xmlSheet->headerFooter->firstHeader);
1188 $docHeaderFooter->setFirstFooter((string) $xmlSheet->headerFooter->firstFooter);
1189 }
1190
1191 if ($xmlSheet && $xmlSheet->rowBreaks && $xmlSheet->rowBreaks->brk && !$this->_readDataOnly) {
1192 foreach ($xmlSheet->rowBreaks->brk as $brk) {
1193 if ($brk["man"]) {
1195 }
1196 }
1197 }
1198 if ($xmlSheet && $xmlSheet->colBreaks && $xmlSheet->colBreaks->brk && !$this->_readDataOnly) {
1199 foreach ($xmlSheet->colBreaks->brk as $brk) {
1200 if ($brk["man"]) {
1202 }
1203 }
1204 }
1205
1206 if ($xmlSheet && $xmlSheet->dataValidations && !$this->_readDataOnly) {
1207 foreach ($xmlSheet->dataValidations->dataValidation as $dataValidation) {
1208
1209 $range = strtoupper($dataValidation["sqref"]);
1210 $rangeSet = explode(' ',$range);
1211 foreach($rangeSet as $range) {
1212 $stRange = $docSheet->shrinkRangeToFit($range);
1213
1214
1216 foreach ($aReferences as $reference) {
1217
1218 $docValidation = $docSheet->getCell($reference)->getDataValidation();
1219 $docValidation->setType((string) $dataValidation["type"]);
1220 $docValidation->setErrorStyle((string) $dataValidation["errorStyle"]);
1221 $docValidation->setOperator((string) $dataValidation["operator"]);
1222 $docValidation->setAllowBlank($dataValidation["allowBlank"] != 0);
1223 $docValidation->setShowDropDown($dataValidation["showDropDown"] == 0);
1224 $docValidation->setShowInputMessage($dataValidation["showInputMessage"] != 0);
1225 $docValidation->setShowErrorMessage($dataValidation["showErrorMessage"] != 0);
1226 $docValidation->setErrorTitle((string) $dataValidation["errorTitle"]);
1227 $docValidation->setError((string) $dataValidation["error"]);
1228 $docValidation->setPromptTitle((string) $dataValidation["promptTitle"]);
1229 $docValidation->setPrompt((string) $dataValidation["prompt"]);
1230 $docValidation->setFormula1((string) $dataValidation->formula1);
1231 $docValidation->setFormula2((string) $dataValidation->formula2);
1232 }
1233 }
1234 }
1235 }
1236
1237
1238 $hyperlinks = array();
1239 if (!$this->_readDataOnly) {
1240
1241 if ($zip->locateName(dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels")) {
1243 foreach ($relsWorksheet->Relationship as $ele) {
1244 if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink") {
1245 $hyperlinks[(string)$ele["Id"]] = (string)$ele["Target"];
1246 }
1247 }
1248 }
1249
1250
1251 if ($xmlSheet && $xmlSheet->hyperlinks) {
1252 foreach ($xmlSheet->hyperlinks->hyperlink as $hyperlink) {
1253
1254 $linkRel = $hyperlink->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships');
1255
1257 $cell = $docSheet->getCell( $cellReference );
1258 if (isset($linkRel['id'])) {
1259 $hyperlinkUrl = $hyperlinks[ (string)$linkRel['id'] ];
1260 if (isset($hyperlink['location'])) {
1261 $hyperlinkUrl .= '#' . (string) $hyperlink['location'];
1262 }
1263 $cell->getHyperlink()->setUrl($hyperlinkUrl);
1264 } elseif (isset($hyperlink['location'])) {
1265 $cell->getHyperlink()->setUrl( 'sheet://' . (string)$hyperlink['location'] );
1266 }
1267
1268
1269 if (isset($hyperlink['tooltip'])) {
1270 $cell->getHyperlink()->setTooltip( (string)$hyperlink['tooltip'] );
1271 }
1272 }
1273 }
1274 }
1275 }
1276
1277
1278 $comments = array();
1279 $vmlComments = array();
1280 if (!$this->_readDataOnly) {
1281
1282 if ($zip->locateName(dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels")) {
1284 foreach ($relsWorksheet->Relationship as $ele) {
1285 if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments") {
1286 $comments[(string)$ele["Id"]] = (string)$ele["Target"];
1287 }
1288 if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing") {
1289 $vmlComments[(string)$ele["Id"]] = (string)$ele["Target"];
1290 }
1291 }
1292 }
1293
1294
1295 foreach ($comments as $relName => $relPath) {
1296
1299
1300
1301 $authors = array();
1302
1303
1304 foreach ($commentsFile->authors->author as $author) {
1305 $authors[] = (string)$author;
1306 }
1307
1308
1309 foreach ($commentsFile->commentList->comment as
$comment) {
1311 $docSheet->getComment( (
string)
$comment[
'ref'] )->setAuthor( $authors[(
string)
$comment[
'authorId']] );
1313 }
1314 }
1315
1316
1317 foreach ($vmlComments as $relName => $relPath) {
1318
1321 $vmlCommentsFile->registerXPathNamespace('v', 'urn:schemas-microsoft-com:vml');
1322
1323 $shapes = $vmlCommentsFile->xpath('//v:shape');
1324 foreach ($shapes as $shape) {
1325 $shape->registerXPathNamespace('v', 'urn:schemas-microsoft-com:vml');
1326
1327 if (isset($shape['style'])) {
1328 $style = (string)$shape[
'style'];
1329 $fillColor = strtoupper( substr( (string)$shape['fillcolor'], 1 ) );
1332
1333 $clientData = $shape->xpath('.//x:ClientData');
1334 if (is_array($clientData) && !empty($clientData)) {
1335 $clientData = $clientData[0];
1336
1337 if ( isset($clientData['ObjectType']) && (string)$clientData['ObjectType'] == 'Note' ) {
1338 $temp = $clientData->xpath('.//x:Row');
1339 if (is_array($temp))
$row = $temp[0];
1340
1341 $temp = $clientData->xpath('.//x:Column');
1342 if (is_array($temp))
$column = $temp[0];
1343 }
1344 }
1345
1347
1349 $comment->getFillColor()->setRGB( $fillColor );
1350
1351
1352 $styleArray = explode(
';', str_replace(
' ',
'',
$style));
1353 foreach ($styleArray as $stylePair) {
1354 $stylePair = explode(':', $stylePair);
1355
1356 if ($stylePair[0] ==
'margin-left')
$comment->setMarginLeft($stylePair[1]);
1357 if ($stylePair[0] ==
'margin-top')
$comment->setMarginTop($stylePair[1]);
1358 if ($stylePair[0] ==
'width')
$comment->setWidth($stylePair[1]);
1359 if ($stylePair[0] ==
'height')
$comment->setHeight($stylePair[1]);
1360 if ($stylePair[0] ==
'visibility')
$comment->setVisible( $stylePair[1] ==
'visible' );
1361
1362 }
1363 }
1364 }
1365 }
1366 }
1367
1368
1369 if ($xmlSheet && $xmlSheet->legacyDrawingHF && !$this->_readDataOnly) {
1370 if ($zip->locateName(dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels")) {
1372 $vmlRelationship = '';
1373
1374 foreach ($relsWorksheet->Relationship as $ele) {
1375 if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing") {
1376 $vmlRelationship =
self::dir_add(
"$dir/$fileWorksheet", $ele[
"Target"]);
1377 }
1378 }
1379
1380 if ($vmlRelationship != '') {
1381
1383 $drawings = array();
1384 foreach ($relsVML->Relationship as $ele) {
1385 if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image") {
1386 $drawings[(string) $ele["Id"]] = self::dir_add($vmlRelationship, $ele["Target"]);
1387 }
1388 }
1389
1390
1392 $vmlDrawing->registerXPathNamespace('v', 'urn:schemas-microsoft-com:vml');
1393
1394 $hfImages = array();
1395
1396 $shapes = $vmlDrawing->xpath('//v:shape');
1397 foreach ($shapes as $idx => $shape) {
1398 $shape->registerXPathNamespace('v', 'urn:schemas-microsoft-com:vml');
1399 $imageData = $shape->xpath('//v:imagedata');
1400 $imageData = $imageData[$idx];
1401
1402 $imageData = $imageData->attributes('urn:schemas-microsoft-com:office:office');
1404
1406 if (isset($imageData['title'])) {
1407 $hfImages[ (string)$shape['id'] ]->setName( (string)$imageData['title'] );
1408 }
1409
1410 $hfImages[ (string)$shape[
'id'] ]->setPath(
"zip://".
PHPExcel_Shared_File::realpath($pFilename).
"#" . $drawings[(string)$imageData[
'relid']],
false);
1411 $hfImages[ (string)$shape['id'] ]->setResizeProportional(false);
1412 $hfImages[ (string)$shape[
'id'] ]->setWidth(
$style[
'width']);
1413 $hfImages[ (string)$shape[
'id'] ]->setHeight(
$style[
'height']);
1414 if (isset(
$style[
'margin-left'])) {
1415 $hfImages[ (string)$shape[
'id'] ]->setOffsetX(
$style[
'margin-left']);
1416 }
1417 $hfImages[ (string)$shape[
'id'] ]->setOffsetY(
$style[
'margin-top']);
1418 $hfImages[ (string)$shape['id'] ]->setResizeProportional(true);
1419 }
1420
1421 $docSheet->getHeaderFooter()->setImages($hfImages);
1422 }
1423 }
1424 }
1425
1426 }
1427
1428
1429 if ($zip->locateName(dirname("$dir/$fileWorksheet") . "/_rels/" . basename($fileWorksheet) . ".rels")) {
1431 $drawings = array();
1432 foreach ($relsWorksheet->Relationship as $ele) {
1433 if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing") {
1434 $drawings[(string) $ele["Id"]] = self::dir_add("$dir/$fileWorksheet", $ele["Target"]);
1435 }
1436 }
1437 if ($xmlSheet->drawing && !$this->_readDataOnly) {
1438 foreach ($xmlSheet->drawing as $drawing) {
1439 $fileDrawing = $drawings[(string) self::array_item($drawing->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships"), "id")];
1441 $images = array();
1442
1443 if ($relsDrawing && $relsDrawing->Relationship) {
1444 foreach ($relsDrawing->Relationship as $ele) {
1445 if ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image") {
1446 $images[(string) $ele["Id"]] = self::dir_add($fileDrawing, $ele["Target"]);
1447 } elseif ($ele["Type"] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart") {
1448 if ($this->_includeCharts) {
1449 $charts[
self::dir_add($fileDrawing, $ele[
"Target"])] = array(
'id' => (
string) $ele[
"Id"],
1450 'sheet' => $docSheet->getTitle()
1451 );
1452 }
1453 }
1454 }
1455 }
1457
1458 if ($xmlDrawing->oneCellAnchor) {
1459 foreach ($xmlDrawing->oneCellAnchor as $oneCellAnchor) {
1460 if ($oneCellAnchor->pic->blipFill) {
1461 $blip = $oneCellAnchor->pic->blipFill->children("http://schemas.openxmlformats.org/drawingml/2006/main")->blip;
1462 $xfrm = $oneCellAnchor->pic->spPr->children("http://schemas.openxmlformats.org/drawingml/2006/main")->xfrm;
1463 $outerShdw = $oneCellAnchor->pic->spPr->children("http://schemas.openxmlformats.org/drawingml/2006/main")->effectLst->outerShdw;
1465 $objDrawing->setName((
string) self::array_item($oneCellAnchor->pic->nvPicPr->cNvPr->attributes(),
"name"));
1466 $objDrawing->setDescription((
string) self::array_item($oneCellAnchor->pic->nvPicPr->cNvPr->attributes(),
"descr"));
1467 $objDrawing->setPath(
"zip://".
PHPExcel_Shared_File::realpath($pFilename).
"#" . $images[(
string) self::array_item($blip->attributes(
"http://schemas.openxmlformats.org/officeDocument/2006/relationships"),
"embed")],
false);
1474 if ($xfrm) {
1476 }
1477 if ($outerShdw) {
1479 $shadow->setVisible(true);
1480 $shadow->setBlurRadius(PHPExcel_Shared_Drawing::EMUTopixels(self::array_item($outerShdw->attributes(), "blurRad")));
1481 $shadow->setDistance(PHPExcel_Shared_Drawing::EMUTopixels(self::array_item($outerShdw->attributes(), "dist")));
1483 $shadow->setAlignment((string) self::array_item($outerShdw->attributes(), "algn"));
1484 $shadow->getColor()->setRGB(self::array_item($outerShdw->srgbClr->attributes(), "val"));
1485 $shadow->setAlpha(self::array_item($outerShdw->srgbClr->alpha->attributes(), "val") / 1000);
1486 }
1488 } else {
1489
1495 }
1496 }
1497 }
1498 if ($xmlDrawing->twoCellAnchor) {
1499 foreach ($xmlDrawing->twoCellAnchor as $twoCellAnchor) {
1500 if ($twoCellAnchor->pic->blipFill) {
1501 $blip = $twoCellAnchor->pic->blipFill->children("http://schemas.openxmlformats.org/drawingml/2006/main")->blip;
1502 $xfrm = $twoCellAnchor->pic->spPr->children("http://schemas.openxmlformats.org/drawingml/2006/main")->xfrm;
1503 $outerShdw = $twoCellAnchor->pic->spPr->children("http://schemas.openxmlformats.org/drawingml/2006/main")->effectLst->outerShdw;
1505 $objDrawing->setName((
string) self::array_item($twoCellAnchor->pic->nvPicPr->cNvPr->attributes(),
"name"));
1506 $objDrawing->setDescription((
string) self::array_item($twoCellAnchor->pic->nvPicPr->cNvPr->attributes(),
"descr"));
1507 $objDrawing->setPath(
"zip://".
PHPExcel_Shared_File::realpath($pFilename).
"#" . $images[(
string) self::array_item($blip->attributes(
"http://schemas.openxmlformats.org/officeDocument/2006/relationships"),
"embed")],
false);
1512
1513 if ($xfrm) {
1517 }
1518 if ($outerShdw) {
1520 $shadow->setVisible(true);
1521 $shadow->setBlurRadius(PHPExcel_Shared_Drawing::EMUTopixels(self::array_item($outerShdw->attributes(), "blurRad")));
1522 $shadow->setDistance(PHPExcel_Shared_Drawing::EMUTopixels(self::array_item($outerShdw->attributes(), "dist")));
1524 $shadow->setAlignment((string) self::array_item($outerShdw->attributes(), "algn"));
1525 $shadow->getColor()->setRGB(self::array_item($outerShdw->srgbClr->attributes(), "val"));
1526 $shadow->setAlpha(self::array_item($outerShdw->srgbClr->alpha->attributes(), "val") / 1000);
1527 }
1529 } elseif(($this->_includeCharts) && ($twoCellAnchor->graphicFrame)) {
1536 $graphic = $twoCellAnchor->graphicFrame->children("http://schemas.openxmlformats.org/drawingml/2006/main")->graphic;
1537 $chartRef = $graphic->graphicData->children("http://schemas.openxmlformats.org/drawingml/2006/chart")->chart;
1538 $thisChart = (string) $chartRef->attributes("http://schemas.openxmlformats.org/officeDocument/2006/relationships");
1539
1540 $chartDetails[$docSheet->getTitle().'!'.$thisChart] =
1541 array( 'fromCoordinate' => $fromCoordinate,
1542 'fromOffsetX' => $fromOffsetX,
1543 'fromOffsetY' => $fromOffsetY,
1544 'toCoordinate' => $toCoordinate,
1545 'toOffsetX' => $toOffsetX,
1546 'toOffsetY' => $toOffsetY,
1547 'worksheetTitle' => $docSheet->getTitle()
1548 );
1549 }
1550 }
1551 }
1552
1553 }
1554 }
1555 }
1556
1557
1558 if ($xmlWorkbook->definedNames) {
1559 foreach ($xmlWorkbook->definedNames->definedName as $definedName) {
1560
1561 $extractedRange = (string)$definedName;
1562 $extractedRange = preg_replace('/\'(\w+)\'\!/', '', $extractedRange);
1563 if (($spos = strpos($extractedRange,'!')) !== false) {
1564 $extractedRange = substr($extractedRange,0,$spos).str_replace('$', '', substr($extractedRange,$spos));
1565 } else {
1566 $extractedRange = str_replace('$', '', $extractedRange);
1567 }
1568
1569
1570 if (stripos((string)$definedName, '#REF!') !== FALSE || $extractedRange == '') {
1571 continue;
1572 }
1573
1574
1575 if ((string)$definedName['localSheetId'] != '' && (string)$definedName['localSheetId'] == $sheetId) {
1576
1577 switch ((string)$definedName['name']) {
1578
1579 case '_xlnm._FilterDatabase':
1580 if ((string)$definedName['hidden'] !== '1') {
1581 $extractedRange = explode(',', $extractedRange);
1582 foreach ($extractedRange as $range) {
1583 $autoFilterRange = $range;
1584 if (strpos($autoFilterRange, ':') !== false) {
1585 $docSheet->getAutoFilter()->setRange($autoFilterRange);
1586 }
1587 }
1588 }
1589 break;
1590
1591 case '_xlnm.Print_Titles':
1592
1593 $extractedRange = explode(',', $extractedRange);
1594
1595
1596 foreach ($extractedRange as $range) {
1597 $matches = array();
1598 $range = str_replace('$', '', $range);
1599
1600
1601 if (preg_match('/!?([A-Z]+)\:([A-Z]+)$/', $range, $matches)) {
1602 $docSheet->getPageSetup()->setColumnsToRepeatAtLeft(array($matches[1], $matches[2]));
1603 }
1604
1605 elseif (preg_match('/!?(\d+)\:(\d+)$/', $range, $matches)) {
1606 $docSheet->getPageSetup()->setRowsToRepeatAtTop(array($matches[1], $matches[2]));
1607 }
1608 }
1609 break;
1610
1611 case '_xlnm.Print_Area':
1612 $rangeSets = explode(',', $extractedRange);
1613 $newRangeSets = array();
1614 foreach($rangeSets as $rangeSet) {
1615 $range = explode('!', $rangeSet);
1616 $rangeSet = isset($range[1]) ? $range[1] : $range[0];
1617 if (strpos($rangeSet, ':') === FALSE) {
1618 $rangeSet = $rangeSet . ':' . $rangeSet;
1619 }
1620 $newRangeSets[] = str_replace('$', '', $rangeSet);
1621 }
1622 $docSheet->getPageSetup()->setPrintArea(implode(',',$newRangeSets));
1623 break;
1624
1625 default:
1626 break;
1627 }
1628 }
1629 }
1630 }
1631
1632
1633 ++$sheetId;
1634 }
1635
1636
1637 if ($xmlWorkbook->definedNames) {
1638 foreach ($xmlWorkbook->definedNames->definedName as $definedName) {
1639
1640 $extractedRange = (string)$definedName;
1641 $extractedRange = preg_replace('/\'(\w+)\'\!/', '', $extractedRange);
1642 if (($spos = strpos($extractedRange,'!')) !== false) {
1643 $extractedRange = substr($extractedRange,0,$spos).str_replace('$', '', substr($extractedRange,$spos));
1644 } else {
1645 $extractedRange = str_replace('$', '', $extractedRange);
1646 }
1647
1648
1649 if (stripos((string)$definedName, '#REF!') !== false || $extractedRange == '') {
1650 continue;
1651 }
1652
1653
1654 if ((string)$definedName['localSheetId'] != '') {
1655
1656
1657 switch ((string)$definedName['name']) {
1658
1659 case '_xlnm._FilterDatabase':
1660 case '_xlnm.Print_Titles':
1661 case '_xlnm.Print_Area':
1662 break;
1663
1664 default:
1665 if ($mapSheetId[(integer) $definedName['localSheetId']] !== null) {
1666 $range = explode('!', (string)$definedName);
1667 if (count($range) == 2) {
1668 $range[0] = str_replace("''", "'", $range[0]);
1669 $range[0] = str_replace("'", "", $range[0]);
1670 if (
$worksheet = $docSheet->getParent()->getSheetByName($range[0])) {
1671 $extractedRange = str_replace('$', '', $range[1]);
1672 $scope = $docSheet->getParent()->getSheet($mapSheetId[(integer) $definedName['localSheetId']]);
1674 }
1675 }
1676 }
1677 break;
1678 }
1679 } else if (!isset($definedName['localSheetId'])) {
1680
1681 $locatedSheet = null;
1682 $extractedSheetName = '';
1683 if (strpos( (string)$definedName, '!' ) !== false) {
1684
1686 $extractedSheetName = $extractedSheetName[0];
1687
1688
1689 $locatedSheet = $excel->getSheetByName($extractedSheetName);
1690
1691
1692 $range = explode('!', $extractedRange);
1693 $extractedRange = isset($range[1]) ? $range[1] : $range[0];
1694 }
1695
1696 if ($locatedSheet !== NULL) {
1697 $excel->addNamedRange(
new PHPExcel_NamedRange((
string)$definedName[
'name'], $locatedSheet, $extractedRange,
false) );
1698 }
1699 }
1700 }
1701 }
1702 }
1703
1704 if ((!$this->_readDataOnly) || (!empty($this->_loadSheetsOnly))) {
1705
1706 $activeTab = intval($xmlWorkbook->bookViews->workbookView["activeTab"]);
1707
1708
1709 if (isset($mapSheetId[$activeTab]) && $mapSheetId[$activeTab] !== null) {
1710 $excel->setActiveSheetIndex($mapSheetId[$activeTab]);
1711 } else {
1712 if ($excel->getSheetCount() == 0) {
1713 $excel->createSheet();
1714 }
1715 $excel->setActiveSheetIndex(0);
1716 }
1717 }
1718 break;
1719 }
1720
1721 }
1722
1723
1724 if (!$this->_readDataOnly) {
1726 foreach ($contentTypes->Override as $contentType) {
1727 switch ($contentType["ContentType"]) {
1728 case "application/vnd.openxmlformats-officedocument.drawingml.chart+xml":
1729 if ($this->_includeCharts) {
1730 $chartEntryRef = ltrim($contentType['PartName'],'/');
1733
1734
1735
1736
1737 if (isset($charts[$chartEntryRef])) {
1738 $chartPositionRef = $charts[$chartEntryRef]['sheet'].'!'.$charts[$chartEntryRef]['id'];
1739
1740 if (isset($chartDetails[$chartPositionRef])) {
1741
1742
1743 $excel->getSheetByName($charts[$chartEntryRef]['sheet'])->addChart($objChart);
1744 $objChart->setWorksheet($excel->getSheetByName($charts[$chartEntryRef]['sheet']));
1745 $objChart->setTopLeftPosition( $chartDetails[$chartPositionRef]['fromCoordinate'],
1746 $chartDetails[$chartPositionRef]['fromOffsetX'],
1747 $chartDetails[$chartPositionRef]['fromOffsetY']
1748 );
1749 $objChart->setBottomRightPosition( $chartDetails[$chartPositionRef]['toCoordinate'],
1750 $chartDetails[$chartPositionRef]['toOffsetX'],
1751 $chartDetails[$chartPositionRef]['toOffsetY']
1752 );
1753 }
1754 }
1755 }
1756 }
1757 }
1758 }
1759
1760 $zip->close();
1761
1762 return $excel;
1763 }
static extractAllCellReferencesInRange($pRange='A1')
Extract all cell references in range.
static convertPropertyType($propertyType)
static convertProperty($propertyValue, $propertyType)
getReadFilter()
Read filter.
static readChart($chartElements, $chartName)
_readRibbon($excel, $customUITarget, $zip)
static toCSSArray($style)
static dir_add($base, $add)
static array_item($array, $key=0)
_castToFormula($c, $r, &$cellDataType, &$value, &$calculatedValue, &$sharedFormulas, $castBaseType)
static _readStyle($docStyle, $style)
static setExcelCalendar($baseDate)
Set the Excel calendar (Windows 1900 or Mac 1904)
const CALENDAR_WINDOWS_1900
constants
static EMUToPixels($pValue=0)
Convert EMU to pixels.
static angleToDegrees($pValue=0)
Convert angle to degrees.
const CONDITION_EXPRESSION
const CONDITION_CONTAINSTEXT
const AUTOFILTER_COLUMN_RULE_TOPTEN_TOP
const AUTOFILTER_RULETYPE_FILTER
const AUTOFILTER_COLUMN_RULE_TOPTEN_PERCENT
const AUTOFILTER_COLUMN_RULE_TOPTEN_BY_VALUE
const AUTOFILTER_RULETYPE_DYNAMICFILTER
const AUTOFILTER_RULETYPE_TOPTENFILTER
const AUTOFILTER_RULETYPE_CUSTOMFILTER
const AUTOFILTER_COLUMN_RULE_TOPTEN_BOTTOM
const AUTOFILTER_RULETYPE_DATEGROUP
const AUTOFILTER_FILTERTYPE_CUSTOMFILTER
const AUTOFILTER_FILTERTYPE_FILTER
const AUTOFILTER_FILTERTYPE_TOPTENFILTER
const AUTOFILTER_FILTERTYPE_DYNAMICFILTER
const AUTOFILTER_COLUMN_JOIN_AND
static extractSheetTitle($pRange, $returnRange=false)
Extract worksheet title from range.