Conditions | 254 |
Paths | > 20000 |
Total Lines | 1221 |
Code Lines | 747 |
Lines | 0 |
Ratio | 0 % |
Tests | 617 |
CRAP Score | 504.1473 |
Changes | 7 | ||
Bugs | 1 | Features | 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 |
||
325 | 48 | public function load($pFilename) |
|
326 | { |
||
327 | 48 | File::assertFile($pFilename); |
|
328 | |||
329 | // Initialisations |
||
330 | 48 | $excel = new Spreadsheet(); |
|
331 | 48 | $excel->removeSheetByIndex(0); |
|
332 | 48 | if (!$this->readDataOnly) { |
|
333 | 48 | $excel->removeCellStyleXfByIndex(0); // remove the default style |
|
334 | 48 | $excel->removeCellXfByIndex(0); // remove the default style |
|
335 | } |
||
336 | 48 | $unparsedLoadedData = []; |
|
337 | |||
338 | 48 | $zip = new ZipArchive(); |
|
339 | 48 | $zip->open($pFilename); |
|
340 | |||
341 | // Read the theme first, because we need the colour scheme when reading the styles |
||
342 | //~ http://schemas.openxmlformats.org/package/2006/relationships" |
||
343 | 48 | $workbookBasename = $this->getWorkbookBaseName($zip); |
|
344 | 48 | $wbRels = simplexml_load_string( |
|
345 | 48 | $this->securityScanner->scan($this->getFromZipArchive($zip, "xl/_rels/${workbookBasename}.rels")), |
|
346 | 48 | 'SimpleXMLElement', |
|
347 | 48 | Settings::getLibXmlLoaderOptions() |
|
348 | ); |
||
349 | 48 | foreach ($wbRels->Relationship as $rel) { |
|
350 | 48 | switch ($rel['Type']) { |
|
351 | 48 | case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme': |
|
352 | 48 | $themeOrderArray = ['lt1', 'dk1', 'lt2', 'dk2']; |
|
353 | 48 | $themeOrderAdditional = count($themeOrderArray); |
|
354 | |||
355 | 48 | $xmlTheme = simplexml_load_string( |
|
356 | 48 | $this->securityScanner->scan($this->getFromZipArchive($zip, "xl/{$rel['Target']}")), |
|
357 | 48 | 'SimpleXMLElement', |
|
358 | 48 | Settings::getLibXmlLoaderOptions() |
|
359 | ); |
||
360 | 48 | if (is_object($xmlTheme)) { |
|
361 | 48 | $xmlThemeName = $xmlTheme->attributes(); |
|
362 | 48 | $xmlTheme = $xmlTheme->children('http://schemas.openxmlformats.org/drawingml/2006/main'); |
|
363 | 48 | $themeName = (string) $xmlThemeName['name']; |
|
364 | |||
365 | 48 | $colourScheme = $xmlTheme->themeElements->clrScheme->attributes(); |
|
366 | 48 | $colourSchemeName = (string) $colourScheme['name']; |
|
367 | 48 | $colourScheme = $xmlTheme->themeElements->clrScheme->children('http://schemas.openxmlformats.org/drawingml/2006/main'); |
|
368 | |||
369 | 48 | $themeColours = []; |
|
370 | 48 | foreach ($colourScheme as $k => $xmlColour) { |
|
371 | 48 | $themePos = array_search($k, $themeOrderArray); |
|
372 | 48 | if ($themePos === false) { |
|
373 | 48 | $themePos = $themeOrderAdditional++; |
|
374 | } |
||
375 | 48 | if (isset($xmlColour->sysClr)) { |
|
376 | 48 | $xmlColourData = $xmlColour->sysClr->attributes(); |
|
377 | 48 | $themeColours[$themePos] = $xmlColourData['lastClr']; |
|
378 | 48 | } elseif (isset($xmlColour->srgbClr)) { |
|
379 | 48 | $xmlColourData = $xmlColour->srgbClr->attributes(); |
|
380 | 48 | $themeColours[$themePos] = $xmlColourData['val']; |
|
381 | } |
||
382 | } |
||
383 | 48 | self::$theme = new Xlsx\Theme($themeName, $colourSchemeName, $themeColours); |
|
384 | } |
||
385 | |||
386 | 48 | break; |
|
387 | } |
||
388 | } |
||
389 | |||
390 | //~ http://schemas.openxmlformats.org/package/2006/relationships" |
||
391 | 48 | $rels = simplexml_load_string( |
|
392 | 48 | $this->securityScanner->scan($this->getFromZipArchive($zip, '_rels/.rels')), |
|
393 | 48 | 'SimpleXMLElement', |
|
394 | 48 | Settings::getLibXmlLoaderOptions() |
|
395 | ); |
||
396 | |||
397 | 48 | $propertyReader = new PropertyReader($this->securityScanner, $excel->getProperties()); |
|
398 | 48 | foreach ($rels->Relationship as $rel) { |
|
399 | 48 | switch ($rel['Type']) { |
|
400 | 48 | case 'http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties': |
|
401 | 47 | $propertyReader->readCoreProperties($this->getFromZipArchive($zip, "{$rel['Target']}")); |
|
402 | |||
403 | 47 | break; |
|
404 | 48 | case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties': |
|
405 | 47 | $propertyReader->readExtendedProperties($this->getFromZipArchive($zip, "{$rel['Target']}")); |
|
406 | |||
407 | 47 | break; |
|
408 | 48 | case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties': |
|
409 | 4 | $propertyReader->readCustomProperties($this->getFromZipArchive($zip, "{$rel['Target']}")); |
|
410 | |||
411 | 4 | break; |
|
412 | //Ribbon |
||
413 | 48 | case 'http://schemas.microsoft.com/office/2006/relationships/ui/extensibility': |
|
414 | $customUI = $rel['Target']; |
||
415 | if ($customUI !== null) { |
||
416 | $this->readRibbon($excel, $customUI, $zip); |
||
417 | } |
||
418 | |||
419 | break; |
||
420 | 48 | case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument': |
|
421 | 48 | $dir = dirname($rel['Target']); |
|
422 | //~ http://schemas.openxmlformats.org/package/2006/relationships" |
||
423 | 48 | $relsWorkbook = simplexml_load_string( |
|
424 | 48 | $this->securityScanner->scan($this->getFromZipArchive($zip, "$dir/_rels/" . basename($rel['Target']) . '.rels')), |
|
425 | 48 | 'SimpleXMLElement', |
|
426 | 48 | Settings::getLibXmlLoaderOptions() |
|
427 | ); |
||
428 | 48 | $relsWorkbook->registerXPathNamespace('rel', 'http://schemas.openxmlformats.org/package/2006/relationships'); |
|
429 | |||
430 | 48 | $sharedStrings = []; |
|
431 | 48 | $xpath = self::getArrayItem($relsWorkbook->xpath("rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings']")); |
|
432 | //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main" |
||
433 | 48 | $xmlStrings = simplexml_load_string( |
|
434 | 48 | $this->securityScanner->scan($this->getFromZipArchive($zip, "$dir/$xpath[Target]")), |
|
435 | 48 | 'SimpleXMLElement', |
|
436 | 48 | Settings::getLibXmlLoaderOptions() |
|
437 | ); |
||
438 | 48 | if (isset($xmlStrings, $xmlStrings->si)) { |
|
439 | 27 | foreach ($xmlStrings->si as $val) { |
|
440 | 27 | if (isset($val->t)) { |
|
441 | 27 | $sharedStrings[] = StringHelper::controlCharacterOOXML2PHP((string) $val->t); |
|
442 | 4 | } elseif (isset($val->r)) { |
|
443 | 4 | $sharedStrings[] = $this->parseRichText($val); |
|
444 | } |
||
445 | } |
||
446 | } |
||
447 | |||
448 | 48 | $worksheets = []; |
|
449 | 48 | $macros = $customUI = null; |
|
450 | 48 | foreach ($relsWorkbook->Relationship as $ele) { |
|
451 | 48 | switch ($ele['Type']) { |
|
452 | 48 | case 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet': |
|
453 | 48 | $worksheets[(string) $ele['Id']] = $ele['Target']; |
|
454 | |||
455 | 48 | break; |
|
456 | // a vbaProject ? (: some macros) |
||
457 | 48 | case 'http://schemas.microsoft.com/office/2006/relationships/vbaProject': |
|
458 | 1 | $macros = $ele['Target']; |
|
459 | |||
460 | 1 | break; |
|
461 | } |
||
462 | } |
||
463 | |||
464 | 48 | if ($macros !== null) { |
|
465 | 1 | $macrosCode = $this->getFromZipArchive($zip, 'xl/vbaProject.bin'); //vbaProject.bin always in 'xl' dir and always named vbaProject.bin |
|
466 | 1 | if ($macrosCode !== false) { |
|
467 | 1 | $excel->setMacrosCode($macrosCode); |
|
468 | 1 | $excel->setHasMacros(true); |
|
469 | //short-circuit : not reading vbaProject.bin.rel to get Signature =>allways vbaProjectSignature.bin in 'xl' dir |
||
470 | 1 | $Certificate = $this->getFromZipArchive($zip, 'xl/vbaProjectSignature.bin'); |
|
471 | 1 | if ($Certificate !== false) { |
|
472 | $excel->setMacrosCertificate($Certificate); |
||
473 | } |
||
474 | } |
||
475 | } |
||
476 | |||
477 | 48 | $xpath = self::getArrayItem($relsWorkbook->xpath("rel:Relationship[@Type='http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles']")); |
|
478 | //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main" |
||
479 | 48 | $xmlStyles = simplexml_load_string( |
|
480 | 48 | $this->securityScanner->scan($this->getFromZipArchive($zip, "$dir/$xpath[Target]")), |
|
481 | 48 | 'SimpleXMLElement', |
|
482 | 48 | Settings::getLibXmlLoaderOptions() |
|
483 | ); |
||
484 | |||
485 | 48 | $styles = []; |
|
486 | 48 | $cellStyles = []; |
|
487 | 48 | $numFmts = null; |
|
488 | 48 | if ($xmlStyles && $xmlStyles->numFmts[0]) { |
|
489 | 35 | $numFmts = $xmlStyles->numFmts[0]; |
|
490 | } |
||
491 | 48 | if (isset($numFmts) && ($numFmts !== null)) { |
|
492 | 35 | $numFmts->registerXPathNamespace('sml', 'http://schemas.openxmlformats.org/spreadsheetml/2006/main'); |
|
493 | } |
||
494 | 48 | if (!$this->readDataOnly && $xmlStyles) { |
|
495 | 48 | foreach ($xmlStyles->cellXfs->xf as $xf) { |
|
496 | 48 | $numFmt = NumberFormat::FORMAT_GENERAL; |
|
497 | |||
498 | 48 | if ($xf['numFmtId']) { |
|
499 | 48 | if (isset($numFmts)) { |
|
500 | 35 | $tmpNumFmt = self::getArrayItem($numFmts->xpath("sml:numFmt[@numFmtId=$xf[numFmtId]]")); |
|
501 | |||
502 | 35 | if (isset($tmpNumFmt['formatCode'])) { |
|
503 | 4 | $numFmt = (string) $tmpNumFmt['formatCode']; |
|
504 | } |
||
505 | } |
||
506 | |||
507 | // We shouldn't override any of the built-in MS Excel values (values below id 164) |
||
508 | // But there's a lot of naughty homebrew xlsx writers that do use "reserved" id values that aren't actually used |
||
509 | // So we make allowance for them rather than lose formatting masks |
||
510 | 48 | if ((int) $xf['numFmtId'] < 164 && |
|
511 | 48 | NumberFormat::builtInFormatCode((int) $xf['numFmtId']) !== '') { |
|
512 | 48 | $numFmt = NumberFormat::builtInFormatCode((int) $xf['numFmtId']); |
|
513 | } |
||
514 | } |
||
515 | 48 | $quotePrefix = false; |
|
516 | 48 | if (isset($xf['quotePrefix'])) { |
|
517 | $quotePrefix = (bool) $xf['quotePrefix']; |
||
518 | } |
||
519 | |||
520 | $style = (object) [ |
||
521 | 48 | 'numFmt' => $numFmt, |
|
522 | 48 | 'font' => $xmlStyles->fonts->font[(int) ($xf['fontId'])], |
|
523 | 48 | 'fill' => $xmlStyles->fills->fill[(int) ($xf['fillId'])], |
|
524 | 48 | 'border' => $xmlStyles->borders->border[(int) ($xf['borderId'])], |
|
525 | 48 | 'alignment' => $xf->alignment, |
|
526 | 48 | 'protection' => $xf->protection, |
|
527 | 48 | 'quotePrefix' => $quotePrefix, |
|
528 | ]; |
||
529 | 48 | $styles[] = $style; |
|
530 | |||
531 | // add style to cellXf collection |
||
532 | 48 | $objStyle = new Style(); |
|
533 | 48 | self::readStyle($objStyle, $style); |
|
534 | 48 | $excel->addCellXf($objStyle); |
|
535 | } |
||
536 | |||
537 | 48 | foreach (isset($xmlStyles->cellStyleXfs->xf) ? $xmlStyles->cellStyleXfs->xf : [] as $xf) { |
|
538 | 48 | $numFmt = NumberFormat::FORMAT_GENERAL; |
|
539 | 48 | if ($numFmts && $xf['numFmtId']) { |
|
540 | 35 | $tmpNumFmt = self::getArrayItem($numFmts->xpath("sml:numFmt[@numFmtId=$xf[numFmtId]]")); |
|
541 | 35 | if (isset($tmpNumFmt['formatCode'])) { |
|
542 | 1 | $numFmt = (string) $tmpNumFmt['formatCode']; |
|
543 | 35 | } elseif ((int) $xf['numFmtId'] < 165) { |
|
544 | 35 | $numFmt = NumberFormat::builtInFormatCode((int) $xf['numFmtId']); |
|
545 | } |
||
546 | } |
||
547 | |||
548 | $cellStyle = (object) [ |
||
549 | 48 | 'numFmt' => $numFmt, |
|
550 | 48 | 'font' => $xmlStyles->fonts->font[(int) ($xf['fontId'])], |
|
551 | 48 | 'fill' => $xmlStyles->fills->fill[(int) ($xf['fillId'])], |
|
552 | 48 | 'border' => $xmlStyles->borders->border[(int) ($xf['borderId'])], |
|
553 | 48 | 'alignment' => $xf->alignment, |
|
554 | 48 | 'protection' => $xf->protection, |
|
555 | 48 | 'quotePrefix' => $quotePrefix, |
|
|
|||
556 | ]; |
||
557 | 48 | $cellStyles[] = $cellStyle; |
|
558 | |||
559 | // add style to cellStyleXf collection |
||
560 | 48 | $objStyle = new Style(); |
|
561 | 48 | self::readStyle($objStyle, $cellStyle); |
|
562 | 48 | $excel->addCellStyleXf($objStyle); |
|
563 | } |
||
564 | } |
||
565 | |||
566 | 48 | $styleReader = new Styles($xmlStyles); |
|
1 ignored issue
–
show
|
|||
567 | 48 | $styleReader->setStyleBaseData(self::$theme, $styles, $cellStyles); |
|
568 | 48 | $dxfs = $styleReader->dxfs($this->readDataOnly); |
|
569 | 48 | $styles = $styleReader->styles(); |
|
570 | |||
571 | //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main" |
||
572 | 48 | $xmlWorkbook = simplexml_load_string( |
|
573 | 48 | $this->securityScanner->scan($this->getFromZipArchive($zip, "{$rel['Target']}")), |
|
574 | 48 | 'SimpleXMLElement', |
|
575 | 48 | Settings::getLibXmlLoaderOptions() |
|
576 | ); |
||
577 | |||
578 | // Set base date |
||
579 | 48 | if ($xmlWorkbook->workbookPr) { |
|
580 | 47 | Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900); |
|
581 | 47 | if (isset($xmlWorkbook->workbookPr['date1904'])) { |
|
582 | if (self::boolean((string) $xmlWorkbook->workbookPr['date1904'])) { |
||
583 | Date::setExcelCalendar(Date::CALENDAR_MAC_1904); |
||
584 | } |
||
585 | } |
||
586 | } |
||
587 | |||
588 | // Set protection |
||
589 | 48 | $this->readProtection($excel, $xmlWorkbook); |
|
1 ignored issue
–
show
|
|||
590 | |||
591 | 48 | $sheetId = 0; // keep track of new sheet id in final workbook |
|
592 | 48 | $oldSheetId = -1; // keep track of old sheet id in final workbook |
|
593 | 48 | $countSkippedSheets = 0; // keep track of number of skipped sheets |
|
594 | 48 | $mapSheetId = []; // mapping of sheet ids from old to new |
|
595 | |||
596 | 48 | $charts = $chartDetails = []; |
|
597 | |||
598 | 48 | if ($xmlWorkbook->sheets) { |
|
599 | /** @var SimpleXMLElement $eleSheet */ |
||
600 | 48 | foreach ($xmlWorkbook->sheets->sheet as $eleSheet) { |
|
601 | 48 | ++$oldSheetId; |
|
602 | |||
603 | // Check if sheet should be skipped |
||
604 | 48 | if (isset($this->loadSheetsOnly) && !in_array((string) $eleSheet['name'], $this->loadSheetsOnly)) { |
|
605 | 1 | ++$countSkippedSheets; |
|
606 | 1 | $mapSheetId[$oldSheetId] = null; |
|
607 | |||
608 | 1 | continue; |
|
609 | } |
||
610 | |||
611 | // Map old sheet id in original workbook to new sheet id. |
||
612 | // They will differ if loadSheetsOnly() is being used |
||
613 | 48 | $mapSheetId[$oldSheetId] = $oldSheetId - $countSkippedSheets; |
|
614 | |||
615 | // Load sheet |
||
616 | 48 | $docSheet = $excel->createSheet(); |
|
617 | // Use false for $updateFormulaCellReferences to prevent adjustment of worksheet |
||
618 | // references in formula cells... during the load, all formulae should be correct, |
||
619 | // and we're simply bringing the worksheet name in line with the formula, not the |
||
620 | // reverse |
||
621 | 48 | $docSheet->setTitle((string) $eleSheet['name'], false, false); |
|
622 | 48 | $fileWorksheet = $worksheets[(string) self::getArrayItem($eleSheet->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'), 'id')]; |
|
623 | //~ http://schemas.openxmlformats.org/spreadsheetml/2006/main" |
||
624 | 48 | $xmlSheet = simplexml_load_string( |
|
625 | 48 | $this->securityScanner->scan($this->getFromZipArchive($zip, "$dir/$fileWorksheet")), |
|
626 | 48 | 'SimpleXMLElement', |
|
627 | 48 | Settings::getLibXmlLoaderOptions() |
|
628 | ); |
||
629 | |||
630 | 48 | $sharedFormulas = []; |
|
631 | |||
632 | 48 | if (isset($eleSheet['state']) && (string) $eleSheet['state'] != '') { |
|
633 | 2 | $docSheet->setSheetState((string) $eleSheet['state']); |
|
634 | } |
||
635 | |||
636 | 48 | if ($xmlSheet) { |
|
637 | 48 | if (isset($xmlSheet->sheetViews, $xmlSheet->sheetViews->sheetView)) { |
|
638 | 48 | $sheetViews = new SheetViews($xmlSheet->sheetViews->sheetView, $docSheet); |
|
639 | 48 | $sheetViews->load(); |
|
640 | } |
||
641 | |||
642 | 48 | $sheetViewOptions = new SheetViewOptions($docSheet, $xmlSheet); |
|
1 ignored issue
–
show
|
|||
643 | 48 | $sheetViewOptions->load($this->getReadDataOnly()); |
|
644 | |||
645 | 48 | (new ColumnAndRowAttributes($docSheet, $xmlSheet)) |
|
1 ignored issue
–
show
|
|||
646 | 48 | ->load($this->getReadFilter(), $this->getReadDataOnly()); |
|
647 | } |
||
648 | |||
649 | 48 | if ($xmlSheet && $xmlSheet->sheetData && $xmlSheet->sheetData->row) { |
|
650 | 41 | $cIndex = 1; // Cell Start from 1 |
|
651 | 41 | foreach ($xmlSheet->sheetData->row as $row) { |
|
652 | 41 | $rowIndex = 1; |
|
653 | 41 | foreach ($row->c as $c) { |
|
654 | 41 | $r = (string) $c['r']; |
|
655 | 41 | if ($r == '') { |
|
656 | 1 | $r = Coordinate::stringFromColumnIndex($rowIndex) . $cIndex; |
|
657 | } |
||
658 | 41 | $cellDataType = (string) $c['t']; |
|
659 | 41 | $value = null; |
|
660 | 41 | $calculatedValue = null; |
|
661 | |||
662 | // Read cell? |
||
663 | 41 | if ($this->getReadFilter() !== null) { |
|
664 | 41 | $coordinates = Coordinate::coordinateFromString($r); |
|
665 | |||
666 | 41 | if (!$this->getReadFilter()->readCell($coordinates[0], (int) $coordinates[1], $docSheet->getTitle())) { |
|
667 | 3 | $rowIndex += 1; |
|
668 | |||
669 | 3 | continue; |
|
670 | } |
||
671 | } |
||
672 | |||
673 | // Read cell! |
||
674 | 41 | switch ($cellDataType) { |
|
675 | 41 | case 's': |
|
676 | 27 | if ((string) $c->v != '') { |
|
677 | 27 | $value = $sharedStrings[(int) ($c->v)]; |
|
678 | |||
679 | 27 | if ($value instanceof RichText) { |
|
680 | 27 | $value = clone $value; |
|
681 | } |
||
682 | } else { |
||
683 | $value = ''; |
||
684 | } |
||
685 | |||
686 | 27 | break; |
|
687 | 31 | case 'b': |
|
688 | 5 | if (!isset($c->f)) { |
|
689 | 3 | $value = self::castToBoolean($c); |
|
690 | } else { |
||
691 | // Formula |
||
692 | 2 | $this->castToFormula($c, $r, $cellDataType, $value, $calculatedValue, $sharedFormulas, 'castToBoolean'); |
|
693 | 2 | if (isset($c->f['t'])) { |
|
694 | $att = $c->f; |
||
695 | $docSheet->getCell($r)->setFormulaAttributes($att); |
||
696 | } |
||
697 | } |
||
698 | |||
699 | 5 | break; |
|
700 | 27 | case 'inlineStr': |
|
701 | 2 | if (isset($c->f)) { |
|
702 | $this->castToFormula($c, $r, $cellDataType, $value, $calculatedValue, $sharedFormulas, 'castToError'); |
||
703 | } else { |
||
704 | 2 | $value = $this->parseRichText($c->is); |
|
705 | } |
||
706 | |||
707 | 2 | break; |
|
708 | 27 | case 'e': |
|
709 | if (!isset($c->f)) { |
||
710 | $value = self::castToError($c); |
||
711 | } else { |
||
712 | // Formula |
||
713 | $this->castToFormula($c, $r, $cellDataType, $value, $calculatedValue, $sharedFormulas, 'castToError'); |
||
714 | } |
||
715 | |||
716 | break; |
||
717 | default: |
||
718 | 27 | if (!isset($c->f)) { |
|
719 | 25 | $value = self::castToString($c); |
|
720 | } else { |
||
721 | // Formula |
||
722 | 7 | $this->castToFormula($c, $r, $cellDataType, $value, $calculatedValue, $sharedFormulas, 'castToString'); |
|
723 | } |
||
724 | |||
725 | 27 | break; |
|
726 | } |
||
727 | |||
728 | // read empty cells or the cells are not empty |
||
729 | 41 | if ($this->readEmptyCells || ($value !== null && $value !== '')) { |
|
730 | // Check for numeric values |
||
731 | 41 | if (is_numeric($value) && $cellDataType != 's') { |
|
732 | 22 | if ($value == (int) $value) { |
|
733 | 21 | $value = (int) $value; |
|
734 | 3 | } elseif ($value == (float) $value) { |
|
735 | 3 | $value = (float) $value; |
|
736 | } |
||
737 | } |
||
738 | |||
739 | // Rich text? |
||
740 | 41 | if ($value instanceof RichText && $this->readDataOnly) { |
|
741 | $value = $value->getPlainText(); |
||
742 | } |
||
743 | |||
744 | 41 | $cell = $docSheet->getCell($r); |
|
745 | // Assign value |
||
746 | 41 | if ($cellDataType != '') { |
|
747 | 31 | $cell->setValueExplicit($value, $cellDataType); |
|
748 | } else { |
||
749 | 25 | $cell->setValue($value); |
|
750 | } |
||
751 | 41 | if ($calculatedValue !== null) { |
|
752 | 8 | $cell->setCalculatedValue($calculatedValue); |
|
753 | } |
||
754 | |||
755 | // Style information? |
||
756 | 41 | if ($c['s'] && !$this->readDataOnly) { |
|
757 | // no style index means 0, it seems |
||
758 | 13 | $cell->setXfIndex(isset($styles[(int) ($c['s'])]) ? |
|
759 | 13 | (int) ($c['s']) : 0); |
|
760 | } |
||
761 | } |
||
762 | 41 | $rowIndex += 1; |
|
763 | } |
||
764 | 41 | $cIndex += 1; |
|
765 | } |
||
766 | } |
||
767 | |||
768 | 48 | if (!$this->readDataOnly && $xmlSheet && $xmlSheet->conditionalFormatting) { |
|
769 | 2 | (new ConditionalStyles($docSheet, $xmlSheet, $dxfs))->load(); |
|
770 | } |
||
771 | |||
772 | 48 | $aKeys = ['sheet', 'objects', 'scenarios', 'formatCells', 'formatColumns', 'formatRows', 'insertColumns', 'insertRows', 'insertHyperlinks', 'deleteColumns', 'deleteRows', 'selectLockedCells', 'sort', 'autoFilter', 'pivotTables', 'selectUnlockedCells']; |
|
773 | 48 | if (!$this->readDataOnly && $xmlSheet && $xmlSheet->sheetProtection) { |
|
774 | 39 | foreach ($aKeys as $key) { |
|
775 | 39 | $method = 'set' . ucfirst($key); |
|
776 | 39 | $docSheet->getProtection()->$method(self::boolean((string) $xmlSheet->sheetProtection[$key])); |
|
777 | } |
||
778 | } |
||
779 | |||
780 | 48 | if (!$this->readDataOnly && $xmlSheet && $xmlSheet->sheetProtection) { |
|
781 | 39 | $docSheet->getProtection()->setPassword((string) $xmlSheet->sheetProtection['password'], true); |
|
782 | 39 | if ($xmlSheet->protectedRanges->protectedRange) { |
|
783 | 2 | foreach ($xmlSheet->protectedRanges->protectedRange as $protectedRange) { |
|
784 | 2 | $docSheet->protectCells((string) $protectedRange['sqref'], (string) $protectedRange['password'], true); |
|
785 | } |
||
786 | } |
||
787 | } |
||
788 | |||
789 | 48 | if ($xmlSheet && $xmlSheet->autoFilter && !$this->readDataOnly) { |
|
790 | 1 | (new AutoFilter($docSheet, $xmlSheet))->load(); |
|
791 | } |
||
792 | |||
793 | 48 | if ($xmlSheet && $xmlSheet->mergeCells && $xmlSheet->mergeCells->mergeCell && !$this->readDataOnly) { |
|
794 | 8 | foreach ($xmlSheet->mergeCells->mergeCell as $mergeCell) { |
|
795 | 8 | $mergeRef = (string) $mergeCell['ref']; |
|
796 | 8 | if (strpos($mergeRef, ':') !== false) { |
|
797 | 8 | $docSheet->mergeCells((string) $mergeCell['ref']); |
|
798 | } |
||
799 | } |
||
800 | } |
||
801 | |||
802 | 48 | if ($xmlSheet && !$this->readDataOnly) { |
|
803 | 48 | $unparsedLoadedData = (new PageSetup($docSheet, $xmlSheet))->load($unparsedLoadedData); |
|
804 | } |
||
805 | |||
806 | 48 | if ($xmlSheet && $xmlSheet->dataValidations && !$this->readDataOnly) { |
|
807 | 1 | (new DataValidations($docSheet, $xmlSheet))->load(); |
|
808 | } |
||
809 | |||
810 | // unparsed sheet AlternateContent |
||
811 | 48 | if ($xmlSheet && !$this->readDataOnly) { |
|
812 | 48 | $mc = $xmlSheet->children('http://schemas.openxmlformats.org/markup-compatibility/2006'); |
|
813 | 48 | if ($mc->AlternateContent) { |
|
814 | 1 | foreach ($mc->AlternateContent as $alternateContent) { |
|
815 | 1 | $unparsedLoadedData['sheets'][$docSheet->getCodeName()]['AlternateContents'][] = $alternateContent->asXML(); |
|
816 | } |
||
817 | } |
||
818 | } |
||
819 | |||
820 | // Add hyperlinks |
||
821 | 48 | if (!$this->readDataOnly) { |
|
822 | 48 | $hyperlinkReader = new Hyperlinks($docSheet); |
|
823 | // Locate hyperlink relations |
||
824 | 48 | $relationsFileName = dirname("$dir/$fileWorksheet") . '/_rels/' . basename($fileWorksheet) . '.rels'; |
|
825 | 48 | if ($zip->locateName($relationsFileName)) { |
|
826 | //~ http://schemas.openxmlformats.org/package/2006/relationships" |
||
827 | 43 | $relsWorksheet = simplexml_load_string( |
|
828 | 43 | $this->securityScanner->scan( |
|
829 | 43 | $this->getFromZipArchive($zip, $relationsFileName) |
|
830 | ), |
||
831 | 43 | 'SimpleXMLElement', |
|
832 | 43 | Settings::getLibXmlLoaderOptions() |
|
833 | ); |
||
834 | 43 | $hyperlinkReader->readHyperlinks($relsWorksheet); |
|
1 ignored issue
–
show
|
|||
835 | } |
||
836 | |||
837 | // Loop through hyperlinks |
||
838 | 48 | if ($xmlSheet && $xmlSheet->hyperlinks) { |
|
839 | 2 | $hyperlinkReader->setHyperlinks($xmlSheet->hyperlinks); |
|
840 | } |
||
841 | } |
||
842 | |||
843 | // Add comments |
||
844 | 48 | $comments = []; |
|
845 | 48 | $vmlComments = []; |
|
846 | 48 | if (!$this->readDataOnly) { |
|
847 | // Locate comment relations |
||
848 | 48 | if ($zip->locateName(dirname("$dir/$fileWorksheet") . '/_rels/' . basename($fileWorksheet) . '.rels')) { |
|
849 | //~ http://schemas.openxmlformats.org/package/2006/relationships" |
||
850 | 43 | $relsWorksheet = simplexml_load_string( |
|
851 | 43 | $this->securityScanner->scan( |
|
852 | 43 | $this->getFromZipArchive($zip, dirname("$dir/$fileWorksheet") . '/_rels/' . basename($fileWorksheet) . '.rels') |
|
853 | ), |
||
854 | 43 | 'SimpleXMLElement', |
|
855 | 43 | Settings::getLibXmlLoaderOptions() |
|
856 | ); |
||
857 | 43 | foreach ($relsWorksheet->Relationship as $ele) { |
|
858 | 16 | if ($ele['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments') { |
|
859 | 3 | $comments[(string) $ele['Id']] = (string) $ele['Target']; |
|
860 | } |
||
861 | 16 | if ($ele['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing') { |
|
862 | 4 | $vmlComments[(string) $ele['Id']] = (string) $ele['Target']; |
|
863 | } |
||
864 | } |
||
865 | } |
||
866 | |||
867 | // Loop through comments |
||
868 | 48 | foreach ($comments as $relName => $relPath) { |
|
869 | // Load comments file |
||
870 | 3 | $relPath = File::realpath(dirname("$dir/$fileWorksheet") . '/' . $relPath); |
|
871 | 3 | $commentsFile = simplexml_load_string( |
|
872 | 3 | $this->securityScanner->scan($this->getFromZipArchive($zip, $relPath)), |
|
873 | 3 | 'SimpleXMLElement', |
|
874 | 3 | Settings::getLibXmlLoaderOptions() |
|
875 | ); |
||
876 | |||
877 | // Utility variables |
||
878 | 3 | $authors = []; |
|
879 | |||
880 | // Loop through authors |
||
881 | 3 | foreach ($commentsFile->authors->author as $author) { |
|
882 | 3 | $authors[] = (string) $author; |
|
883 | } |
||
884 | |||
885 | // Loop through contents |
||
886 | 3 | foreach ($commentsFile->commentList->comment as $comment) { |
|
887 | 3 | if (!empty($comment['authorId'])) { |
|
888 | $docSheet->getComment((string) $comment['ref'])->setAuthor($authors[(string) $comment['authorId']]); |
||
889 | } |
||
890 | 3 | $docSheet->getComment((string) $comment['ref'])->setText($this->parseRichText($comment->text)); |
|
891 | } |
||
892 | } |
||
893 | |||
894 | // later we will remove from it real vmlComments |
||
895 | 48 | $unparsedVmlDrawings = $vmlComments; |
|
896 | |||
897 | // Loop through VML comments |
||
898 | 48 | foreach ($vmlComments as $relName => $relPath) { |
|
899 | // Load VML comments file |
||
900 | 4 | $relPath = File::realpath(dirname("$dir/$fileWorksheet") . '/' . $relPath); |
|
901 | |||
902 | try { |
||
903 | 4 | $vmlCommentsFile = simplexml_load_string( |
|
904 | 4 | $this->securityScanner->scan($this->getFromZipArchive($zip, $relPath)), |
|
905 | 4 | 'SimpleXMLElement', |
|
906 | 4 | Settings::getLibXmlLoaderOptions() |
|
907 | ); |
||
908 | 4 | $vmlCommentsFile->registerXPathNamespace('v', 'urn:schemas-microsoft-com:vml'); |
|
909 | } catch (\Throwable $ex) { |
||
910 | //Ignore unparsable vmlDrawings. Later they will be moved from $unparsedVmlDrawings to $unparsedLoadedData |
||
911 | continue; |
||
912 | } |
||
913 | |||
914 | 4 | $shapes = $vmlCommentsFile->xpath('//v:shape'); |
|
915 | 4 | foreach ($shapes as $shape) { |
|
916 | 4 | $shape->registerXPathNamespace('v', 'urn:schemas-microsoft-com:vml'); |
|
917 | |||
918 | 4 | if (isset($shape['style'])) { |
|
919 | 4 | $style = (string) $shape['style']; |
|
920 | 4 | $fillColor = strtoupper(substr((string) $shape['fillcolor'], 1)); |
|
921 | 4 | $column = null; |
|
922 | 4 | $row = null; |
|
923 | |||
924 | 4 | $clientData = $shape->xpath('.//x:ClientData'); |
|
925 | 4 | if (is_array($clientData) && !empty($clientData)) { |
|
926 | 4 | $clientData = $clientData[0]; |
|
927 | |||
928 | 4 | if (isset($clientData['ObjectType']) && (string) $clientData['ObjectType'] == 'Note') { |
|
929 | 3 | $temp = $clientData->xpath('.//x:Row'); |
|
930 | 3 | if (is_array($temp)) { |
|
931 | 3 | $row = $temp[0]; |
|
932 | } |
||
933 | |||
934 | 3 | $temp = $clientData->xpath('.//x:Column'); |
|
935 | 3 | if (is_array($temp)) { |
|
936 | 3 | $column = $temp[0]; |
|
937 | } |
||
938 | } |
||
939 | } |
||
940 | |||
941 | 4 | if (($column !== null) && ($row !== null)) { |
|
942 | // Set comment properties |
||
943 | 3 | $comment = $docSheet->getCommentByColumnAndRow($column + 1, $row + 1); |
|
944 | 3 | $comment->getFillColor()->setRGB($fillColor); |
|
945 | |||
946 | // Parse style |
||
947 | 3 | $styleArray = explode(';', str_replace(' ', '', $style)); |
|
948 | 3 | foreach ($styleArray as $stylePair) { |
|
949 | 3 | $stylePair = explode(':', $stylePair); |
|
950 | |||
951 | 3 | if ($stylePair[0] == 'margin-left') { |
|
952 | 3 | $comment->setMarginLeft($stylePair[1]); |
|
953 | } |
||
954 | 3 | if ($stylePair[0] == 'margin-top') { |
|
955 | 3 | $comment->setMarginTop($stylePair[1]); |
|
956 | } |
||
957 | 3 | if ($stylePair[0] == 'width') { |
|
958 | 3 | $comment->setWidth($stylePair[1]); |
|
959 | } |
||
960 | 3 | if ($stylePair[0] == 'height') { |
|
961 | 3 | $comment->setHeight($stylePair[1]); |
|
962 | } |
||
963 | 3 | if ($stylePair[0] == 'visibility') { |
|
964 | 3 | $comment->setVisible($stylePair[1] == 'visible'); |
|
965 | } |
||
966 | } |
||
967 | |||
968 | 3 | unset($unparsedVmlDrawings[$relName]); |
|
969 | } |
||
970 | } |
||
971 | } |
||
972 | } |
||
973 | |||
974 | // unparsed vmlDrawing |
||
975 | 48 | if ($unparsedVmlDrawings) { |
|
976 | 1 | foreach ($unparsedVmlDrawings as $rId => $relPath) { |
|
977 | 1 | $rId = substr($rId, 3); // rIdXXX |
|
978 | 1 | $unparsedVmlDrawing = &$unparsedLoadedData['sheets'][$docSheet->getCodeName()]['vmlDrawings']; |
|
979 | 1 | $unparsedVmlDrawing[$rId] = []; |
|
980 | 1 | $unparsedVmlDrawing[$rId]['filePath'] = self::dirAdd("$dir/$fileWorksheet", $relPath); |
|
981 | 1 | $unparsedVmlDrawing[$rId]['relFilePath'] = $relPath; |
|
982 | 1 | $unparsedVmlDrawing[$rId]['content'] = $this->securityScanner->scan($this->getFromZipArchive($zip, $unparsedVmlDrawing[$rId]['filePath'])); |
|
983 | 1 | unset($unparsedVmlDrawing); |
|
984 | } |
||
985 | } |
||
986 | |||
987 | // Header/footer images |
||
988 | 48 | if ($xmlSheet && $xmlSheet->legacyDrawingHF && !$this->readDataOnly) { |
|
989 | if ($zip->locateName(dirname("$dir/$fileWorksheet") . '/_rels/' . basename($fileWorksheet) . '.rels')) { |
||
990 | //~ http://schemas.openxmlformats.org/package/2006/relationships" |
||
991 | $relsWorksheet = simplexml_load_string( |
||
992 | $this->securityScanner->scan( |
||
993 | $this->getFromZipArchive($zip, dirname("$dir/$fileWorksheet") . '/_rels/' . basename($fileWorksheet) . '.rels') |
||
994 | ), |
||
995 | 'SimpleXMLElement', |
||
996 | Settings::getLibXmlLoaderOptions() |
||
997 | ); |
||
998 | $vmlRelationship = ''; |
||
999 | |||
1000 | foreach ($relsWorksheet->Relationship as $ele) { |
||
1001 | if ($ele['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/vmlDrawing') { |
||
1002 | $vmlRelationship = self::dirAdd("$dir/$fileWorksheet", $ele['Target']); |
||
1003 | } |
||
1004 | } |
||
1005 | |||
1006 | if ($vmlRelationship != '') { |
||
1007 | // Fetch linked images |
||
1008 | //~ http://schemas.openxmlformats.org/package/2006/relationships" |
||
1009 | $relsVML = simplexml_load_string( |
||
1010 | $this->securityScanner->scan( |
||
1011 | $this->getFromZipArchive($zip, dirname($vmlRelationship) . '/_rels/' . basename($vmlRelationship) . '.rels') |
||
1012 | ), |
||
1013 | 'SimpleXMLElement', |
||
1014 | Settings::getLibXmlLoaderOptions() |
||
1015 | ); |
||
1016 | $drawings = []; |
||
1017 | foreach ($relsVML->Relationship as $ele) { |
||
1018 | if ($ele['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image') { |
||
1019 | $drawings[(string) $ele['Id']] = self::dirAdd($vmlRelationship, $ele['Target']); |
||
1020 | } |
||
1021 | } |
||
1022 | |||
1023 | // Fetch VML document |
||
1024 | $vmlDrawing = simplexml_load_string( |
||
1025 | $this->securityScanner->scan($this->getFromZipArchive($zip, $vmlRelationship)), |
||
1026 | 'SimpleXMLElement', |
||
1027 | Settings::getLibXmlLoaderOptions() |
||
1028 | ); |
||
1029 | $vmlDrawing->registerXPathNamespace('v', 'urn:schemas-microsoft-com:vml'); |
||
1030 | |||
1031 | $hfImages = []; |
||
1032 | |||
1033 | $shapes = $vmlDrawing->xpath('//v:shape'); |
||
1034 | foreach ($shapes as $idx => $shape) { |
||
1035 | $shape->registerXPathNamespace('v', 'urn:schemas-microsoft-com:vml'); |
||
1036 | $imageData = $shape->xpath('//v:imagedata'); |
||
1037 | |||
1038 | if (!$imageData) { |
||
1039 | continue; |
||
1040 | } |
||
1041 | |||
1042 | $imageData = $imageData[$idx]; |
||
1043 | |||
1044 | $imageData = $imageData->attributes('urn:schemas-microsoft-com:office:office'); |
||
1045 | $style = self::toCSSArray((string) $shape['style']); |
||
1046 | |||
1047 | $hfImages[(string) $shape['id']] = new HeaderFooterDrawing(); |
||
1048 | if (isset($imageData['title'])) { |
||
1049 | $hfImages[(string) $shape['id']]->setName((string) $imageData['title']); |
||
1050 | } |
||
1051 | |||
1052 | $hfImages[(string) $shape['id']]->setPath('zip://' . File::realpath($pFilename) . '#' . $drawings[(string) $imageData['relid']], false); |
||
1053 | $hfImages[(string) $shape['id']]->setResizeProportional(false); |
||
1054 | $hfImages[(string) $shape['id']]->setWidth($style['width']); |
||
1055 | $hfImages[(string) $shape['id']]->setHeight($style['height']); |
||
1056 | if (isset($style['margin-left'])) { |
||
1057 | $hfImages[(string) $shape['id']]->setOffsetX($style['margin-left']); |
||
1058 | } |
||
1059 | $hfImages[(string) $shape['id']]->setOffsetY($style['margin-top']); |
||
1060 | $hfImages[(string) $shape['id']]->setResizeProportional(true); |
||
1061 | } |
||
1062 | |||
1063 | $docSheet->getHeaderFooter()->setImages($hfImages); |
||
1064 | } |
||
1065 | } |
||
1066 | } |
||
1067 | } |
||
1068 | |||
1069 | // TODO: Autoshapes from twoCellAnchors! |
||
1070 | 48 | if ($zip->locateName(dirname("$dir/$fileWorksheet") . '/_rels/' . basename($fileWorksheet) . '.rels')) { |
|
1071 | //~ http://schemas.openxmlformats.org/package/2006/relationships" |
||
1072 | 43 | $relsWorksheet = simplexml_load_string( |
|
1073 | 43 | $this->securityScanner->scan( |
|
1074 | 43 | $this->getFromZipArchive($zip, dirname("$dir/$fileWorksheet") . '/_rels/' . basename($fileWorksheet) . '.rels') |
|
1075 | ), |
||
1076 | 43 | 'SimpleXMLElement', |
|
1077 | 43 | Settings::getLibXmlLoaderOptions() |
|
1078 | ); |
||
1079 | 43 | $drawings = []; |
|
1080 | 43 | foreach ($relsWorksheet->Relationship as $ele) { |
|
1081 | 16 | if ($ele['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing') { |
|
1082 | 8 | $drawings[(string) $ele['Id']] = self::dirAdd("$dir/$fileWorksheet", $ele['Target']); |
|
1083 | } |
||
1084 | } |
||
1085 | 43 | if ($xmlSheet->drawing && !$this->readDataOnly) { |
|
1086 | 8 | $unparsedDrawings = []; |
|
1087 | 8 | foreach ($xmlSheet->drawing as $drawing) { |
|
1088 | 8 | $drawingRelId = (string) self::getArrayItem($drawing->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'), 'id'); |
|
1089 | 8 | $fileDrawing = $drawings[$drawingRelId]; |
|
1090 | //~ http://schemas.openxmlformats.org/package/2006/relationships" |
||
1091 | 8 | $relsDrawing = simplexml_load_string( |
|
1092 | 8 | $this->securityScanner->scan( |
|
1093 | 8 | $this->getFromZipArchive($zip, dirname($fileDrawing) . '/_rels/' . basename($fileDrawing) . '.rels') |
|
1094 | ), |
||
1095 | 8 | 'SimpleXMLElement', |
|
1096 | 8 | Settings::getLibXmlLoaderOptions() |
|
1097 | ); |
||
1098 | 8 | $images = []; |
|
1099 | 8 | $hyperlinks = []; |
|
1100 | 8 | if ($relsDrawing && $relsDrawing->Relationship) { |
|
1101 | 6 | foreach ($relsDrawing->Relationship as $ele) { |
|
1102 | 6 | if ($ele['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink') { |
|
1103 | 2 | $hyperlinks[(string) $ele['Id']] = (string) $ele['Target']; |
|
1104 | } |
||
1105 | 6 | if ($ele['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/image') { |
|
1106 | 6 | $images[(string) $ele['Id']] = self::dirAdd($fileDrawing, $ele['Target']); |
|
1107 | 4 | } elseif ($ele['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/chart') { |
|
1108 | 2 | if ($this->includeCharts) { |
|
1109 | 2 | $charts[self::dirAdd($fileDrawing, $ele['Target'])] = [ |
|
1110 | 2 | 'id' => (string) $ele['Id'], |
|
1111 | 2 | 'sheet' => $docSheet->getTitle(), |
|
1112 | ]; |
||
1113 | } |
||
1114 | } |
||
1115 | } |
||
1116 | } |
||
1117 | 8 | $xmlDrawing = simplexml_load_string( |
|
1118 | 8 | $this->securityScanner->scan($this->getFromZipArchive($zip, $fileDrawing)), |
|
1119 | 8 | 'SimpleXMLElement', |
|
1120 | 8 | Settings::getLibXmlLoaderOptions() |
|
1121 | ); |
||
1122 | 8 | $xmlDrawingChildren = $xmlDrawing->children('http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing'); |
|
1123 | |||
1124 | 8 | if ($xmlDrawingChildren->oneCellAnchor) { |
|
1125 | 4 | foreach ($xmlDrawingChildren->oneCellAnchor as $oneCellAnchor) { |
|
1126 | 4 | if ($oneCellAnchor->pic->blipFill) { |
|
1127 | /** @var SimpleXMLElement $blip */ |
||
1128 | 4 | $blip = $oneCellAnchor->pic->blipFill->children('http://schemas.openxmlformats.org/drawingml/2006/main')->blip; |
|
1129 | /** @var SimpleXMLElement $xfrm */ |
||
1130 | 4 | $xfrm = $oneCellAnchor->pic->spPr->children('http://schemas.openxmlformats.org/drawingml/2006/main')->xfrm; |
|
1131 | /** @var SimpleXMLElement $outerShdw */ |
||
1132 | 4 | $outerShdw = $oneCellAnchor->pic->spPr->children('http://schemas.openxmlformats.org/drawingml/2006/main')->effectLst->outerShdw; |
|
1133 | /** @var \SimpleXMLElement $hlinkClick */ |
||
1134 | 4 | $hlinkClick = $oneCellAnchor->pic->nvPicPr->cNvPr->children('http://schemas.openxmlformats.org/drawingml/2006/main')->hlinkClick; |
|
1135 | |||
1136 | 4 | $objDrawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing(); |
|
1137 | 4 | $objDrawing->setName((string) self::getArrayItem($oneCellAnchor->pic->nvPicPr->cNvPr->attributes(), 'name')); |
|
1138 | 4 | $objDrawing->setDescription((string) self::getArrayItem($oneCellAnchor->pic->nvPicPr->cNvPr->attributes(), 'descr')); |
|
1139 | 4 | $objDrawing->setPath( |
|
1140 | 4 | 'zip://' . File::realpath($pFilename) . '#' . |
|
1141 | 4 | $images[(string) self::getArrayItem( |
|
1142 | 4 | $blip->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'), |
|
1143 | 4 | 'embed' |
|
1144 | )], |
||
1145 | 4 | false |
|
1146 | ); |
||
1147 | 4 | $objDrawing->setCoordinates(Coordinate::stringFromColumnIndex(((string) $oneCellAnchor->from->col) + 1) . ($oneCellAnchor->from->row + 1)); |
|
1148 | 4 | $objDrawing->setOffsetX(Drawing::EMUToPixels($oneCellAnchor->from->colOff)); |
|
1149 | 4 | $objDrawing->setOffsetY(Drawing::EMUToPixels($oneCellAnchor->from->rowOff)); |
|
1150 | 4 | $objDrawing->setResizeProportional(false); |
|
1151 | 4 | $objDrawing->setWidth(Drawing::EMUToPixels(self::getArrayItem($oneCellAnchor->ext->attributes(), 'cx'))); |
|
1152 | 4 | $objDrawing->setHeight(Drawing::EMUToPixels(self::getArrayItem($oneCellAnchor->ext->attributes(), 'cy'))); |
|
1153 | 4 | if ($xfrm) { |
|
1154 | 4 | $objDrawing->setRotation(Drawing::angleToDegrees(self::getArrayItem($xfrm->attributes(), 'rot'))); |
|
1 ignored issue
–
show
|
|||
1155 | } |
||
1156 | 4 | if ($outerShdw) { |
|
1157 | 2 | $shadow = $objDrawing->getShadow(); |
|
1158 | 2 | $shadow->setVisible(true); |
|
1159 | 2 | $shadow->setBlurRadius(Drawing::EMUToPixels(self::getArrayItem($outerShdw->attributes(), 'blurRad'))); |
|
1 ignored issue
–
show
|
|||
1160 | 2 | $shadow->setDistance(Drawing::EMUToPixels(self::getArrayItem($outerShdw->attributes(), 'dist'))); |
|
1161 | 2 | $shadow->setDirection(Drawing::angleToDegrees(self::getArrayItem($outerShdw->attributes(), 'dir'))); |
|
1162 | 2 | $shadow->setAlignment((string) self::getArrayItem($outerShdw->attributes(), 'algn')); |
|
1163 | 2 | $clr = isset($outerShdw->srgbClr) ? $outerShdw->srgbClr : $outerShdw->prstClr; |
|
1164 | 2 | $shadow->getColor()->setRGB(self::getArrayItem($clr->attributes(), 'val')); |
|
1165 | 2 | $shadow->setAlpha(self::getArrayItem($clr->alpha->attributes(), 'val') / 1000); |
|
1166 | } |
||
1167 | |||
1168 | 4 | $this->readHyperLinkDrawing($objDrawing, $oneCellAnchor, $hyperlinks); |
|
1169 | |||
1170 | 4 | $objDrawing->setWorksheet($docSheet); |
|
1171 | } else { |
||
1172 | // ? Can charts be positioned with a oneCellAnchor ? |
||
1173 | $coordinates = Coordinate::stringFromColumnIndex(((string) $oneCellAnchor->from->col) + 1) . ($oneCellAnchor->from->row + 1); |
||
1174 | $offsetX = Drawing::EMUToPixels($oneCellAnchor->from->colOff); |
||
1175 | $offsetY = Drawing::EMUToPixels($oneCellAnchor->from->rowOff); |
||
1176 | $width = Drawing::EMUToPixels(self::getArrayItem($oneCellAnchor->ext->attributes(), 'cx')); |
||
1177 | $height = Drawing::EMUToPixels(self::getArrayItem($oneCellAnchor->ext->attributes(), 'cy')); |
||
1178 | } |
||
1179 | } |
||
1180 | } |
||
1181 | 8 | if ($xmlDrawingChildren->twoCellAnchor) { |
|
1182 | 2 | foreach ($xmlDrawingChildren->twoCellAnchor as $twoCellAnchor) { |
|
1183 | 2 | if ($twoCellAnchor->pic->blipFill) { |
|
1184 | 2 | $blip = $twoCellAnchor->pic->blipFill->children('http://schemas.openxmlformats.org/drawingml/2006/main')->blip; |
|
1185 | 2 | $xfrm = $twoCellAnchor->pic->spPr->children('http://schemas.openxmlformats.org/drawingml/2006/main')->xfrm; |
|
1186 | 2 | $outerShdw = $twoCellAnchor->pic->spPr->children('http://schemas.openxmlformats.org/drawingml/2006/main')->effectLst->outerShdw; |
|
1187 | 2 | $hlinkClick = $twoCellAnchor->pic->nvPicPr->cNvPr->children('http://schemas.openxmlformats.org/drawingml/2006/main')->hlinkClick; |
|
1188 | 2 | $objDrawing = new \PhpOffice\PhpSpreadsheet\Worksheet\Drawing(); |
|
1189 | 2 | $objDrawing->setName((string) self::getArrayItem($twoCellAnchor->pic->nvPicPr->cNvPr->attributes(), 'name')); |
|
1190 | 2 | $objDrawing->setDescription((string) self::getArrayItem($twoCellAnchor->pic->nvPicPr->cNvPr->attributes(), 'descr')); |
|
1191 | 2 | $objDrawing->setPath( |
|
1192 | 2 | 'zip://' . File::realpath($pFilename) . '#' . |
|
1193 | 2 | $images[(string) self::getArrayItem( |
|
1194 | 2 | $blip->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'), |
|
1195 | 2 | 'embed' |
|
1196 | )], |
||
1197 | 2 | false |
|
1198 | ); |
||
1199 | 2 | $objDrawing->setCoordinates(Coordinate::stringFromColumnIndex(((string) $twoCellAnchor->from->col) + 1) . ($twoCellAnchor->from->row + 1)); |
|
1200 | 2 | $objDrawing->setOffsetX(Drawing::EMUToPixels($twoCellAnchor->from->colOff)); |
|
1201 | 2 | $objDrawing->setOffsetY(Drawing::EMUToPixels($twoCellAnchor->from->rowOff)); |
|
1202 | 2 | $objDrawing->setResizeProportional(false); |
|
1203 | |||
1204 | 2 | if ($xfrm) { |
|
1205 | 2 | $objDrawing->setWidth(Drawing::EMUToPixels(self::getArrayItem($xfrm->ext->attributes(), 'cx'))); |
|
1206 | 2 | $objDrawing->setHeight(Drawing::EMUToPixels(self::getArrayItem($xfrm->ext->attributes(), 'cy'))); |
|
1207 | 2 | $objDrawing->setRotation(Drawing::angleToDegrees(self::getArrayItem($xfrm->attributes(), 'rot'))); |
|
1208 | } |
||
1209 | 2 | if ($outerShdw) { |
|
1210 | $shadow = $objDrawing->getShadow(); |
||
1211 | $shadow->setVisible(true); |
||
1212 | $shadow->setBlurRadius(Drawing::EMUToPixels(self::getArrayItem($outerShdw->attributes(), 'blurRad'))); |
||
1213 | $shadow->setDistance(Drawing::EMUToPixels(self::getArrayItem($outerShdw->attributes(), 'dist'))); |
||
1214 | $shadow->setDirection(Drawing::angleToDegrees(self::getArrayItem($outerShdw->attributes(), 'dir'))); |
||
1215 | $shadow->setAlignment((string) self::getArrayItem($outerShdw->attributes(), 'algn')); |
||
1216 | $clr = isset($outerShdw->srgbClr) ? $outerShdw->srgbClr : $outerShdw->prstClr; |
||
1217 | $shadow->getColor()->setRGB(self::getArrayItem($clr->attributes(), 'val')); |
||
1218 | $shadow->setAlpha(self::getArrayItem($clr->alpha->attributes(), 'val') / 1000); |
||
1219 | } |
||
1220 | |||
1221 | 2 | $this->readHyperLinkDrawing($objDrawing, $twoCellAnchor, $hyperlinks); |
|
1222 | |||
1223 | 2 | $objDrawing->setWorksheet($docSheet); |
|
1224 | 2 | } elseif (($this->includeCharts) && ($twoCellAnchor->graphicFrame)) { |
|
1225 | 2 | $fromCoordinate = Coordinate::stringFromColumnIndex(((string) $twoCellAnchor->from->col) + 1) . ($twoCellAnchor->from->row + 1); |
|
1226 | 2 | $fromOffsetX = Drawing::EMUToPixels($twoCellAnchor->from->colOff); |
|
1227 | 2 | $fromOffsetY = Drawing::EMUToPixels($twoCellAnchor->from->rowOff); |
|
1228 | 2 | $toCoordinate = Coordinate::stringFromColumnIndex(((string) $twoCellAnchor->to->col) + 1) . ($twoCellAnchor->to->row + 1); |
|
1229 | 2 | $toOffsetX = Drawing::EMUToPixels($twoCellAnchor->to->colOff); |
|
1230 | 2 | $toOffsetY = Drawing::EMUToPixels($twoCellAnchor->to->rowOff); |
|
1231 | 2 | $graphic = $twoCellAnchor->graphicFrame->children('http://schemas.openxmlformats.org/drawingml/2006/main')->graphic; |
|
1232 | /** @var SimpleXMLElement $chartRef */ |
||
1233 | 2 | $chartRef = $graphic->graphicData->children('http://schemas.openxmlformats.org/drawingml/2006/chart')->chart; |
|
1234 | 2 | $thisChart = (string) $chartRef->attributes('http://schemas.openxmlformats.org/officeDocument/2006/relationships'); |
|
1235 | |||
1236 | 2 | $chartDetails[$docSheet->getTitle() . '!' . $thisChart] = [ |
|
1237 | 2 | 'fromCoordinate' => $fromCoordinate, |
|
1238 | 2 | 'fromOffsetX' => $fromOffsetX, |
|
1239 | 2 | 'fromOffsetY' => $fromOffsetY, |
|
1240 | 2 | 'toCoordinate' => $toCoordinate, |
|
1241 | 2 | 'toOffsetX' => $toOffsetX, |
|
1242 | 2 | 'toOffsetY' => $toOffsetY, |
|
1243 | 2 | 'worksheetTitle' => $docSheet->getTitle(), |
|
1244 | ]; |
||
1245 | } |
||
1246 | } |
||
1247 | } |
||
1248 | 8 | if ($relsDrawing === false && $xmlDrawing->count() == 0) { |
|
1249 | // Save Drawing without rels and children as unparsed |
||
1250 | 2 | $unparsedDrawings[$drawingRelId] = $xmlDrawing->asXML(); |
|
1251 | } |
||
1252 | } |
||
1253 | |||
1254 | // store original rId of drawing files |
||
1255 | 8 | $unparsedLoadedData['sheets'][$docSheet->getCodeName()]['drawingOriginalIds'] = []; |
|
1256 | 8 | foreach ($relsWorksheet->Relationship as $ele) { |
|
1257 | 8 | if ($ele['Type'] == 'http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing') { |
|
1258 | 8 | $drawingRelId = (string) $ele['Id']; |
|
1259 | 8 | $unparsedLoadedData['sheets'][$docSheet->getCodeName()]['drawingOriginalIds'][(string) $ele['Target']] = $drawingRelId; |
|
1260 | 8 | if (isset($unparsedDrawings[$drawingRelId])) { |
|
1261 | 2 | $unparsedLoadedData['sheets'][$docSheet->getCodeName()]['Drawings'][$drawingRelId] = $unparsedDrawings[$drawingRelId]; |
|
1262 | } |
||
1263 | } |
||
1264 | } |
||
1265 | |||
1266 | // unparsed drawing AlternateContent |
||
1267 | 8 | $xmlAltDrawing = simplexml_load_string( |
|
1268 | 8 | $this->securityScanner->scan($this->getFromZipArchive($zip, $fileDrawing)), |
|
1269 | 8 | 'SimpleXMLElement', |
|
1270 | 8 | Settings::getLibXmlLoaderOptions() |
|
1271 | 8 | )->children('http://schemas.openxmlformats.org/markup-compatibility/2006'); |
|
1272 | |||
1273 | 8 | if ($xmlAltDrawing->AlternateContent) { |
|
1274 | 1 | foreach ($xmlAltDrawing->AlternateContent as $alternateContent) { |
|
1275 | 1 | $unparsedLoadedData['sheets'][$docSheet->getCodeName()]['drawingAlternateContents'][] = $alternateContent->asXML(); |
|
1276 | } |
||
1277 | } |
||
1278 | } |
||
1279 | } |
||
1280 | |||
1281 | 48 | $this->readFormControlProperties($excel, $zip, $dir, $fileWorksheet, $docSheet, $unparsedLoadedData); |
|
1282 | 48 | $this->readPrinterSettings($excel, $zip, $dir, $fileWorksheet, $docSheet, $unparsedLoadedData); |
|
1283 | |||
1284 | // Loop through definedNames |
||
1285 | 48 | if ($xmlWorkbook->definedNames) { |
|
1286 | 34 | foreach ($xmlWorkbook->definedNames->definedName as $definedName) { |
|
1287 | // Extract range |
||
1288 | 3 | $extractedRange = (string) $definedName; |
|
1289 | 3 | if (($spos = strpos($extractedRange, '!')) !== false) { |
|
1290 | 3 | $extractedRange = substr($extractedRange, 0, $spos) . str_replace('$', '', substr($extractedRange, $spos)); |
|
1291 | } else { |
||
1292 | $extractedRange = str_replace('$', '', $extractedRange); |
||
1293 | } |
||
1294 | |||
1295 | // Valid range? |
||
1296 | 3 | if (stripos((string) $definedName, '#REF!') !== false || $extractedRange == '') { |
|
1297 | continue; |
||
1298 | } |
||
1299 | |||
1300 | // Some definedNames are only applicable if we are on the same sheet... |
||
1301 | 3 | if ((string) $definedName['localSheetId'] != '' && (string) $definedName['localSheetId'] == $oldSheetId) { |
|
1302 | // Switch on type |
||
1303 | 3 | switch ((string) $definedName['name']) { |
|
1304 | 3 | case '_xlnm._FilterDatabase': |
|
1305 | 1 | if ((string) $definedName['hidden'] !== '1') { |
|
1306 | $extractedRange = explode(',', $extractedRange); |
||
1307 | foreach ($extractedRange as $range) { |
||
1308 | $autoFilterRange = $range; |
||
1309 | if (strpos($autoFilterRange, ':') !== false) { |
||
1310 | $docSheet->getAutoFilter()->setRange($autoFilterRange); |
||
1311 | } |
||
1312 | } |
||
1313 | } |
||
1314 | |||
1315 | 1 | break; |
|
1316 | 2 | case '_xlnm.Print_Titles': |
|
1317 | // Split $extractedRange |
||
1318 | 1 | $extractedRange = explode(',', $extractedRange); |
|
1319 | |||
1320 | // Set print titles |
||
1321 | 1 | foreach ($extractedRange as $range) { |
|
1322 | 1 | $matches = []; |
|
1323 | 1 | $range = str_replace('$', '', $range); |
|
1324 | |||
1325 | // check for repeating columns, e g. 'A:A' or 'A:D' |
||
1326 | 1 | if (preg_match('/!?([A-Z]+)\:([A-Z]+)$/', $range, $matches)) { |
|
1327 | $docSheet->getPageSetup()->setColumnsToRepeatAtLeft([$matches[1], $matches[2]]); |
||
1328 | 1 | } elseif (preg_match('/!?(\d+)\:(\d+)$/', $range, $matches)) { |
|
1329 | // check for repeating rows, e.g. '1:1' or '1:5' |
||
1330 | 1 | $docSheet->getPageSetup()->setRowsToRepeatAtTop([$matches[1], $matches[2]]); |
|
1331 | } |
||
1332 | } |
||
1333 | |||
1334 | 1 | break; |
|
1335 | 1 | case '_xlnm.Print_Area': |
|
1336 | 1 | $rangeSets = preg_split("/('?(?:.*?)'?(?:![A-Z0-9]+:[A-Z0-9]+)),?/", $extractedRange, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); |
|
1337 | 1 | $newRangeSets = []; |
|
1338 | 1 | foreach ($rangeSets as $rangeSet) { |
|
1339 | 1 | [$sheetName, $rangeSet] = Worksheet::extractSheetTitle($rangeSet, true); |
|
1340 | 1 | if (strpos($rangeSet, ':') === false) { |
|
1341 | $rangeSet = $rangeSet . ':' . $rangeSet; |
||
1342 | } |
||
1343 | 1 | $newRangeSets[] = str_replace('$', '', $rangeSet); |
|
1344 | } |
||
1345 | 1 | $docSheet->getPageSetup()->setPrintArea(implode(',', $newRangeSets)); |
|
1346 | |||
1347 | 1 | break; |
|
1348 | default: |
||
1349 | break; |
||
1350 | } |
||
1351 | } |
||
1352 | } |
||
1353 | } |
||
1354 | |||
1355 | // Next sheet id |
||
1356 | 48 | ++$sheetId; |
|
1357 | } |
||
1358 | |||
1359 | // Loop through definedNames |
||
1360 | 48 | if ($xmlWorkbook->definedNames) { |
|
1361 | 34 | foreach ($xmlWorkbook->definedNames->definedName as $definedName) { |
|
1362 | // Extract range |
||
1363 | 3 | $extractedRange = (string) $definedName; |
|
1364 | 3 | if (($spos = strpos($extractedRange, '!')) !== false) { |
|
1365 | 3 | $extractedRange = substr($extractedRange, 0, $spos) . str_replace('$', '', substr($extractedRange, $spos)); |
|
1366 | } else { |
||
1367 | $extractedRange = str_replace('$', '', $extractedRange); |
||
1368 | } |
||
1369 | |||
1370 | // Valid range? |
||
1371 | 3 | if (stripos((string) $definedName, '#REF!') !== false || $extractedRange == '') { |
|
1372 | continue; |
||
1373 | } |
||
1374 | |||
1375 | // Some definedNames are only applicable if we are on the same sheet... |
||
1376 | 3 | if ((string) $definedName['localSheetId'] != '') { |
|
1377 | // Local defined name |
||
1378 | // Switch on type |
||
1379 | 3 | switch ((string) $definedName['name']) { |
|
1380 | 3 | case '_xlnm._FilterDatabase': |
|
1381 | 2 | case '_xlnm.Print_Titles': |
|
1382 | 1 | case '_xlnm.Print_Area': |
|
1383 | 3 | break; |
|
1384 | default: |
||
1385 | if ($mapSheetId[(int) $definedName['localSheetId']] !== null) { |
||
1386 | if (strpos((string) $definedName, '!') !== false) { |
||
1387 | $range = Worksheet::extractSheetTitle((string) $definedName, true); |
||
1388 | $range[0] = str_replace("''", "'", $range[0]); |
||
1389 | $range[0] = str_replace("'", '', $range[0]); |
||
1390 | if ($worksheet = $docSheet->getParent()->getSheetByName($range[0])) { |
||
1391 | $extractedRange = str_replace('$', '', $range[1]); |
||
1392 | $scope = $docSheet->getParent()->getSheet($mapSheetId[(int) $definedName['localSheetId']]); |
||
1393 | $excel->addNamedRange(new NamedRange((string) $definedName['name'], $worksheet, $extractedRange, true, $scope)); |
||
1394 | } |
||
1395 | } |
||
1396 | } |
||
1397 | |||
1398 | 3 | break; |
|
1399 | } |
||
1400 | } elseif (!isset($definedName['localSheetId'])) { |
||
1401 | // "Global" definedNames |
||
1402 | $locatedSheet = null; |
||
1403 | $extractedSheetName = ''; |
||
1404 | if (strpos((string) $definedName, '!') !== false) { |
||
1405 | // Extract sheet name |
||
1406 | $extractedSheetName = Worksheet::extractSheetTitle((string) $definedName, true); |
||
1407 | $extractedSheetName = trim($extractedSheetName[0], "'"); |
||
1408 | |||
1409 | // Locate sheet |
||
1410 | $locatedSheet = $excel->getSheetByName($extractedSheetName); |
||
1411 | |||
1412 | // Modify range |
||
1413 | [$worksheetName, $extractedRange] = Worksheet::extractSheetTitle($extractedRange, true); |
||
1414 | } |
||
1415 | |||
1416 | if ($locatedSheet !== null) { |
||
1417 | $excel->addNamedRange(new NamedRange((string) $definedName['name'], $locatedSheet, $extractedRange, false)); |
||
1418 | } |
||
1419 | } |
||
1420 | } |
||
1421 | } |
||
1422 | } |
||
1423 | |||
1424 | 48 | if ((!$this->readDataOnly) || (!empty($this->loadSheetsOnly))) { |
|
1425 | 48 | $workbookView = $xmlWorkbook->bookViews->workbookView; |
|
1426 | |||
1427 | // active sheet index |
||
1428 | 48 | $activeTab = (int) ($workbookView['activeTab']); // refers to old sheet index |
|
1429 | |||
1430 | // keep active sheet index if sheet is still loaded, else first sheet is set as the active |
||
1431 | 48 | if (isset($mapSheetId[$activeTab]) && $mapSheetId[$activeTab] !== null) { |
|
1432 | 48 | $excel->setActiveSheetIndex($mapSheetId[$activeTab]); |
|
1433 | } else { |
||
1434 | if ($excel->getSheetCount() == 0) { |
||
1435 | $excel->createSheet(); |
||
1436 | } |
||
1437 | $excel->setActiveSheetIndex(0); |
||
1438 | } |
||
1439 | |||
1440 | 48 | if (isset($workbookView['showHorizontalScroll'])) { |
|
1441 | 33 | $showHorizontalScroll = (string) $workbookView['showHorizontalScroll']; |
|
1442 | 33 | $excel->setShowHorizontalScroll($this->castXsdBooleanToBool($showHorizontalScroll)); |
|
1443 | } |
||
1444 | |||
1445 | 48 | if (isset($workbookView['showVerticalScroll'])) { |
|
1446 | 33 | $showVerticalScroll = (string) $workbookView['showVerticalScroll']; |
|
1447 | 33 | $excel->setShowVerticalScroll($this->castXsdBooleanToBool($showVerticalScroll)); |
|
1448 | } |
||
1449 | |||
1450 | 48 | if (isset($workbookView['showSheetTabs'])) { |
|
1451 | 33 | $showSheetTabs = (string) $workbookView['showSheetTabs']; |
|
1452 | 33 | $excel->setShowSheetTabs($this->castXsdBooleanToBool($showSheetTabs)); |
|
1453 | } |
||
1454 | |||
1455 | 48 | if (isset($workbookView['minimized'])) { |
|
1456 | 33 | $minimized = (string) $workbookView['minimized']; |
|
1457 | 33 | $excel->setMinimized($this->castXsdBooleanToBool($minimized)); |
|
1458 | } |
||
1459 | |||
1460 | 48 | if (isset($workbookView['autoFilterDateGrouping'])) { |
|
1461 | 33 | $autoFilterDateGrouping = (string) $workbookView['autoFilterDateGrouping']; |
|
1462 | 33 | $excel->setAutoFilterDateGrouping($this->castXsdBooleanToBool($autoFilterDateGrouping)); |
|
1463 | } |
||
1464 | |||
1465 | 48 | if (isset($workbookView['firstSheet'])) { |
|
1466 | 33 | $firstSheet = (string) $workbookView['firstSheet']; |
|
1467 | 33 | $excel->setFirstSheetIndex((int) $firstSheet); |
|
1468 | } |
||
1469 | |||
1470 | 48 | if (isset($workbookView['visibility'])) { |
|
1471 | 33 | $visibility = (string) $workbookView['visibility']; |
|
1472 | 33 | $excel->setVisibility($visibility); |
|
1473 | } |
||
1474 | |||
1475 | 48 | if (isset($workbookView['tabRatio'])) { |
|
1476 | 33 | $tabRatio = (string) $workbookView['tabRatio']; |
|
1477 | 33 | $excel->setTabRatio((int) $tabRatio); |
|
1478 | } |
||
1479 | } |
||
1480 | |||
1481 | 48 | break; |
|
1482 | } |
||
1483 | } |
||
1484 | |||
1485 | 48 | if (!$this->readDataOnly) { |
|
1486 | 48 | $contentTypes = simplexml_load_string( |
|
1487 | 48 | $this->securityScanner->scan( |
|
1488 | 48 | $this->getFromZipArchive($zip, '[Content_Types].xml') |
|
1489 | ), |
||
1490 | 48 | 'SimpleXMLElement', |
|
1491 | 48 | Settings::getLibXmlLoaderOptions() |
|
1492 | ); |
||
1493 | |||
1494 | // Default content types |
||
1495 | 48 | foreach ($contentTypes->Default as $contentType) { |
|
1496 | 48 | switch ($contentType['ContentType']) { |
|
1497 | 48 | case 'application/vnd.openxmlformats-officedocument.spreadsheetml.printerSettings': |
|
1498 | 11 | $unparsedLoadedData['default_content_types'][(string) $contentType['Extension']] = (string) $contentType['ContentType']; |
|
1499 | |||
1500 | 11 | break; |
|
1501 | } |
||
1502 | } |
||
1503 | |||
1504 | // Override content types |
||
1505 | 48 | foreach ($contentTypes->Override as $contentType) { |
|
1506 | 48 | switch ($contentType['ContentType']) { |
|
1507 | 48 | case 'application/vnd.openxmlformats-officedocument.drawingml.chart+xml': |
|
1508 | 2 | if ($this->includeCharts) { |
|
1509 | 2 | $chartEntryRef = ltrim($contentType['PartName'], '/'); |
|
1510 | 2 | $chartElements = simplexml_load_string( |
|
1511 | 2 | $this->securityScanner->scan( |
|
1512 | 2 | $this->getFromZipArchive($zip, $chartEntryRef) |
|
1513 | ), |
||
1514 | 2 | 'SimpleXMLElement', |
|
1515 | 2 | Settings::getLibXmlLoaderOptions() |
|
1516 | ); |
||
1517 | 2 | $objChart = Chart::readChart($chartElements, basename($chartEntryRef, '.xml')); |
|
1 ignored issue
–
show
|
|||
1518 | |||
1519 | 2 | if (isset($charts[$chartEntryRef])) { |
|
1520 | 2 | $chartPositionRef = $charts[$chartEntryRef]['sheet'] . '!' . $charts[$chartEntryRef]['id']; |
|
1521 | 2 | if (isset($chartDetails[$chartPositionRef])) { |
|
1522 | 2 | $excel->getSheetByName($charts[$chartEntryRef]['sheet'])->addChart($objChart); |
|
1523 | 2 | $objChart->setWorksheet($excel->getSheetByName($charts[$chartEntryRef]['sheet'])); |
|
1524 | 2 | $objChart->setTopLeftPosition($chartDetails[$chartPositionRef]['fromCoordinate'], $chartDetails[$chartPositionRef]['fromOffsetX'], $chartDetails[$chartPositionRef]['fromOffsetY']); |
|
1525 | 2 | $objChart->setBottomRightPosition($chartDetails[$chartPositionRef]['toCoordinate'], $chartDetails[$chartPositionRef]['toOffsetX'], $chartDetails[$chartPositionRef]['toOffsetY']); |
|
1526 | } |
||
1527 | } |
||
1528 | } |
||
1529 | |||
1530 | 2 | break; |
|
1531 | |||
1532 | // unparsed |
||
1533 | 48 | case 'application/vnd.ms-excel.controlproperties+xml': |
|
1534 | 1 | $unparsedLoadedData['override_content_types'][(string) $contentType['PartName']] = (string) $contentType['ContentType']; |
|
1535 | |||
1536 | 1 | break; |
|
1537 | } |
||
1538 | } |
||
1539 | } |
||
1540 | |||
1541 | 48 | $excel->setUnparsedLoadedData($unparsedLoadedData); |
|
1542 | |||
1543 | 48 | $zip->close(); |
|
1544 | |||
1545 | 48 | return $excel; |
|
1546 | } |
||
2048 |