/add-ons/PHPExcel/PHPExcel/Reader/Excel5.php
PHP | 5416 lines | 3082 code | 806 blank | 1528 comment | 378 complexity | b5e81007ba75bc114280ff950053af5d MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, GPL-3.0, Apache-2.0, BSD-3-Clause
Large files files are truncated, but you can click here to view the full file
- <?php
- /**
- * PHPExcel
- *
- * Copyright (c) 2006 - 2009 PHPExcel
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * @category PHPExcel
- * @package PHPExcel_Reader_Excel5
- * @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
- * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
- * @version 1.7.1, 2009-11-02
- */
-
- // Original file header of ParseXL (used as the base for this class):
- // --------------------------------------------------------------------------------
- // Adapted from Excel_Spreadsheet_Reader developed by users bizon153,
- // trex005, and mmp11 (SourceForge.net)
- // http://sourceforge.net/projects/phpexcelreader/
- // Primary changes made by canyoncasa (dvc) for ParseXL 1.00 ...
- // Modelled moreso after Perl Excel Parse/Write modules
- // Added Parse_Excel_Spreadsheet object
- // Reads a whole worksheet or tab as row,column array or as
- // associated hash of indexed rows and named column fields
- // Added variables for worksheet (tab) indexes and names
- // Added an object call for loading individual woorksheets
- // Changed default indexing defaults to 0 based arrays
- // Fixed date/time and percent formats
- // Includes patches found at SourceForge...
- // unicode patch by nobody
- // unpack("d") machine depedency patch by matchy
- // boundsheet utf16 patch by bjaenichen
- // Renamed functions for shorter names
- // General code cleanup and rigor, including <80 column width
- // Included a testcase Excel file and PHP example calls
- // Code works for PHP 5.x
-
- // Primary changes made by canyoncasa (dvc) for ParseXL 1.10 ...
- // http://sourceforge.net/tracker/index.php?func=detail&aid=1466964&group_id=99160&atid=623334
- // Decoding of formula conditions, results, and tokens.
- // Support for user-defined named cells added as an array "namedcells"
- // Patch code for user-defined named cells supports single cells only.
- // NOTE: this patch only works for BIFF8 as BIFF5-7 use a different
- // external sheet reference structure
-
-
- /** PHPExcel root directory */
- if (!defined('PHPEXCEL_ROOT')) {
- /**
- * @ignore
- */
- define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
- }
-
- /** PHPExcel */
- require_once PHPEXCEL_ROOT . 'PHPExcel.php';
-
- /** PHPExcel_Reader_IReader */
- require_once PHPEXCEL_ROOT . 'PHPExcel/Reader/IReader.php';
-
- /** PHPExcel_Reader_Excel5_Escher */
- require_once PHPEXCEL_ROOT . 'PHPExcel/Reader/Excel5/Escher.php';
-
- /** PHPExcel_Shared_Date */
- require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Date.php';
-
- /** PHPExcel_Shared_Excel5 */
- require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Excel5.php';
-
- /** PHPExcel_Shared_Escher */
- require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Escher.php';
-
- /** PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE */
- require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/Escher/DggContainer/BstoreContainer/BSE.php';
-
- /** PHPExcel_Shared_OLERead */
- require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/OLERead.php';
-
- /** PHPExcel_Shared_String */
- require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/String.php';
-
- /** PHPExcel_Cell */
- require_once PHPEXCEL_ROOT . 'PHPExcel/Cell.php';
-
- /** PHPExcel_NamedRange */
- require_once PHPEXCEL_ROOT . 'PHPExcel/NamedRange.php';
-
- /** PHPExcel_Reader_IReadFilter */
- require_once PHPEXCEL_ROOT . 'PHPExcel/Reader/IReadFilter.php';
-
- /** PHPExcel_Reader_DefaultReadFilter */
- require_once PHPEXCEL_ROOT . 'PHPExcel/Reader/DefaultReadFilter.php';
-
- /** PHPExcel_Worksheet_MemoryDrawing */
- require_once PHPEXCEL_ROOT . 'PHPExcel/Worksheet/MemoryDrawing.php';
-
-
- /**
- * PHPExcel_Reader_Excel5
- *
- * This class uses {@link http://sourceforge.net/projects/phpexcelreader/parseXL}
- *
- * @category PHPExcel
- * @package PHPExcel_Reader_Excel5
- * @copyright Copyright (c) 2006 - 2009 PHPExcel (http://www.codeplex.com/PHPExcel)
- */
- class PHPExcel_Reader_Excel5 implements PHPExcel_Reader_IReader
- {
- // ParseXL definitions
- const XLS_BIFF8 = 0x0600;
- const XLS_BIFF7 = 0x0500;
- const XLS_WorkbookGlobals = 0x0005;
- const XLS_Worksheet = 0x0010;
-
- // record identifiers
- const XLS_Type_FORMULA = 0x0006;
- const XLS_Type_EOF = 0x000a;
- const XLS_Type_PROTECT = 0x0012;
- const XLS_Type_PASSWORD = 0x0013;
- const XLS_Type_HEADER = 0x0014;
- const XLS_Type_FOOTER = 0x0015;
- const XLS_Type_EXTERNSHEET = 0x0017;
- const XLS_Type_DEFINEDNAME = 0x0018;
- const XLS_Type_VERTICALPAGEBREAKS = 0x001a;
- const XLS_Type_HORIZONTALPAGEBREAKS = 0x001b;
- const XLS_Type_NOTE = 0x001c;
- const XLS_Type_DATEMODE = 0x0022;
- const XLS_Type_LEFTMARGIN = 0x0026;
- const XLS_Type_RIGHTMARGIN = 0x0027;
- const XLS_Type_TOPMARGIN = 0x0028;
- const XLS_Type_BOTTOMMARGIN = 0x0029;
- const XLS_Type_PRINTGRIDLINES = 0x002b;
- const XLS_Type_FILEPASS = 0x002f;
- const XLS_Type_FONT = 0x0031;
- const XLS_Type_CONTINUE = 0x003c;
- const XLS_Type_PANE = 0x0041;
- const XLS_Type_CODEPAGE = 0x0042;
- const XLS_Type_DEFCOLWIDTH = 0x0055;
- const XLS_Type_OBJ = 0x005d;
- const XLS_Type_COLINFO = 0x007d;
- const XLS_Type_IMDATA = 0x007f;
- const XLS_Type_SHEETPR = 0x0081;
- const XLS_Type_HCENTER = 0x0083;
- const XLS_Type_VCENTER = 0x0084;
- const XLS_Type_SHEET = 0x0085;
- const XLS_Type_PALETTE = 0x0092;
- const XLS_Type_SCL = 0x00a0;
- const XLS_Type_PAGESETUP = 0x00a1;
- const XLS_Type_MULRK = 0x00bd;
- const XLS_Type_MULBLANK = 0x00be;
- const XLS_Type_DBCELL = 0x00d7;
- const XLS_Type_XF = 0x00e0;
- const XLS_Type_MERGEDCELLS = 0x00e5;
- const XLS_Type_MSODRAWINGGROUP = 0x00eb;
- const XLS_Type_MSODRAWING = 0x00ec;
- const XLS_Type_SST = 0x00fc;
- const XLS_Type_LABELSST = 0x00fd;
- const XLS_Type_EXTSST = 0x00ff;
- const XLS_Type_EXTERNALBOOK = 0x01ae;
- const XLS_Type_TXO = 0x01b6;
- const XLS_Type_HYPERLINK = 0x01b8;
- const XLS_Type_DIMENSION = 0x0200;
- const XLS_Type_BLANK = 0x0201;
- const XLS_Type_NUMBER = 0x0203;
- const XLS_Type_LABEL = 0x0204;
- const XLS_Type_BOOLERR = 0x0205;
- const XLS_Type_STRING = 0x0207;
- const XLS_Type_ROW = 0x0208;
- const XLS_Type_INDEX = 0x020b;
- const XLS_Type_ARRAY = 0x0221;
- const XLS_Type_DEFAULTROWHEIGHT = 0x0225;
- const XLS_Type_WINDOW2 = 0x023e;
- const XLS_Type_RK = 0x027e;
- const XLS_Type_STYLE = 0x0293;
- const XLS_Type_FORMAT = 0x041e;
- const XLS_Type_SHAREDFMLA = 0x04bc;
- const XLS_Type_BOF = 0x0809;
- const XLS_Type_RANGEPROTECTION = 0x0868;
- const XLS_Type_SHEETLAYOUT = 0x0862;
- const XLS_Type_UNKNOWN = 0xffff;
-
- /**
- * Read data only?
- *
- * @var boolean
- */
- private $_readDataOnly = false;
-
- /**
- * Restict which sheets should be loaded?
- *
- * @var array
- */
- private $_loadSheetsOnly = null;
-
- /**
- * PHPExcel_Reader_IReadFilter instance
- *
- * @var PHPExcel_Reader_IReadFilter
- */
- private $_readFilter = null;
-
- /**
- * OLE reader
- *
- * @var PHPExcel_Shared_OLERead
- */
- private $_ole;
-
- /**
- * Stream data that is read. Includes workbook globals substream as well as sheet substreams
- *
- * @var string
- */
- private $_data;
-
- /**
- * Size in bytes of $this->_data
- *
- * @var int
- */
- private $_dataSize;
-
- /**
- * Current position in stream
- *
- * @var integer
- */
- private $_pos;
-
- /**
- * Workbook to be returned by the reader.
- *
- * @var PHPExcel
- */
- private $_phpExcel;
-
- /**
- * Worksheet that is currently being built by the reader.
- *
- * @var PHPExcel_Worksheet
- */
- private $_phpSheet;
-
- /**
- * BIFF version
- *
- * @var int
- */
- private $_version;
-
- /**
- * Codepage set in the Excel file being read. Only important for BIFF5 (Excel 5.0 - Excel 95)
- * For BIFF8 (Excel 97 - Excel 2003) this will always have the value 'UTF-16LE'
- *
- * @var string
- */
- private $_codepage;
-
- /**
- * Shared formats
- *
- * @var array
- */
- private $_formats;
-
- /**
- * Shared fonts
- *
- * @var array
- */
- private $_objFonts;
-
- /**
- * Color palette
- *
- * @var array
- */
- private $_palette;
-
- /**
- * Worksheets
- *
- * @var array
- */
- private $_sheets;
-
- /**
- * External books
- *
- * @var array
- */
- private $_externalBooks;
-
- /**
- * REF structures. Only applies to BIFF8.
- *
- * @var array
- */
- private $_ref;
-
- /**
- * Defined names
- *
- * @var array
- */
- private $_definedname;
-
- /**
- * Shared strings. Only applies to BIFF8.
- *
- * @var array
- */
- private $_sst;
-
- /**
- * Panes are frozen? (in sheet currently being read). See WINDOW2 record.
- *
- * @var boolean
- */
- private $_frozen;
-
- /**
- * Fit printout to number of pages? (in sheet currently being read). See SHEETPR record.
- *
- * @var boolean
- */
- private $_isFitToPages;
-
- /**
- * Objects. One OBJ record contributes with one entry.
- *
- * @var array
- */
- private $_objs;
-
- /**
- * The combined MSODRAWINGGROUP data
- *
- * @var string
- */
- private $_drawingGroupData;
-
- /**
- * The combined MSODRAWING data (per sheet)
- *
- * @var string
- */
- private $_drawingData;
-
- /**
- * Keep track of XF index
- *
- * @var int
- */
- private $_xfIndex;
-
- /**
- * Mapping of XF index (that is a cell XF) to final index in cellXf collection
- *
- * @var array
- */
- private $_mapCellXfIndex;
-
- /**
- * Mapping of XF index (that is a style XF) to final index in cellStyleXf collection
- *
- * @var array
- */
- private $_mapCellStyleXfIndex;
-
- /**
- * The shared formulas in a sheet. One SHAREDFMLA record contributes with one value.
- *
- * @var array
- */
- private $_sharedFormulas;
-
- /**
- * The shared formula parts in a sheet. One FORMULA record contributes with one value if it
- * refers to a shared formula.
- *
- * @var array
- */
- private $_sharedFormulaParts;
-
- /**
- * Read data only?
- *
- * @return boolean
- */
- public function getReadDataOnly()
- {
- return $this->_readDataOnly;
- }
-
- /**
- * Set read data only
- *
- * @param boolean $pValue
- * @return PHPExcel_Reader_Excel5
- */
- public function setReadDataOnly($pValue = false)
- {
- $this->_readDataOnly = $pValue;
- return $this;
- }
-
- /**
- * Get which sheets to load
- *
- * @return mixed
- */
- public function getLoadSheetsOnly()
- {
- return $this->_loadSheetsOnly;
- }
-
- /**
- * Set which sheets to load
- *
- * @param mixed $value
- * @return PHPExcel_Reader_Excel5
- */
- public function setLoadSheetsOnly($value = null)
- {
- $this->_loadSheetsOnly = is_array($value) ?
- $value : array($value);
- return $this;
- }
-
- /**
- * Set all sheets to load
- *
- * @return PHPExcel_Reader_Excel5
- */
- public function setLoadAllSheets()
- {
- $this->_loadSheetsOnly = null;
- return $this;
- }
-
- /**
- * Read filter
- *
- * @return PHPExcel_Reader_IReadFilter
- */
- public function getReadFilter() {
- return $this->_readFilter;
- }
-
- /**
- * Set read filter
- *
- * @param PHPExcel_Reader_IReadFilter $pValue
- * @return PHPExcel_Reader_Excel5
- */
- public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) {
- $this->_readFilter = $pValue;
- return $this;
- }
-
- /**
- * Create a new PHPExcel_Reader_Excel5 instance
- */
- public function __construct() {
- $this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
- }
-
- /**
- * Can the current PHPExcel_Reader_IReader read the file?
- *
- * @param string $pFileName
- * @return boolean
- */
- public function canRead($pFilename)
- {
- // Check if file exists
- if (!file_exists($pFilename)) {
- throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
- }
-
- try {
- // Use ParseXL for the hard work.
- $this->_ole = new PHPExcel_Shared_OLERead();
-
- // get excel data
- $res = $this->_ole->read($pFilename);
- return true;
-
- } catch (Exception $e) {
- return false;
- }
- }
-
- /**
- * Loads PHPExcel from file
- *
- * @param string $pFilename
- * @throws Exception
- */
- public function load($pFilename)
- {
- // Initialisations
- $this->_phpExcel = new PHPExcel;
- $this->_phpExcel->removeSheetByIndex(0); // remove 1st sheet
- if (!$this->_readDataOnly) {
- $this->_phpExcel->removeCellStyleXfByIndex(0); // remove the default style
- $this->_phpExcel->removeCellXfByIndex(0); // remove the default style
- }
-
- // Use ParseXL for the hard work.
- $this->_ole = new PHPExcel_Shared_OLERead();
-
- // get excel data
- $res = $this->_ole->read($pFilename);
- $this->_data = $this->_ole->getWorkBook();
-
- // total byte size of Excel data (workbook global substream + sheet substreams)
- $this->_dataSize = strlen($this->_data);
-
- // initialize
- $this->_pos = 0;
- $this->_codepage = 'CP1252';
- $this->_formats = array();
- $this->_objFonts = array();
- $this->_palette = array();
- $this->_sheets = array();
- $this->_externalBooks = array();
- $this->_ref = array();
- $this->_definedname = array();
- $this->_sst = array();
- $this->_drawingGroupData = '';
- $this->_xfIndex = '';
- $this->_mapCellXfIndex = array();
- $this->_mapCellStyleXfIndex = array();
-
- // Parse Workbook Global Substream
- while ($this->_pos < $this->_dataSize) {
- $code = $this->_GetInt2d($this->_data, $this->_pos);
-
- switch ($code) {
- case self::XLS_Type_BOF:
- $pos = $this->_pos;
- $length = $this->_GetInt2d($this->_data, $pos + 2);
- $recordData = substr($this->_data, $pos + 4, $length);
-
- // offset: 0; size: 2; BIFF version
- $this->_version = $this->_GetInt2d($this->_data, $pos + 4);
-
- if (($this->_version != self::XLS_BIFF8) && ($this->_version != self::XLS_BIFF7)) {
- return false;
- }
-
- // offset: 2; size: 2; type of stream
- $substreamType = $this->_GetInt2d($this->_data, $pos + 6);
- if ($substreamType != self::XLS_WorkbookGlobals) {
- return false;
- }
- $this->_pos += 4 + $length;
- break;
-
- case self::XLS_Type_FILEPASS: $this->_readFilepass(); break;
- case self::XLS_Type_CODEPAGE: $this->_readCodepage(); break;
- case self::XLS_Type_DATEMODE: $this->_readDateMode(); break;
- case self::XLS_Type_FONT: $this->_readFont(); break;
- case self::XLS_Type_FORMAT: $this->_readFormat(); break;
- case self::XLS_Type_XF: $this->_readXf(); break;
- case self::XLS_Type_STYLE: $this->_readStyle(); break;
- case self::XLS_Type_PALETTE: $this->_readPalette(); break;
- case self::XLS_Type_SHEET: $this->_readSheet(); break;
- case self::XLS_Type_EXTERNALBOOK: $this->_readExternalBook(); break;
- case self::XLS_Type_EXTERNSHEET: $this->_readExternSheet(); break;
- case self::XLS_Type_DEFINEDNAME: $this->_readDefinedName(); break;
- case self::XLS_Type_MSODRAWINGGROUP: $this->_readMsoDrawingGroup(); break;
- case self::XLS_Type_SST: $this->_readSst(); break;
- case self::XLS_Type_EOF: $this->_readDefault(); break 2;
- default: $this->_readDefault(); break;
- }
- }
-
- // Resolve indexed colors for font, fill, and border colors
- // Cannot be resolved already in XF record, because PALETTE record comes afterwards
- if (!$this->_readDataOnly) {
- foreach ($this->_objFonts as $objFont) {
- $color = $this->_readColor($objFont->colorIndex);
- $objFont->getColor()->setRGB($color['rgb']);
- }
-
- foreach ($this->_phpExcel->getCellXfCollection() as $objStyle) {
- // fill start and end color
- $startColor = $this->_readColor($objStyle->getFill()->startcolorIndex);
- $objStyle->getFill()->getStartColor()->setRGB($startColor['rgb']);
-
- $endColor = $this->_readColor($objStyle->getFill()->endcolorIndex);
- $objStyle->getFill()->getEndColor()->setRGB($endColor['rgb']);
-
- // border colors
- $borderTopColor = $this->_readColor($objStyle->getBorders()->getTop()->colorIndex);
- $objStyle->getBorders()->getTop()->getColor()->setRGB($borderTopColor['rgb']);
-
- $borderRightColor = $this->_readColor($objStyle->getBorders()->getRight()->colorIndex);
- $objStyle->getBorders()->getRight()->getColor()->setRGB($borderRightColor['rgb']);
-
- $borderBottomColor = $this->_readColor($objStyle->getBorders()->getBottom()->colorIndex);
- $objStyle->getBorders()->getBottom()->getColor()->setRGB($borderBottomColor['rgb']);
-
- $borderLeftColor = $this->_readColor($objStyle->getBorders()->getLeft()->colorIndex);
- $objStyle->getBorders()->getLeft()->getColor()->setRGB($borderLeftColor['rgb']);
- }
- }
-
- // treat MSODRAWINGGROUP records, workbook-level Escher
- if (!$this->_readDataOnly && $this->_drawingGroupData) {
- $escherWorkbook = new PHPExcel_Shared_Escher();
- $reader = new PHPExcel_Reader_Excel5_Escher($escherWorkbook);
- $escherWorkbook = $reader->load($this->_drawingGroupData);
-
- // debug Escher stream
- //$debug = new Debug_Escher(new PHPExcel_Shared_Escher());
- //$debug->load($this->_drawingGroupData);
- }
-
- // Parse the individual sheets
- foreach ($this->_sheets as $sheet) {
-
- // check if sheet should be skipped
- if (isset($this->_loadSheetsOnly) && !in_array($sheet['name'], $this->_loadSheetsOnly)) {
- continue;
- }
-
- // add sheet to PHPExcel object
- $this->_phpSheet = $this->_phpExcel->createSheet();
- $this->_phpSheet->setTitle($sheet['name']);
- $this->_phpSheet->setSheetState($sheet['sheetState']);
-
- $this->_pos = $sheet['offset'];
-
- // Initialize isFitToPages. May change after reading SHEETPR record.
- $this->_isFitToPages = false;
-
- // Initialize drawingData
- $this->_drawingData = '';
-
- // Initialize objs
- $this->_objs = array();
-
- // Initialize shared formula parts
- $this->_sharedFormulaParts = array();
-
- // Initialize shared formulas
- $this->_sharedFormulas = array();
-
- while ($this->_pos < $this->_dataSize) {
- $code = $this->_GetInt2d($this->_data, $this->_pos);
-
- switch ($code) {
- case self::XLS_Type_BOF:
- $length = $this->_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // do not use this version information for anything
- // it is unreliable (OpenOffice doc, 5.8), use only version information from the global stream
-
- // offset: 2; size: 2; type of the following data
- $substreamType = $this->_GetInt2d($recordData, 2);
- if ($substreamType != self::XLS_Worksheet) {
- break 2;
- }
- break;
-
- case self::XLS_Type_PRINTGRIDLINES: $this->_readPrintGridlines(); break;
- case self::XLS_Type_DEFAULTROWHEIGHT: $this->_readDefaultRowHeight(); break;
- case self::XLS_Type_SHEETPR: $this->_readSheetPr(); break;
- case self::XLS_Type_HORIZONTALPAGEBREAKS: $this->_readHorizontalPageBreaks(); break;
- case self::XLS_Type_VERTICALPAGEBREAKS: $this->_readVerticalPageBreaks(); break;
- case self::XLS_Type_HEADER: $this->_readHeader(); break;
- case self::XLS_Type_FOOTER: $this->_readFooter(); break;
- case self::XLS_Type_HCENTER: $this->_readHcenter(); break;
- case self::XLS_Type_VCENTER: $this->_readVcenter(); break;
- case self::XLS_Type_LEFTMARGIN: $this->_readLeftMargin(); break;
- case self::XLS_Type_RIGHTMARGIN: $this->_readRightMargin(); break;
- case self::XLS_Type_TOPMARGIN: $this->_readTopMargin(); break;
- case self::XLS_Type_BOTTOMMARGIN: $this->_readBottomMargin(); break;
- case self::XLS_Type_PAGESETUP: $this->_readPageSetup(); break;
- case self::XLS_Type_PROTECT: $this->_readProtect(); break;
- case self::XLS_Type_PASSWORD: $this->_readPassword(); break;
- case self::XLS_Type_DEFCOLWIDTH: $this->_readDefColWidth(); break;
- case self::XLS_Type_COLINFO: $this->_readColInfo(); break;
- case self::XLS_Type_DIMENSION: $this->_readDefault(); break;
- case self::XLS_Type_ROW: $this->_readRow(); break;
- case self::XLS_Type_DBCELL: $this->_readDefault(); break;
- case self::XLS_Type_RK: $this->_readRk(); break;
- case self::XLS_Type_LABELSST: $this->_readLabelSst(); break;
- case self::XLS_Type_MULRK: $this->_readMulRk(); break;
- case self::XLS_Type_NUMBER: $this->_readNumber(); break;
- case self::XLS_Type_FORMULA: $this->_readFormula(); break;
- case self::XLS_Type_SHAREDFMLA: $this->_readSharedFmla(); break;
- case self::XLS_Type_BOOLERR: $this->_readBoolErr(); break;
- case self::XLS_Type_MULBLANK: $this->_readMulBlank(); break;
- case self::XLS_Type_LABEL: $this->_readLabel(); break;
- case self::XLS_Type_BLANK: $this->_readBlank(); break;
- case self::XLS_Type_MSODRAWING: $this->_readMsoDrawing(); break;
- case self::XLS_Type_OBJ: $this->_readObj(); break;
- case self::XLS_Type_WINDOW2: $this->_readWindow2(); break;
- case self::XLS_Type_SCL: $this->_readScl(); break;
- case self::XLS_Type_PANE: $this->_readPane(); break;
- case self::XLS_Type_MERGEDCELLS: $this->_readMergedCells(); break;
- case self::XLS_Type_HYPERLINK: $this->_readHyperLink(); break;
- case self::XLS_Type_SHEETLAYOUT: $this->_readSheetLayout(); break;
- case self::XLS_Type_RANGEPROTECTION: $this->_readRangeProtection(); break;
- //case self::XLS_Type_IMDATA: $this->_readImData(); break;
- case self::XLS_Type_CONTINUE: $this->_readContinue(); break;
- case self::XLS_Type_EOF: $this->_readDefault(); break 2;
- default: $this->_readDefault(); break;
- }
-
- }
-
- // treat MSODRAWING records, sheet-level Escher
- if (!$this->_readDataOnly && $this->_drawingData) {
- $escherWorksheet = new PHPExcel_Shared_Escher();
- $reader = new PHPExcel_Reader_Excel5_Escher($escherWorksheet);
- $escherWorksheet = $reader->load($this->_drawingData);
-
- // debug Escher stream
- //$debug = new Debug_Escher(new PHPExcel_Shared_Escher());
- //$debug->load($this->_drawingData);
-
- // get all spContainers in one long array, so they can be mapped to OBJ records
- $allSpContainers = $escherWorksheet->getDgContainer()->getSpgrContainer()->getAllSpContainers();
- }
-
- // treat OBJ records
- foreach ($this->_objs as $n => $obj) {
-
- // the first shape container never has a corresponding OBJ record, hence $n + 1
- $spContainer = $allSpContainers[$n + 1];
-
- // we skip all spContainers that are a part of a group shape since we cannot yet handle those
- if ($spContainer->getNestingLevel() > 1) {
- continue;
- }
-
- // calculate the width and height of the shape
- list($startColumn, $startRow) = PHPExcel_Cell::coordinateFromString($spContainer->getStartCoordinates());
- list($endColumn, $endRow) = PHPExcel_Cell::coordinateFromString($spContainer->getEndCoordinates());
-
- $startOffsetX = $spContainer->getStartOffsetX();
- $startOffsetY = $spContainer->getStartOffsetY();
- $endOffsetX = $spContainer->getEndOffsetX();
- $endOffsetY = $spContainer->getEndOffsetY();
-
- $width = PHPExcel_Shared_Excel5::getDistanceX($this->_phpSheet, $startColumn, $startOffsetX, $endColumn, $endOffsetX);
- $height = PHPExcel_Shared_Excel5::getDistanceY($this->_phpSheet, $startRow, $startOffsetY, $endRow, $endOffsetY);
-
- // calculate offsetX and offsetY of the shape
- $offsetX = $startOffsetX * PHPExcel_Shared_Excel5::sizeCol($this->_phpSheet, $startColumn) / 1024;
- $offsetY = $startOffsetY * PHPExcel_Shared_Excel5::sizeRow($this->_phpSheet, $startRow) / 256;
-
- switch ($obj['type']) {
-
- case 0x08:
- // picture
-
- // get index to BSE entry (1-based)
- $BSEindex = $spContainer->getOPT(0x0104);
- $BSECollection = $escherWorkbook->getDggContainer()->getBstoreContainer()->getBSECollection();
- $BSE = $BSECollection[$BSEindex - 1];
- $blipType = $BSE->getBlipType();
-
- // need check because some blip types are not supported by Escher reader such as EMF
- if ($blip = $BSE->getBlip()) {
- $ih = imagecreatefromstring($blip->getData());
- $drawing = new PHPExcel_Worksheet_MemoryDrawing();
- $drawing->setImageResource($ih);
-
- // width, height, offsetX, offsetY
- $drawing->setResizeProportional(false);
- $drawing->setWidth($width);
- $drawing->setHeight($height);
- $drawing->setOffsetX($offsetX);
- $drawing->setOffsetY($offsetY);
-
- switch ($blipType) {
-
- case PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_JPEG:
- $drawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
- $drawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_JPEG);
- break;
-
- case PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_PNG:
- $drawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_PNG);
- $drawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_PNG);
- break;
- }
-
- $drawing->setWorksheet($this->_phpSheet);
- $drawing->setCoordinates($spContainer->getStartCoordinates());
- }
-
- break;
-
- default:
- // other object type
- break;
-
- }
- }
-
- // treat SHAREDFMLA records
- if ($this->_version == self::XLS_BIFF8) {
- foreach ($this->_sharedFormulaParts as $cell => $baseCell) {
- $formula = $this->_getFormulaFromStructure($this->_sharedFormulas[$baseCell], $cell);
- $this->_phpSheet->getCell($cell)->setValueExplicit('=' . $formula, PHPExcel_Cell_DataType::TYPE_FORMULA);
- }
- }
- }
-
- // add the named ranges (defined names)
- foreach ($this->_definedname as $definedName) {
- if ($definedName['isBuiltInName']) {
- switch ($definedName['name']) {
-
- case pack('C', 0x06):
- // print area
- // in general, formula looks like this: Foo!$C$7:$J$66,Bar!$A$1:$IV$2
-
- $ranges = explode(',', $definedName['formula']); // FIXME: what if sheetname contains comma?
-
- foreach ($ranges as $range) {
- // $range should look like this one of these
- // Foo!$C$7:$J$66
- // Bar!$A$1:$IV$2
-
- $explodes = explode('!', $range);
-
- if (count($explodes) == 2) {
- if ($docSheet = $this->_phpExcel->getSheetByName($explodes[0])) {
- $extractedRange = $explodes[1];
- $extractedRange = str_replace('$', '', $extractedRange);
- $docSheet->getPageSetup()->setPrintArea($extractedRange);
- }
- }
- }
- break;
-
- case pack('C', 0x07):
- // print titles (repeating rows)
- // Assuming BIFF8, there are 3 cases
- // 1. repeating rows
- // formula looks like this: Sheet!$A$1:$IV$2
- // rows 1-2 repeat
- // 2. repeating columns
- // formula looks like this: Sheet!$A$1:$B$65536
- // columns A-B repeat
- // 3. both repeating rows and repeating columns
- // formula looks like this: Sheet!$A$1:$B$65536,Sheet!$A$1:$IV$2
-
- $ranges = explode(',', $definedName['formula']); // FIXME: what if sheetname contains comma?
-
- foreach ($ranges as $range) {
- // $range should look like this one of these
- // Sheet!$A$1:$B$65536
- // Sheet!$A$1:$IV$2
-
- $explodes = explode('!', $range);
-
- if (count($explodes) == 2) {
- if ($docSheet = $this->_phpExcel->getSheetByName($explodes[0])) {
-
- $extractedRange = $explodes[1];
- $extractedRange = str_replace('$', '', $extractedRange);
-
- $coordinateStrings = explode(':', $extractedRange);
- if (count($coordinateStrings) == 2) {
- list($firstColumn, $firstRow) = PHPExcel_Cell::coordinateFromString($coordinateStrings[0]);
- list($lastColumn, $lastRow) = PHPExcel_Cell::coordinateFromString($coordinateStrings[1]);
-
- if ($firstColumn == 'A' and $lastColumn == 'IV') {
- // then we have repeating rows
- $docSheet->getPageSetup()->setRowsToRepeatAtTop(array($firstRow, $lastRow));
- } elseif ($firstRow == 1 and $lastRow == 65536) {
- // then we have repeating columns
- $docSheet->getPageSetup()->setColumnsToRepeatAtLeft(array($firstColumn, $lastColumn));
- }
- }
- }
- }
- }
- break;
-
- }
- } else {
- // Extract range
- $explodes = explode('!', $definedName['formula']);
-
- if (count($explodes) == 2) {
- if ($docSheet = $this->_phpExcel->getSheetByName($explodes[0])) {
- $extractedRange = $explodes[1];
- $extractedRange = str_replace('$', '', $extractedRange);
-
- $this->_phpExcel->addNamedRange( new PHPExcel_NamedRange((string)$definedName['name'], $docSheet, $extractedRange, false) );
- }
- }
- }
- }
-
- return $this->_phpExcel;
- }
-
- /**
- * Reads a general type of BIFF record. Does nothing except for moving stream pointer forward to next record.
- */
- private function _readDefault()
- {
- $length = $this->_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
- }
-
- /**
- * FILEPASS
- *
- * This record is part of the File Protection Block. It
- * contains information about the read/write password of the
- * file. All record contents following this record will be
- * encrypted.
- *
- * -- "OpenOffice.org's Documentation of the Microsoft
- * Excel File Format"
- */
- private function _readFilepass()
- {
- $length = $this->_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- throw new Exception('Cannot read encrypted file');
- }
-
- /**
- * CODEPAGE
- *
- * This record stores the text encoding used to write byte
- * strings, stored as MS Windows code page identifier.
- *
- * -- "OpenOffice.org's Documentation of the Microsoft
- * Excel File Format"
- */
- private function _readCodepage()
- {
- $length = $this->_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // offset: 0; size: 2; code page identifier
- $codepage = $this->_GetInt2d($recordData, 0);
-
- switch ($codepage) {
-
- case 367: // ASCII
- $this->_codepage ="ASCII";
- break;
-
- case 437: //OEM US
- $this->_codepage ="CP437";
- break;
-
- case 720: //OEM Arabic
- // currently not supported by libiconv
- $this->_codepage = "";
- break;
-
- case 737: //OEM Greek
- $this->_codepage ="CP737";
- break;
-
- case 775: //OEM Baltic
- $this->_codepage ="CP775";
- break;
-
- case 850: //OEM Latin I
- $this->_codepage ="CP850";
- break;
-
- case 852: //OEM Latin II (Central European)
- $this->_codepage ="CP852";
- break;
-
- case 855: //OEM Cyrillic
- $this->_codepage ="CP855";
- break;
-
- case 857: //OEM Turkish
- $this->_codepage ="CP857";
- break;
-
- case 858: //OEM Multilingual Latin I with Euro
- $this->_codepage ="CP858";
- break;
-
- case 860: //OEM Portugese
- $this->_codepage ="CP860";
- break;
-
- case 861: //OEM Icelandic
- $this->_codepage ="CP861";
- break;
-
- case 862: //OEM Hebrew
- $this->_codepage ="CP862";
- break;
-
- case 863: //OEM Canadian (French)
- $this->_codepage ="CP863";
- break;
-
- case 864: //OEM Arabic
- $this->_codepage ="CP864";
- break;
-
- case 865: //OEM Nordic
- $this->_codepage ="CP865";
- break;
-
- case 866: //OEM Cyrillic (Russian)
- $this->_codepage ="CP866";
- break;
-
- case 869: //OEM Greek (Modern)
- $this->_codepage ="CP869";
- break;
-
- case 874: //ANSI Thai
- $this->_codepage ="CP874";
- break;
-
- case 932: //ANSI Japanese Shift-JIS
- $this->_codepage ="CP932";
- break;
-
- case 936: //ANSI Chinese Simplified GBK
- $this->_codepage ="CP936";
- break;
-
- case 949: //ANSI Korean (Wansung)
- $this->_codepage ="CP949";
- break;
-
- case 950: //ANSI Chinese Traditional BIG5
- $this->_codepage ="CP950";
- break;
-
- case 1200: //UTF-16 (BIFF8)
- $this->_codepage ="UTF-16LE";
- break;
-
- case 1250:// ANSI Latin II (Central European)
- $this->_codepage ="CP1250";
- break;
-
- case 1251: //ANSI Cyrillic
- $this->_codepage ="CP1251";
- break;
-
- case 1252: //ANSI Latin I (BIFF4-BIFF7)
- $this->_codepage ="CP1252";
- break;
-
- case 1253: //ANSI Greek
- $this->_codepage ="CP1253";
- break;
-
- case 1254: //ANSI Turkish
- $this->_codepage ="CP1254";
- break;
-
- case 1255: //ANSI Hebrew
- $this->_codepage ="CP1255";
- break;
-
- case 1256: //ANSI Arabic
- $this->_codepage ="CP1256";
- break;
-
- case 1257: //ANSI Baltic
- $this->_codepage ="CP1257";
- break;
-
- case 1258: //ANSI Vietnamese
- $this->_codepage ="CP1258";
- break;
-
- case 1361: //ANSI Korean (Johab)
- $this->_codepage ="CP1361";
- break;
-
- case 10000: //Apple Roman
- $this->_codepage = 'MAC';
- break;
-
- case 32768: //Apple Roman
- $this->_codepage = 'MAC';
- break;
-
- case 32769: //ANSI Latin I (BIFF2-BIFF3)
- // currently not supported by libiconv
- $this->_codepage = "";
- break;
-
- }
- }
-
- /**
- * DATEMODE
- *
- * This record specifies the base date for displaying date
- * values. All dates are stored as count of days past this
- * base date. In BIFF2-BIFF4 this record is part of the
- * Calculation Settings Block. In BIFF5-BIFF8 it is
- * stored in the Workbook Globals Substream.
- *
- * -- "OpenOffice.org's Documentation of the Microsoft
- * Excel File Format"
- */
- private function _readDateMode()
- {
- $length = $this->_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- // offset: 0; size: 2; 0 = base 1900, 1 = base 1904
- PHPExcel_Shared_Date::setExcelCalendar(PHPExcel_Shared_Date::CALENDAR_WINDOWS_1900);
- if (ord($recordData{0}) == 1) {
- PHPExcel_Shared_Date::setExcelCalendar(PHPExcel_Shared_Date::CALENDAR_MAC_1904);
- }
- }
-
- /**
- * Read a FONT record
- */
- private function _readFont()
- {
- $length = $this->_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if (!$this->_readDataOnly) {
- $objFont = new PHPExcel_Style_Font();
-
- // offset: 0; size: 2; height of the font (in twips = 1/20 of a point)
- $size = $this->_GetInt2d($recordData, 0);
- $objFont->setSize($size / 20);
-
- // offset: 2; size: 2; option flags
- // bit: 0; mask 0x0001; bold (redundant in BIFF5-BIFF8)
- // bit: 1; mask 0x0002; italic
- $isItalic = (0x0002 & $this->_GetInt2d($recordData, 2)) >> 1;
- if ($isItalic) $objFont->setItalic(true);
-
- // bit: 2; mask 0x0004; underlined (redundant in BIFF5-BIFF8)
- // bit: 3; mask 0x0008; strike
- $isStrike = (0x0008 & $this->_GetInt2d($recordData, 2)) >> 3;
- if ($isStrike) $objFont->setStrikethrough(true);
-
- // offset: 4; size: 2; colour index
- $colorIndex = $this->_GetInt2d($recordData, 4);
- $objFont->colorIndex = $colorIndex;
-
- // offset: 6; size: 2; font weight
- $weight = $this->_GetInt2d($recordData, 6);
- switch ($weight) {
- case 0x02BC:
- $objFont->setBold(true);
- break;
- }
-
- // offset: 8; size: 2; escapement type
- $escapement = $this->_GetInt2d($recordData, 8);
- switch ($escapement) {
- case 0x0001:
- $objFont->setSuperScript(true);
- break;
- case 0x0002:
- $objFont->setSubScript(true);
- break;
- }
-
- // offset: 10; size: 1; underline type
- $underlineType = ord($recordData{10});
- switch ($underlineType) {
- case 0x00:
- break; // no underline
- case 0x01:
- $objFont->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);
- break;
- case 0x02:
- $objFont->setUnderline(PHPExcel_Style_Font::UNDERLINE_DOUBLE);
- break;
- case 0x21:
- $objFont->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLEACCOUNTING);
- break;
- case 0x22:
- $objFont->setUnderline(PHPExcel_Style_Font::UNDERLINE_DOUBLEACCOUNTING);
- break;
- }
-
- // offset: 11; size: 1; font family
- // offset: 12; size: 1; character set
- // offset: 13; size: 1; not used
- // offset: 14; size: var; font name
- if ($this->_version == self::XLS_BIFF8) {
- $string = $this->_readUnicodeStringShort(substr($recordData, 14));
- } else {
- $string = $this->_readByteStringShort(substr($recordData, 14));
- }
- $objFont->setName($string['value']);
-
- $this->_objFonts[] = $objFont;
- }
- }
-
- /**
- * FORMAT
- *
- * This record contains information about a number format.
- * All FORMAT records occur together in a sequential list.
- *
- * In BIFF2-BIFF4 other records referencing a FORMAT record
- * contain a zero-based index into this list. From BIFF5 on
- * the FORMAT record contains the index itself that will be
- * used by other records.
- *
- * -- "OpenOffice.org's Documentation of the Microsoft
- * Excel File Format"
- */
- private function _readFormat()
- {
- $length = $this->_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- if (!$this->_readDataOnly) {
- $indexCode = $this->_GetInt2d($recordData, 0);
-
- if ($this->_version == self::XLS_BIFF8) {
- $string = $this->_readUnicodeStringLong(substr($recordData, 2));
- } else {
- // BIFF7
- $string = $this->_readByteStringShort(substr($recordData, 2));
- }
-
- $formatString = $string['value'];
- $this->_formats[$indexCode] = $formatString;
- }
- }
-
- /**
- * XF - Extended Format
- *
- * This record contains formatting information for cells, rows, columns or styles.
- * According to http://support.microsoft.com/kb/147732 there are always at least 15 cell style XF
- * and 1 cell XF.
- * Inspection of Excel files generated by MS Office Excel shows that XF records 0-14 are cell style XF
- * and XF record 15 is a cell XF
- * We only read the first cell style XF and skip the remaining cell style XF records
- * We read all cell XF records.
- *
- * -- "OpenOffice.org's Documentation of the Microsoft
- * Excel File Format"
- */
- private function _readXf()
- {
- $length = $this->_GetInt2d($this->_data, $this->_pos + 2);
- $recordData = substr($this->_data, $this->_pos + 4, $length);
-
- // move stream pointer to next record
- $this->_pos += 4 + $length;
-
- $objStyle = new PHPExcel_Style();
-
- if (!$this->_readDataOnly) {
- // offset: 0; size: 2; Index to FONT record
- if ($this->_GetInt2d($recordData, 0) < 4) {
- $fontIndex = $this->_GetInt2d($recordData, 0);
- } else {
- // this has to do with that index 4 is omitted in all BIFF versions for some strange reason
- // check the OpenOffice documentation of the FONT record
- $fontIndex = $this->_GetInt2d($recordData, 0) - 1;
- }
- $objStyle->setFont($this->_objFonts[$fontIndex]);
-
- // offset: 2; size: 2; Index to FORMAT record
- $numberFormatIndex = $this->_GetInt2d($recordData, 2);
- if (isset($this->_formats[$numberFormatIndex])) {
- // then we have user-defined format code
- $numberformat = array('code' => $this->_formats[$numberFormatIndex]);
- } elseif (($code = PHPExcel_Style_NumberFormat::builtInFormatCode($numberFormatIndex)) !== '') {
- // then we have built-in format code
- $numberformat = array('code' => $code);
- } else {
- // we set the general format code
- $numberformat = array('code' => 'General');
- }
- $objStyle->getNumberFormat()->setFormatCode($numberformat['code']);
-
- // offset: 4; size: 2; XF type, cell protection, and parent style XF
- // bit 2-0; mask 0x0007; XF_TYPE_PROT
- $xfTypeProt = $this->_GetInt2d($recordData, 4);
- // bit 0; mask 0x01; 1 = cell is locked
- $isLocked = (0x01 & $xfTypeProt) >> 0;
- $objStyle->getProtection()->setLocked($isLocked ?
- PHPExcel_Style_Protection::PROTECTION_INHERIT : PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);
-
- // bit 1; mask 0x02; 1 = Formula is hidden
- $isHidden = (0x02 & $xfTypeProt) >> 1;
- $objStyle->getProtection()->setHidden($isHidden ?
- PHPExcel_Style_Protection::PROTECTION_PROTECTED : PHPExcel_Style_Protection::PROTECTION_UNPROTECTED);
-
- // bit 2; mask 0x04; 0 = Cell XF, 1 = Cell Style XF
- $isCellStyleXf = (0x04 & $xfTypeProt) >> 2;
-
- // offset: 6; size: 1; Alignment and text break
- // bit 2-0, mask 0x07; horizontal alignment
- $horAlign = (0x07 & ord($recordData{6})) >> 0;
- switch ($horAlign) {
- case 0:
- $objStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_GENERAL);
- break;
- case 1:
- $objStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
- break;
- case 2:
- $objStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- break;
- case 3:
- $objStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
- break;
- case 5:
- $objStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY);
- break;
- case 6:
- $objStyle->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS);
- break;
- }
- // bit 3, mask 0x08; wrap text
- $wrapText = (0x08 & ord($recordData{6})) >> 3;
- switch ($wrapText) {
- case 0:
- $objStyle->getAlignment()->setWrapText(false);
- break;
- case 1:
- $objStyle->getAlignment()->setWrapText(true);
- break;
- }
- // bit 6-4, mask 0x70; vertical alignment
- $vertAlign = (0x70 & ord($recordData{6})) >> 4;
- switch ($vertAlign) {
- case 0:
- $objStyle->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
- break;
- case 1:
- $objStyle->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
- break;
- case 2:
- $objStyle->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_BOTTOM);
- break;
- case 3:
- $objStyle->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_JUSTIFY);
- break;
- }
-
- if ($this->_version == self::XLS_BIFF8) {
- // offset: 7; size: 1; XF_ROTATION: Text rotation angle
- $angle = ord($recordData{7});
- $rotation = 0;
- if ($angle <= 90) {
- $rotation = $angle;
- } else if ($angle <= 180) {
- $rotation = 90 - $angle;
- } else if ($angle == 255) {
- $rotation = -165;
- }
- $objStyle->getAlignment()->setTextRotation($rotation);
-
- // offset: 8; size: 1; Indentation, shrink to cell size, and text direction
- // bit: 3-0; mask: 0x0F; indent level
- $indent = (0x0F & ord($recordData{8})) >> 0;
- $objStyle->getAlignment()->setIndent($indent);
-
- // bit: 4; mask: 0x10; 1 = shrink content to fit into cell
- $shrinkToFit = (0x10 & ord($recordData{8})) >> 4;
- switch ($shrinkToFit) {
- case 0:
- $objStyle->getAlignment()->setShrinkToFit(false);
- break;
- case 1:
- $objStyle->getAlignment()->setShrinkToFit(true);
- break;
- }
-
- // offset: 9; size: 1; Flags used for attribute groups
-
- // offset: 10; size: 4; Cell border lines and background area
- // bit: 3-0; mask: 0x0000000F; left style
- if ($bordersLeftStyle = $this->_mapBorderStyle((0x0000000F & $this->_GetInt4d($recordData, 10)) >> 0)) {
- $objStyle->getBorders()->getLeft()->setBorderStyle($bordersLeftStyle);
- }
- // bit: 7-4; mask: 0x000000F0; right style
- if ($bordersRightStyle = $this->_mapBorderStyle((0x000000F0 & $this->_GetInt4d($recordData, 10)) >> 4)) {
- $objStyle->getBorders()->getRight()->setBorderStyle($bordersRightStyle);
- }
- // bit: 11-8; mask: 0x00000F00; top style
- if ($bordersTopStyle = $this->_mapBorderStyle((0x00000F00 & $this->_GetInt4d($recordData, 10)) >> 8)) {
- $objStyle->getBorders()->getTop()->setBorderStyle($bordersTopStyle);
- }
- // bit: 15-12; mask: 0x0000F000; bottom style
- if ($bordersBottomStyle = $this->_mapBorderStyle((0x0000F000 & $this->_GetInt4d($recordData, 10)) >> 12)) {
- $objStyle->getBorders()->getBottom()->setBorderStyle($bordersBottomStyle);
- }
- // bit: 22-16; mask: 0x007F0000; left color
- $objStyle->getBorders()->getLeft()->colorIndex = (0x007F0000 & $this->_GetInt4d($recordData, 10)) >> 16;
-
- // bit: 29-23; mask: 0x3F800000; right color
- $objStyle->getBorders()->getRight()->colorIndex = (0x3F800000 & $this->_GetInt4d($recordData, 10)) >> 23;
-
- // offset: 14; size: 4;
- // bit: 6-0; mask: 0x0000007F; top color
- $objStyle->getBorders()->getTop()->colorIndex = (0x0000007F & $this->_GetInt4d($recordData, 14)) >> 0;
-
- // bit: 13-7; mask: 0x00003F80; bottom color
- $objStyle->getBorders()->getBottom()->colorIndex = (0x00003F80 & $this->_GetInt4d($recordData, 14)) >> 7;
-
- // bit: 31-26; mask: 0xFC000000 fill pattern
- if ($fillType = $this->_mapFillPattern((0xFC000000 & $this->_GetInt4d($recordData, 14)) >> 26)) {
- $objStyle->getFill()->setFillType($fillType);
- }
- // offset: 18; size: 2; pattern and background colour
- // bit: 6-0; mask: 0x007F; color index for pattern color
- $objStyle->getFill()->startcolorIndex = (0x007F & $this->_GetInt2d($recordData, 18)) >> 0;
-
- // bit: 13-7; mask: 0x3F80; color index for pattern background
- $objStyle->getFill()->endcolorIndex = (0x3F80 & $this->_GetInt2d($recordData, 18)) >> 7;
- } else {
- // BIFF5
-
- // offset: 7; size: 1; Text orientation and flags
- $orientationAndFlags = ord($recordData{7});
-
- // bit: 1-0; mask: 0x03; XF_ORIENTATION: Text orientation
- $xfOrientation = (0x03 & $orientationAndFlags) >> 0;
- switch ($xfOrientation) {
- case 0:
- $objStyle->getAlignment()->setTextRotation(0);
- break;
- case 1:
- $objStyle->getAlignment()->setTextRotation(-165);
- break;
- case 2:
- $objStyle->getAlignment()->setTextRotation(90);
- break;
- case 3:
- $objStyle->getAlignment()->setTextRotation(-90);
- break;
- }
-
- // offset: 8; size: 4; cell border lines and background area
- $borderAndBackground = $this->_GetInt4d($recordData, 8);
-
- // bit: 6-0; mask: 0x0000007F; color index for pattern color
- $objStyle->getFill()->startcolorIndex = (0x0000007F & $borderAndBackground) >> 0;
-
- // bit: 13-7; mask: 0x00003F80; color index for pattern background
- $objStyle->getFill()->endcolorIndex = (0x00003F80 & $borderAndBackground) >> 7;
-
- // bit: 21-16; mask: 0x003F0000; fill pattern
- $objStyle->getFill()->setFillType($this->_mapFillPattern((0x003F0000 & $borderAndBackground) >> 16));
-
- // bit: 24-22; mask: 0x01C00000; bottom line style
- $objStyle->getBorders()->getBottom()->setBorderStyle($this->_mapBorderStyle((0x01C00000 & $borderAndBackground) >> 22));
-
- // bit: 31-25; mask: 0xFE000000; bottom line color
- $objStyle->getBorders()->getBottom()->colorIndex = (0xFE000000 & $borderAndBackground) >> 25;
-
- // offset: 12; size: 4; cell border lines
- $borderLines = $this->_GetInt4d($recordData, 12);
-
- // bit: 2-0; mask: 0x00000007; top line style
- $objStyle->getBorders()->getTop()->setBorderStyle($this->_mapBorderStyle((0x00000007 & $borderLines) >> 0));
-
- // bit: 5-3; mask: 0x00000038; left line style
- $objStyle->getBorders()->getLeft()->setBorderStyle($this->_mapBorderStyle((0x00000038 & $borderLines) >> 3));
-
- // bit: 8-6; mask: 0x000001C0; right line style
- $objStyle->getBorders()->getRight()->setBorderStyle($this->_mapBorderStyle((0x000001C0 & $borderLines) >> 6));
-
- // bit: 15-9; mask: 0x0000FE00; top line color index
- $objStyle->getBorders()->getTop()->colorIndex = (0x0000FE00 & $borderLines) >> 9;
-
- // bit: 22-16; mask: 0x007F0000; left line color index
- $objStyle->getBorders()->getLeft()->colorIndex = (0x007F0000 & $borderLines) >> 16;
-
- // bit: 29-23; mask: 0x3F800000; right line color index
- $objStyle->getBorders()->getRight()->colorIndex = (0x3F800000 & $borderLines) >> 23;
- }
-
- // add cellStyleXf or cellXf and update mapping
- if ($isCellStyleXf) {
- // we only read one style XF record which is always the first
- if ($this->_xfIndex == 0) {
- $this->_phpExcel->addCellStyleXf($objStyle);
- $this->_mapCellStyleXfIndex[$this->_xfIndex] = 0;
- }
- } else {
- // we read all cell XF records
- $this->_phpExcel->addCellXf($objStyle);
- $this->_mapCellXfIndex[$this->_xfIndex] = count($this->_phpExcel…
Large files files are truncated, but you can click here to view the full file