34        define(
'PHPEXCEL_ROOT', dirname(__FILE__) . 
'/../../');
 
   35        require(PHPEXCEL_ROOT . 
'PHPExcel/Autoloader.php');
 
   73                if (!file_exists($pFilename)) {
 
   84        $mimeType = 
'UNKNOWN';
 
   87                if ($zip->open($pFilename) === 
true) {
 
   89                        $stat = $zip->statName(
'mimetype');
 
   90                        if ($stat && ($stat[
'size'] <= 255)) {
 
   91                                $mimeType = $zip->getFromName($stat[
'name']);
 
   92                        } elseif($stat = $zip->statName(
'META-INF/manifest.xml')) {
 
   94                        $namespacesContent = 
$xml->getNamespaces(
true);
 
   95                                if (isset($namespacesContent[
'manifest'])) {
 
   96                                $manifest = 
$xml->children($namespacesContent[
'manifest']);
 
   97                                    foreach($manifest as $manifestDataSet) {
 
   98                                            $manifestAttributes = $manifestDataSet->attributes($namespacesContent[
'manifest']);
 
   99                                        if ($manifestAttributes->{
'full-path'} == 
'/') {
 
  100                                            $mimeType = (string) $manifestAttributes->{
'media-type'};
 
  109                        return ($mimeType === 
'application/vnd.oasis.opendocument.spreadsheet');
 
  125                if (!file_exists($pFilename)) {
 
  131                $zip = 
new $zipClass;
 
  132                if (!$zip->open($pFilename)) {
 
  136                $worksheetNames = array();
 
  138                $xml = 
new XMLReader();
 
  140                $xml->setParserProperty(2,
true);
 
  144                while (
$xml->read()) {
 
  146                        while (
$xml->name !== 
'office:body') {
 
  147                                if (
$xml->isEmptyElement)
 
  153                        while (
$xml->read()) {
 
  154                                if (
$xml->name == 
'table:table' && 
$xml->nodeType == XMLReader::ELEMENT) {
 
  157                                                $worksheetNames[] = 
$xml->getAttribute(
'table:name');
 
  159                                        } 
while (
$xml->name == 
'table:table' && 
$xml->nodeType == XMLReader::ELEMENT);
 
  164                return $worksheetNames;
 
  177                if (!file_exists($pFilename)) {
 
  181                $worksheetInfo = array();
 
  185                $zip = 
new $zipClass;
 
  186                if (!$zip->open($pFilename)) {
 
  190                $xml = 
new XMLReader();
 
  192                $xml->setParserProperty(2,
true);
 
  196                while (
$xml->read()) {
 
  198                        while (
$xml->name !== 
'office:body') {
 
  199                                if (
$xml->isEmptyElement)
 
  205                        while (
$xml->read()) {
 
  206                                if (
$xml->name == 
'table:table' && 
$xml->nodeType == XMLReader::ELEMENT) {
 
  207                                        $worksheetNames[] = 
$xml->getAttribute(
'table:name');
 
  210                                                'worksheetName' => 
$xml->getAttribute(
'table:name'),
 
  211                                                'lastColumnLetter' => 
'A',
 
  212                                                'lastColumnIndex' => 0,
 
  221                                                if (
$xml->name == 
'table:table-row' && 
$xml->nodeType == XMLReader::ELEMENT) {
 
  222                                                        $rowspan = 
$xml->getAttribute(
'table:number-rows-repeated');
 
  223                                                        $rowspan = empty($rowspan) ? 1 : $rowspan;
 
  224                                                        $tmpInfo[
'totalRows'] += $rowspan;
 
  225                                                        $tmpInfo[
'totalColumns'] = max($tmpInfo[
'totalColumns'],$currCells);
 
  230                                                                if (
$xml->name == 
'table:table-cell' && 
$xml->nodeType == XMLReader::ELEMENT) {
 
  231                                                                        if (!
$xml->isEmptyElement) {
 
  237                                                                } elseif (
$xml->name == 
'table:covered-table-cell' && 
$xml->nodeType == XMLReader::ELEMENT) {
 
  238                                                                        $mergeSize = 
$xml->getAttribute(
'table:number-columns-repeated');
 
  239                                                                        $currCells += $mergeSize;
 
  242                                                        } 
while (
$xml->name != 
'table:table-row');
 
  244                                        } 
while (
$xml->name != 
'table:table');
 
  246                                        $tmpInfo[
'totalColumns'] = max($tmpInfo[
'totalColumns'],$currCells);
 
  247                                        $tmpInfo[
'lastColumnIndex'] = $tmpInfo[
'totalColumns'] - 1;
 
  249                                        $worksheetInfo[] = $tmpInfo;
 
  289                return $worksheetInfo;
 
  300        public function load($pFilename)
 
  306                return $this->loadIntoExisting($pFilename, 
$objPHPExcel);
 
  311                $styleAttributeValue = strtolower($styleAttributeValue);
 
  312                foreach($styleList as 
$style) {
 
  313                        if ($styleAttributeValue == strtolower(
$style)) {
 
  314                                $styleAttributeValue = 
$style;
 
  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'];
 
  465                                        $objPHPExcel->getActiveSheet()->setTitle($worksheetName,
false);
 
  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) {
 
  483                                                                if ($this->getReadFilter() !== NULL) {
 
  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)) {
 
  520                                                                                        $textArray[] = (string)
$text;
 
  523                                                                                $textArray[] = (string) 
$t;
 
  526                                                                        $text = implode(
"\n",$textArray);
 
  528                                                                        $objPHPExcel->getActiveSheet()->getComment( $columnID.$rowID )
 
  530                                                                                                                                        ->setText($this->_parseRichText(
$text) );
 
  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;
 
  706                $value->createText($is);
 
An exception for terminatinating execution or to throw for unit testing.
static _translateSeparator($fromSeparator, $toSeparator, $formula, &$inBraces)
static stringFromColumnIndex($pColumnIndex=0)
String from columnindex.
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)
securityScan($xml)
Scan theXML for use of <!ENTITY to prevent XXE/XEE attacks.
static identifyFixedStyleValue($styleList, &$styleAttributeValue)
listWorksheetNames($pFilename)
Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object.
load($pFilename)
Loads PHPExcel from file.
__construct()
Create a new PHPExcel_Reader_OOCalc.
canRead($pFilename)
Can the current PHPExcel_Reader_IReader read the file?
loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
Loads PHPExcel from file into PHPExcel instance.
listWorksheetInfo($pFilename)
Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns)
static getZipClass()
Return the name of the Zip handler Class that PHPExcel is configured to use (PCLZip or ZipArchive) or...
static getLibXmlLoaderOptions()
Get default options for libxml loader.
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.
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
foreach($_POST as $key=> $value) $res