331 {
332
333 if (!file_exists($pFilename)) {
335 }
336
337 $timezoneObj = new DateTimeZone('Europe/London');
338 $GMT = new DateTimeZone('UTC');
339
341
342 $zip = new $zipClass;
343 if (!$zip->open($pFilename)) {
345 }
346
347
349 $namespacesMeta = $xml->getNamespaces(true);
350
351
352
353
355 $officeProperty = $xml->children($namespacesMeta['office']);
356 foreach($officeProperty as $officePropertyData) {
357 $officePropertyDC = array();
358 if (isset($namespacesMeta['dc'])) {
359 $officePropertyDC = $officePropertyData->children($namespacesMeta['dc']);
360 }
361 foreach($officePropertyDC as $propertyName => $propertyValue) {
362 $propertyValue = (string) $propertyValue;
363 switch ($propertyName) {
364 case 'title' :
365 $docProps->setTitle($propertyValue);
366 break;
367 case 'subject' :
368 $docProps->setSubject($propertyValue);
369 break;
370 case 'creator' :
371 $docProps->setCreator($propertyValue);
372 $docProps->setLastModifiedBy($propertyValue);
373 break;
374 case 'date' :
375 $creationDate = strtotime($propertyValue);
376 $docProps->setCreated($creationDate);
377 $docProps->setModified($creationDate);
378 break;
379 case 'description' :
380 $docProps->setDescription($propertyValue);
381 break;
382 }
383 }
384 $officePropertyMeta = array();
385 if (isset($namespacesMeta['dc'])) {
386 $officePropertyMeta = $officePropertyData->children($namespacesMeta['meta']);
387 }
388 foreach($officePropertyMeta as $propertyName => $propertyValue) {
389 $propertyValueAttributes = $propertyValue->attributes($namespacesMeta['meta']);
390 $propertyValue = (string) $propertyValue;
391 switch ($propertyName) {
392 case 'initial-creator' :
393 $docProps->setCreator($propertyValue);
394 break;
395 case 'keyword' :
396 $docProps->setKeywords($propertyValue);
397 break;
398 case 'creation-date' :
399 $creationDate = strtotime($propertyValue);
400 $docProps->setCreated($creationDate);
401 break;
402 case 'user-defined' :
404 foreach ($propertyValueAttributes as $key => $value) {
405 if ($key == 'name') {
406 $propertyValueName = (string) $value;
407 } elseif($key == 'value-type') {
408 switch ($value) {
409 case 'date' :
412 break;
413 case 'boolean' :
416 break;
417 case 'float' :
420 break;
421 default :
423 }
424 }
425 }
426 $docProps->setCustomProperty($propertyValueName,$propertyValue,$propertyValueType);
427 break;
428 }
429 }
430 }
431
432
433
435 $namespacesContent = $xml->getNamespaces(true);
436
437
438
439
440 $workbook = $xml->children($namespacesContent['office']);
441 foreach($workbook->body->spreadsheet as $workbookData) {
442 $workbookData = $workbookData->children($namespacesContent['table']);
443 $worksheetID = 0;
444 foreach($workbookData->table as $worksheetDataSet) {
445 $worksheetData = $worksheetDataSet->children($namespacesContent['table']);
446
447
448 $worksheetDataAttributes = $worksheetDataSet->attributes($namespacesContent['table']);
449
450
451 if ((isset($this->_loadSheetsOnly)) && (isset($worksheetDataAttributes['name'])) &&
452 (!in_array($worksheetDataAttributes['name'], $this->_loadSheetsOnly))) {
453 continue;
454 }
455
456
457
460 if (isset($worksheetDataAttributes['name'])) {
461 $worksheetName = (string) $worksheetDataAttributes['name'];
462
463
464
465 $objPHPExcel->getActiveSheet()->setTitle($worksheetName,
false);
466 }
467
468 $rowID = 1;
469 foreach($worksheetData as $key => $rowData) {
470
471 switch ($key) {
472 case 'table-header-rows':
473 foreach ($rowData as $key=>$cellData) {
474 $rowData = $cellData;
475 break;
476 }
477 case 'table-row' :
478 $rowDataTableAttributes = $rowData->attributes($namespacesContent['table']);
479 $rowRepeats = (isset($rowDataTableAttributes['number-rows-repeated'])) ?
480 $rowDataTableAttributes['number-rows-repeated'] : 1;
481 $columnID = 'A';
482 foreach($rowData as $key => $cellData) {
484 if (!$this->
getReadFilter()->readCell($columnID, $rowID, $worksheetName)) {
485 continue;
486 }
487 }
488
489
490 $cellDataText = (isset($namespacesContent['text'])) ?
491 $cellData->children($namespacesContent['text']) :
492 '';
493 $cellDataOffice = $cellData->children($namespacesContent['office']);
494 $cellDataOfficeAttributes = $cellData->attributes($namespacesContent['office']);
495 $cellDataTableAttributes = $cellData->attributes($namespacesContent['table']);
496
497
498
499
500
501
502
503
504
505 $type = $formatting = $hyperlink = null;
506 $hasCalculatedValue = false;
507 $cellDataFormula = '';
508 if (isset($cellDataTableAttributes['formula'])) {
509 $cellDataFormula = $cellDataTableAttributes['formula'];
510 $hasCalculatedValue = true;
511 }
512
513 if (isset($cellDataOffice->annotation)) {
514
515 $annotationText = $cellDataOffice->annotation->children($namespacesContent['text']);
516 $textArray = array();
517 foreach($annotationText as
$t) {
518 if (isset(
$t->span)) {
520 $textArray[] = (string)
$text;
521 }
522 } else {
523 $textArray[] = (string)
$t;
524 }
525 }
526 $text = implode(
"\n",$textArray);
527
528 $objPHPExcel->getActiveSheet()->getComment( $columnID.$rowID )
529
531 }
532
533 if (isset($cellDataText->p)) {
534
536
537
538
539
540 foreach ($cellDataText->p as $pData) {
541 if (isset($pData->span)) {
542
543 $spanSection = "";
544 foreach ($pData->span as $spanData) {
545 $spanSection .= $spanData;
546 }
548 } else {
550 }
551 }
553
554
555 switch ($cellDataOfficeAttributes['value-type']) {
556 case 'string' :
558 $dataValue = $allCellDataText;
559 if (isset($dataValue->a)) {
560 $dataValue = $dataValue->a;
561 $cellXLinkAttributes = $dataValue->attributes($namespacesContent['xlink']);
562 $hyperlink = $cellXLinkAttributes['href'];
563 }
564 break;
565 case 'boolean' :
567 $dataValue = ($allCellDataText == 'TRUE') ? True : False;
568 break;
569 case 'percentage' :
571 $dataValue = (float) $cellDataOfficeAttributes['value'];
572 if (floor($dataValue) == $dataValue) {
573 $dataValue = (integer) $dataValue;
574 }
576 break;
577 case 'currency' :
579 $dataValue = (float) $cellDataOfficeAttributes['value'];
580 if (floor($dataValue) == $dataValue) {
581 $dataValue = (integer) $dataValue;
582 }
584 break;
585 case 'float' :
587 $dataValue = (float) $cellDataOfficeAttributes['value'];
588 if (floor($dataValue) == $dataValue) {
589 if ($dataValue == (integer) $dataValue)
590 $dataValue = (integer) $dataValue;
591 else
592 $dataValue = (float) $dataValue;
593 }
594 break;
595 case 'date' :
597 $dateObj = new DateTime($cellDataOfficeAttributes['date-value'], $GMT);
598 $dateObj->setTimeZone($timezoneObj);
599 list($year,$month,$day,$hour,$minute,$second) = explode(' ',$dateObj->format('Y m d H i s'));
601 if ($dataValue != floor($dataValue)) {
603 } else {
605 }
606 break;
607 case 'time' :
611 break;
612 }
613
614
615
616
617 } else {
619 $dataValue = NULL;
620 }
621
622 if ($hasCalculatedValue) {
624
625 $cellDataFormula = substr($cellDataFormula,strpos($cellDataFormula,':=')+1);
626 $temp = explode('"',$cellDataFormula);
627 $tKey = false;
628 foreach($temp as &$value) {
629
630 if ($tKey = !$tKey) {
631 $value = preg_replace('/\[([^\.]+)\.([^\.]+):\.([^\.]+)\]/Ui','$1!$2:$3',$value);
632 $value = preg_replace('/\[([^\.]+)\.([^\.]+)\]/Ui','$1!$2',$value);
633 $value = preg_replace('/\[\.([^\.]+):\.([^\.]+)\]/Ui','$1:$2',$value);
634 $value = preg_replace('/\[\.([^\.]+)\]/Ui','$1',$value);
636 }
637 }
638 unset($value);
639
640 $cellDataFormula = implode('"',$temp);
641
642 }
643
644 $colRepeats = (isset($cellDataTableAttributes['number-columns-repeated'])) ?
645 $cellDataTableAttributes['number-columns-repeated'] : 1;
646 if ($type !== NULL) {
647 for ($i = 0; $i < $colRepeats; ++$i) {
648 if ($i > 0) {
649 ++$columnID;
650 }
652 for ($rowAdjust = 0; $rowAdjust < $rowRepeats; ++$rowAdjust) {
653 $rID = $rowID + $rowAdjust;
654 $objPHPExcel->getActiveSheet()->getCell($columnID.$rID)->setValueExplicit((($hasCalculatedValue) ? $cellDataFormula : $dataValue),$type);
655 if ($hasCalculatedValue) {
656
657 $objPHPExcel->getActiveSheet()->getCell($columnID.$rID)->setCalculatedValue($dataValue);
658 }
659 if ($formatting !== NULL) {
660 $objPHPExcel->getActiveSheet()->getStyle($columnID.$rID)->getNumberFormat()->setFormatCode($formatting);
661 } else {
663 }
664 if ($hyperlink !== NULL) {
665 $objPHPExcel->getActiveSheet()->getCell($columnID.$rID)->getHyperlink()->setUrl($hyperlink);
666 }
667 }
668 }
669 }
670 }
671
672
673 if ((isset($cellDataTableAttributes['number-columns-spanned'])) || (isset($cellDataTableAttributes['number-rows-spanned']))) {
675 $columnTo = $columnID;
676 if (isset($cellDataTableAttributes['number-columns-spanned'])) {
678 }
679 $rowTo = $rowID;
680 if (isset($cellDataTableAttributes['number-rows-spanned'])) {
681 $rowTo = $rowTo + $cellDataTableAttributes['number-rows-spanned'] - 1;
682 }
683 $cellRange = $columnID.$rowID.':'.$columnTo.$rowTo;
685 }
686 }
687
688 ++$columnID;
689 }
690 $rowID += $rowRepeats;
691 break;
692 }
693 }
694 ++$worksheetID;
695 }
696 }
697
698
700 }
static _translateSeparator($fromSeparator, $toSeparator, $formula, &$inBraces)
static columnIndexFromString($pString='A')
Column index from string.
const PROPERTY_TYPE_BOOLEAN
constants
const PROPERTY_TYPE_FLOAT
const PROPERTY_TYPE_STRING
static convertProperty($propertyValue, $propertyType)
getReadFilter()
Read filter.
static FormattedPHPToExcel($year, $month, $day, $hours=0, $minutes=0, $seconds=0)
FormattedPHPToExcel.
static PHPToExcel($dateValue=0, $adjustToTimezone=FALSE, $timezone=NULL)
Convert a date from PHP to Excel.