30 if (!
defined(
'PHPEXCEL_ROOT')) {
34 define(
'PHPEXCEL_ROOT', dirname(__FILE__) .
'/../../');
35 require(PHPEXCEL_ROOT .
'PHPExcel/Autoloader.php');
83 if (!file_exists($pFilename)) {
88 if (!function_exists(
'gzread')) {
93 $fh = fopen($pFilename,
'r');
97 if (
$data != chr(0x1F).chr(0x8B)) {
114 if (!file_exists($pFilename)) {
118 $xml =
new XMLReader();
122 $xml->setParserProperty(2,
true);
124 $worksheetNames =
array();
125 while (
$xml->read()) {
126 if (
$xml->name ==
'gnm:SheetName' &&
$xml->nodeType == XMLReader::ELEMENT) {
129 } elseif (
$xml->name ==
'gnm:Sheets') {
135 return $worksheetNames;
148 if (!file_exists($pFilename)) {
152 $xml =
new XMLReader();
156 $xml->setParserProperty(2,
true);
158 $worksheetInfo =
array();
159 while (
$xml->read()) {
160 if (
$xml->name ==
'gnm:Sheet' &&
$xml->nodeType == XMLReader::ELEMENT) {
162 'worksheetName' =>
'',
163 'lastColumnLetter' =>
'A',
164 'lastColumnIndex' => 0,
169 while (
$xml->read()) {
170 if (
$xml->name ==
'gnm:Name' &&
$xml->nodeType == XMLReader::ELEMENT) {
172 $tmpInfo[
'worksheetName'] = (
string)
$xml->value;
173 } elseif (
$xml->name ==
'gnm:MaxCol' &&
$xml->nodeType == XMLReader::ELEMENT) {
175 $tmpInfo[
'lastColumnIndex'] = (int)
$xml->value;
176 $tmpInfo[
'totalColumns'] = (
int)
$xml->value + 1;
177 } elseif (
$xml->name ==
'gnm:MaxRow' &&
$xml->nodeType == XMLReader::ELEMENT) {
179 $tmpInfo[
'totalRows'] = (int)
$xml->value + 1;
184 $worksheetInfo[] = $tmpInfo;
188 return $worksheetInfo;
194 if (
$file !==
false) {
196 while (!gzeof(
$file)) {
212 public function load($pFilename)
233 if (!file_exists($pFilename)) {
237 $timezoneObj =
new DateTimeZone(
'Europe/London');
238 $GMT =
new DateTimeZone(
'UTC');
247 $namespacesMeta =
$xml->getNamespaces(
true);
251 $gnmXML =
$xml->children($namespacesMeta[
'gnm']);
255 if (isset($namespacesMeta[
'office'])) {
256 $officeXML =
$xml->children($namespacesMeta[
'office']);
257 $officeDocXML = $officeXML->{
'document-meta'};
258 $officeDocMetaXML = $officeDocXML->meta;
260 foreach($officeDocMetaXML as $officePropertyData) {
262 $officePropertyDC =
array();
263 if (isset($namespacesMeta[
'dc'])) {
264 $officePropertyDC = $officePropertyData->children($namespacesMeta[
'dc']);
266 foreach($officePropertyDC as $propertyName => $propertyValue) {
267 $propertyValue = (
string) $propertyValue;
268 switch ($propertyName) {
270 $docProps->setTitle(trim($propertyValue));
273 $docProps->setSubject(trim($propertyValue));
276 $docProps->setCreator(trim($propertyValue));
277 $docProps->setLastModifiedBy(trim($propertyValue));
280 $creationDate = strtotime(trim($propertyValue));
281 $docProps->setCreated($creationDate);
282 $docProps->setModified($creationDate);
285 $docProps->setDescription(trim($propertyValue));
289 $officePropertyMeta =
array();
290 if (isset($namespacesMeta[
'meta'])) {
291 $officePropertyMeta = $officePropertyData->children($namespacesMeta[
'meta']);
293 foreach($officePropertyMeta as $propertyName => $propertyValue) {
294 $attributes = $propertyValue->attributes($namespacesMeta[
'meta']);
295 $propertyValue = (
string) $propertyValue;
296 switch ($propertyName) {
298 $docProps->setKeywords(trim($propertyValue));
300 case 'initial-creator' :
301 $docProps->setCreator(trim($propertyValue));
302 $docProps->setLastModifiedBy(trim($propertyValue));
304 case 'creation-date' :
305 $creationDate = strtotime(trim($propertyValue));
306 $docProps->setCreated($creationDate);
307 $docProps->setModified($creationDate);
309 case 'user-defined' :
310 list(,$attrName) = explode(
':',
$attributes[
'name']);
313 $docProps->setCompany(trim($propertyValue));
316 $docProps->setCategory(trim($propertyValue));
319 $docProps->setManager(trim($propertyValue));
326 } elseif (isset($gnmXML->Summary)) {
327 foreach($gnmXML->Summary->Item as $summaryItem) {
328 $propertyName = $summaryItem->name;
329 $propertyValue = $summaryItem->{
'val-string'};
330 switch ($propertyName) {
332 $docProps->setTitle(trim($propertyValue));
335 $docProps->setDescription(trim($propertyValue));
338 $docProps->setKeywords(trim($propertyValue));
341 $docProps->setCategory(trim($propertyValue));
344 $docProps->setManager(trim($propertyValue));
347 $docProps->setCreator(trim($propertyValue));
348 $docProps->setLastModifiedBy(trim($propertyValue));
351 $docProps->setCompany(trim($propertyValue));
358 foreach($gnmXML->Sheets->Sheet as $sheet) {
359 $worksheetName = (
string) $sheet->Name;
361 if ((isset($this->_loadSheetsOnly)) && (!in_array($worksheetName, $this->_loadSheetsOnly))) {
365 $maxRow = $maxCol = 0;
373 $objPHPExcel->getActiveSheet()->setTitle($worksheetName,
false);
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']) {
382 $marginSize = intval($marginAttributes[
'Points']) / 100;
387 $objPHPExcel->getActiveSheet()->getPageMargins()->setTop($marginSize);
390 $objPHPExcel->getActiveSheet()->getPageMargins()->setBottom($marginSize);
393 $objPHPExcel->getActiveSheet()->getPageMargins()->setLeft($marginSize);
396 $objPHPExcel->getActiveSheet()->getPageMargins()->setRight($marginSize);
399 $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader($marginSize);
402 $objPHPExcel->getActiveSheet()->getPageMargins()->setFooter($marginSize);
409 foreach($sheet->Cells->Cell as $cell) {
410 $cellAttributes = $cell->attributes();
411 $row = (int) $cellAttributes->Row + 1;
412 $column = (
int) $cellAttributes->Col;
426 $ValueType = $cellAttributes->ValueType;
427 $ExprID = (
string) $cellAttributes->ExprID;
433 if (((
string) $cell) >
'') {
435 $this->_expressions[$ExprID] =
array(
'column' => $cellAttributes->Col,
436 'row' => $cellAttributes->Row,
437 'formula' => (
string) $cell
441 $expression = $this->_expressions[$ExprID];
443 $cell = $this->_referenceHelper->updateFormulaReferences( $expression[
'formula'],
445 $cellAttributes->Col - $expression[
'column'],
446 $cellAttributes->Row - $expression[
'row'],
460 $cell = ($cell ==
'TRUE') ? True : False;
463 $cell = intval($cell);
480 if ((!$this->_readDataOnly) && (isset($sheet->Objects))) {
481 foreach($sheet->Objects->children(
'gnm',TRUE) as
$key =>
$comment) {
482 $commentAttributes =
$comment->attributes();
484 if ($commentAttributes->Text) {
485 $objPHPExcel->getActiveSheet()->getComment( (
string)$commentAttributes->ObjectBound )
486 ->setAuthor( (
string)$commentAttributes->Author )
487 ->setText($this->
_parseRichText((
string)$commentAttributes->Text) );
493 foreach($sheet->Styles->StyleRegion as $styleRegion) {
494 $styleAttributes = $styleRegion->attributes();
495 if (($styleAttributes[
'startRow'] <= $maxRow) &&
496 ($styleAttributes[
'startCol'] <= $maxCol)) {
499 $startRow = $styleAttributes[
'startRow'] + 1;
501 $endColumn = ($styleAttributes[
'endCol'] > $maxCol) ? $maxCol : (
int) $styleAttributes[
'endCol'];
503 $endRow = ($styleAttributes[
'endRow'] > $maxRow) ? $maxRow : $styleAttributes[
'endRow'];
505 $cellRange = $startColumn.$startRow.
':'.$endColumn.$endRow;
508 $styleAttributes = $styleRegion->Style->attributes();
513 if ((!$this->_readDataOnly) ||
515 $styleArray =
array();
516 $styleArray[
'numberformat'][
'code'] = (
string) $styleAttributes[
'Format'];
518 if (!$this->_readDataOnly) {
519 switch($styleAttributes[
'HAlign']) {
541 switch($styleAttributes[
'VAlign']) {
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;
560 $RGB = self::_parseGnumericColour($styleAttributes[
"Fore"]);
561 $styleArray[
'font'][
'color'][
'rgb'] = $RGB;
562 $RGB = self::_parseGnumericColour($styleAttributes[
"Back"]);
563 $shade = $styleAttributes[
"Shade"];
564 if (($RGB !=
'000000') || ($shade !=
'0')) {
565 $styleArray[
'fill'][
'color'][
'rgb'] = $styleArray[
'fill'][
'startcolor'][
'rgb'] = $RGB;
566 $RGB2 = self::_parseGnumericColour($styleAttributes[
"PatternColor"]);
567 $styleArray[
'fill'][
'endcolor'][
'rgb'] = $RGB2;
632 $fontAttributes = $styleRegion->Style->Font->attributes();
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']) {
657 switch($fontAttributes[
'Script']) {
659 $styleArray[
'font'][
'superScript'] = True;
662 $styleArray[
'font'][
'subScript'] = True;
666 if (isset($styleRegion->Style->StyleBorder)) {
667 if (isset($styleRegion->Style->StyleBorder->Top)) {
668 $styleArray[
'borders'][
'top'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->Top->attributes());
670 if (isset($styleRegion->Style->StyleBorder->Bottom)) {
671 $styleArray[
'borders'][
'bottom'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->Bottom->attributes());
673 if (isset($styleRegion->Style->StyleBorder->Left)) {
674 $styleArray[
'borders'][
'left'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->Left->attributes());
676 if (isset($styleRegion->Style->StyleBorder->Right)) {
677 $styleArray[
'borders'][
'right'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->Right->attributes());
679 if ((isset($styleRegion->Style->StyleBorder->Diagonal)) && (isset($styleRegion->Style->StyleBorder->{
'Rev-Diagonal'}))) {
680 $styleArray[
'borders'][
'diagonal'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->Diagonal->attributes());
682 } elseif (isset($styleRegion->Style->StyleBorder->Diagonal)) {
683 $styleArray[
'borders'][
'diagonal'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->Diagonal->attributes());
685 } elseif (isset($styleRegion->Style->StyleBorder->{
'Rev-Diagonal'})) {
686 $styleArray[
'borders'][
'diagonal'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->{
'Rev-Diagonal'}->attributes());
690 if (isset($styleRegion->Style->HyperLink)) {
692 $hyperlink = $styleRegion->Style->HyperLink->attributes();
697 $objPHPExcel->getActiveSheet()->getStyle($cellRange)->applyFromArray($styleArray);
702 if ((!$this->_readDataOnly) && (isset($sheet->Cols))) {
704 $columnAttributes = $sheet->Cols->attributes();
705 $defaultWidth = $columnAttributes[
'DefaultSizePts'] / 5.4;
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;
717 while (($c < (
$column+$columnCount)) && ($c <= $maxCol)) {
725 while ($c <= $maxCol) {
731 if ((!$this->_readDataOnly) && (isset($sheet->Rows))) {
733 $rowAttributes = $sheet->Rows->attributes();
734 $defaultHeight = $rowAttributes[
'DefaultSizePts'];
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);
747 while ((
$r < (
$row+$rowCount)) && (
$r < $maxRow)) {
749 $objPHPExcel->getActiveSheet()->getRowDimension(
$r)->setRowHeight($rowHeight);
751 $objPHPExcel->getActiveSheet()->getRowDimension(
$r)->setVisible(
false);
755 while (
$r < $maxRow) {
757 $objPHPExcel->getActiveSheet()->getRowDimension(
$r)->setRowHeight($defaultHeight);
762 if (isset($sheet->MergedRegions)) {
763 foreach($sheet->MergedRegions->Merge as $mergeCells) {
764 if (strpos($mergeCells,
':') !== FALSE) {
765 $objPHPExcel->getActiveSheet()->mergeCells($mergeCells);
774 if (isset($gnmXML->Names)) {
775 foreach($gnmXML->Names->Name as $namedRange) {
777 $range = (
string) $namedRange->value;
778 if (stripos($range,
'#REF!') !==
false) {
782 $range = explode(
'!',$range);
783 $range[0] = trim($range[0],
"'");;
785 $extractedRange = str_replace(
'$',
'', $range[1]);
799 $styleArray =
array();
801 if (isset($borderAttributes[
"Color"])) {
802 $RGB = self::_parseGnumericColour($borderAttributes[
"Color"]);
803 $styleArray[
'color'][
'rgb'] = $RGB;
806 switch ($borderAttributes[
"Style"]) {
857 $value->createText($is);
864 list($gnmR,$gnmG,$gnmB) = explode(
':',$gnmColour);
865 $gnmR = substr(str_pad($gnmR,4,
'0',STR_PAD_RIGHT),0,2);
866 $gnmG = substr(str_pad($gnmG,4,
'0',STR_PAD_RIGHT),0,2);
867 $gnmB = substr(str_pad($gnmB,4,
'0',STR_PAD_RIGHT),0,2);
868 $RGB = $gnmR.$gnmG.$gnmB;
static _parseBorderAttributes($borderAttributes)
const FILL_PATTERN_LIGHTHORIZONTAL
const FILL_PATTERN_LIGHTGRAY
canRead($pFilename)
Can the current PHPExcel_Reader_IReader read the file?
const FILL_PATTERN_DARKGRID
const FILL_PATTERN_DARKHORIZONTAL
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 getInstance()
Get an instance of this class.
__construct()
Create a new PHPExcel_Reader_Gnumeric.
const BORDER_MEDIUMDASHDOT
getProperties()
Get properties.
load($pFilename)
Loads PHPExcel from file.
const FILL_PATTERN_LIGHTTRELLIS
securityScan($xml)
Scan theXML for use of <!ENTITY to prevent XXE/XEE attacks.
securityScanFile($filestream)
Scan theXML for use of <!ENTITY to prevent XXE/XEE attacks.
static _parseGnumericColour($gnmColour)
const UNDERLINE_DOUBLEACCOUNTING
listWorksheetNames($pFilename)
Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object...
const HORIZONTAL_CENTER_CONTINUOUS
const FILL_PATTERN_LIGHTDOWN
const FILL_PATTERN_MEDIUMGRAY
const FILL_PATTERN_DARKDOWN
const FILL_PATTERN_GRAY125
const FILL_PATTERN_DARKTRELLIS
static getLibXmlLoaderOptions()
Get default options for libxml loader.
const FILL_PATTERN_LIGHTVERTICAL
const UNDERLINE_SINGLEACCOUNTING
const BORDER_MEDIUMDASHDOTDOT
Create styles array
The data for the language used.
const FILL_PATTERN_GRAY0625
getReadFilter()
Read filter.
_gzfileGetContents($filename)
const FILL_PATTERN_LIGHTGRID
static isDateTimeFormatCode($pFormatCode='')
Is a given number format code a date/time?
const BORDER_SLANTDASHDOT
const FILL_PATTERN_DARKVERTICAL
static stringFromColumnIndex($pColumnIndex=0)
String from columnindex.
const FILL_PATTERN_DARKGRAY
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
const FILL_PATTERN_LIGHTUP
defined( 'APPLICATION_ENV')||define( 'APPLICATION_ENV'
const FILL_PATTERN_DARKUP
const BORDER_MEDIUMDASHED
const FILL_GRADIENT_LINEAR