Conditions | 382 |
Paths | > 20000 |
Total Lines | 1656 |
Code Lines | 1027 |
Lines | 0 |
Ratio | 0 % |
Tests | 779 |
CRAP Score | 2024.2992 |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
387 | 38 | public function load($pFilename) |
|
388 | { |
||
389 | 38 | File::assertFile($pFilename); |
|
390 | |||
391 | // Initialisations |
||
392 | 38 | $excel = new Spreadsheet(); |
|
393 | 38 | $excel->removeSheetByIndex(0); |
|
394 | 38 | if (!$this->readDataOnly) { |
|
395 | 38 | $excel->removeCellStyleXfByIndex(0); // remove the default style |
|
396 | 38 | $excel->removeCellXfByIndex(0); // remove the default style |
|
397 | } |
||
398 | 38 | $unparsedLoadedData = []; |
|
399 | |||
400 | 38 | $zip = new ZipArchive(); |
|
401 | 38 | $zip->open($pFilename); |
|
402 | |||
403 | // Read the theme first, because we need the colour scheme when reading the styles |
||
404 | //~ http://schemas.openxmlformats.org/package/2006/relationships" |
||
405 | 38 | $wbRels = simplexml_load_string( |
|
406 | 38 | $this->securityScan($this->getFromZipArchive($zip, 'xl/_rels/workbook.xml.rels')), |
|
407 | 38 | 'SimpleXMLElement', |
|
408 | 38 | Settings::getLibXmlLoaderOptions() |
|
409 | ); |
||
410 | 38 | foreach ($wbRels->Relationship as $rel) { |
|
411 | 38 | switch ($rel['Type']) { |
|
412 | 38 | case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme': |
|
413 | 38 | $themeOrderArray = ['lt1', 'dk1', 'lt2', 'dk2']; |
|
414 | 38 | $themeOrderAdditional = count($themeOrderArray); |
|
415 | |||
416 | 38 | $xmlTheme = simplexml_load_string( |
|
417 | 38 | $this->securityScan($this->getFromZipArchive($zip, "xl/{$rel['Target']}")), |
|
418 | 38 | 'SimpleXMLElement', |
|
419 | 38 | Settings::getLibXmlLoaderOptions() |
|
420 | ); |
||
421 | 38 | if (is_object($xmlTheme)) { |
|
422 | 38 | $xmlThemeName = $xmlTheme->attributes(); |
|
423 | 38 | $xmlTheme = $xmlTheme->children('http://schemas.openxmlformats.org/drawingml/2006/main'); |
|
424 | 38 | $themeName = (string) $xmlThemeName['name']; |
|
425 | |||
426 | 38 | $colourScheme = $xmlTheme->themeElements->clrScheme->attributes(); |
|
427 | 38 | $colourSchemeName = (string) $colourScheme['name']; |
|
428 | 38 | $colourScheme = $xmlTheme->themeElements->clrScheme->children('http://schemas.openxmlformats.org/drawingml/2006/main'); |
|
429 | |||
430 | 38 | $themeColours = []; |
|
431 | 38 | foreach ($colourScheme as $k => $xmlColour) { |
|
432 | 38 | $themePos = array_search($k, $themeOrderArray); |
|
433 | 38 | if ($themePos === false) { |
|
434 | 38 | $themePos = $themeOrderAdditional++; |
|
435 | } |
||
436 | 38 | if (isset($xmlColour->sysClr)) { |
|
437 | 38 | $xmlColourData = $xmlColour->sysClr->attributes(); |
|
438 | 38 | $themeColours[$themePos] = $xmlColourData['lastClr']; |
|
439 | 38 | } elseif (isset($xmlColour->srgbClr)) { |
|
440 | 38 | $xmlColourData = $xmlColour->srgbClr->attributes(); |
|
441 | 38 | $themeColours[$themePos] = $xmlColourData['val']; |
|
442 | } |
||
443 | } |
||
444 | 38 | self::$theme = new Xlsx\Theme($themeName, $colourSchemeName, $themeColours); |
|
445 | } |
||
446 | |||
447 | 38 | break; |
|
448 | } |
||
449 | } |
||
450 | |||
451 | //~ http://schemas.openxmlformats.org/package/2006/relationships" |
||
452 | 38 | $rels = simplexml_load_string( |
|
453 | 38 | $this->securityScan($this->getFromZipArchive($zip, '_rels/.rels')), |
|
454 | 38 | 'SimpleXMLElement', |
|
455 | 38 | Settings::getLibXmlLoaderOptions() |
|
456 | ); |
||
457 | 38 | foreach ($rels->Relationship as $rel) { |
|
458 | 38 | switch ($rel['Type']) { |
|
459 | 38 | case 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties': |
|
460 | 37 | $xmlCore = simplexml_load_string( |
|
461 | 37 | $this->securityScan($this->getFromZipArchive($zip, "{$rel['Target']}")), |
|
462 | 37 | 'SimpleXMLElement', |
|
463 | 37 | Settings::getLibXmlLoaderOptions() |
|
464 | ); |
||
465 | 37 | if (is_object($xmlCore)) { |
|
466 | 37 | $xmlCore->registerXPathNamespace('dc', 'http://purl.org/dc/elements/1.1/'); |
|
467 | 37 | $xmlCore->registerXPathNamespace('dcterms', 'http://purl.org/dc/terms/'); |
|
468 | 37 | $xmlCore->registerXPathNamespace('cp', 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties'); |
|
469 | 37 | $docProps = $excel->getProperties(); |
|
470 | 37 | $docProps->setCreator((string) self::getArrayItem($xmlCore->xpath('dc:creator'))); |
|
471 | 37 | $docProps->setLastModifiedBy((string) self::getArrayItem($xmlCore->xpath('cp:lastModifiedBy'))); |
|
472 | 37 | $docProps->setCreated(strtotime(self::getArrayItem($xmlCore->xpath('dcterms:created')))); //! respect xsi:type |
|
473 | 37 | $docProps->setModified(strtotime(self::getArrayItem($xmlCore->xpath('dcterms:modified')))); //! respect xsi:type |
|
474 | 37 | $docProps->setTitle((string) self::getArrayItem($xmlCore->xpath('dc:title'))); |
|
475 | 37 | $docProps->setDescription((string) self::getArrayItem($xmlCore->xpath('dc:description'))); |
|
476 | 37 | $docProps->setSubject((string) self::getArrayItem($xmlCore->xpath('dc:subject'))); |
|
477 | 37 | $docProps->setKeywords((string) self::getArrayItem($xmlCore->xpath('cp:keywords'))); |
|
478 | 37 | $docProps->setCategory((string) self::getArrayItem($xmlCore->xpath('cp:category'))); |
|
479 | } |
||
480 | |||
481 | 37 | break; |
|
482 | 38 | case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties': |
|
483 | 37 | $xmlCore = simplexml_load_string( |
|
484 | 37 | $this->securityScan($this->getFromZipArchive($zip, "{$rel['Target']}")), |
|
485 | 37 | 'SimpleXMLElement', |
|
486 | 37 | Settings::getLibXmlLoaderOptions() |
|
487 | ); |
||
488 | 37 | if (is_object($xmlCore)) { |
|
489 | 37 | $docProps = $excel->getProperties(); |
|
490 | 37 | if (isset($xmlCore->Company)) { |
|
491 | 35 | $docProps->setCompany((string) $xmlCore->Company); |
|
492 | } |
||
493 | 37 | if (isset($xmlCore->Manager)) { |
|
494 | 32 | $docProps->setManager((string) $xmlCore->Manager); |
|
495 | } |
||
496 | } |
||
497 | |||
498 | 37 | break; |
|
499 | 38 | case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties': |
|
500 | 3 | $xmlCore = simplexml_load_string( |
|
501 | 3 | $this->securityScan($this->getFromZipArchive($zip, "{$rel['Target']}")), |
|
502 | 3 | 'SimpleXMLElement', |
|
503 | 3 | Settings::getLibXmlLoaderOptions() |
|
504 | ); |
||
505 | 3 | if (is_object($xmlCore)) { |
|
506 | 3 | $docProps = $excel->getProperties(); |
|
507 | /** @var SimpleXMLElement $xmlProperty */ |
||
508 | 3 | foreach ($xmlCore as $xmlProperty) { |
|
509 | 3 | $cellDataOfficeAttributes = $xmlProperty->attributes(); |
|
510 | 3 | if (isset($cellDataOfficeAttributes['name'])) { |
|
511 | 3 | $propertyName = (string) $cellDataOfficeAttributes['name']; |
|
512 | 3 | $cellDataOfficeChildren = $xmlProperty->children('http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes'); |
|
513 | 3 | $attributeType = $cellDataOfficeChildren->getName(); |
|
514 | 3 | $attributeValue = (string) $cellDataOfficeChildren->{$attributeType}; |
|
515 | 3 | $attributeValue = Properties::convertProperty($attributeValue, $attributeType); |
|
516 | 3 | $attributeType = Properties::convertPropertyType($attributeType); |
|
517 | 3 | $docProps->setCustomProperty($propertyName, $attributeValue, $attributeType); |
|
518 | } |
||
519 | } |
||
520 | } |
||
521 | |||
522 | 3 | break; |
|
523 | //Ribbon |
||
524 | 38 | case 'http://schemas.microsoft.com/office/2006/relationships/ui/extensibility': |
|
525 | $customUI = $rel['Target']; |
||
526 | if ($customUI !== null) { |
||
527 | $this->readRibbon($excel, $customUI, $zip); |
||
528 | } |
||
529 | |||
530 | break; |
||
531 | 38 | case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument': |
|
532 | 38 | $dir = dirname($rel['Target']); |
|
533 | //~ http://schemas.openxmlformats.org/package/2006/relationships" |
||
534 | 38 | $relsWorkbook = simplexml_load_string( |
|
535 | 38 | $this->securityScan($this->getFromZipArchive($zip, "$dir/_rels/" . basename($rel['Target']) . '.rels')), |
|
536 | 38 | 'SimpleXMLElement', |
|
537 | 38 | Settings::getLibXmlLoaderOptions() |
|
538 | ); |
||
539 | 38 | $relsWorkbook->registerXPathNamespace('rel', 'http://schemas.openxmlformats.org/package/2006/relationships'); |
|
540 | |||
541 | 38 | $sharedStrings = []; |
|
542 | 38 | $xpath = self::getArrayItem($relsWorkbook->xpath("rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings']")); |
|
543 | //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main" |
||
544 | 38 | $xmlStrings = simplexml_load_string( |
|
545 | 38 | $this->securityScan($this->getFromZipArchive($zip, "$dir/$xpath[Target]")), |
|
546 | 38 | 'SimpleXMLElement', |
|
547 | 38 | Settings::getLibXmlLoaderOptions() |
|
548 | ); |
||
549 | 38 | if (isset($xmlStrings, $xmlStrings->si)) { |
|
550 | 19 | foreach ($xmlStrings->si as $val) { |
|
551 | 19 | if (isset($val->t)) { |
|
552 | 19 | $sharedStrings[] = StringHelper::controlCharacterOOXML2PHP((string) $val->t); |
|
553 | 3 | } elseif (isset($val->r)) { |
|
554 | 19 | $sharedStrings[] = $this->parseRichText($val); |
|
555 | } |
||
556 | } |
||
557 | } |
||
558 | |||
559 | 38 | $worksheets = []; |
|
560 | 38 | $macros = $customUI = null; |
|
561 | 38 | foreach ($relsWorkbook->Relationship as $ele) { |
|
562 | 38 | switch ($ele['Type']) { |
|
563 | 38 | case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet': |
|
564 | 38 | $worksheets[(string) $ele['Id']] = $ele['Target']; |
|
565 | |||
566 | 38 | break; |
|
567 | // a vbaProject ? (: some macros) |
||
568 | 38 | case 'http://schemas.microsoft.com/office/2006/relationships/vbaProject': |
|
569 | 1 | $macros = $ele['Target']; |
|
570 | |||
571 | 38 | break; |
|
572 | } |
||
573 | } |
||
574 | |||
575 | 38 | if ($macros !== null) { |
|
576 | 1 | $macrosCode = $this->getFromZipArchive($zip, 'xl/vbaProject.bin'); //vbaProject.bin always in 'xl' dir and always named vbaProject.bin |
|
577 | 1 | if ($macrosCode !== false) { |
|
578 | 1 | $excel->setMacrosCode($macrosCode); |
|
579 | 1 | $excel->setHasMacros(true); |
|
580 | //short-circuit : not reading vbaProject.bin.rel to get Signature =>allways vbaProjectSignature.bin in 'xl' dir |
||
581 | 1 | $Certificate = $this->getFromZipArchive($zip, 'xl/vbaProjectSignature.bin'); |
|
582 | 1 | if ($Certificate !== false) { |
|
583 | $excel->setMacrosCertificate($Certificate); |
||
584 | } |
||
585 | } |
||
586 | } |
||
587 | 38 | $styles = []; |
|
588 | 38 | $cellStyles = []; |
|
589 | 38 | $xpath = self::getArrayItem($relsWorkbook->xpath("rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles']")); |
|
590 | //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main" |
||
591 | 38 | $xmlStyles = simplexml_load_string( |
|
592 | 38 | $this->securityScan($this->getFromZipArchive($zip, "$dir/$xpath[Target]")), |
|
593 | 38 | 'SimpleXMLElement', |
|
594 | 38 | Settings::getLibXmlLoaderOptions() |
|
595 | ); |
||
596 | 38 | $numFmts = null; |
|
597 | 38 | if ($xmlStyles && $xmlStyles->numFmts[0]) { |
|
598 | 31 | $numFmts = $xmlStyles->numFmts[0]; |
|
599 | } |
||
600 | 38 | if (isset($numFmts) && ($numFmts !== null)) { |
|
601 | 31 | $numFmts->registerXPathNamespace('sml', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main'); |
|
602 | } |
||
603 | 38 | if (!$this->readDataOnly && $xmlStyles) { |
|
604 | 38 | foreach ($xmlStyles->cellXfs->xf as $xf) { |
|
605 | 38 | $numFmt = NumberFormat::FORMAT_GENERAL; |
|
606 | |||
607 | 38 | if ($xf['numFmtId']) { |
|
608 | 38 | if (isset($numFmts)) { |
|
609 | 31 | $tmpNumFmt = self::getArrayItem($numFmts->xpath("sml:numFmt[@numFmtId=$xf[numFmtId]]")); |
|
610 | |||
611 | 31 | if (isset($tmpNumFmt['formatCode'])) { |
|
612 | 3 | $numFmt = (string) $tmpNumFmt['formatCode']; |
|
613 | } |
||
614 | } |
||
615 | |||
616 | // We shouldn't override any of the built-in MS Excel values (values below id 164) |
||
617 | // But there's a lot of naughty homebrew xlsx writers that do use "reserved" id values that aren't actually used |
||
618 | // So we make allowance for them rather than lose formatting masks |
||
619 | 38 | if ((int) $xf['numFmtId'] < 164 && |
|
620 | 38 | NumberFormat::builtInFormatCode((int) $xf['numFmtId']) !== '') { |
|
621 | 38 | $numFmt = NumberFormat::builtInFormatCode((int) $xf['numFmtId']); |
|
622 | } |
||
623 | } |
||
624 | 38 | $quotePrefix = false; |
|
625 | 38 | if (isset($xf['quotePrefix'])) { |
|
626 | $quotePrefix = (bool) $xf['quotePrefix']; |
||
627 | } |
||
628 | |||
629 | $style = (object) [ |
||
630 | 38 | 'numFmt' => $numFmt, |
|
631 | 38 | 'font' => $xmlStyles->fonts->font[(int) ($xf['fontId'])], |
|
632 | 38 | 'fill' => $xmlStyles->fills->fill[(int) ($xf['fillId'])], |
|
633 | 38 | 'border' => $xmlStyles->borders->border[(int) ($xf['borderId'])], |
|
634 | 38 | 'alignment' => $xf->alignment, |
|
635 | 38 | 'protection' => $xf->protection, |
|
636 | 38 | 'quotePrefix' => $quotePrefix, |
|
637 | ]; |
||
638 | 38 | $styles[] = $style; |
|
639 | |||
640 | // add style to cellXf collection |
||
641 | 38 | $objStyle = new Style(); |
|
642 | 38 | self::readStyle($objStyle, $style); |
|
643 | 38 | $excel->addCellXf($objStyle); |
|
644 | } |
||
645 | |||
646 | 38 | foreach (isset($xmlStyles->cellStyleXfs->xf) ? $xmlStyles->cellStyleXfs->xf : [] as $xf) { |
|
647 | 38 | $numFmt = NumberFormat::FORMAT_GENERAL; |
|
648 | 38 | if ($numFmts && $xf['numFmtId']) { |
|
649 | 31 | $tmpNumFmt = self::getArrayItem($numFmts->xpath("sml:numFmt[@numFmtId=$xf[numFmtId]]")); |
|
650 | 31 | if (isset($tmpNumFmt['formatCode'])) { |
|
651 | 1 | $numFmt = (string) $tmpNumFmt['formatCode']; |
|
652 | 31 | } elseif ((int) $xf['numFmtId'] < 165) { |
|
653 | 31 | $numFmt = NumberFormat::builtInFormatCode((int) $xf['numFmtId']); |
|
654 | } |
||
655 | } |
||
656 | |||
657 | $cellStyle = (object) [ |
||
658 | 38 | 'numFmt' => $numFmt, |
|
659 | 38 | 'font' => $xmlStyles->fonts->font[(int) ($xf['fontId'])], |
|
660 | 38 | 'fill' => $xmlStyles->fills->fill[(int) ($xf['fillId'])], |
|
661 | 38 | 'border' => $xmlStyles->borders->border[(int) ($xf['borderId'])], |
|
662 | 38 | 'alignment' => $xf->alignment, |
|
663 | 38 | 'protection' => $xf->protection, |
|
664 | 38 | 'quotePrefix' => $quotePrefix, |
|
665 | ]; |
||
666 | 38 | $cellStyles[] = $cellStyle; |
|
667 | |||
668 | // add style to cellStyleXf collection |
||
669 | 38 | $objStyle = new Style(); |
|
670 | 38 | self::readStyle($objStyle, $cellStyle); |
|
671 | 38 | $excel->addCellStyleXf($objStyle); |
|
672 | } |
||
673 | } |
||
674 | |||
675 | 38 | $dxfs = []; |
|
676 | 38 | if (!$this->readDataOnly && $xmlStyles) { |
|
677 | // Conditional Styles |
||
678 | 38 | if ($xmlStyles->dxfs) { |
|
679 | 38 | foreach ($xmlStyles->dxfs->dxf as $dxf) { |
|
680 | 1 | $style = new Style(false, true); |
|
681 | 1 | self::readStyle($style, $dxf); |
|
682 | 1 | $dxfs[] = $style; |
|
683 | } |
||
684 | } |
||
685 | // Cell Styles |
||
686 | 38 | if ($xmlStyles->cellStyles) { |
|
687 | 38 | foreach ($xmlStyles->cellStyles->cellStyle as $cellStyle) { |
|
688 | 38 | if ((int) ($cellStyle['builtinId']) == 0) { |
|
689 | 38 | if (isset($cellStyles[(int) ($cellStyle['xfId'])])) { |
|
690 | // Set default style |
||
691 | 38 | $style = new Style(); |
|
692 | 38 | self::readStyle($style, $cellStyles[(int) ($cellStyle['xfId'])]); |
|
693 | |||
694 | // normal style, currently not using it for anything |
||
695 | } |
||
696 | } |
||
697 | } |
||
698 | } |
||
699 | } |
||
700 | |||
701 | //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main" |
||
702 | 38 | $xmlWorkbook = simplexml_load_string( |
|
703 | 38 | $this->securityScan($this->getFromZipArchive($zip, "{$rel['Target']}")), |
|
704 | 38 | 'SimpleXMLElement', |
|
705 | 38 | Settings::getLibXmlLoaderOptions() |
|
706 | ); |
||
707 | |||
708 | // Set base date |
||
709 | 38 | if ($xmlWorkbook->workbookPr) { |
|
710 | 37 | Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900); |
|
711 | 37 | if (isset($xmlWorkbook->workbookPr['date1904'])) { |
|
712 | if (self::boolean((string) $xmlWorkbook->workbookPr['date1904'])) { |
||
713 | Date::setExcelCalendar(Date::CALENDAR_MAC_1904); |
||
714 | } |
||
715 | } |
||
716 | } |
||
717 | |||
718 | // Set protection |
||
719 | 38 | $this->readProtection($excel, $xmlWorkbook); |
|
1 ignored issue
–
show
|
|||
720 | |||
721 | 38 | $sheetId = 0; // keep track of new sheet id in final workbook |
|
722 | 38 | $oldSheetId = -1; // keep track of old sheet id in final workbook |
|
723 | 38 | $countSkippedSheets = 0; // keep track of number of skipped sheets |
|
724 | 38 | $mapSheetId = []; // mapping of sheet ids from old to new |
|
725 | |||
726 | 38 | $charts = $chartDetails = []; |
|
727 | |||
728 | 38 | if ($xmlWorkbook->sheets) { |
|
729 | /** @var SimpleXMLElement $eleSheet */ |
||
730 | 38 | foreach ($xmlWorkbook->sheets->sheet as $eleSheet) { |
|
731 | 38 | ++$oldSheetId; |
|
732 | |||
733 | // Check if sheet should be skipped |
||
734 | 38 | if (isset($this->loadSheetsOnly) && !in_array((string) $eleSheet['name'], $this->loadSheetsOnly)) { |
|
735 | 1 | ++$countSkippedSheets; |
|
736 | 1 | $mapSheetId[$oldSheetId] = null; |
|
737 | |||
738 | 1 | continue; |
|
739 | } |
||
740 | |||
741 | // Map old sheet id in original workbook to new sheet id. |
||
742 | // They will differ if loadSheetsOnly() is being used |
||
743 | 38 | $mapSheetId[$oldSheetId] = $oldSheetId - $countSkippedSheets; |
|
744 | |||
745 | // Load sheet |
||
746 | 38 | $docSheet = $excel->createSheet(); |
|
747 | // Use false for $updateFormulaCellReferences to prevent adjustment of worksheet |
||
748 | // references in formula cells... during the load, all formulae should be correct, |
||
749 | // and we're simply bringing the worksheet name in line with the formula, not the |
||
750 | // reverse |
||
751 | 38 | $docSheet->setTitle((string) $eleSheet['name'], false, false); |
|
752 | 38 | $fileWorksheet = $worksheets[(string) self::getArrayItem($eleSheet->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'), 'id')]; |
|
753 | //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main" |
||
754 | 38 | $xmlSheet = simplexml_load_string( |
|
755 | 38 | $this->securityScan($this->getFromZipArchive($zip, "$dir/$fileWorksheet")), |
|
756 | 38 | 'SimpleXMLElement', |
|
757 | 38 | Settings::getLibXmlLoaderOptions() |
|
758 | ); |
||
759 | |||
760 | 38 | $sharedFormulas = []; |
|
761 | |||
762 | 38 | if (isset($eleSheet['state']) && (string) $eleSheet['state'] != '') { |
|
763 | 1 | $docSheet->setSheetState((string) $eleSheet['state']); |
|
764 | } |
||
765 | |||
766 | 38 | if (isset($xmlSheet->sheetViews, $xmlSheet->sheetViews->sheetView)) { |
|
767 | 38 | if (isset($xmlSheet->sheetViews->sheetView['zoomScale'])) { |
|
768 | $zoomScale = (int) ($xmlSheet->sheetViews->sheetView['zoomScale']); |
||
769 | if ($zoomScale <= 0) { |
||
770 | // setZoomScale will throw an Exception if the scale is less than or equals 0 |
||
771 | // that is OK when manually creating documents, but we should be able to read all documents |
||
772 | $zoomScale = 100; |
||
773 | } |
||
774 | |||
775 | $docSheet->getSheetView()->setZoomScale($zoomScale); |
||
776 | } |
||
777 | 38 | if (isset($xmlSheet->sheetViews->sheetView['zoomScaleNormal'])) { |
|
778 | $zoomScaleNormal = (int) ($xmlSheet->sheetViews->sheetView['zoomScaleNormal']); |
||
779 | if ($zoomScaleNormal <= 0) { |
||
780 | // setZoomScaleNormal will throw an Exception if the scale is less than or equals 0 |
||
781 | // that is OK when manually creating documents, but we should be able to read all documents |
||
782 | $zoomScaleNormal = 100; |
||
783 | } |
||
784 | |||
785 | $docSheet->getSheetView()->setZoomScaleNormal($zoomScaleNormal); |
||
786 | } |
||
787 | 38 | if (isset($xmlSheet->sheetViews->sheetView['view'])) { |
|
788 | $docSheet->getSheetView()->setView((string) $xmlSheet->sheetViews->sheetView['view']); |
||
789 | } |
||
790 | 38 | if (isset($xmlSheet->sheetViews->sheetView['showGridLines'])) { |
|
791 | 30 | $docSheet->setShowGridLines(self::boolean((string) $xmlSheet->sheetViews->sheetView['showGridLines'])); |
|
792 | } |
||
793 | 38 | if (isset($xmlSheet->sheetViews->sheetView['showRowColHeaders'])) { |
|
794 | 30 | $docSheet->setShowRowColHeaders(self::boolean((string) $xmlSheet->sheetViews->sheetView['showRowColHeaders'])); |
|
795 | } |
||
796 | 38 | if (isset($xmlSheet->sheetViews->sheetView['rightToLeft'])) { |
|
797 | $docSheet->setRightToLeft(self::boolean((string) $xmlSheet->sheetViews->sheetView['rightToLeft'])); |
||
798 | } |
||
799 | 38 | if (isset($xmlSheet->sheetViews->sheetView->pane)) { |
|
800 | 3 | $xSplit = 0; |
|
801 | 3 | $ySplit = 0; |
|
802 | 3 | $topLeftCell = null; |
|
803 | |||
804 | 3 | if (isset($xmlSheet->sheetViews->sheetView->pane['xSplit'])) { |
|
805 | 1 | $xSplit = (int) ($xmlSheet->sheetViews->sheetView->pane['xSplit']); |
|
806 | } |
||
807 | |||
808 | 3 | if (isset($xmlSheet->sheetViews->sheetView->pane['ySplit'])) { |
|
809 | 3 | $ySplit = (int) ($xmlSheet->sheetViews->sheetView->pane['ySplit']); |
|
810 | } |
||
811 | |||
812 | 3 | if (isset($xmlSheet->sheetViews->sheetView->pane['topLeftCell'])) { |
|
813 | 3 | $topLeftCell = (string) $xmlSheet->sheetViews->sheetView->pane['topLeftCell']; |
|
814 | } |
||
815 | |||
816 | 3 | $docSheet->freezePane(Coordinate::stringFromColumnIndex($xSplit + 1) . ($ySplit + 1), $topLeftCell); |
|
817 | } |
||
818 | |||
819 | 38 | if (isset($xmlSheet->sheetViews->sheetView->selection)) { |
|
820 | 36 | if (isset($xmlSheet->sheetViews->sheetView->selection['sqref'])) { |
|
821 | 35 | $sqref = (string) $xmlSheet->sheetViews->sheetView->selection['sqref']; |
|
822 | 35 | $sqref = explode(' ', $sqref); |
|
823 | 35 | $sqref = $sqref[0]; |
|
824 | 35 | $docSheet->setSelectedCells($sqref); |
|
825 | } |
||
826 | } |
||
827 | } |
||
828 | |||
829 | 38 | if (isset($xmlSheet->sheetPr, $xmlSheet->sheetPr->tabColor)) { |
|
830 | 2 | if (isset($xmlSheet->sheetPr->tabColor['rgb'])) { |
|
831 | 2 | $docSheet->getTabColor()->setARGB((string) $xmlSheet->sheetPr->tabColor['rgb']); |
|
832 | } |
||
833 | } |
||
834 | 38 | if (isset($xmlSheet->sheetPr, $xmlSheet->sheetPr['codeName'])) { |
|
835 | 1 | $docSheet->setCodeName((string) $xmlSheet->sheetPr['codeName'], false); |
|
836 | } |
||
837 | 38 | if (isset($xmlSheet->sheetPr, $xmlSheet->sheetPr->outlinePr)) { |
|
838 | 30 | if (isset($xmlSheet->sheetPr->outlinePr['summaryRight']) && |
|
839 | 30 | !self::boolean((string) $xmlSheet->sheetPr->outlinePr['summaryRight'])) { |
|
840 | $docSheet->setShowSummaryRight(false); |
||
841 | } else { |
||
842 | 30 | $docSheet->setShowSummaryRight(true); |
|
843 | } |
||
844 | |||
845 | 30 | if (isset($xmlSheet->sheetPr->outlinePr['summaryBelow']) && |
|
846 | 30 | !self::boolean((string) $xmlSheet->sheetPr->outlinePr['summaryBelow'])) { |
|
847 | $docSheet->setShowSummaryBelow(false); |
||
848 | } else { |
||
849 | 30 | $docSheet->setShowSummaryBelow(true); |
|
850 | } |
||
851 | } |
||
852 | |||
853 | 38 | if (isset($xmlSheet->sheetPr, $xmlSheet->sheetPr->pageSetUpPr)) { |
|
854 | if (isset($xmlSheet->sheetPr->pageSetUpPr['fitToPage']) && |
||
855 | !self::boolean((string) $xmlSheet->sheetPr->pageSetUpPr['fitToPage'])) { |
||
856 | $docSheet->getPageSetup()->setFitToPage(false); |
||
857 | } else { |
||
858 | $docSheet->getPageSetup()->setFitToPage(true); |
||
859 | } |
||
860 | } |
||
861 | |||
862 | 38 | if (isset($xmlSheet->sheetFormatPr)) { |
|
863 | 38 | if (isset($xmlSheet->sheetFormatPr['customHeight']) && |
|
864 | 38 | self::boolean((string) $xmlSheet->sheetFormatPr['customHeight']) && |
|
865 | 38 | isset($xmlSheet->sheetFormatPr['defaultRowHeight'])) { |
|
866 | 1 | $docSheet->getDefaultRowDimension()->setRowHeight((float) $xmlSheet->sheetFormatPr['defaultRowHeight']); |
|
867 | } |
||
868 | 38 | if (isset($xmlSheet->sheetFormatPr['defaultColWidth'])) { |
|
869 | 1 | $docSheet->getDefaultColumnDimension()->setWidth((float) $xmlSheet->sheetFormatPr['defaultColWidth']); |
|
870 | } |
||
871 | 38 | if (isset($xmlSheet->sheetFormatPr['zeroHeight']) && |
|
872 | 38 | ((string) $xmlSheet->sheetFormatPr['zeroHeight'] == '1')) { |
|
873 | $docSheet->getDefaultRowDimension()->setZeroHeight(true); |
||
874 | } |
||
875 | } |
||
876 | |||
877 | 38 | if (isset($xmlSheet->printOptions) && !$this->readDataOnly) { |
|
878 | 30 | if (self::boolean((string) $xmlSheet->printOptions['gridLinesSet'])) { |
|
879 | 30 | $docSheet->setShowGridlines(true); |
|
880 | } |
||
881 | 30 | if (self::boolean((string) $xmlSheet->printOptions['gridLines'])) { |
|
882 | $docSheet->setPrintGridlines(true); |
||
883 | } |
||
884 | 30 | if (self::boolean((string) $xmlSheet->printOptions['horizontalCentered'])) { |
|
885 | $docSheet->getPageSetup()->setHorizontalCentered(true); |
||
886 | } |
||
887 | 30 | if (self::boolean((string) $xmlSheet->printOptions['verticalCentered'])) { |
|
888 | $docSheet->getPageSetup()->setVerticalCentered(true); |
||
889 | } |
||
890 | } |
||
891 | |||
892 | 38 | $this->readColumnsAndRowsAttributes($xmlSheet, $docSheet); |
|
1 ignored issue
–
show
|
|||
893 | |||
894 | 38 | if ($xmlSheet && $xmlSheet->sheetData && $xmlSheet->sheetData->row) { |
|
895 | 32 | $cIndex = 1; // Cell Start from 1 |
|
896 | 32 | foreach ($xmlSheet->sheetData->row as $row) { |
|
897 | 32 | $rowIndex = 1; |
|
898 | 32 | foreach ($row->c as $c) { |
|
899 | 32 | $r = (string) $c['r']; |
|
900 | 32 | if ($r == '') { |
|
901 | 1 | $r = Coordinate::stringFromColumnIndex($rowIndex) . $cIndex; |
|
902 | } |
||
903 | 32 | $cellDataType = (string) $c['t']; |
|
904 | 32 | $value = null; |
|
905 | 32 | $calculatedValue = null; |
|
906 | |||
907 | // Read cell? |
||
908 | 32 | if ($this->getReadFilter() !== null) { |
|
909 | 32 | $coordinates = Coordinate::coordinateFromString($r); |
|
910 | |||
911 | 32 | if (!$this->getReadFilter()->readCell($coordinates[0], (int) $coordinates[1], $docSheet->getTitle())) { |
|
912 | 2 | continue; |
|
913 | } |
||
914 | } |
||
915 | |||
916 | // Read cell! |
||
917 | switch ($cellDataType) { |
||
918 | 32 | case 's': |
|
919 | 19 | if ((string) $c->v != '') { |
|
920 | 19 | $value = $sharedStrings[(int) ($c->v)]; |
|
921 | |||
922 | 19 | if ($value instanceof RichText) { |
|
923 | 19 | $value = clone $value; |
|
924 | } |
||
925 | } else { |
||
926 | $value = ''; |
||
927 | } |
||
928 | |||
929 | 19 | break; |
|
930 | 22 | case 'b': |
|
931 | 4 | if (!isset($c->f)) { |
|
932 | 2 | $value = self::castToBoolean($c); |
|
933 | } else { |
||
934 | // Formula |
||
935 | 2 | $this->castToFormula($c, $r, $cellDataType, $value, $calculatedValue, $sharedFormulas, 'castToBoolean'); |
|
936 | 2 | if (isset($c->f['t'])) { |
|
937 | $att = $c->f; |
||
938 | $docSheet->getCell($r)->setFormulaAttributes($att); |
||
939 | } |
||
940 | } |
||
941 | |||
942 | 4 | break; |
|
943 | 19 | case 'inlineStr': |
|
944 | 2 | if (isset($c->f)) { |
|
945 | $this->castToFormula($c, $r, $cellDataType, $value, $calculatedValue, $sharedFormulas, 'castToError'); |
||
946 | } else { |
||
947 | 2 | $value = $this->parseRichText($c->is); |
|
948 | } |
||
949 | |||
950 | 2 | break; |
|
951 | 19 | case 'e': |
|
952 | if (!isset($c->f)) { |
||
953 | $value = self::castToError($c); |
||
954 | } else { |
||
955 | // Formula |
||
956 | $this->castToFormula($c, $r, $cellDataType, $value, $calculatedValue, $sharedFormulas, 'castToError'); |
||
957 | } |
||
958 | |||
959 | break; |
||
960 | default: |
||
961 | 19 | if (!isset($c->f)) { |
|
962 | 17 | $value = self::castToString($c); |
|
963 | } else { |
||
964 | // Formula |
||
965 | 6 | $this->castToFormula($c, $r, $cellDataType, $value, $calculatedValue, $sharedFormulas, 'castToString'); |
|
966 | } |
||
967 | |||
968 | 19 | break; |
|
969 | } |
||
970 | |||
971 | // Check for numeric values |
||
972 | 32 | if (is_numeric($value) && $cellDataType != 's') { |
|
973 | 15 | if ($value == (int) $value) { |
|
974 | 14 | $value = (int) $value; |
|
975 | 1 | } elseif ($value == (float) $value) { |
|
976 | 1 | $value = (float) $value; |
|
977 | } elseif ($value == (float) $value) { |
||
978 | $value = (float) $value; |
||
979 | } |
||
980 | } |
||
981 | |||
982 | // Rich text? |
||
983 | 32 | if ($value instanceof RichText && $this->readDataOnly) { |
|
984 | $value = $value->getPlainText(); |
||
985 | } |
||
986 | |||
987 | 32 | $cell = $docSheet->getCell($r); |
|
988 | // Assign value |
||
989 | 32 | if ($cellDataType != '') { |
|
990 | 23 | $cell->setValueExplicit($value, $cellDataType); |
|
991 | } else { |
||
992 | 17 | $cell->setValue($value); |
|
993 | } |
||
994 | 32 | if ($calculatedValue !== null) { |
|
995 | 7 | $cell->setCalculatedValue($calculatedValue); |
|
996 | } |
||
997 | |||
998 | // Style information? |
||
999 | 32 | if ($c['s'] && !$this->readDataOnly) { |
|
1000 | // no style index means 0, it seems |
||
1001 | 7 | $cell->setXfIndex(isset($styles[(int) ($c['s'])]) ? |
|
1002 | 7 | (int) ($c['s']) : 0); |
|
1003 | } |
||
1004 | 32 | $rowIndex += 1; |
|
1005 | } |
||
1006 | 32 | $cIndex += 1; |
|
1007 | } |
||
1008 | } |
||
1009 | |||
1010 | 38 | $conditionals = []; |
|
1011 | 38 | if (!$this->readDataOnly && $xmlSheet && $xmlSheet->conditionalFormatting) { |
|
1012 | 1 | foreach ($xmlSheet->conditionalFormatting as $conditional) { |
|
1013 | 1 | foreach ($conditional->cfRule as $cfRule) { |
|
1014 | 1 | if (((string) $cfRule['type'] == Conditional::CONDITION_NONE || (string) $cfRule['type'] == Conditional::CONDITION_CELLIS || (string) $cfRule['type'] == Conditional::CONDITION_CONTAINSTEXT || (string) $cfRule['type'] == Conditional::CONDITION_EXPRESSION) && isset($dxfs[(int) ($cfRule['dxfId'])])) { |
|
1015 | 1 | $conditionals[(string) $conditional['sqref']][(int) ($cfRule['priority'])] = $cfRule; |
|
1016 | } |
||
1017 | } |
||
1018 | } |
||
1019 | |||
1020 | 1 | foreach ($conditionals as $ref => $cfRules) { |
|
1021 | 1 | ksort($cfRules); |
|
1022 | 1 | $conditionalStyles = []; |
|
1023 | 1 | foreach ($cfRules as $cfRule) { |
|
1024 | 1 | $objConditional = new Conditional(); |
|
1025 | 1 | $objConditional->setConditionType((string) $cfRule['type']); |
|
1026 | 1 | $objConditional->setOperatorType((string) $cfRule['operator']); |
|
1027 | |||
1028 | 1 | if ((string) $cfRule['text'] != '') { |
|
1029 | $objConditional->setText((string) $cfRule['text']); |
||
1030 | } |
||
1031 | |||
1032 | 1 | if (isset($cfRule['stopIfTrue']) && (int) $cfRule['stopIfTrue'] === 1) { |
|
1033 | 1 | $objConditional->setStopIfTrue(true); |
|
1034 | } |
||
1035 | |||
1036 | 1 | if (count($cfRule->formula) > 1) { |
|
1037 | foreach ($cfRule->formula as $formula) { |
||
1038 | $objConditional->addCondition((string) $formula); |
||
1039 | } |
||
1040 | } else { |
||
1041 | 1 | $objConditional->addCondition((string) $cfRule->formula); |
|
1042 | } |
||
1043 | 1 | $objConditional->setStyle(clone $dxfs[(int) ($cfRule['dxfId'])]); |
|
1044 | 1 | $conditionalStyles[] = $objConditional; |
|
1045 | } |
||
1046 | |||
1047 | // Extract all cell references in $ref |
||
1048 | 1 | $cellBlocks = explode(' ', str_replace('$', '', strtoupper($ref))); |
|
1049 | 1 | foreach ($cellBlocks as $cellBlock) { |
|
1050 | 1 | $docSheet->getStyle($cellBlock)->setConditionalStyles($conditionalStyles); |
|
1051 | } |
||
1052 | } |
||
1053 | } |
||
1054 | |||
1055 | 38 | $aKeys = ['sheet', 'objects', 'scenarios', 'formatCells', 'formatColumns', 'formatRows', 'insertColumns', 'insertRows', 'insertHyperlinks', 'deleteColumns', 'deleteRows', 'selectLockedCells', 'sort', 'autoFilter', 'pivotTables', 'selectUnlockedCells']; |
|
1056 | 38 | if (!$this->readDataOnly && $xmlSheet && $xmlSheet->sheetProtection) { |
|
1057 | 33 | foreach ($aKeys as $key) { |
|
1058 | 33 | $method = 'set' . ucfirst($key); |
|
1059 | 33 | $docSheet->getProtection()->$method(self::boolean((string) $xmlSheet->sheetProtection[$key])); |
|
1060 | } |
||
1061 | } |
||
1062 | |||
1063 | 38 | if (!$this->readDataOnly && $xmlSheet && $xmlSheet->sheetProtection) { |
|
1064 | 33 | $docSheet->getProtection()->setPassword((string) $xmlSheet->sheetProtection['password'], true); |
|
1065 | 33 | if ($xmlSheet->protectedRanges->protectedRange) { |
|
1066 | 2 | foreach ($xmlSheet->protectedRanges->protectedRange as $protectedRange) { |
|
1067 | 2 | $docSheet->protectCells((string) $protectedRange['sqref'], (string) $protectedRange['password'], true); |
|
1068 | } |
||
1069 | } |
||
1070 | } |
||
1071 | |||
1072 | 38 | if ($xmlSheet && $xmlSheet->autoFilter && !$this->readDataOnly) { |
|
1073 | $autoFilterRange = (string) $xmlSheet->autoFilter['ref']; |
||
1074 | if (strpos($autoFilterRange, ':') !== false) { |
||
1075 | $autoFilter = $docSheet->getAutoFilter(); |
||
1076 | $autoFilter->setRange($autoFilterRange); |
||
1077 | |||
1078 | foreach ($xmlSheet->autoFilter->filterColumn as $filterColumn) { |
||
1079 | $column = $autoFilter->getColumnByOffset((int) $filterColumn['colId']); |
||
1080 | // Check for standard filters |
||
1081 | if ($filterColumn->filters) { |
||
1082 | $column->setFilterType(Column::AUTOFILTER_FILTERTYPE_FILTER); |
||
1083 | $filters = $filterColumn->filters; |
||
1084 | if ((isset($filters['blank'])) && ($filters['blank'] == 1)) { |
||
1085 | // Operator is undefined, but always treated as EQUAL |
||
1086 | $column->createRule()->setRule(null, '')->setRuleType(Column\Rule::AUTOFILTER_RULETYPE_FILTER); |
||
1087 | } |
||
1088 | // Standard filters are always an OR join, so no join rule needs to be set |
||
1089 | // Entries can be either filter elements |
||
1090 | foreach ($filters->filter as $filterRule) { |
||
1091 | // Operator is undefined, but always treated as EQUAL |
||
1092 | $column->createRule()->setRule(null, (string) $filterRule['val'])->setRuleType(Column\Rule::AUTOFILTER_RULETYPE_FILTER); |
||
1093 | } |
||
1094 | // Or Date Group elements |
||
1095 | foreach ($filters->dateGroupItem as $dateGroupItem) { |
||
1096 | // Operator is undefined, but always treated as EQUAL |
||
1097 | $column->createRule()->setRule( |
||
1098 | null, |
||
1099 | [ |
||
1100 | 'year' => (string) $dateGroupItem['year'], |
||
1101 | 'month' => (string) $dateGroupItem['month'], |
||
1102 | 'day' => (string) $dateGroupItem['day'], |
||
1103 | 'hour' => (string) $dateGroupItem['hour'], |
||
1104 | 'minute' => (string) $dateGroupItem['minute'], |
||
1105 | 'second' => (string) $dateGroupItem['second'], |
||
1106 | ], |
||
1107 | (string) $dateGroupItem['dateTimeGrouping'] |
||
1108 | ) |
||
1109 | ->setRuleType(Column\Rule::AUTOFILTER_RULETYPE_DATEGROUP); |
||
1110 | } |
||
1111 | } |
||
1112 | // Check for custom filters |
||
1113 | if ($filterColumn->customFilters) { |
||
1114 | $column->setFilterType(Column::AUTOFILTER_FILTERTYPE_CUSTOMFILTER); |
||
1115 | $customFilters = $filterColumn->customFilters; |
||
1116 | // Custom filters can an AND or an OR join; |
||
1117 | // and there should only ever be one or two entries |
||
1118 | if ((isset($customFilters['and'])) && ($customFilters['and'] == 1)) { |
||
1119 | $column->setJoin(Column::AUTOFILTER_COLUMN_JOIN_AND); |
||
1120 | } |
||
1121 | foreach ($customFilters->customFilter as $filterRule) { |
||
1122 | $column->createRule()->setRule( |
||
1123 | (string) $filterRule['operator'], |
||
1124 | (string) $filterRule['val'] |
||
1125 | ) |
||
1126 | ->setRuleType(Column\Rule::AUTOFILTER_RULETYPE_CUSTOMFILTER); |
||
1127 | } |
||
1128 | } |
||
1129 | // Check for dynamic filters |
||
1130 | if ($filterColumn->dynamicFilter) { |
||
1131 | $column->setFilterType(Column::AUTOFILTER_FILTERTYPE_DYNAMICFILTER); |
||
1132 | // We should only ever have one dynamic filter |
||
1133 | foreach ($filterColumn->dynamicFilter as $filterRule) { |
||
1134 | // Operator is undefined, but always treated as EQUAL |
||
1135 | $column->createRule()->setRule( |
||
1136 | null, |
||
1137 | (string) $filterRule['val'], |
||
1138 | (string) $filterRule['type'] |
||
1139 | ) |
||
1140 | ->setRuleType(Column\Rule::AUTOFILTER_RULETYPE_DYNAMICFILTER); |
||
1141 | if (isset($filterRule['val'])) { |
||
1142 | $column->setAttribute('val', (string) $filterRule['val']); |
||
1143 | } |
||
1144 | if (isset($filterRule['maxVal'])) { |
||
1145 | $column->setAttribute('maxVal', (string) $filterRule['maxVal']); |
||
1146 | } |
||
1147 | } |
||
1148 | } |
||
1149 | // Check for dynamic filters |
||
1150 | if ($filterColumn->top10) { |
||
1151 | $column->setFilterType(Column::AUTOFILTER_FILTERTYPE_TOPTENFILTER); |
||
1152 | // We should only ever have one top10 filter |
||
1153 | foreach ($filterColumn->top10 as $filterRule) { |
||
1154 | $column->createRule()->setRule( |
||
1155 | (((isset($filterRule['percent'])) && ($filterRule['percent'] == 1)) |
||
1156 | ? Column\Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_PERCENT |
||
1157 | : Column\Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_BY_VALUE |
||
1158 | ), |
||
1159 | (string) $filterRule['val'], |
||
1160 | (((isset($filterRule['top'])) && ($filterRule['top'] == 1)) |
||
1161 | ? Column\Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_TOP |
||
1162 | : Column\Rule::AUTOFILTER_COLUMN_RULE_TOPTEN_BOTTOM |
||
1163 | ) |
||
1164 | ) |
||
1165 | ->setRuleType(Column\Rule::AUTOFILTER_RULETYPE_TOPTENFILTER); |
||
1166 | } |
||
1167 | } |
||
1168 | } |
||
1169 | } |
||
1170 | } |
||
1171 | |||
1172 | 38 | if ($xmlSheet && $xmlSheet->mergeCells && $xmlSheet->mergeCells->mergeCell && !$this->readDataOnly) { |
|
1173 | 6 | foreach ($xmlSheet->mergeCells->mergeCell as $mergeCell) { |
|
1174 | 6 | $mergeRef = (string) $mergeCell['ref']; |
|
1175 | 6 | if (strpos($mergeRef, ':') !== false) { |
|
1176 | 6 | $docSheet->mergeCells((string) $mergeCell['ref']); |
|
1177 | } |
||
1178 | } |
||
1179 | } |
||
1180 | |||
1181 | 38 | if ($xmlSheet && $xmlSheet->pageMargins && !$this->readDataOnly) { |
|
1182 | 37 | $docPageMargins = $docSheet->getPageMargins(); |
|
1183 | 37 | $docPageMargins->setLeft((float) ($xmlSheet->pageMargins['left'])); |
|
1184 | 37 | $docPageMargins->setRight((float) ($xmlSheet->pageMargins['right'])); |
|
1185 | 37 | $docPageMargins->setTop((float) ($xmlSheet->pageMargins['top'])); |
|
1186 | 37 | $docPageMargins->setBottom((float) ($xmlSheet->pageMargins['bottom'])); |
|
1187 | 37 | $docPageMargins->setHeader((float) ($xmlSheet->pageMargins['header'])); |
|
1188 | 37 | $docPageMargins->setFooter((float) ($xmlSheet->pageMargins['footer'])); |
|
1189 | } |
||
1190 | |||
1191 | 38 | if ($xmlSheet && $xmlSheet->pageSetup && !$this->readDataOnly) { |
|
1192 | 37 | $docPageSetup = $docSheet->getPageSetup(); |
|
1193 | |||
1194 | 37 | if (isset($xmlSheet->pageSetup['orientation'])) { |
|
1195 | 37 | $docPageSetup->setOrientation((string) $xmlSheet->pageSetup['orientation']); |
|
1196 | } |
||
1197 | 37 | if (isset($xmlSheet->pageSetup['paperSize'])) { |
|
1198 | 34 | $docPageSetup->setPaperSize((int) ($xmlSheet->pageSetup['paperSize'])); |
|
1199 | } |
||
1200 | 37 | if (isset($xmlSheet->pageSetup['scale'])) { |
|
1201 | 30 | $docPageSetup->setScale((int) ($xmlSheet->pageSetup['scale']), false); |
|
1202 | } |
||
1203 | 37 | if (isset($xmlSheet->pageSetup['fitToHeight']) && (int) ($xmlSheet->pageSetup['fitToHeight']) >= 0) { |
|
1204 | 30 | $docPageSetup->setFitToHeight((int) ($xmlSheet->pageSetup['fitToHeight']), false); |
|
1205 | } |
||
1206 | 37 | if (isset($xmlSheet->pageSetup['fitToWidth']) && (int) ($xmlSheet->pageSetup['fitToWidth']) >= 0) { |
|
1207 | 30 | $docPageSetup->setFitToWidth((int) ($xmlSheet->pageSetup['fitToWidth']), false); |
|
1208 | } |
||
1209 | 37 | if (isset($xmlSheet->pageSetup['firstPageNumber'], $xmlSheet->pageSetup['useFirstPageNumber']) && |
|
1210 | 37 | self::boolean((string) $xmlSheet->pageSetup['useFirstPageNumber'])) { |
|
1211 | $docPageSetup->setFirstPageNumber((int) ($xmlSheet->pageSetup['firstPageNumber'])); |
||
1212 | } |
||
1213 | |||
1214 | 37 | $relAttributes = $xmlSheet->pageSetup->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'); |
|
1215 | 37 | if (isset($relAttributes['id'])) { |
|
1216 | 7 | $unparsedLoadedData['sheets'][$docSheet->getCodeName()]['pageSetupRelId'] = (string) $relAttributes['id']; |
|
1217 | } |
||
1218 | } |
||
1219 | |||
1220 | 38 | if ($xmlSheet && $xmlSheet->headerFooter && !$this->readDataOnly) { |
|
1221 | 32 | $docHeaderFooter = $docSheet->getHeaderFooter(); |
|
1222 | |||
1223 | 32 | if (isset($xmlSheet->headerFooter['differentOddEven']) && |
|
1224 | 32 | self::boolean((string) $xmlSheet->headerFooter['differentOddEven'])) { |
|
1225 | $docHeaderFooter->setDifferentOddEven(true); |
||
1226 | } else { |
||
1227 | 32 | $docHeaderFooter->setDifferentOddEven(false); |
|
1228 | } |
||
1229 | 32 | if (isset($xmlSheet->headerFooter['differentFirst']) && |
|
1230 | 32 | self::boolean((string) $xmlSheet->headerFooter['differentFirst'])) { |
|
1231 | $docHeaderFooter->setDifferentFirst(true); |
||
1232 | } else { |
||
1233 | 32 | $docHeaderFooter->setDifferentFirst(false); |
|
1234 | } |
||
1235 | 32 | if (isset($xmlSheet->headerFooter['scaleWithDoc']) && |
|
1236 | 32 | !self::boolean((string) $xmlSheet->headerFooter['scaleWithDoc'])) { |
|
1237 | $docHeaderFooter->setScaleWithDocument(false); |
||
1238 | } else { |
||
1239 | 32 | $docHeaderFooter->setScaleWithDocument(true); |
|
1240 | } |
||
1241 | 32 | if (isset($xmlSheet->headerFooter['alignWithMargins']) && |
|
1242 | 32 | !self::boolean((string) $xmlSheet->headerFooter['alignWithMargins'])) { |
|
1243 | 3 | $docHeaderFooter->setAlignWithMargins(false); |
|
1244 | } else { |
||
1245 | 29 | $docHeaderFooter->setAlignWithMargins(true); |
|
1246 | } |
||
1247 | |||
1248 | 32 | $docHeaderFooter->setOddHeader((string) $xmlSheet->headerFooter->oddHeader); |
|
1249 | 32 | $docHeaderFooter->setOddFooter((string) $xmlSheet->headerFooter->oddFooter); |
|
1250 | 32 | $docHeaderFooter->setEvenHeader((string) $xmlSheet->headerFooter->evenHeader); |
|
1251 | 32 | $docHeaderFooter->setEvenFooter((string) $xmlSheet->headerFooter->evenFooter); |
|
1252 | 32 | $docHeaderFooter->setFirstHeader((string) $xmlSheet->headerFooter->firstHeader); |
|
1253 | 32 | $docHeaderFooter->setFirstFooter((string) $xmlSheet->headerFooter->firstFooter); |
|
1254 | } |
||
1255 | |||
1256 | 38 | if ($xmlSheet && $xmlSheet->rowBreaks && $xmlSheet->rowBreaks->brk && !$this->readDataOnly) { |
|
1257 | foreach ($xmlSheet->rowBreaks->brk as $brk) { |
||
1258 | if ($brk['man']) { |
||
1259 | $docSheet->setBreak("A$brk[id]", Worksheet::BREAK_ROW); |
||
1260 | } |
||
1261 | } |
||
1262 | } |
||
1263 | 38 | if ($xmlSheet && $xmlSheet->colBreaks && $xmlSheet->colBreaks->brk && !$this->readDataOnly) { |
|
1264 | foreach ($xmlSheet->colBreaks->brk as $brk) { |
||
1265 | if ($brk['man']) { |
||
1266 | $docSheet->setBreak(Coordinate::stringFromColumnIndex((string) $brk['id'] + 1) . '1', Worksheet::BREAK_COLUMN); |
||
1267 | } |
||
1268 | } |
||
1269 | } |
||
1270 | |||
1271 | 38 | if ($xmlSheet && $xmlSheet->dataValidations && !$this->readDataOnly) { |
|
1272 | foreach ($xmlSheet->dataValidations->dataValidation as $dataValidation) { |
||
1273 | // Uppercase coordinate |
||
1274 | $range = strtoupper($dataValidation['sqref']); |
||
1275 | $rangeSet = explode(' ', $range); |
||
1276 | foreach ($rangeSet as $range) { |
||
1277 | $stRange = $docSheet->shrinkRangeToFit($range); |
||
1278 | |||
1279 | // Extract all cell references in $range |
||
1280 | foreach (Coordinate::extractAllCellReferencesInRange($stRange) as $reference) { |
||
1281 | // Create validation |
||
1282 | $docValidation = $docSheet->getCell($reference)->getDataValidation(); |
||
1283 | $docValidation->setType((string) $dataValidation['type']); |
||
1284 | $docValidation->setErrorStyle((string) $dataValidation['errorStyle']); |
||
1285 | $docValidation->setOperator((string) $dataValidation['operator']); |
||
1286 | $docValidation->setAllowBlank($dataValidation['allowBlank'] != 0); |
||
1287 | $docValidation->setShowDropDown($dataValidation['showDropDown'] == 0); |
||
1288 | $docValidation->setShowInputMessage($dataValidation['showInputMessage'] != 0); |
||
1289 | $docValidation->setShowErrorMessage($dataValidation['showErrorMessage'] != 0); |
||
1290 | $docValidation->setErrorTitle((string) $dataValidation['errorTitle']); |
||
1291 | $docValidation->setError((string) $dataValidation['error']); |
||
1292 | $docValidation->setPromptTitle((string) $dataValidation['promptTitle']); |
||
1293 | $docValidation->setPrompt((string) $dataValidation['prompt']); |
||
1294 | $docValidation->setFormula1((string) $dataValidation->formula1); |
||
1295 | $docValidation->setFormula2((string) $dataValidation->formula2); |
||
1296 | } |
||
1297 | } |
||
1298 | } |
||
1299 | } |
||
1300 | |||
1301 | // unparsed sheet AlternateContent |
||
1302 | 38 | if ($xmlSheet && !$this->readDataOnly) { |
|
1303 | 38 | $mc = $xmlSheet->children('http://schemas.openxmlformats.org/markup-compatibility/2006'); |
|
1304 | 38 | if ($mc->AlternateContent) { |
|
1305 | 1 | foreach ($mc->AlternateContent as $alternateContent) { |
|
1306 | 1 | $unparsedLoadedData['sheets'][$docSheet->getCodeName()]['AlternateContents'][] = $alternateContent->asXML(); |
|
1307 | } |
||
1308 | } |
||
1309 | } |
||
1310 | |||
1311 | // Add hyperlinks |
||
1312 | 38 | $hyperlinks = []; |
|
1313 | 38 | if (!$this->readDataOnly) { |
|
1314 | // Locate hyperlink relations |
||
1315 | 38 | if ($zip->locateName(dirname("$dir/$fileWorksheet") . '/_rels/' . basename($fileWorksheet) . '.rels')) { |
|
1316 | //~ http://schemas.openxmlformats.org/package/2006/relationships" |
||
1317 | 37 | $relsWorksheet = simplexml_load_string( |
|
1318 | 37 | $this->securityScan( |
|
1319 | 37 | $this->getFromZipArchive($zip, dirname("$dir/$fileWorksheet") . '/_rels/' . basename($fileWorksheet) . '.rels') |
|
1320 | ), |
||
1321 | 37 | 'SimpleXMLElement', |
|
1322 | 37 | Settings::getLibXmlLoaderOptions() |
|
1323 | ); |
||
1324 | 37 | foreach ($relsWorksheet->Relationship as $ele) { |
|
1325 | 12 | if ($ele['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink') { |
|
1326 | 12 | $hyperlinks[(string) $ele['Id']] = (string) $ele['Target']; |
|
1327 | } |
||
1328 | } |
||
1329 | } |
||
1330 | |||
1331 | // Loop through hyperlinks |
||
1332 | 38 | if ($xmlSheet && $xmlSheet->hyperlinks) { |
|
1333 | /** @var SimpleXMLElement $hyperlink */ |
||
1334 | 2 | foreach ($xmlSheet->hyperlinks->hyperlink as $hyperlink) { |
|
1335 | // Link url |
||
1336 | 2 | $linkRel = $hyperlink->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'); |
|
1337 | |||
1338 | 2 | foreach (Coordinate::extractAllCellReferencesInRange($hyperlink['ref']) as $cellReference) { |
|
1339 | 2 | $cell = $docSheet->getCell($cellReference); |
|
1340 | 2 | if (isset($linkRel['id'])) { |
|
1341 | 2 | $hyperlinkUrl = $hyperlinks[(string) $linkRel['id']]; |
|
1342 | 2 | if (isset($hyperlink['location'])) { |
|
1343 | $hyperlinkUrl .= '#' . (string) $hyperlink['location']; |
||
1344 | } |
||
1345 | 2 | $cell->getHyperlink()->setUrl($hyperlinkUrl); |
|
1346 | 2 | } elseif (isset($hyperlink['location'])) { |
|
1347 | 2 | $cell->getHyperlink()->setUrl('sheet://' . (string) $hyperlink['location']); |
|
1348 | } |
||
1349 | |||
1350 | // Tooltip |
||
1351 | 2 | if (isset($hyperlink['tooltip'])) { |
|
1352 | 2 | $cell->getHyperlink()->setTooltip((string) $hyperlink['tooltip']); |
|
1353 | } |
||
1354 | } |
||
1355 | } |
||
1356 | } |
||
1357 | } |
||
1358 | |||
1359 | // Add comments |
||
1360 | 38 | $comments = []; |
|
1361 | 38 | $vmlComments = []; |
|
1362 | 38 | if (!$this->readDataOnly) { |
|
1363 | // Locate comment relations |
||
1364 | 38 | if ($zip->locateName(dirname("$dir/$fileWorksheet") . '/_rels/' . basename($fileWorksheet) . '.rels')) { |
|
1365 | //~ http://schemas.openxmlformats.org/package/2006/relationships" |
||
1366 | 37 | $relsWorksheet = simplexml_load_string( |
|
1367 | 37 | $this->securityScan( |
|
1368 | 37 | $this->getFromZipArchive($zip, dirname("$dir/$fileWorksheet") . '/_rels/' . basename($fileWorksheet) . '.rels') |
|
1369 | ), |
||
1370 | 37 | 'SimpleXMLElement', |
|
1371 | 37 | Settings::getLibXmlLoaderOptions() |
|
1372 | ); |
||
1373 | 37 | foreach ($relsWorksheet->Relationship as $ele) { |
|
1374 | 12 | if ($ele['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments') { |
|
1375 | 3 | $comments[(string) $ele['Id']] = (string) $ele['Target']; |
|
1376 | } |
||
1377 | 12 | if ($ele['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing') { |
|
1378 | 12 | $vmlComments[(string) $ele['Id']] = (string) $ele['Target']; |
|
1379 | } |
||
1380 | } |
||
1381 | } |
||
1382 | |||
1383 | // Loop through comments |
||
1384 | 38 | foreach ($comments as $relName => $relPath) { |
|
1385 | // Load comments file |
||
1386 | 3 | $relPath = File::realpath(dirname("$dir/$fileWorksheet") . '/' . $relPath); |
|
1387 | 3 | $commentsFile = simplexml_load_string( |
|
1388 | 3 | $this->securityScan($this->getFromZipArchive($zip, $relPath)), |
|
1389 | 3 | 'SimpleXMLElement', |
|
1390 | 3 | Settings::getLibXmlLoaderOptions() |
|
1391 | ); |
||
1392 | |||
1393 | // Utility variables |
||
1394 | 3 | $authors = []; |
|
1395 | |||
1396 | // Loop through authors |
||
1397 | 3 | foreach ($commentsFile->authors->author as $author) { |
|
1398 | 3 | $authors[] = (string) $author; |
|
1399 | } |
||
1400 | |||
1401 | // Loop through contents |
||
1402 | 3 | foreach ($commentsFile->commentList->comment as $comment) { |
|
1403 | 3 | if (!empty($comment['authorId'])) { |
|
1404 | $docSheet->getComment((string) $comment['ref'])->setAuthor($authors[(string) $comment['authorId']]); |
||
1405 | } |
||
1406 | 3 | $docSheet->getComment((string) $comment['ref'])->setText($this->parseRichText($comment->text)); |
|
1407 | } |
||
1408 | } |
||
1409 | |||
1410 | // later we will remove from it real vmlComments |
||
1411 | 38 | $unparsedVmlDrawings = $vmlComments; |
|
1412 | |||
1413 | // Loop through VML comments |
||
1414 | 38 | foreach ($vmlComments as $relName => $relPath) { |
|
1415 | // Load VML comments file |
||
1416 | 4 | $relPath = File::realpath(dirname("$dir/$fileWorksheet") . '/' . $relPath); |
|
1417 | 4 | $vmlCommentsFile = simplexml_load_string( |
|
1418 | 4 | $this->securityScan($this->getFromZipArchive($zip, $relPath)), |
|
1419 | 4 | 'SimpleXMLElement', |
|
1420 | 4 | Settings::getLibXmlLoaderOptions() |
|
1421 | ); |
||
1422 | 4 | $vmlCommentsFile->registerXPathNamespace('v', 'urn:schemas-microsoft-com:vml'); |
|
1423 | |||
1424 | 4 | $shapes = $vmlCommentsFile->xpath('//v:shape'); |
|
1425 | 4 | foreach ($shapes as $shape) { |
|
1426 | 4 | $shape->registerXPathNamespace('v', 'urn:schemas-microsoft-com:vml'); |
|
1427 | |||
1428 | 4 | if (isset($shape['style'])) { |
|
1429 | 4 | $style = (string) $shape['style']; |
|
1430 | 4 | $fillColor = strtoupper(substr((string) $shape['fillcolor'], 1)); |
|
1431 | 4 | $column = null; |
|
1432 | 4 | $row = null; |
|
1433 | |||
1434 | 4 | $clientData = $shape->xpath('.//x:ClientData'); |
|
1435 | 4 | if (is_array($clientData) && !empty($clientData)) { |
|
1436 | 4 | $clientData = $clientData[0]; |
|
1437 | |||
1438 | 4 | if (isset($clientData['ObjectType']) && (string) $clientData['ObjectType'] == 'Note') { |
|
1439 | 3 | $temp = $clientData->xpath('.//x:Row'); |
|
1440 | 3 | if (is_array($temp)) { |
|
1441 | 3 | $row = $temp[0]; |
|
1442 | } |
||
1443 | |||
1444 | 3 | $temp = $clientData->xpath('.//x:Column'); |
|
1445 | 3 | if (is_array($temp)) { |
|
1446 | 3 | $column = $temp[0]; |
|
1447 | } |
||
1448 | } |
||
1449 | } |
||
1450 | |||
1451 | 4 | if (($column !== null) && ($row !== null)) { |
|
1452 | // Set comment properties |
||
1453 | 3 | $comment = $docSheet->getCommentByColumnAndRow($column + 1, $row + 1); |
|
1454 | 3 | $comment->getFillColor()->setRGB($fillColor); |
|
1455 | |||
1456 | // Parse style |
||
1457 | 3 | $styleArray = explode(';', str_replace(' ', '', $style)); |
|
1458 | 3 | foreach ($styleArray as $stylePair) { |
|
1459 | 3 | $stylePair = explode(':', $stylePair); |
|
1460 | |||
1461 | 3 | if ($stylePair[0] == 'margin-left') { |
|
1462 | 3 | $comment->setMarginLeft($stylePair[1]); |
|
1463 | } |
||
1464 | 3 | if ($stylePair[0] == 'margin-top') { |
|
1465 | 3 | $comment->setMarginTop($stylePair[1]); |
|
1466 | } |
||
1467 | 3 | if ($stylePair[0] == 'width') { |
|
1468 | 3 | $comment->setWidth($stylePair[1]); |
|
1469 | } |
||
1470 | 3 | if ($stylePair[0] == 'height') { |
|
1471 | 3 | $comment->setHeight($stylePair[1]); |
|
1472 | } |
||
1473 | 3 | if ($stylePair[0] == 'visibility') { |
|
1474 | 3 | $comment->setVisible($stylePair[1] == 'visible'); |
|
1475 | } |
||
1476 | } |
||
1477 | |||
1478 | 4 | unset($unparsedVmlDrawings[$relName]); |
|
1479 | } |
||
1480 | } |
||
1481 | } |
||
1482 | } |
||
1483 | |||
1484 | // unparsed vmlDrawing |
||
1485 | 38 | if ($unparsedVmlDrawings) { |
|
1486 | 1 | foreach ($unparsedVmlDrawings as $rId => $relPath) { |
|
1487 | 1 | $rId = substr($rId, 3); // rIdXXX |
|
1488 | 1 | $unparsedVmlDrawing = &$unparsedLoadedData['sheets'][$docSheet->getCodeName()]['vmlDrawings']; |
|
1489 | 1 | $unparsedVmlDrawing[$rId] = []; |
|
1490 | 1 | $unparsedVmlDrawing[$rId]['filePath'] = self::dirAdd("$dir/$fileWorksheet", $relPath); |
|
1491 | 1 | $unparsedVmlDrawing[$rId]['relFilePath'] = $relPath; |
|
1492 | 1 | $unparsedVmlDrawing[$rId]['content'] = $this->securityScan($this->getFromZipArchive($zip, $unparsedVmlDrawing[$rId]['filePath'])); |
|
1493 | 1 | unset($unparsedVmlDrawing); |
|
1494 | } |
||
1495 | } |
||
1496 | |||
1497 | // Header/footer images |
||
1498 | 38 | if ($xmlSheet && $xmlSheet->legacyDrawingHF && !$this->readDataOnly) { |
|
1499 | if ($zip->locateName(dirname("$dir/$fileWorksheet") . '/_rels/' . basename($fileWorksheet) . '.rels')) { |
||
1500 | //~ http://schemas.openxmlformats.org/package/2006/relationships" |
||
1501 | $relsWorksheet = simplexml_load_string( |
||
1502 | $this->securityScan( |
||
1503 | $this->getFromZipArchive($zip, dirname("$dir/$fileWorksheet") . '/_rels/' . basename($fileWorksheet) . '.rels') |
||
1504 | ), |
||
1505 | 'SimpleXMLElement', |
||
1506 | Settings::getLibXmlLoaderOptions() |
||
1507 | ); |
||
1508 | $vmlRelationship = ''; |
||
1509 | |||
1510 | foreach ($relsWorksheet->Relationship as $ele) { |
||
1511 | if ($ele['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing') { |
||
1512 | $vmlRelationship = self::dirAdd("$dir/$fileWorksheet", $ele['Target']); |
||
1513 | } |
||
1514 | } |
||
1515 | |||
1516 | if ($vmlRelationship != '') { |
||
1517 | // Fetch linked images |
||
1518 | //~ http://schemas.openxmlformats.org/package/2006/relationships" |
||
1519 | $relsVML = simplexml_load_string( |
||
1520 | $this->securityScan( |
||
1521 | $this->getFromZipArchive($zip, dirname($vmlRelationship) . '/_rels/' . basename($vmlRelationship) . '.rels') |
||
1522 | ), |
||
1523 | 'SimpleXMLElement', |
||
1524 | Settings::getLibXmlLoaderOptions() |
||
1525 | ); |
||
1526 | $drawings = []; |
||
1527 | foreach ($relsVML->Relationship as $ele) { |
||
1528 | if ($ele['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image') { |
||
1529 | $drawings[(string) $ele['Id']] = self::dirAdd($vmlRelationship, $ele['Target']); |
||
1530 | } |
||
1531 | } |
||
1532 | |||
1533 | // Fetch VML document |
||
1534 | $vmlDrawing = simplexml_load_string( |
||
1535 | $this->securityScan($this->getFromZipArchive($zip, $vmlRelationship)), |
||
1536 | 'SimpleXMLElement', |
||
1537 | Settings::getLibXmlLoaderOptions() |
||
1538 | ); |
||
1539 | $vmlDrawing->registerXPathNamespace('v', 'urn:schemas-microsoft-com:vml'); |
||
1540 | |||
1541 | $hfImages = []; |
||
1542 | |||
1543 | $shapes = $vmlDrawing->xpath('//v:shape'); |
||
1544 | foreach ($shapes as $idx => $shape) { |
||
1545 | $shape->registerXPathNamespace('v', 'urn:schemas-microsoft-com:vml'); |
||
1546 | $imageData = $shape->xpath('//v:imagedata'); |
||
1547 | |||
1548 | if (!$imageData) { |
||
1549 | continue; |
||
1550 | } |
||
1551 | |||
1552 | $imageData = $imageData[$idx]; |
||
1553 | |||
1554 | $imageData = $imageData->attributes('urn:schemas-microsoft-com:office:office'); |
||
1555 | $style = self::toCSSArray((string) $shape['style']); |
||
1556 | |||
1557 | $hfImages[(string) $shape['id']] = new HeaderFooterDrawing(); |
||
1558 | if (isset($imageData['title'])) { |
||
1559 | $hfImages[(string) $shape['id']]->setName((string) $imageData['title']); |
||
1560 | } |
||
1561 | |||
1562 | $hfImages[(string) $shape['id']]->setPath('zip://' . File::realpath($pFilename) . '#' . $drawings[(string) $imageData['relid']], false); |
||
1563 | $hfImages[(string) $shape['id']]->setResizeProportional(false); |
||
1564 | $hfImages[(string) $shape['id']]->setWidth($style['width']); |
||
1565 | $hfImages[(string) $shape['id']]->setHeight($style['height']); |
||
1566 | if (isset($style['margin-left'])) { |
||
1567 | $hfImages[(string) $shape['id']]->setOffsetX($style['margin-left']); |
||
1568 | } |
||
1569 | $hfImages[(string) $shape['id']]->setOffsetY($style['margin-top']); |
||
1570 | $hfImages[(string) $shape['id']]->setResizeProportional(true); |
||
1571 | } |
||
1572 | |||
1573 | $docSheet->getHeaderFooter()->setImages($hfImages); |
||
1574 | } |
||
1575 | } |
||
1576 | } |
||
1577 | } |
||
1578 | |||
1579 | // TODO: Autoshapes from twoCellAnchors! |
||
1580 | 38 | if ($zip->locateName(dirname("$dir/$fileWorksheet") . '/_rels/' . basename($fileWorksheet) . '.rels')) { |
|
1581 | //~ http://schemas.openxmlformats.org/package/2006/relationships" |
||
1582 | 37 | $relsWorksheet = simplexml_load_string( |
|
1583 | 37 | $this->securityScan( |
|
1584 | 37 | $this->getFromZipArchive($zip, dirname("$dir/$fileWorksheet") . '/_rels/' . basename($fileWorksheet) . '.rels') |
|
1585 | ), |
||
1586 | 37 | 'SimpleXMLElement', |
|
1587 | 37 | Settings::getLibXmlLoaderOptions() |
|
1588 | ); |
||
1589 | 37 | $drawings = []; |
|
1590 | 37 | foreach ($relsWorksheet->Relationship as $ele) { |
|
1591 | 12 | if ($ele['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing') { |
|
1592 | 12 | $drawings[(string) $ele['Id']] = self::dirAdd("$dir/$fileWorksheet", $ele['Target']); |
|
1593 | } |
||
1594 | } |
||
1595 | 37 | if ($xmlSheet->drawing && !$this->readDataOnly) { |
|
1596 | 7 | foreach ($xmlSheet->drawing as $drawing) { |
|
1597 | 7 | $fileDrawing = $drawings[(string) self::getArrayItem($drawing->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'), 'id')]; |
|
1598 | //~ http://schemas.openxmlformats.org/package/2006/relationships" |
||
1599 | 7 | $relsDrawing = simplexml_load_string( |
|
1600 | 7 | $this->securityScan( |
|
1601 | 7 | $this->getFromZipArchive($zip, dirname($fileDrawing) . '/_rels/' . basename($fileDrawing) . '.rels') |
|
1602 | ), |
||
1603 | 7 | 'SimpleXMLElement', |
|
1604 | 7 | Settings::getLibXmlLoaderOptions() |
|
1605 | ); |
||
1606 | 7 | $images = []; |
|
1607 | 7 | $hyperlinks = []; |
|
1608 | 7 | if ($relsDrawing && $relsDrawing->Relationship) { |
|
1609 | 6 | foreach ($relsDrawing->Relationship as $ele) { |
|
1610 | 6 | if ($ele['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink') { |
|
1611 | 2 | $hyperlinks[(string) $ele['Id']] = (string) $ele['Target']; |
|
1612 | } |
||
1613 | 6 | if ($ele['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image') { |
|
1614 | 6 | $images[(string) $ele['Id']] = self::dirAdd($fileDrawing, $ele['Target']); |
|
1615 | 4 | } elseif ($ele['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart') { |
|
1616 | 2 | if ($this->includeCharts) { |
|
1617 | 2 | $charts[self::dirAdd($fileDrawing, $ele['Target'])] = [ |
|
1618 | 2 | 'id' => (string) $ele['Id'], |
|
1619 | 6 | 'sheet' => $docSheet->getTitle(), |
|
1620 | ]; |
||
1621 | } |
||
1622 | } |
||
1623 | } |
||
1624 | } |
||
1625 | 7 | $xmlDrawing = simplexml_load_string( |
|
1626 | 7 | $this->securityScan($this->getFromZipArchive($zip, $fileDrawing)), |
|
1627 | 7 | 'SimpleXMLElement', |
|
1628 | 7 | Settings::getLibXmlLoaderOptions() |
|
1629 | 7 | )->children('http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing'); |
|
1630 | |||
1631 | 7 | if ($xmlDrawing->oneCellAnchor) { |
|
1632 | 4 | foreach ($xmlDrawing->oneCellAnchor as $oneCellAnchor) { |
|
1633 | 4 | if ($oneCellAnchor->pic->blipFill) { |
|
1634 | /** @var SimpleXMLElement $blip */ |
||
1635 | 4 | $blip = $oneCellAnchor->pic->blipFill->children('http://schemas.openxmlformats.org/drawingml/2006/main')->blip; |
|
1636 | /** @var SimpleXMLElement $xfrm */ |
||
1637 | 4 | $xfrm = $oneCellAnchor->pic->spPr->children('http://schemas.openxmlformats.org/drawingml/2006/main')->xfrm; |
|
1638 | /** @var SimpleXMLElement $outerShdw */ |
||
1639 | 4 | $outerShdw = $oneCellAnchor->pic->spPr->children('http://schemas.openxmlformats.org/drawingml/2006/main')->effectLst->outerShdw; |
|
1640 | /** @var \SimpleXMLElement $hlinkClick */ |
||
1641 | 4 | $hlinkClick = $oneCellAnchor->pic->nvPicPr->cNvPr->children('http://schemas.openxmlformats.org/drawingml/2006/main')->hlinkClick; |
|
1642 | |||
1643 | 4 | $objDrawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing(); |
|
1644 | 4 | $objDrawing->setName((string) self::getArrayItem($oneCellAnchor->pic->nvPicPr->cNvPr->attributes(), 'name')); |
|
1645 | 4 | $objDrawing->setDescription((string) self::getArrayItem($oneCellAnchor->pic->nvPicPr->cNvPr->attributes(), 'descr')); |
|
1646 | 4 | $objDrawing->setPath( |
|
1647 | 4 | 'zip://' . File::realpath($pFilename) . '#' . |
|
1648 | 4 | $images[(string) self::getArrayItem( |
|
1649 | 4 | $blip->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'), |
|
1650 | 4 | 'embed' |
|
1651 | )], |
||
1652 | 4 | false |
|
1653 | ); |
||
1654 | 4 | $objDrawing->setCoordinates(Coordinate::stringFromColumnIndex(((string) $oneCellAnchor->from->col) + 1) . ($oneCellAnchor->from->row + 1)); |
|
1655 | 4 | $objDrawing->setOffsetX(Drawing::EMUToPixels($oneCellAnchor->from->colOff)); |
|
1656 | 4 | $objDrawing->setOffsetY(Drawing::EMUToPixels($oneCellAnchor->from->rowOff)); |
|
1657 | 4 | $objDrawing->setResizeProportional(false); |
|
1658 | 4 | $objDrawing->setWidth(Drawing::EMUToPixels(self::getArrayItem($oneCellAnchor->ext->attributes(), 'cx'))); |
|
1659 | 4 | $objDrawing->setHeight(Drawing::EMUToPixels(self::getArrayItem($oneCellAnchor->ext->attributes(), 'cy'))); |
|
1660 | 4 | if ($xfrm) { |
|
1661 | 4 | $objDrawing->setRotation(Drawing::angleToDegrees(self::getArrayItem($xfrm->attributes(), 'rot'))); |
|
1 ignored issue
–
show
|
|||
1662 | } |
||
1663 | 4 | if ($outerShdw) { |
|
1664 | 2 | $shadow = $objDrawing->getShadow(); |
|
1665 | 2 | $shadow->setVisible(true); |
|
1666 | 2 | $shadow->setBlurRadius(Drawing::EMUTopixels(self::getArrayItem($outerShdw->attributes(), 'blurRad'))); |
|
1 ignored issue
–
show
|
|||
1667 | 2 | $shadow->setDistance(Drawing::EMUTopixels(self::getArrayItem($outerShdw->attributes(), 'dist'))); |
|
1668 | 2 | $shadow->setDirection(Drawing::angleToDegrees(self::getArrayItem($outerShdw->attributes(), 'dir'))); |
|
1669 | 2 | $shadow->setAlignment((string) self::getArrayItem($outerShdw->attributes(), 'algn')); |
|
1670 | 2 | $shadow->getColor()->setRGB(self::getArrayItem($outerShdw->srgbClr->attributes(), 'val')); |
|
1671 | 2 | $shadow->setAlpha(self::getArrayItem($outerShdw->srgbClr->alpha->attributes(), 'val') / 1000); |
|
1672 | } |
||
1673 | |||
1674 | 4 | $this->readHyperLinkDrawing($objDrawing, $oneCellAnchor, $hyperlinks); |
|
1675 | |||
1676 | 4 | $objDrawing->setWorksheet($docSheet); |
|
1677 | } else { |
||
1678 | // ? Can charts be positioned with a oneCellAnchor ? |
||
1679 | $coordinates = Coordinate::stringFromColumnIndex(((string) $oneCellAnchor->from->col) + 1) . ($oneCellAnchor->from->row + 1); |
||
1680 | $offsetX = Drawing::EMUToPixels($oneCellAnchor->from->colOff); |
||
1681 | $offsetY = Drawing::EMUToPixels($oneCellAnchor->from->rowOff); |
||
1682 | $width = Drawing::EMUToPixels(self::getArrayItem($oneCellAnchor->ext->attributes(), 'cx')); |
||
1683 | 4 | $height = Drawing::EMUToPixels(self::getArrayItem($oneCellAnchor->ext->attributes(), 'cy')); |
|
1684 | } |
||
1685 | } |
||
1686 | } |
||
1687 | 7 | if ($xmlDrawing->twoCellAnchor) { |
|
1688 | 2 | foreach ($xmlDrawing->twoCellAnchor as $twoCellAnchor) { |
|
1689 | 2 | if ($twoCellAnchor->pic->blipFill) { |
|
1690 | 2 | $blip = $twoCellAnchor->pic->blipFill->children('http://schemas.openxmlformats.org/drawingml/2006/main')->blip; |
|
1691 | 2 | $xfrm = $twoCellAnchor->pic->spPr->children('http://schemas.openxmlformats.org/drawingml/2006/main')->xfrm; |
|
1692 | 2 | $outerShdw = $twoCellAnchor->pic->spPr->children('http://schemas.openxmlformats.org/drawingml/2006/main')->effectLst->outerShdw; |
|
1693 | 2 | $hlinkClick = $twoCellAnchor->pic->nvPicPr->cNvPr->children('http://schemas.openxmlformats.org/drawingml/2006/main')->hlinkClick; |
|
1694 | 2 | $objDrawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing(); |
|
1695 | 2 | $objDrawing->setName((string) self::getArrayItem($twoCellAnchor->pic->nvPicPr->cNvPr->attributes(), 'name')); |
|
1696 | 2 | $objDrawing->setDescription((string) self::getArrayItem($twoCellAnchor->pic->nvPicPr->cNvPr->attributes(), 'descr')); |
|
1697 | 2 | $objDrawing->setPath( |
|
1698 | 2 | 'zip://' . File::realpath($pFilename) . '#' . |
|
1699 | 2 | $images[(string) self::getArrayItem( |
|
1700 | 2 | $blip->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'), |
|
1701 | 2 | 'embed' |
|
1702 | )], |
||
1703 | 2 | false |
|
1704 | ); |
||
1705 | 2 | $objDrawing->setCoordinates(Coordinate::stringFromColumnIndex(((string) $twoCellAnchor->from->col) + 1) . ($twoCellAnchor->from->row + 1)); |
|
1706 | 2 | $objDrawing->setOffsetX(Drawing::EMUToPixels($twoCellAnchor->from->colOff)); |
|
1707 | 2 | $objDrawing->setOffsetY(Drawing::EMUToPixels($twoCellAnchor->from->rowOff)); |
|
1708 | 2 | $objDrawing->setResizeProportional(false); |
|
1709 | |||
1710 | 2 | if ($xfrm) { |
|
1711 | 2 | $objDrawing->setWidth(Drawing::EMUToPixels(self::getArrayItem($xfrm->ext->attributes(), 'cx'))); |
|
1712 | 2 | $objDrawing->setHeight(Drawing::EMUToPixels(self::getArrayItem($xfrm->ext->attributes(), 'cy'))); |
|
1713 | 2 | $objDrawing->setRotation(Drawing::angleToDegrees(self::getArrayItem($xfrm->attributes(), 'rot'))); |
|
1714 | } |
||
1715 | 2 | if ($outerShdw) { |
|
1716 | $shadow = $objDrawing->getShadow(); |
||
1717 | $shadow->setVisible(true); |
||
1718 | $shadow->setBlurRadius(Drawing::EMUTopixels(self::getArrayItem($outerShdw->attributes(), 'blurRad'))); |
||
1719 | $shadow->setDistance(Drawing::EMUTopixels(self::getArrayItem($outerShdw->attributes(), 'dist'))); |
||
1720 | $shadow->setDirection(Drawing::angleToDegrees(self::getArrayItem($outerShdw->attributes(), 'dir'))); |
||
1721 | $shadow->setAlignment((string) self::getArrayItem($outerShdw->attributes(), 'algn')); |
||
1722 | $shadow->getColor()->setRGB(self::getArrayItem($outerShdw->srgbClr->attributes(), 'val')); |
||
1723 | $shadow->setAlpha(self::getArrayItem($outerShdw->srgbClr->alpha->attributes(), 'val') / 1000); |
||
1724 | } |
||
1725 | |||
1726 | 2 | $this->readHyperLinkDrawing($objDrawing, $twoCellAnchor, $hyperlinks); |
|
1727 | |||
1728 | 2 | $objDrawing->setWorksheet($docSheet); |
|
1729 | 2 | } elseif (($this->includeCharts) && ($twoCellAnchor->graphicFrame)) { |
|
1730 | 2 | $fromCoordinate = Coordinate::stringFromColumnIndex(((string) $twoCellAnchor->from->col) + 1) . ($twoCellAnchor->from->row + 1); |
|
1731 | 2 | $fromOffsetX = Drawing::EMUToPixels($twoCellAnchor->from->colOff); |
|
1732 | 2 | $fromOffsetY = Drawing::EMUToPixels($twoCellAnchor->from->rowOff); |
|
1733 | 2 | $toCoordinate = Coordinate::stringFromColumnIndex(((string) $twoCellAnchor->to->col) + 1) . ($twoCellAnchor->to->row + 1); |
|
1734 | 2 | $toOffsetX = Drawing::EMUToPixels($twoCellAnchor->to->colOff); |
|
1735 | 2 | $toOffsetY = Drawing::EMUToPixels($twoCellAnchor->to->rowOff); |
|
1736 | 2 | $graphic = $twoCellAnchor->graphicFrame->children('http://schemas.openxmlformats.org/drawingml/2006/main')->graphic; |
|
1737 | /** @var SimpleXMLElement $chartRef */ |
||
1738 | 2 | $chartRef = $graphic->graphicData->children('http://schemas.openxmlformats.org/drawingml/2006/chart')->chart; |
|
1739 | 2 | $thisChart = (string) $chartRef->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'); |
|
1740 | |||
1741 | 2 | $chartDetails[$docSheet->getTitle() . '!' . $thisChart] = [ |
|
1742 | 2 | 'fromCoordinate' => $fromCoordinate, |
|
1743 | 2 | 'fromOffsetX' => $fromOffsetX, |
|
1744 | 2 | 'fromOffsetY' => $fromOffsetY, |
|
1745 | 2 | 'toCoordinate' => $toCoordinate, |
|
1746 | 2 | 'toOffsetX' => $toOffsetX, |
|
1747 | 2 | 'toOffsetY' => $toOffsetY, |
|
1748 | 7 | 'worksheetTitle' => $docSheet->getTitle(), |
|
1749 | ]; |
||
1750 | } |
||
1751 | } |
||
1752 | } |
||
1753 | } |
||
1754 | |||
1755 | // store original rId of drawing files |
||
1756 | 7 | $unparsedLoadedData['sheets'][$docSheet->getCodeName()]['drawingOriginalIds'] = []; |
|
1757 | 7 | foreach ($relsWorksheet->Relationship as $ele) { |
|
1758 | 7 | if ($ele['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing') { |
|
1759 | 7 | $unparsedLoadedData['sheets'][$docSheet->getCodeName()]['drawingOriginalIds'][(string) $ele['Target']] = (string) $ele['Id']; |
|
1760 | } |
||
1761 | } |
||
1762 | |||
1763 | // unparsed drawing AlternateContent |
||
1764 | 7 | $xmlAltDrawing = simplexml_load_string( |
|
1765 | 7 | $this->securityScan($this->getFromZipArchive($zip, $fileDrawing)), |
|
1766 | 7 | 'SimpleXMLElement', |
|
1767 | 7 | Settings::getLibXmlLoaderOptions() |
|
1768 | 7 | )->children('http://schemas.openxmlformats.org/markup-compatibility/2006'); |
|
1769 | |||
1770 | 7 | if ($xmlAltDrawing->AlternateContent) { |
|
1771 | 1 | foreach ($xmlAltDrawing->AlternateContent as $alternateContent) { |
|
1772 | 1 | $unparsedLoadedData['sheets'][$docSheet->getCodeName()]['drawingAlternateContents'][] = $alternateContent->asXML(); |
|
1773 | } |
||
1774 | } |
||
1775 | } |
||
1776 | } |
||
1777 | |||
1778 | 38 | $this->readFormControlProperties($excel, $zip, $dir, $fileWorksheet, $docSheet, $unparsedLoadedData); |
|
1779 | 38 | $this->readPrinterSettings($excel, $zip, $dir, $fileWorksheet, $docSheet, $unparsedLoadedData); |
|
1780 | |||
1781 | // Loop through definedNames |
||
1782 | 38 | if ($xmlWorkbook->definedNames) { |
|
1783 | 30 | foreach ($xmlWorkbook->definedNames->definedName as $definedName) { |
|
1784 | // Extract range |
||
1785 | 2 | $extractedRange = (string) $definedName; |
|
1786 | 2 | if (($spos = strpos($extractedRange, '!')) !== false) { |
|
1787 | 2 | $extractedRange = substr($extractedRange, 0, $spos) . str_replace('$', '', substr($extractedRange, $spos)); |
|
1788 | } else { |
||
1789 | $extractedRange = str_replace('$', '', $extractedRange); |
||
1790 | } |
||
1791 | |||
1792 | // Valid range? |
||
1793 | 2 | if (stripos((string) $definedName, '#REF!') !== false || $extractedRange == '') { |
|
1794 | continue; |
||
1795 | } |
||
1796 | |||
1797 | // Some definedNames are only applicable if we are on the same sheet... |
||
1798 | 2 | if ((string) $definedName['localSheetId'] != '' && (string) $definedName['localSheetId'] == $oldSheetId) { |
|
1799 | // Switch on type |
||
1800 | 2 | switch ((string) $definedName['name']) { |
|
1801 | 2 | case '_xlnm._FilterDatabase': |
|
1802 | if ((string) $definedName['hidden'] !== '1') { |
||
1803 | $extractedRange = explode(',', $extractedRange); |
||
1804 | foreach ($extractedRange as $range) { |
||
1805 | $autoFilterRange = $range; |
||
1806 | if (strpos($autoFilterRange, ':') !== false) { |
||
1807 | $docSheet->getAutoFilter()->setRange($autoFilterRange); |
||
1808 | } |
||
1809 | } |
||
1810 | } |
||
1811 | |||
1812 | break; |
||
1813 | 2 | case '_xlnm.Print_Titles': |
|
1814 | // Split $extractedRange |
||
1815 | 1 | $extractedRange = explode(',', $extractedRange); |
|
1816 | |||
1817 | // Set print titles |
||
1818 | 1 | foreach ($extractedRange as $range) { |
|
1819 | 1 | $matches = []; |
|
1820 | 1 | $range = str_replace('$', '', $range); |
|
1821 | |||
1822 | // check for repeating columns, e g. 'A:A' or 'A:D' |
||
1823 | 1 | if (preg_match('/!?([A-Z]+)\:([A-Z]+)$/', $range, $matches)) { |
|
1824 | $docSheet->getPageSetup()->setColumnsToRepeatAtLeft([$matches[1], $matches[2]]); |
||
1825 | 1 | } elseif (preg_match('/!?(\d+)\:(\d+)$/', $range, $matches)) { |
|
1826 | // check for repeating rows, e.g. '1:1' or '1:5' |
||
1827 | 1 | $docSheet->getPageSetup()->setRowsToRepeatAtTop([$matches[1], $matches[2]]); |
|
1828 | } |
||
1829 | } |
||
1830 | |||
1831 | 1 | break; |
|
1832 | 1 | case '_xlnm.Print_Area': |
|
1833 | 1 | $rangeSets = preg_split("/'(.*?)'(?:![A-Z0-9]+:[A-Z0-9]+,?)/", $extractedRange, PREG_SPLIT_NO_EMPTY); |
|
1834 | 1 | $newRangeSets = []; |
|
1835 | 1 | foreach ($rangeSets as $rangeSet) { |
|
1836 | 1 | list($sheetName, $rangeSet) = Worksheet::extractSheetTitle($rangeSet, true); |
|
1837 | 1 | if (strpos($rangeSet, ':') === false) { |
|
1838 | $rangeSet = $rangeSet . ':' . $rangeSet; |
||
1839 | } |
||
1840 | 1 | $newRangeSets[] = str_replace('$', '', $rangeSet); |
|
1841 | } |
||
1842 | 1 | $docSheet->getPageSetup()->setPrintArea(implode(',', $newRangeSets)); |
|
1843 | |||
1844 | 1 | break; |
|
1845 | default: |
||
1846 | 2 | break; |
|
1847 | } |
||
1848 | } |
||
1849 | } |
||
1850 | } |
||
1851 | |||
1852 | // Next sheet id |
||
1853 | 38 | ++$sheetId; |
|
1854 | } |
||
1855 | |||
1856 | // Loop through definedNames |
||
1857 | 38 | if ($xmlWorkbook->definedNames) { |
|
1858 | 30 | foreach ($xmlWorkbook->definedNames->definedName as $definedName) { |
|
1859 | // Extract range |
||
1860 | 2 | $extractedRange = (string) $definedName; |
|
1861 | 2 | if (($spos = strpos($extractedRange, '!')) !== false) { |
|
1862 | 2 | $extractedRange = substr($extractedRange, 0, $spos) . str_replace('$', '', substr($extractedRange, $spos)); |
|
1863 | } else { |
||
1864 | $extractedRange = str_replace('$', '', $extractedRange); |
||
1865 | } |
||
1866 | |||
1867 | // Valid range? |
||
1868 | 2 | if (stripos((string) $definedName, '#REF!') !== false || $extractedRange == '') { |
|
1869 | continue; |
||
1870 | } |
||
1871 | |||
1872 | // Some definedNames are only applicable if we are on the same sheet... |
||
1873 | 2 | if ((string) $definedName['localSheetId'] != '') { |
|
1874 | // Local defined name |
||
1875 | // Switch on type |
||
1876 | 2 | switch ((string) $definedName['name']) { |
|
1877 | 2 | case '_xlnm._FilterDatabase': |
|
1878 | 2 | case '_xlnm.Print_Titles': |
|
1879 | 1 | case '_xlnm.Print_Area': |
|
1880 | 2 | break; |
|
1881 | default: |
||
1882 | if ($mapSheetId[(int) $definedName['localSheetId']] !== null) { |
||
1883 | if (strpos((string) $definedName, '!') !== false) { |
||
1884 | $range = Worksheet::extractSheetTitle((string) $definedName, true); |
||
1885 | $range[0] = str_replace("''", "'", $range[0]); |
||
1886 | $range[0] = str_replace("'", '', $range[0]); |
||
1887 | if ($worksheet = $docSheet->getParent()->getSheetByName($range[0])) { |
||
1888 | $extractedRange = str_replace('$', '', $range[1]); |
||
1889 | $scope = $docSheet->getParent()->getSheet($mapSheetId[(int) $definedName['localSheetId']]); |
||
1890 | $excel->addNamedRange(new NamedRange((string) $definedName['name'], $worksheet, $extractedRange, true, $scope)); |
||
1891 | } |
||
1892 | } |
||
1893 | } |
||
1894 | |||
1895 | 2 | break; |
|
1896 | } |
||
1897 | } elseif (!isset($definedName['localSheetId'])) { |
||
1898 | // "Global" definedNames |
||
1899 | $locatedSheet = null; |
||
1900 | $extractedSheetName = ''; |
||
1901 | if (strpos((string) $definedName, '!') !== false) { |
||
1902 | // Extract sheet name |
||
1903 | $extractedSheetName = Worksheet::extractSheetTitle((string) $definedName, true); |
||
1904 | $extractedSheetName = $extractedSheetName[0]; |
||
1905 | |||
1906 | // Locate sheet |
||
1907 | $locatedSheet = $excel->getSheetByName($extractedSheetName); |
||
1908 | |||
1909 | // Modify range |
||
1910 | list($worksheetName, $extractedRange) = Worksheet::extractSheetTitle($extractedRange, true); |
||
1911 | } |
||
1912 | |||
1913 | if ($locatedSheet !== null) { |
||
1914 | 2 | $excel->addNamedRange(new NamedRange((string) $definedName['name'], $locatedSheet, $extractedRange, false)); |
|
1915 | } |
||
1916 | } |
||
1917 | } |
||
1918 | } |
||
1919 | } |
||
1920 | |||
1921 | 38 | if ((!$this->readDataOnly) || (!empty($this->loadSheetsOnly))) { |
|
1922 | 38 | $workbookView = $xmlWorkbook->bookViews->workbookView; |
|
1923 | |||
1924 | // active sheet index |
||
1925 | 38 | $activeTab = (int) ($workbookView['activeTab']); // refers to old sheet index |
|
1926 | |||
1927 | // keep active sheet index if sheet is still loaded, else first sheet is set as the active |
||
1928 | 38 | if (isset($mapSheetId[$activeTab]) && $mapSheetId[$activeTab] !== null) { |
|
1929 | 38 | $excel->setActiveSheetIndex($mapSheetId[$activeTab]); |
|
1930 | } else { |
||
1931 | if ($excel->getSheetCount() == 0) { |
||
1932 | $excel->createSheet(); |
||
1933 | } |
||
1934 | $excel->setActiveSheetIndex(0); |
||
1935 | } |
||
1936 | |||
1937 | 38 | if (isset($workbookView['showHorizontalScroll'])) { |
|
1938 | 30 | $showHorizontalScroll = (string) $workbookView['showHorizontalScroll']; |
|
1939 | 30 | $excel->setShowHorizontalScroll($this->castXsdBooleanToBool($showHorizontalScroll)); |
|
1940 | } |
||
1941 | |||
1942 | 38 | if (isset($workbookView['showVerticalScroll'])) { |
|
1943 | 30 | $showVerticalScroll = (string) $workbookView['showVerticalScroll']; |
|
1944 | 30 | $excel->setShowVerticalScroll($this->castXsdBooleanToBool($showVerticalScroll)); |
|
1945 | } |
||
1946 | |||
1947 | 38 | if (isset($workbookView['showSheetTabs'])) { |
|
1948 | 30 | $showSheetTabs = (string) $workbookView['showSheetTabs']; |
|
1949 | 30 | $excel->setShowSheetTabs($this->castXsdBooleanToBool($showSheetTabs)); |
|
1950 | } |
||
1951 | |||
1952 | 38 | if (isset($workbookView['minimized'])) { |
|
1953 | 30 | $minimized = (string) $workbookView['minimized']; |
|
1954 | 30 | $excel->setMinimized($this->castXsdBooleanToBool($minimized)); |
|
1955 | } |
||
1956 | |||
1957 | 38 | if (isset($workbookView['autoFilterDateGrouping'])) { |
|
1958 | 30 | $autoFilterDateGrouping = (string) $workbookView['autoFilterDateGrouping']; |
|
1959 | 30 | $excel->setAutoFilterDateGrouping($this->castXsdBooleanToBool($autoFilterDateGrouping)); |
|
1960 | } |
||
1961 | |||
1962 | 38 | if (isset($workbookView['firstSheet'])) { |
|
1963 | 30 | $firstSheet = (string) $workbookView['firstSheet']; |
|
1964 | 30 | $excel->setFirstSheetIndex((int) $firstSheet); |
|
1965 | } |
||
1966 | |||
1967 | 38 | if (isset($workbookView['visibility'])) { |
|
1968 | 30 | $visibility = (string) $workbookView['visibility']; |
|
1969 | 30 | $excel->setVisibility($visibility); |
|
1970 | } |
||
1971 | |||
1972 | 38 | if (isset($workbookView['tabRatio'])) { |
|
1973 | 30 | $tabRatio = (string) $workbookView['tabRatio']; |
|
1974 | 30 | $excel->setTabRatio((int) $tabRatio); |
|
1975 | } |
||
1976 | } |
||
1977 | |||
1978 | 38 | break; |
|
1979 | } |
||
1980 | } |
||
1981 | |||
1982 | 38 | if (!$this->readDataOnly) { |
|
1983 | 38 | $contentTypes = simplexml_load_string( |
|
1984 | 38 | $this->securityScan( |
|
1985 | 38 | $this->getFromZipArchive($zip, '[Content_Types].xml') |
|
1986 | ), |
||
1987 | 38 | 'SimpleXMLElement', |
|
1988 | 38 | Settings::getLibXmlLoaderOptions() |
|
1989 | ); |
||
1990 | |||
1991 | // Default content types |
||
1992 | 38 | foreach ($contentTypes->Default as $contentType) { |
|
1993 | 38 | switch ($contentType['ContentType']) { |
|
1994 | 38 | case 'application/vnd.openxmlformats-officedocument.spreadsheetml.printerSettings': |
|
1995 | 8 | $unparsedLoadedData['default_content_types'][(string) $contentType['Extension']] = (string) $contentType['ContentType']; |
|
1996 | |||
1997 | 38 | break; |
|
1998 | } |
||
1999 | } |
||
2000 | |||
2001 | // Override content types |
||
2002 | 38 | foreach ($contentTypes->Override as $contentType) { |
|
2003 | 38 | switch ($contentType['ContentType']) { |
|
2004 | 38 | case 'application/vnd.openxmlformats-officedocument.drawingml.chart+xml': |
|
2005 | 2 | if ($this->includeCharts) { |
|
2006 | 2 | $chartEntryRef = ltrim($contentType['PartName'], '/'); |
|
2007 | 2 | $chartElements = simplexml_load_string( |
|
2008 | 2 | $this->securityScan( |
|
2009 | 2 | $this->getFromZipArchive($zip, $chartEntryRef) |
|
2010 | ), |
||
2011 | 2 | 'SimpleXMLElement', |
|
2012 | 2 | Settings::getLibXmlLoaderOptions() |
|
2013 | ); |
||
2014 | 2 | $objChart = Chart::readChart($chartElements, basename($chartEntryRef, '.xml')); |
|
1 ignored issue
–
show
|
|||
2015 | |||
2016 | 2 | if (isset($charts[$chartEntryRef])) { |
|
2017 | 2 | $chartPositionRef = $charts[$chartEntryRef]['sheet'] . '!' . $charts[$chartEntryRef]['id']; |
|
2018 | 2 | if (isset($chartDetails[$chartPositionRef])) { |
|
2019 | 2 | $excel->getSheetByName($charts[$chartEntryRef]['sheet'])->addChart($objChart); |
|
2020 | 2 | $objChart->setWorksheet($excel->getSheetByName($charts[$chartEntryRef]['sheet'])); |
|
2021 | 2 | $objChart->setTopLeftPosition($chartDetails[$chartPositionRef]['fromCoordinate'], $chartDetails[$chartPositionRef]['fromOffsetX'], $chartDetails[$chartPositionRef]['fromOffsetY']); |
|
2022 | 2 | $objChart->setBottomRightPosition($chartDetails[$chartPositionRef]['toCoordinate'], $chartDetails[$chartPositionRef]['toOffsetX'], $chartDetails[$chartPositionRef]['toOffsetY']); |
|
2023 | } |
||
2024 | } |
||
2025 | } |
||
2026 | |||
2027 | 2 | break; |
|
2028 | |||
2029 | // unparsed |
||
2030 | 38 | case 'application/vnd.ms-excel.controlproperties+xml': |
|
2031 | 1 | $unparsedLoadedData['override_content_types'][(string) $contentType['PartName']] = (string) $contentType['ContentType']; |
|
2032 | |||
2033 | 38 | break; |
|
2034 | } |
||
2035 | } |
||
2036 | } |
||
2037 | |||
2038 | 38 | $excel->setUnparsedLoadedData($unparsedLoadedData); |
|
2039 | |||
2040 | 38 | $zip->close(); |
|
2041 | |||
2042 | 38 | return $excel; |
|
2043 | } |
||
2599 |