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