5 * Copyright (c) 2006 - 2014 PHPExcel
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 * @package PHPExcel_Reader
23 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
24 * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
25 * @version ##VERSION##, ##DATE##
29 /** PHPExcel root directory */
30 if (!defined('PHPEXCEL_ROOT')) {
34 define('PHPEXCEL_ROOT', dirname(__FILE__
) . '/../../');
35 require(PHPEXCEL_ROOT
. 'PHPExcel/Autoloader.php');
39 * PHPExcel_Reader_Gnumeric
42 * @package PHPExcel_Reader
43 * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
45 class PHPExcel_Reader_Gnumeric
extends PHPExcel_Reader_Abstract
implements PHPExcel_Reader_IReader
52 private $_styles = array();
59 private $_expressions = array();
61 private $_referenceHelper = null;
65 * Create a new PHPExcel_Reader_Gnumeric
67 public function __construct() {
68 $this->_readFilter
= new PHPExcel_Reader_DefaultReadFilter();
69 $this->_referenceHelper
= PHPExcel_ReferenceHelper
::getInstance();
74 * Can the current PHPExcel_Reader_IReader read the file?
76 * @param string $pFilename
78 * @throws PHPExcel_Reader_Exception
80 public function canRead($pFilename)
82 // Check if file exists
83 if (!file_exists($pFilename)) {
84 throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
87 // Check if gzlib functions are available
88 if (!function_exists('gzread')) {
89 throw new PHPExcel_Reader_Exception("gzlib library is not enabled");
92 // Read signature data (first 3 bytes)
93 $fh = fopen($pFilename, 'r');
94 $data = fread($fh, 2);
97 if ($data != chr(0x1F).chr(0x8B)) {
106 * Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object
108 * @param string $pFilename
109 * @throws PHPExcel_Reader_Exception
111 public function listWorksheetNames($pFilename)
113 // Check if file exists
114 if (!file_exists($pFilename)) {
115 throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
118 $xml = new XMLReader();
120 $this->securityScanFile('compress.zlib://'.realpath($pFilename)), null, PHPExcel_Settings
::getLibXmlLoaderOptions()
122 $xml->setParserProperty(2,true);
124 $worksheetNames = array();
125 while ($xml->read()) {
126 if ($xml->name
== 'gnm:SheetName' && $xml->nodeType
== XMLReader
::ELEMENT
) {
127 $xml->read(); // Move onto the value node
128 $worksheetNames[] = (string) $xml->value
;
129 } elseif ($xml->name
== 'gnm:Sheets') {
130 // break out of the loop once we've got our sheet names rather than parse the entire file
135 return $worksheetNames;
140 * Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns)
142 * @param string $pFilename
143 * @throws PHPExcel_Reader_Exception
145 public function listWorksheetInfo($pFilename)
147 // Check if file exists
148 if (!file_exists($pFilename)) {
149 throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
152 $xml = new XMLReader();
154 $this->securityScanFile('compress.zlib://'.realpath($pFilename)), null, PHPExcel_Settings
::getLibXmlLoaderOptions()
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
) {
171 $xml->read(); // Move onto the value node
172 $tmpInfo['worksheetName'] = (string) $xml->value
;
173 } elseif ($xml->name
== 'gnm:MaxCol' && $xml->nodeType
== XMLReader
::ELEMENT
) {
174 $xml->read(); // Move onto the value node
175 $tmpInfo['lastColumnIndex'] = (int) $xml->value
;
176 $tmpInfo['totalColumns'] = (int) $xml->value +
1;
177 } elseif ($xml->name
== 'gnm:MaxRow' && $xml->nodeType
== XMLReader
::ELEMENT
) {
178 $xml->read(); // Move onto the value node
179 $tmpInfo['totalRows'] = (int) $xml->value +
1;
183 $tmpInfo['lastColumnLetter'] = PHPExcel_Cell
::stringFromColumnIndex($tmpInfo['lastColumnIndex']);
184 $worksheetInfo[] = $tmpInfo;
188 return $worksheetInfo;
192 private function _gzfileGetContents($filename) {
193 $file = @gzopen
($filename, 'rb');
194 if ($file !== false) {
196 while (!gzeof($file)) {
197 $data .= gzread($file, 1024);
206 * Loads PHPExcel from file
208 * @param string $pFilename
210 * @throws PHPExcel_Reader_Exception
212 public function load($pFilename)
214 // Create new PHPExcel
215 $objPHPExcel = new PHPExcel();
217 // Load into this instance
218 return $this->loadIntoExisting($pFilename, $objPHPExcel);
223 * Loads PHPExcel from file into PHPExcel instance
225 * @param string $pFilename
226 * @param PHPExcel $objPHPExcel
228 * @throws PHPExcel_Reader_Exception
230 public function loadIntoExisting($pFilename, PHPExcel
$objPHPExcel)
232 // Check if file exists
233 if (!file_exists($pFilename)) {
234 throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
237 $timezoneObj = new DateTimeZone('Europe/London');
238 $GMT = new DateTimeZone('UTC');
240 $gFileData = $this->_gzfileGetContents($pFilename);
243 // echo htmlentities($gFileData,ENT_QUOTES,'UTF-8');
244 // echo '</pre><hr />';
246 $xml = simplexml_load_string($this->securityScan($gFileData), 'SimpleXMLElement', PHPExcel_Settings
::getLibXmlLoaderOptions());
247 $namespacesMeta = $xml->getNamespaces(true);
249 // var_dump($namespacesMeta);
251 $gnmXML = $xml->children($namespacesMeta['gnm']);
253 $docProps = $objPHPExcel->getProperties();
254 // Document Properties are held differently, depending on the version of Gnumeric
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
;
360 // echo '<b>Worksheet: ',$worksheetName,'</b><br />';
361 if ((isset($this->_loadSheetsOnly
)) && (!in_array($worksheetName, $this->_loadSheetsOnly
))) {
365 $maxRow = $maxCol = 0;
367 // Create new Worksheet
368 $objPHPExcel->createSheet();
369 $objPHPExcel->setActiveSheetIndex($worksheetID);
370 // Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in formula
371 // cells... during the load, all formulae should be correct, and we're simply bringing the worksheet
372 // name in line with the formula, not the reverse
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; // Default
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
;
414 if ($row > $maxRow) $maxRow = $row;
415 if ($column > $maxCol) $maxCol = $column;
417 $column = PHPExcel_Cell
::stringFromColumnIndex($column);
420 if ($this->getReadFilter() !== NULL) {
421 if (!$this->getReadFilter()->readCell($column, $row, $worksheetName)) {
426 $ValueType = $cellAttributes->ValueType
;
427 $ExprID = (string) $cellAttributes->ExprID
;
428 // echo 'Cell ',$column,$row,'<br />';
429 // echo 'Type is ',$ValueType,'<br />';
430 // echo 'Value is ',$cell,'<br />';
431 $type = PHPExcel_Cell_DataType
::TYPE_FORMULA
;
433 if (((string) $cell) > '') {
435 $this->_expressions
[$ExprID] = array( 'column' => $cellAttributes->Col
,
436 'row' => $cellAttributes->Row
,
437 'formula' => (string) $cell
439 // echo 'NEW EXPRESSION ',$ExprID,'<br />';
441 $expression = $this->_expressions
[$ExprID];
443 $cell = $this->_referenceHelper
->updateFormulaReferences( $expression['formula'],
445 $cellAttributes->Col
- $expression['column'],
446 $cellAttributes->Row
- $expression['row'],
449 // echo 'SHARED EXPRESSION ',$ExprID,'<br />';
450 // echo 'New Value is ',$cell,'<br />';
452 $type = PHPExcel_Cell_DataType
::TYPE_FORMULA
;
456 $type = PHPExcel_Cell_DataType
::TYPE_NULL
;
458 case '20' : // Boolean
459 $type = PHPExcel_Cell_DataType
::TYPE_BOOL
;
460 $cell = ($cell == 'TRUE') ?
True : False;
462 case '30' : // Integer
463 $cell = intval($cell);
465 $type = PHPExcel_Cell_DataType
::TYPE_NUMERIC
;
468 $type = PHPExcel_Cell_DataType
::TYPE_ERROR
;
470 case '60' : // String
471 $type = PHPExcel_Cell_DataType
::TYPE_STRING
;
473 case '70' : // Cell Range
477 $objPHPExcel->getActiveSheet()->getCell($column.$row)->setValueExplicit($cell,$type);
480 if ((!$this->_readDataOnly
) && (isset($sheet->Objects
))) {
481 foreach($sheet->Objects
->children('gnm',TRUE) as $key => $comment) {
482 $commentAttributes = $comment->attributes();
483 // Only comment objects are handled at the moment
484 if ($commentAttributes->Text
) {
485 $objPHPExcel->getActiveSheet()->getComment( (string)$commentAttributes->ObjectBound
)
486 ->setAuthor( (string)$commentAttributes->Author
)
487 ->setText($this->_parseRichText((string)$commentAttributes->Text
) );
491 // echo '$maxCol=',$maxCol,'; $maxRow=',$maxRow,'<br />';
493 foreach($sheet->Styles
->StyleRegion
as $styleRegion) {
494 $styleAttributes = $styleRegion->attributes();
495 if (($styleAttributes['startRow'] <= $maxRow) &&
496 ($styleAttributes['startCol'] <= $maxCol)) {
498 $startColumn = PHPExcel_Cell
::stringFromColumnIndex((int) $styleAttributes['startCol']);
499 $startRow = $styleAttributes['startRow'] +
1;
501 $endColumn = ($styleAttributes['endCol'] > $maxCol) ?
$maxCol : (int) $styleAttributes['endCol'];
502 $endColumn = PHPExcel_Cell
::stringFromColumnIndex($endColumn);
503 $endRow = ($styleAttributes['endRow'] > $maxRow) ?
$maxRow : $styleAttributes['endRow'];
505 $cellRange = $startColumn.$startRow.':'.$endColumn.$endRow;
506 // echo $cellRange,'<br />';
508 $styleAttributes = $styleRegion->Style
->attributes();
509 // var_dump($styleAttributes);
512 // We still set the number format mask for date/time values, even if _readDataOnly is true
513 if ((!$this->_readDataOnly
) ||
514 (PHPExcel_Shared_Date
::isDateTimeFormatCode((string) $styleAttributes['Format']))) {
515 $styleArray = array();
516 $styleArray['numberformat']['code'] = (string) $styleAttributes['Format'];
517 // If _readDataOnly is false, we set all formatting information
518 if (!$this->_readDataOnly
) {
519 switch($styleAttributes['HAlign']) {
521 $styleArray['alignment']['horizontal'] = PHPExcel_Style_Alignment
::HORIZONTAL_GENERAL
;
524 $styleArray['alignment']['horizontal'] = PHPExcel_Style_Alignment
::HORIZONTAL_LEFT
;
527 $styleArray['alignment']['horizontal'] = PHPExcel_Style_Alignment
::HORIZONTAL_RIGHT
;
530 $styleArray['alignment']['horizontal'] = PHPExcel_Style_Alignment
::HORIZONTAL_CENTER
;
534 $styleArray['alignment']['horizontal'] = PHPExcel_Style_Alignment
::HORIZONTAL_CENTER_CONTINUOUS
;
537 $styleArray['alignment']['horizontal'] = PHPExcel_Style_Alignment
::HORIZONTAL_JUSTIFY
;
541 switch($styleAttributes['VAlign']) {
543 $styleArray['alignment']['vertical'] = PHPExcel_Style_Alignment
::VERTICAL_TOP
;
546 $styleArray['alignment']['vertical'] = PHPExcel_Style_Alignment
::VERTICAL_BOTTOM
;
549 $styleArray['alignment']['vertical'] = PHPExcel_Style_Alignment
::VERTICAL_CENTER
;
552 $styleArray['alignment']['vertical'] = PHPExcel_Style_Alignment
::VERTICAL_JUSTIFY
;
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;
570 $styleArray['fill']['type'] = PHPExcel_Style_Fill
::FILL_SOLID
;
573 $styleArray['fill']['type'] = PHPExcel_Style_Fill
::FILL_GRADIENT_LINEAR
;
576 $styleArray['fill']['type'] = PHPExcel_Style_Fill
::FILL_GRADIENT_PATH
;
579 $styleArray['fill']['type'] = PHPExcel_Style_Fill
::FILL_PATTERN_DARKDOWN
;
582 $styleArray['fill']['type'] = PHPExcel_Style_Fill
::FILL_PATTERN_DARKGRAY
;
585 $styleArray['fill']['type'] = PHPExcel_Style_Fill
::FILL_PATTERN_DARKGRID
;
588 $styleArray['fill']['type'] = PHPExcel_Style_Fill
::FILL_PATTERN_DARKHORIZONTAL
;
591 $styleArray['fill']['type'] = PHPExcel_Style_Fill
::FILL_PATTERN_DARKTRELLIS
;
594 $styleArray['fill']['type'] = PHPExcel_Style_Fill
::FILL_PATTERN_DARKUP
;
597 $styleArray['fill']['type'] = PHPExcel_Style_Fill
::FILL_PATTERN_DARKVERTICAL
;
600 $styleArray['fill']['type'] = PHPExcel_Style_Fill
::FILL_PATTERN_GRAY0625
;
603 $styleArray['fill']['type'] = PHPExcel_Style_Fill
::FILL_PATTERN_GRAY125
;
606 $styleArray['fill']['type'] = PHPExcel_Style_Fill
::FILL_PATTERN_LIGHTDOWN
;
609 $styleArray['fill']['type'] = PHPExcel_Style_Fill
::FILL_PATTERN_LIGHTGRAY
;
612 $styleArray['fill']['type'] = PHPExcel_Style_Fill
::FILL_PATTERN_LIGHTGRID
;
615 $styleArray['fill']['type'] = PHPExcel_Style_Fill
::FILL_PATTERN_LIGHTHORIZONTAL
;
618 $styleArray['fill']['type'] = PHPExcel_Style_Fill
::FILL_PATTERN_LIGHTTRELLIS
;
621 $styleArray['fill']['type'] = PHPExcel_Style_Fill
::FILL_PATTERN_LIGHTUP
;
624 $styleArray['fill']['type'] = PHPExcel_Style_Fill
::FILL_PATTERN_LIGHTVERTICAL
;
627 $styleArray['fill']['type'] = PHPExcel_Style_Fill
::FILL_PATTERN_MEDIUMGRAY
;
632 $fontAttributes = $styleRegion->Style
->Font
->attributes();
633 // var_dump($fontAttributes);
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']) {
642 $styleArray['font']['underline'] = PHPExcel_Style_Font
::UNDERLINE_SINGLE
;
645 $styleArray['font']['underline'] = PHPExcel_Style_Font
::UNDERLINE_DOUBLE
;
648 $styleArray['font']['underline'] = PHPExcel_Style_Font
::UNDERLINE_SINGLEACCOUNTING
;
651 $styleArray['font']['underline'] = PHPExcel_Style_Font
::UNDERLINE_DOUBLEACCOUNTING
;
654 $styleArray['font']['underline'] = PHPExcel_Style_Font
::UNDERLINE_NONE
;
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());
681 $styleArray['borders']['diagonaldirection'] = PHPExcel_Style_Borders
::DIAGONAL_BOTH
;
682 } elseif (isset($styleRegion->Style
->StyleBorder
->Diagonal
)) {
683 $styleArray['borders']['diagonal'] = self
::_parseBorderAttributes($styleRegion->Style
->StyleBorder
->Diagonal
->attributes());
684 $styleArray['borders']['diagonaldirection'] = PHPExcel_Style_Borders
::DIAGONAL_UP
;
685 } elseif (isset($styleRegion->Style
->StyleBorder
->{'Rev-Diagonal'})) {
686 $styleArray['borders']['diagonal'] = self
::_parseBorderAttributes($styleRegion->Style
->StyleBorder
->{'Rev-Diagonal'}->attributes());
687 $styleArray['borders']['diagonaldirection'] = PHPExcel_Style_Borders
::DIAGONAL_DOWN
;
690 if (isset($styleRegion->Style
->HyperLink
)) {
692 $hyperlink = $styleRegion->Style
->HyperLink
->attributes();
695 // var_dump($styleArray);
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;
713 while ($c < $column) {
714 $objPHPExcel->getActiveSheet()->getColumnDimension(PHPExcel_Cell
::stringFromColumnIndex($c))->setWidth($defaultWidth);
717 while (($c < ($column+
$columnCount)) && ($c <= $maxCol)) {
718 $objPHPExcel->getActiveSheet()->getColumnDimension(PHPExcel_Cell
::stringFromColumnIndex($c))->setWidth($columnWidth);
720 $objPHPExcel->getActiveSheet()->getColumnDimension(PHPExcel_Cell
::stringFromColumnIndex($c))->setVisible(false);
725 while ($c <= $maxCol) {
726 $objPHPExcel->getActiveSheet()->getColumnDimension(PHPExcel_Cell
::stringFromColumnIndex($c))->setWidth($defaultWidth);
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);
761 // Handle Merged Cells in this worksheet
762 if (isset($sheet->MergedRegions
)) {
763 foreach($sheet->MergedRegions
->Merge
as $mergeCells) {
764 if (strpos($mergeCells,':') !== FALSE) {
765 $objPHPExcel->getActiveSheet()->mergeCells($mergeCells);
773 // Loop through definedNames (global named ranges)
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) {
782 $range = explode('!',$range);
783 $range[0] = trim($range[0],"'");;
784 if ($worksheet = $objPHPExcel->getSheetByName($range[0])) {
785 $extractedRange = str_replace('$', '', $range[1]);
786 $objPHPExcel->addNamedRange( new PHPExcel_NamedRange($name, $worksheet, $extractedRange) );
797 private static function _parseBorderAttributes($borderAttributes)
799 $styleArray = array();
801 if (isset($borderAttributes["Color"])) {
802 $RGB = self
::_parseGnumericColour($borderAttributes["Color"]);
803 $styleArray['color']['rgb'] = $RGB;
806 switch ($borderAttributes["Style"]) {
808 $styleArray['style'] = PHPExcel_Style_Border
::BORDER_NONE
;
811 $styleArray['style'] = PHPExcel_Style_Border
::BORDER_THIN
;
814 $styleArray['style'] = PHPExcel_Style_Border
::BORDER_MEDIUM
;
817 $styleArray['style'] = PHPExcel_Style_Border
::BORDER_DASHED
;
820 $styleArray['style'] = PHPExcel_Style_Border
::BORDER_THICK
;
823 $styleArray['style'] = PHPExcel_Style_Border
::BORDER_DOUBLE
;
826 $styleArray['style'] = PHPExcel_Style_Border
::BORDER_DOTTED
;
829 $styleArray['style'] = PHPExcel_Style_Border
::BORDER_DASHDOT
;
832 $styleArray['style'] = PHPExcel_Style_Border
::BORDER_MEDIUMDASHDOT
;
835 $styleArray['style'] = PHPExcel_Style_Border
::BORDER_DASHDOTDOT
;
838 $styleArray['style'] = PHPExcel_Style_Border
::BORDER_MEDIUMDASHDOTDOT
;
841 $styleArray['style'] = PHPExcel_Style_Border
::BORDER_MEDIUMDASHDOTDOT
;
844 $styleArray['style'] = PHPExcel_Style_Border
::BORDER_SLANTDASHDOT
;
847 $styleArray['style'] = PHPExcel_Style_Border
::BORDER_MEDIUMDASHED
;
854 private function _parseRichText($is = '') {
855 $value = new PHPExcel_RichText();
857 $value->createText($is);
863 private static function _parseGnumericColour($gnmColour) {
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;
869 // echo 'Excel Colour: ',$RGB,'<br />';