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