333 if (!file_exists($pFilename)) {
337 $timezoneObj =
new DateTimeZone(
'Europe/London');
338 $GMT =
new DateTimeZone(
'UTC');
342 $zip =
new $zipClass;
343 if (!$zip->open($pFilename)) {
349 $namespacesMeta = $xml->getNamespaces(
true);
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']);
361 foreach($officePropertyDC as $propertyName => $propertyValue) {
362 $propertyValue = (
string) $propertyValue;
363 switch ($propertyName) {
365 $docProps->setTitle($propertyValue);
368 $docProps->setSubject($propertyValue);
371 $docProps->setCreator($propertyValue);
372 $docProps->setLastModifiedBy($propertyValue);
375 $creationDate = strtotime($propertyValue);
376 $docProps->setCreated($creationDate);
377 $docProps->setModified($creationDate);
380 $docProps->setDescription($propertyValue);
384 $officePropertyMeta =
array();
385 if (isset($namespacesMeta[
'dc'])) {
386 $officePropertyMeta = $officePropertyData->children($namespacesMeta[
'meta']);
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);
396 $docProps->setKeywords($propertyValue);
398 case 'creation-date' :
399 $creationDate = strtotime($propertyValue);
400 $docProps->setCreated($creationDate);
402 case 'user-defined' :
404 foreach ($propertyValueAttributes as $key => $value) {
405 if ($key ==
'name') {
406 $propertyValueName = (
string) $value;
407 } elseif($key ==
'value-type') {
426 $docProps->setCustomProperty($propertyValueName,$propertyValue,$propertyValueType);
435 $namespacesContent = $xml->getNamespaces(
true);
440 $workbook = $xml->children($namespacesContent[
'office']);
441 foreach($workbook->body->spreadsheet as $workbookData) {
442 $workbookData = $workbookData->children($namespacesContent[
'table']);
444 foreach($workbookData->table as $worksheetDataSet) {
445 $worksheetData = $worksheetDataSet->children($namespacesContent[
'table']);
448 $worksheetDataAttributes = $worksheetDataSet->attributes($namespacesContent[
'table']);
451 if ((isset($this->_loadSheetsOnly)) && (isset($worksheetDataAttributes[
'name'])) &&
452 (!in_array($worksheetDataAttributes[
'name'], $this->_loadSheetsOnly))) {
460 if (isset($worksheetDataAttributes[
'name'])) {
461 $worksheetName = (
string) $worksheetDataAttributes[
'name'];
469 foreach($worksheetData as $key => $rowData) {
472 case 'table-header-rows':
473 foreach ($rowData as $key=>$cellData) {
474 $rowData = $cellData;
478 $rowDataTableAttributes = $rowData->attributes($namespacesContent[
'table']);
479 $rowRepeats = (isset($rowDataTableAttributes[
'number-rows-repeated'])) ?
480 $rowDataTableAttributes[
'number-rows-repeated'] : 1;
482 foreach($rowData as $key => $cellData) {
484 if (!$this->
getReadFilter()->readCell($columnID, $rowID, $worksheetName)) {
490 $cellDataText = (isset($namespacesContent[
'text'])) ?
491 $cellData->children($namespacesContent[
'text']) :
493 $cellDataOffice = $cellData->children($namespacesContent[
'office']);
494 $cellDataOfficeAttributes = $cellData->attributes($namespacesContent[
'office']);
495 $cellDataTableAttributes = $cellData->attributes($namespacesContent[
'table']);
505 $type = $formatting = $hyperlink = null;
506 $hasCalculatedValue =
false;
507 $cellDataFormula =
'';
508 if (isset($cellDataTableAttributes[
'formula'])) {
509 $cellDataFormula = $cellDataTableAttributes[
'formula'];
510 $hasCalculatedValue =
true;
513 if (isset($cellDataOffice->annotation)) {
515 $annotationText = $cellDataOffice->annotation->children($namespacesContent[
'text']);
516 $textArray =
array();
517 foreach($annotationText as
$t) {
518 if (isset($t->span)) {
519 foreach($t->span as
$text) {
520 $textArray[] = (
string)$text;
523 $textArray[] = (
string) $t;
526 $text = implode(
"\n",$textArray);
533 if (isset($cellDataText->p)) {
540 foreach ($cellDataText->p as $pData) {
541 if (isset($pData->span)) {
544 foreach ($pData->span as $spanData) {
545 $spanSection .= $spanData;
555 switch ($cellDataOfficeAttributes[
'value-type']) {
558 $dataValue = $allCellDataText;
559 if (isset($dataValue->a)) {
560 $dataValue = $dataValue->a;
561 $cellXLinkAttributes = $dataValue->attributes($namespacesContent[
'xlink']);
562 $hyperlink = $cellXLinkAttributes[
'href'];
567 $dataValue = ($allCellDataText ==
'TRUE') ? True : False;
571 $dataValue = (float) $cellDataOfficeAttributes[
'value'];
572 if (floor($dataValue) == $dataValue) {
573 $dataValue = (integer) $dataValue;
579 $dataValue = (float) $cellDataOfficeAttributes[
'value'];
580 if (floor($dataValue) == $dataValue) {
581 $dataValue = (integer) $dataValue;
587 $dataValue = (float) $cellDataOfficeAttributes[
'value'];
588 if (floor($dataValue) == $dataValue) {
589 if ($dataValue == (integer) $dataValue)
590 $dataValue = (integer) $dataValue;
592 $dataValue = (float) $dataValue;
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)) {
622 if ($hasCalculatedValue) {
625 $cellDataFormula = substr($cellDataFormula,strpos($cellDataFormula,
':=')+1);
626 $temp = explode(
'"',$cellDataFormula);
628 foreach($temp as &$value) {
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);
640 $cellDataFormula = implode(
'"',$temp);
644 $colRepeats = (isset($cellDataTableAttributes[
'number-columns-repeated'])) ?
645 $cellDataTableAttributes[
'number-columns-repeated'] : 1;
646 if ($type !== NULL) {
647 for ($i = 0; $i < $colRepeats; ++$i) {
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) {
657 $objPHPExcel->
getActiveSheet()->getCell($columnID.$rID)->setCalculatedValue($dataValue);
659 if ($formatting !== NULL) {
660 $objPHPExcel->
getActiveSheet()->getStyle($columnID.$rID)->getNumberFormat()->setFormatCode($formatting);
664 if ($hyperlink !== NULL) {
665 $objPHPExcel->
getActiveSheet()->getCell($columnID.$rID)->getHyperlink()->setUrl($hyperlink);
673 if ((isset($cellDataTableAttributes[
'number-columns-spanned'])) || (isset($cellDataTableAttributes[
'number-rows-spanned']))) {
675 $columnTo = $columnID;
676 if (isset($cellDataTableAttributes[
'number-columns-spanned'])) {
680 if (isset($cellDataTableAttributes[
'number-rows-spanned'])) {
681 $rowTo = $rowTo + $cellDataTableAttributes[
'number-rows-spanned'] - 1;
683 $cellRange = $columnID.$rowID.
':'.$columnTo.$rowTo;
690 $rowID += $rowRepeats;
static getZipClass()
Return the name of the Zip handler Class that PHPExcel is configured to use (PCLZip or ZipArchive) or...
getProperties()
Get properties.
Add rich text string
The name of the decorator.
createSheet($iSheetIndex=NULL)
Create sheet and add it to this workbook.
static FormattedPHPToExcel($year, $month, $day, $hours=0, $minutes=0, $seconds=0)
FormattedPHPToExcel.
securityScan($xml)
Scan theXML for use of <!ENTITY to prevent XXE/XEE attacks.
const PROPERTY_TYPE_STRING
static convertProperty($propertyValue, $propertyType)
const PROPERTY_TYPE_FLOAT
static _translateSeparator($fromSeparator, $toSeparator, $formula, &$inBraces)
const PROPERTY_TYPE_BOOLEAN
constants
static getLibXmlLoaderOptions()
Get default options for libxml loader.
Create styles array
The data for the language used.
getActiveSheet()
Get active sheet.
getReadFilter()
Read filter.
static columnIndexFromString($pString='A')
Column index from string.
static stringFromColumnIndex($pColumnIndex=0)
String from columnindex.
setActiveSheetIndex($pIndex=0)
Set active sheet index.
static PHPToExcel($dateValue=0, $adjustToTimezone=FALSE, $timezone=NULL)
Convert a date from PHP to Excel.