231 {
232
233 if (!file_exists($pFilename)) {
235 }
236
237 $timezoneObj = new DateTimeZone('Europe/London');
238 $GMT = new DateTimeZone('UTC');
239
241
242
243
244
245
247 $namespacesMeta = $xml->getNamespaces(true);
248
249
250
251 $gnmXML = $xml->children($namespacesMeta['gnm']);
252
254
255 if (isset($namespacesMeta['office'])) {
256 $officeXML = $xml->children($namespacesMeta['office']);
257 $officeDocXML = $officeXML->{'document-meta'};
258 $officeDocMetaXML = $officeDocXML->meta;
259
260 foreach($officeDocMetaXML as $officePropertyData) {
261
262 $officePropertyDC = array();
263 if (isset($namespacesMeta['dc'])) {
264 $officePropertyDC = $officePropertyData->children($namespacesMeta['dc']);
265 }
266 foreach($officePropertyDC as $propertyName => $propertyValue) {
267 $propertyValue = (string) $propertyValue;
268 switch ($propertyName) {
269 case 'title' :
270 $docProps->setTitle(trim($propertyValue));
271 break;
272 case 'subject' :
273 $docProps->setSubject(trim($propertyValue));
274 break;
275 case 'creator' :
276 $docProps->setCreator(trim($propertyValue));
277 $docProps->setLastModifiedBy(trim($propertyValue));
278 break;
279 case 'date' :
280 $creationDate = strtotime(trim($propertyValue));
281 $docProps->setCreated($creationDate);
282 $docProps->setModified($creationDate);
283 break;
284 case 'description' :
285 $docProps->setDescription(trim($propertyValue));
286 break;
287 }
288 }
289 $officePropertyMeta = array();
290 if (isset($namespacesMeta['meta'])) {
291 $officePropertyMeta = $officePropertyData->children($namespacesMeta['meta']);
292 }
293 foreach($officePropertyMeta as $propertyName => $propertyValue) {
294 $attributes = $propertyValue->attributes($namespacesMeta['meta']);
295 $propertyValue = (string) $propertyValue;
296 switch ($propertyName) {
297 case 'keyword' :
298 $docProps->setKeywords(trim($propertyValue));
299 break;
300 case 'initial-creator' :
301 $docProps->setCreator(trim($propertyValue));
302 $docProps->setLastModifiedBy(trim($propertyValue));
303 break;
304 case 'creation-date' :
305 $creationDate = strtotime(trim($propertyValue));
306 $docProps->setCreated($creationDate);
307 $docProps->setModified($creationDate);
308 break;
309 case 'user-defined' :
310 list(,$attrName) = explode(':',$attributes['name']);
311 switch ($attrName) {
312 case 'publisher' :
313 $docProps->setCompany(trim($propertyValue));
314 break;
315 case 'category' :
316 $docProps->setCategory(trim($propertyValue));
317 break;
318 case 'manager' :
319 $docProps->setManager(trim($propertyValue));
320 break;
321 }
322 break;
323 }
324 }
325 }
326 } elseif (isset($gnmXML->Summary)) {
327 foreach($gnmXML->Summary->Item as $summaryItem) {
328 $propertyName = $summaryItem->name;
329 $propertyValue = $summaryItem->{'val-string'};
330 switch ($propertyName) {
331 case 'title' :
332 $docProps->setTitle(trim($propertyValue));
333 break;
334 case 'comments' :
335 $docProps->setDescription(trim($propertyValue));
336 break;
337 case 'keywords' :
338 $docProps->setKeywords(trim($propertyValue));
339 break;
340 case 'category' :
341 $docProps->setCategory(trim($propertyValue));
342 break;
343 case 'manager' :
344 $docProps->setManager(trim($propertyValue));
345 break;
346 case 'author' :
347 $docProps->setCreator(trim($propertyValue));
348 $docProps->setLastModifiedBy(trim($propertyValue));
349 break;
350 case 'company' :
351 $docProps->setCompany(trim($propertyValue));
352 break;
353 }
354 }
355 }
356
357 $worksheetID = 0;
358 foreach($gnmXML->Sheets->Sheet as $sheet) {
359 $worksheetName = (string) $sheet->Name;
360
361 if ((isset($this->_loadSheetsOnly)) && (!in_array($worksheetName, $this->_loadSheetsOnly))) {
362 continue;
363 }
364
365 $maxRow = $maxCol = 0;
366
367
370
371
372
373 $objPHPExcel->getActiveSheet()->setTitle($worksheetName,
false);
374
375 if ((!$this->_readDataOnly) && (isset($sheet->PrintInformation))) {
376 if (isset($sheet->PrintInformation->Margins)) {
377 foreach($sheet->PrintInformation->Margins->children('gnm',TRUE) as $key => $margin) {
378 $marginAttributes = $margin->attributes();
379 $marginSize = 72 / 100;
380 switch($marginAttributes['PrefUnit']) {
381 case 'mm' :
382 $marginSize = intval($marginAttributes['Points']) / 100;
383 break;
384 }
385 switch($key) {
386 case 'top' :
387 $objPHPExcel->getActiveSheet()->getPageMargins()->setTop($marginSize);
388 break;
389 case 'bottom' :
390 $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom($marginSize);
391 break;
392 case 'left' :
393 $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft($marginSize);
394 break;
395 case 'right' :
396 $objPHPExcel->getActiveSheet()->getPageMargins()->setRight($marginSize);
397 break;
398 case 'header' :
399 $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader($marginSize);
400 break;
401 case 'footer' :
402 $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter($marginSize);
403 break;
404 }
405 }
406 }
407 }
408
409 foreach($sheet->Cells->Cell as $cell) {
410 $cellAttributes = $cell->attributes();
411 $row = (int) $cellAttributes->Row + 1;
412 $column = (
int) $cellAttributes->Col;
413
416
418
419
422 continue;
423 }
424 }
425
426 $ValueType = $cellAttributes->ValueType;
427 $ExprID = (string) $cellAttributes->ExprID;
428
429
430
433 if (((string) $cell) > '') {
434
435 $this->_expressions[$ExprID] = array( 'column' => $cellAttributes->Col,
436 'row' => $cellAttributes->Row,
437 'formula' => (string) $cell
438 );
439
440 } else {
441 $expression = $this->_expressions[$ExprID];
442
443 $cell = $this->_referenceHelper->updateFormulaReferences( $expression['formula'],
444 'A1',
445 $cellAttributes->Col - $expression['column'],
446 $cellAttributes->Row - $expression['row'],
447 $worksheetName
448 );
449
450
451 }
453 } else {
454 switch($ValueType) {
455 case '10' :
457 break;
458 case '20' :
460 $cell = ($cell == 'TRUE') ? True : False;
461 break;
462 case '30' :
463 $cell = intval($cell);
464 case '40' :
466 break;
467 case '50' :
469 break;
470 case '60' :
472 break;
473 case '70' :
474 case '80' :
475 }
476 }
478 }
479
480 if ((!$this->_readDataOnly) && (isset($sheet->Objects))) {
481 foreach($sheet->Objects->children(
'gnm',TRUE) as $key =>
$comment) {
482 $commentAttributes =
$comment->attributes();
483
484 if ($commentAttributes->Text) {
485 $objPHPExcel->getActiveSheet()->getComment( (
string)$commentAttributes->ObjectBound )
486 ->setAuthor( (string)$commentAttributes->Author )
487 ->setText($this->
_parseRichText((
string)$commentAttributes->Text) );
488 }
489 }
490 }
491
492
493 foreach($sheet->Styles->StyleRegion as $styleRegion) {
494 $styleAttributes = $styleRegion->attributes();
495 if (($styleAttributes['startRow'] <= $maxRow) &&
496 ($styleAttributes['startCol'] <= $maxCol)) {
497
499 $startRow = $styleAttributes['startRow'] + 1;
500
501 $endColumn = ($styleAttributes['endCol'] > $maxCol) ? $maxCol : (int) $styleAttributes['endCol'];
503 $endRow = ($styleAttributes['endRow'] > $maxRow) ? $maxRow : $styleAttributes['endRow'];
504 $endRow += 1;
505 $cellRange = $startColumn.$startRow.':'.$endColumn.$endRow;
506
507
508 $styleAttributes = $styleRegion->Style->attributes();
509
510
511
512
513 if ((!$this->_readDataOnly) ||
515 $styleArray = array();
516 $styleArray['numberformat']['code'] = (string) $styleAttributes['Format'];
517
518 if (!$this->_readDataOnly) {
519 switch($styleAttributes['HAlign']) {
520 case '1' :
522 break;
523 case '2' :
525 break;
526 case '4' :
528 break;
529 case '8' :
531 break;
532 case '16' :
533 case '64' :
535 break;
536 case '32' :
538 break;
539 }
540
541 switch($styleAttributes['VAlign']) {
542 case '1' :
544 break;
545 case '2' :
547 break;
548 case '4' :
550 break;
551 case '8' :
553 break;
554 }
555
556 $styleArray['alignment']['wrap'] = ($styleAttributes['WrapText'] == '1') ? True : False;
557 $styleArray['alignment']['shrinkToFit'] = ($styleAttributes['ShrinkToFit'] == '1') ? True : False;
558 $styleArray['alignment']['indent'] = (intval($styleAttributes["Indent"]) > 0) ? $styleAttributes["indent"] : 0;
559
561 $styleArray['font']['color']['rgb'] = $RGB;
563 $shade = $styleAttributes["Shade"];
564 if (($RGB != '000000') || ($shade != '0')) {
565 $styleArray['fill']['color']['rgb'] = $styleArray['fill']['startcolor']['rgb'] = $RGB;
567 $styleArray['fill']['endcolor']['rgb'] = $RGB2;
568 switch($shade) {
569 case '1' :
571 break;
572 case '2' :
574 break;
575 case '3' :
577 break;
578 case '4' :
580 break;
581 case '5' :
583 break;
584 case '6' :
586 break;
587 case '7' :
589 break;
590 case '8' :
592 break;
593 case '9' :
595 break;
596 case '10' :
598 break;
599 case '11' :
601 break;
602 case '12' :
604 break;
605 case '13' :
607 break;
608 case '14' :
610 break;
611 case '15' :
613 break;
614 case '16' :
616 break;
617 case '17' :
619 break;
620 case '18' :
622 break;
623 case '19' :
625 break;
626 case '20' :
628 break;
629 }
630 }
631
632 $fontAttributes = $styleRegion->Style->Font->attributes();
633
634
635 $styleArray['font']['name'] = (string) $styleRegion->Style->Font;
636 $styleArray['font']['size'] = intval($fontAttributes['Unit']);
637 $styleArray['font']['bold'] = ($fontAttributes['Bold'] == '1') ? True : False;
638 $styleArray['font']['italic'] = ($fontAttributes['Italic'] == '1') ? True : False;
639 $styleArray['font']['strike'] = ($fontAttributes['StrikeThrough'] == '1') ? True : False;
640 switch($fontAttributes['Underline']) {
641 case '1' :
643 break;
644 case '2' :
646 break;
647 case '3' :
649 break;
650 case '4' :
652 break;
653 default :
655 break;
656 }
657 switch($fontAttributes['Script']) {
658 case '1' :
659 $styleArray['font']['superScript'] = True;
660 break;
661 case '-1' :
662 $styleArray['font']['subScript'] = True;
663 break;
664 }
665
666 if (isset($styleRegion->Style->StyleBorder)) {
667 if (isset($styleRegion->Style->StyleBorder->Top)) {
669 }
670 if (isset($styleRegion->Style->StyleBorder->Bottom)) {
672 }
673 if (isset($styleRegion->Style->StyleBorder->Left)) {
675 }
676 if (isset($styleRegion->Style->StyleBorder->Right)) {
678 }
679 if ((isset($styleRegion->Style->StyleBorder->Diagonal)) && (isset($styleRegion->Style->StyleBorder->{'Rev-Diagonal'}))) {
682 } elseif (isset($styleRegion->Style->StyleBorder->Diagonal)) {
685 } elseif (isset($styleRegion->Style->StyleBorder->{'Rev-Diagonal'})) {
688 }
689 }
690 if (isset($styleRegion->Style->HyperLink)) {
691
692 $hyperlink = $styleRegion->Style->HyperLink->attributes();
693 }
694 }
695
696
697 $objPHPExcel->getActiveSheet()->getStyle($cellRange)->applyFromArray($styleArray);
698 }
699 }
700 }
701
702 if ((!$this->_readDataOnly) && (isset($sheet->Cols))) {
703
704 $columnAttributes = $sheet->Cols->attributes();
705 $defaultWidth = $columnAttributes['DefaultSizePts'] / 5.4;
706 $c = 0;
707 foreach($sheet->Cols->ColInfo as $columnOverride) {
708 $columnAttributes = $columnOverride->attributes();
709 $column = $columnAttributes[
'No'];
710 $columnWidth = $columnAttributes['Unit'] / 5.4;
711 $hidden = ((isset($columnAttributes['Hidden'])) && ($columnAttributes['Hidden'] == '1')) ? true : false;
712 $columnCount = (isset($columnAttributes['Count'])) ? $columnAttributes['Count'] : 1;
715 ++$c;
716 }
717 while (($c < (
$column+$columnCount)) && ($c <= $maxCol)) {
719 if ($hidden) {
721 }
722 ++$c;
723 }
724 }
725 while ($c <= $maxCol) {
727 ++$c;
728 }
729 }
730
731 if ((!$this->_readDataOnly) && (isset($sheet->Rows))) {
732
733 $rowAttributes = $sheet->Rows->attributes();
734 $defaultHeight = $rowAttributes['DefaultSizePts'];
736
737 foreach($sheet->Rows->RowInfo as $rowOverride) {
738 $rowAttributes = $rowOverride->attributes();
739 $row = $rowAttributes[
'No'];
740 $rowHeight = $rowAttributes['Unit'];
741 $hidden = ((isset($rowAttributes['Hidden'])) && ($rowAttributes['Hidden'] == '1')) ? true : false;
742 $rowCount = (isset($rowAttributes['Count'])) ? $rowAttributes['Count'] : 1;
745 $objPHPExcel->getActiveSheet()->getRowDimension(
$r)->setRowHeight($defaultHeight);
746 }
747 while ((
$r < (
$row+$rowCount)) && (
$r < $maxRow)) {
749 $objPHPExcel->getActiveSheet()->getRowDimension(
$r)->setRowHeight($rowHeight);
750 if ($hidden) {
751 $objPHPExcel->getActiveSheet()->getRowDimension(
$r)->setVisible(
false);
752 }
753 }
754 }
755 while (
$r < $maxRow) {
757 $objPHPExcel->getActiveSheet()->getRowDimension(
$r)->setRowHeight($defaultHeight);
758 }
759 }
760
761
762 if (isset($sheet->MergedRegions)) {
763 foreach($sheet->MergedRegions->Merge as $mergeCells) {
764 if (strpos($mergeCells,':') !== FALSE) {
765 $objPHPExcel->getActiveSheet()->mergeCells($mergeCells);
766 }
767 }
768 }
769
770 $worksheetID++;
771 }
772
773
774 if (isset($gnmXML->Names)) {
775 foreach($gnmXML->Names->Name as $namedRange) {
776 $name = (string) $namedRange->name;
777 $range = (string) $namedRange->value;
778 if (stripos($range, '#REF!') !== false) {
779 continue;
780 }
781
782 $range = explode('!',$range);
783 $range[0] = trim($range[0],"'");;
785 $extractedRange = str_replace('$', '', $range[1]);
787 }
788 }
789 }
790
791
792
794 }
securityScan($xml)
Scan theXML for use of <!ENTITY to prevent XXE/XEE attacks.
getReadFilter()
Read filter.
_gzfileGetContents($filename)
static _parseBorderAttributes($borderAttributes)
static isDateTimeFormatCode($pFormatCode='')
Is a given number format code a date/time?
const HORIZONTAL_CENTER_CONTINUOUS
const FILL_PATTERN_LIGHTUP
const FILL_PATTERN_DARKDOWN
const FILL_PATTERN_DARKUP
const FILL_PATTERN_LIGHTVERTICAL
const FILL_PATTERN_LIGHTGRAY
const FILL_PATTERN_LIGHTDOWN
const FILL_PATTERN_DARKGRAY
const FILL_PATTERN_GRAY125
const FILL_PATTERN_LIGHTHORIZONTAL
const FILL_PATTERN_DARKTRELLIS
const FILL_PATTERN_GRAY0625
const FILL_PATTERN_MEDIUMGRAY
const FILL_GRADIENT_LINEAR
const FILL_PATTERN_DARKVERTICAL
const FILL_PATTERN_DARKHORIZONTAL
const FILL_PATTERN_LIGHTGRID
const FILL_PATTERN_LIGHTTRELLIS
const FILL_PATTERN_DARKGRID
const UNDERLINE_SINGLEACCOUNTING
const UNDERLINE_DOUBLEACCOUNTING