You've already forked qlg.tsgz.moe
Init Repo
This commit is contained in:
227
extend/phpexcel/PHPExcel/Reader/Abstract.php
Executable file
227
extend/phpexcel/PHPExcel/Reader/Abstract.php
Executable file
@ -0,0 +1,227 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2014 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
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version 1.8.0, 2014-03-02
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* PHPExcel_Reader_Abstract
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Reader
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
abstract class PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
|
||||
{
|
||||
/**
|
||||
* Read data only?
|
||||
* Identifies whether the Reader should only read data values for cells, and ignore any formatting information;
|
||||
* or whether it should read both data and formatting
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_readDataOnly = FALSE;
|
||||
|
||||
/**
|
||||
* Read charts that are defined in the workbook?
|
||||
* Identifies whether the Reader should read the definitions for any charts that exist in the workbook;
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_includeCharts = FALSE;
|
||||
|
||||
/**
|
||||
* Restrict which sheets should be loaded?
|
||||
* This property holds an array of worksheet names to be loaded. If null, then all worksheets will be loaded.
|
||||
*
|
||||
* @var array of string
|
||||
*/
|
||||
protected $_loadSheetsOnly = NULL;
|
||||
|
||||
/**
|
||||
* PHPExcel_Reader_IReadFilter instance
|
||||
*
|
||||
* @var PHPExcel_Reader_IReadFilter
|
||||
*/
|
||||
protected $_readFilter = NULL;
|
||||
|
||||
protected $_fileHandle = NULL;
|
||||
|
||||
|
||||
/**
|
||||
* Read data only?
|
||||
* If this is true, then the Reader will only read data values for cells, it will not read any formatting information.
|
||||
* If false (the default) it will read data and formatting.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getReadDataOnly() {
|
||||
return $this->_readDataOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set read data only
|
||||
* Set to true, to advise the Reader only to read data values for cells, and to ignore any formatting information.
|
||||
* Set to false (the default) to advise the Reader to read both data and formatting for cells.
|
||||
*
|
||||
* @param boolean $pValue
|
||||
*
|
||||
* @return PHPExcel_Reader_IReader
|
||||
*/
|
||||
public function setReadDataOnly($pValue = FALSE) {
|
||||
$this->_readDataOnly = $pValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read charts in workbook?
|
||||
* If this is true, then the Reader will include any charts that exist in the workbook.
|
||||
* Note that a ReadDataOnly value of false overrides, and charts won't be read regardless of the IncludeCharts value.
|
||||
* If false (the default) it will ignore any charts defined in the workbook file.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getIncludeCharts() {
|
||||
return $this->_includeCharts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set read charts in workbook
|
||||
* Set to true, to advise the Reader to include any charts that exist in the workbook.
|
||||
* Note that a ReadDataOnly value of false overrides, and charts won't be read regardless of the IncludeCharts value.
|
||||
* Set to false (the default) to discard charts.
|
||||
*
|
||||
* @param boolean $pValue
|
||||
*
|
||||
* @return PHPExcel_Reader_IReader
|
||||
*/
|
||||
public function setIncludeCharts($pValue = FALSE) {
|
||||
$this->_includeCharts = (boolean) $pValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get which sheets to load
|
||||
* Returns either an array of worksheet names (the list of worksheets that should be loaded), or a null
|
||||
* indicating that all worksheets in the workbook should be loaded.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getLoadSheetsOnly()
|
||||
{
|
||||
return $this->_loadSheetsOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set which sheets to load
|
||||
*
|
||||
* @param mixed $value
|
||||
* This should be either an array of worksheet names to be loaded, or a string containing a single worksheet name.
|
||||
* If NULL, then it tells the Reader to read all worksheets in the workbook
|
||||
*
|
||||
* @return PHPExcel_Reader_IReader
|
||||
*/
|
||||
public function setLoadSheetsOnly($value = NULL)
|
||||
{
|
||||
$this->_loadSheetsOnly = is_array($value) ?
|
||||
$value : array($value);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set all sheets to load
|
||||
* Tells the Reader to load all worksheets from the workbook.
|
||||
*
|
||||
* @return PHPExcel_Reader_IReader
|
||||
*/
|
||||
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_IReader
|
||||
*/
|
||||
public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) {
|
||||
$this->_readFilter = $pValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Open file for reading
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
* @return resource
|
||||
*/
|
||||
protected function _openFile($pFilename)
|
||||
{
|
||||
// Check if file exists
|
||||
if (!file_exists($pFilename) || !is_readable($pFilename)) {
|
||||
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
|
||||
}
|
||||
|
||||
// Open file
|
||||
$this->_fileHandle = fopen($pFilename, 'r');
|
||||
if ($this->_fileHandle === FALSE) {
|
||||
throw new PHPExcel_Reader_Exception("Could not open file " . $pFilename . " for reading.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Can the current PHPExcel_Reader_IReader read the file?
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @return boolean
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function canRead($pFilename)
|
||||
{
|
||||
// Check if file exists
|
||||
try {
|
||||
$this->_openFile($pFilename);
|
||||
} catch (Exception $e) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$readable = $this->_isValidFormat();
|
||||
fclose ($this->_fileHandle);
|
||||
return $readable;
|
||||
}
|
||||
|
||||
}
|
415
extend/phpexcel/PHPExcel/Reader/CSV.php
Executable file
415
extend/phpexcel/PHPExcel/Reader/CSV.php
Executable file
@ -0,0 +1,415 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2014 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
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version 1.8.0, 2014-03-02
|
||||
*/
|
||||
|
||||
|
||||
/** PHPExcel root directory */
|
||||
if (!defined('PHPEXCEL_ROOT')) {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
|
||||
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* PHPExcel_Reader_CSV
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Reader
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class PHPExcel_Reader_CSV extends PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
|
||||
{
|
||||
/**
|
||||
* Input encoding
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
private $_inputEncoding = 'UTF-8';
|
||||
|
||||
/**
|
||||
* Delimiter
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
private $_delimiter = ',';
|
||||
|
||||
/**
|
||||
* Enclosure
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
private $_enclosure = '"';
|
||||
|
||||
/**
|
||||
* Line ending
|
||||
*
|
||||
* @access private
|
||||
* @var string
|
||||
*/
|
||||
private $_lineEnding = PHP_EOL;
|
||||
|
||||
/**
|
||||
* Sheet index to read
|
||||
*
|
||||
* @access private
|
||||
* @var int
|
||||
*/
|
||||
private $_sheetIndex = 0;
|
||||
|
||||
/**
|
||||
* Load rows contiguously
|
||||
*
|
||||
* @access private
|
||||
* @var int
|
||||
*/
|
||||
private $_contiguous = false;
|
||||
|
||||
/**
|
||||
* Row counter for loading rows contiguously
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_contiguousRow = -1;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new PHPExcel_Reader_CSV
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that the current file is a CSV file
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function _isValidFormat()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set input encoding
|
||||
*
|
||||
* @param string $pValue Input encoding
|
||||
*/
|
||||
public function setInputEncoding($pValue = 'UTF-8')
|
||||
{
|
||||
$this->_inputEncoding = $pValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get input encoding
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getInputEncoding()
|
||||
{
|
||||
return $this->_inputEncoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move filepointer past any BOM marker
|
||||
*
|
||||
*/
|
||||
protected function _skipBOM()
|
||||
{
|
||||
rewind($this->_fileHandle);
|
||||
|
||||
switch ($this->_inputEncoding) {
|
||||
case 'UTF-8':
|
||||
fgets($this->_fileHandle, 4) == "\xEF\xBB\xBF" ?
|
||||
fseek($this->_fileHandle, 3) : fseek($this->_fileHandle, 0);
|
||||
break;
|
||||
case 'UTF-16LE':
|
||||
fgets($this->_fileHandle, 3) == "\xFF\xFE" ?
|
||||
fseek($this->_fileHandle, 2) : fseek($this->_fileHandle, 0);
|
||||
break;
|
||||
case 'UTF-16BE':
|
||||
fgets($this->_fileHandle, 3) == "\xFE\xFF" ?
|
||||
fseek($this->_fileHandle, 2) : fseek($this->_fileHandle, 0);
|
||||
break;
|
||||
case 'UTF-32LE':
|
||||
fgets($this->_fileHandle, 5) == "\xFF\xFE\x00\x00" ?
|
||||
fseek($this->_fileHandle, 4) : fseek($this->_fileHandle, 0);
|
||||
break;
|
||||
case 'UTF-32BE':
|
||||
fgets($this->_fileHandle, 5) == "\x00\x00\xFE\xFF" ?
|
||||
fseek($this->_fileHandle, 4) : fseek($this->_fileHandle, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns)
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function listWorksheetInfo($pFilename)
|
||||
{
|
||||
// Open file
|
||||
$this->_openFile($pFilename);
|
||||
if (!$this->_isValidFormat()) {
|
||||
fclose ($this->_fileHandle);
|
||||
throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid Spreadsheet file.");
|
||||
}
|
||||
$fileHandle = $this->_fileHandle;
|
||||
|
||||
// Skip BOM, if any
|
||||
$this->_skipBOM();
|
||||
|
||||
$escapeEnclosures = array( "\\" . $this->_enclosure, $this->_enclosure . $this->_enclosure );
|
||||
|
||||
$worksheetInfo = array();
|
||||
$worksheetInfo[0]['worksheetName'] = 'Worksheet';
|
||||
$worksheetInfo[0]['lastColumnLetter'] = 'A';
|
||||
$worksheetInfo[0]['lastColumnIndex'] = 0;
|
||||
$worksheetInfo[0]['totalRows'] = 0;
|
||||
$worksheetInfo[0]['totalColumns'] = 0;
|
||||
|
||||
// Loop through each line of the file in turn
|
||||
while (($rowData = fgetcsv($fileHandle, 0, $this->_delimiter, $this->_enclosure)) !== FALSE) {
|
||||
$worksheetInfo[0]['totalRows']++;
|
||||
$worksheetInfo[0]['lastColumnIndex'] = max($worksheetInfo[0]['lastColumnIndex'], count($rowData) - 1);
|
||||
}
|
||||
|
||||
$worksheetInfo[0]['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($worksheetInfo[0]['lastColumnIndex']);
|
||||
$worksheetInfo[0]['totalColumns'] = $worksheetInfo[0]['lastColumnIndex'] + 1;
|
||||
|
||||
// Close file
|
||||
fclose($fileHandle);
|
||||
|
||||
return $worksheetInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads PHPExcel from file
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @return PHPExcel
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function load($pFilename)
|
||||
{
|
||||
// Create new PHPExcel
|
||||
$objPHPExcel = new PHPExcel();
|
||||
|
||||
// Load into this instance
|
||||
return $this->loadIntoExisting($pFilename, $objPHPExcel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads PHPExcel from file into PHPExcel instance
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @param PHPExcel $objPHPExcel
|
||||
* @return PHPExcel
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
|
||||
{
|
||||
$lineEnding = ini_get('auto_detect_line_endings');
|
||||
ini_set('auto_detect_line_endings', true);
|
||||
|
||||
// Open file
|
||||
$this->_openFile($pFilename);
|
||||
if (!$this->_isValidFormat()) {
|
||||
fclose ($this->_fileHandle);
|
||||
throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid Spreadsheet file.");
|
||||
}
|
||||
$fileHandle = $this->_fileHandle;
|
||||
|
||||
// Skip BOM, if any
|
||||
$this->_skipBOM();
|
||||
|
||||
// Create new PHPExcel object
|
||||
while ($objPHPExcel->getSheetCount() <= $this->_sheetIndex) {
|
||||
$objPHPExcel->createSheet();
|
||||
}
|
||||
$sheet = $objPHPExcel->setActiveSheetIndex($this->_sheetIndex);
|
||||
|
||||
$escapeEnclosures = array( "\\" . $this->_enclosure,
|
||||
$this->_enclosure . $this->_enclosure
|
||||
);
|
||||
|
||||
// Set our starting row based on whether we're in contiguous mode or not
|
||||
$currentRow = 1;
|
||||
if ($this->_contiguous) {
|
||||
$currentRow = ($this->_contiguousRow == -1) ? $sheet->getHighestRow(): $this->_contiguousRow;
|
||||
}
|
||||
|
||||
// Loop through each line of the file in turn
|
||||
while (($rowData = fgetcsv($fileHandle, 0, $this->_delimiter, $this->_enclosure)) !== FALSE) {
|
||||
$columnLetter = 'A';
|
||||
foreach($rowData as $rowDatum) {
|
||||
if ($rowDatum != '' && $this->_readFilter->readCell($columnLetter, $currentRow)) {
|
||||
// Unescape enclosures
|
||||
$rowDatum = str_replace($escapeEnclosures, $this->_enclosure, $rowDatum);
|
||||
|
||||
// Convert encoding if necessary
|
||||
if ($this->_inputEncoding !== 'UTF-8') {
|
||||
$rowDatum = PHPExcel_Shared_String::ConvertEncoding($rowDatum, 'UTF-8', $this->_inputEncoding);
|
||||
}
|
||||
|
||||
// Set cell value
|
||||
$sheet->getCell($columnLetter . $currentRow)->setValue($rowDatum);
|
||||
}
|
||||
++$columnLetter;
|
||||
}
|
||||
++$currentRow;
|
||||
}
|
||||
|
||||
// Close file
|
||||
fclose($fileHandle);
|
||||
|
||||
if ($this->_contiguous) {
|
||||
$this->_contiguousRow = $currentRow;
|
||||
}
|
||||
|
||||
ini_set('auto_detect_line_endings', $lineEnding);
|
||||
|
||||
// Return
|
||||
return $objPHPExcel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get delimiter
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDelimiter() {
|
||||
return $this->_delimiter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set delimiter
|
||||
*
|
||||
* @param string $pValue Delimiter, defaults to ,
|
||||
* @return PHPExcel_Reader_CSV
|
||||
*/
|
||||
public function setDelimiter($pValue = ',') {
|
||||
$this->_delimiter = $pValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get enclosure
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEnclosure() {
|
||||
return $this->_enclosure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set enclosure
|
||||
*
|
||||
* @param string $pValue Enclosure, defaults to "
|
||||
* @return PHPExcel_Reader_CSV
|
||||
*/
|
||||
public function setEnclosure($pValue = '"') {
|
||||
if ($pValue == '') {
|
||||
$pValue = '"';
|
||||
}
|
||||
$this->_enclosure = $pValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get line ending
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLineEnding() {
|
||||
return $this->_lineEnding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set line ending
|
||||
*
|
||||
* @param string $pValue Line ending, defaults to OS line ending (PHP_EOL)
|
||||
* @return PHPExcel_Reader_CSV
|
||||
*/
|
||||
public function setLineEnding($pValue = PHP_EOL) {
|
||||
$this->_lineEnding = $pValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sheet index
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getSheetIndex() {
|
||||
return $this->_sheetIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set sheet index
|
||||
*
|
||||
* @param integer $pValue Sheet index
|
||||
* @return PHPExcel_Reader_CSV
|
||||
*/
|
||||
public function setSheetIndex($pValue = 0) {
|
||||
$this->_sheetIndex = $pValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Contiguous
|
||||
*
|
||||
* @param boolean $contiguous
|
||||
*/
|
||||
public function setContiguous($contiguous = FALSE)
|
||||
{
|
||||
$this->_contiguous = (bool) $contiguous;
|
||||
if (!$contiguous) {
|
||||
$this->_contiguousRow = -1;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Contiguous
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function getContiguous() {
|
||||
return $this->_contiguous;
|
||||
}
|
||||
|
||||
}
|
58
extend/phpexcel/PHPExcel/Reader/DefaultReadFilter.php
Executable file
58
extend/phpexcel/PHPExcel/Reader/DefaultReadFilter.php
Executable file
@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2014 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
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version 1.8.0, 2014-03-02
|
||||
*/
|
||||
|
||||
|
||||
/** PHPExcel root directory */
|
||||
if (!defined('PHPEXCEL_ROOT')) {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
|
||||
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* PHPExcel_Reader_DefaultReadFilter
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Reader
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class PHPExcel_Reader_DefaultReadFilter implements PHPExcel_Reader_IReadFilter
|
||||
{
|
||||
/**
|
||||
* Should this cell be read?
|
||||
*
|
||||
* @param $column String column index
|
||||
* @param $row Row index
|
||||
* @param $worksheetName Optional worksheet name
|
||||
* @return boolean
|
||||
*/
|
||||
public function readCell($column, $row, $worksheetName = '') {
|
||||
return true;
|
||||
}
|
||||
}
|
802
extend/phpexcel/PHPExcel/Reader/Excel2003XML.php
Executable file
802
extend/phpexcel/PHPExcel/Reader/Excel2003XML.php
Executable file
@ -0,0 +1,802 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2014 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
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version 1.8.0, 2014-03-02
|
||||
*/
|
||||
|
||||
|
||||
/** PHPExcel root directory */
|
||||
if (!defined('PHPEXCEL_ROOT')) {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
|
||||
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* PHPExcel_Reader_Excel2003XML
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Reader
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class PHPExcel_Reader_Excel2003XML extends PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
|
||||
{
|
||||
/**
|
||||
* Formats
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_styles = array();
|
||||
|
||||
/**
|
||||
* Character set used in the file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_charSet = 'UTF-8';
|
||||
|
||||
|
||||
/**
|
||||
* Create a new PHPExcel_Reader_Excel2003XML
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Can the current PHPExcel_Reader_IReader read the file?
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @return boolean
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function canRead($pFilename)
|
||||
{
|
||||
|
||||
// Office xmlns:o="urn:schemas-microsoft-com:office:office"
|
||||
// Excel xmlns:x="urn:schemas-microsoft-com:office:excel"
|
||||
// XML Spreadsheet xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
|
||||
// Spreadsheet component xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet"
|
||||
// XML schema xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882"
|
||||
// XML data type xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
|
||||
// MS-persist recordset xmlns:rs="urn:schemas-microsoft-com:rowset"
|
||||
// Rowset xmlns:z="#RowsetSchema"
|
||||
//
|
||||
|
||||
$signature = array(
|
||||
'<?xml version="1.0"',
|
||||
'<?mso-application progid="Excel.Sheet"?>'
|
||||
);
|
||||
|
||||
// Open file
|
||||
$this->_openFile($pFilename);
|
||||
$fileHandle = $this->_fileHandle;
|
||||
|
||||
// Read sample data (first 2 KB will do)
|
||||
$data = fread($fileHandle, 2048);
|
||||
fclose($fileHandle);
|
||||
|
||||
$valid = true;
|
||||
foreach($signature as $match) {
|
||||
// every part of the signature must be present
|
||||
if (strpos($data, $match) === false) {
|
||||
$valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Retrieve charset encoding
|
||||
if(preg_match('/<?xml.*encoding=[\'"](.*?)[\'"].*?>/um',$data,$matches)) {
|
||||
$this->_charSet = strtoupper($matches[1]);
|
||||
}
|
||||
// echo 'Character Set is ',$this->_charSet,'<br />';
|
||||
|
||||
return $valid;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function listWorksheetNames($pFilename)
|
||||
{
|
||||
// Check if file exists
|
||||
if (!file_exists($pFilename)) {
|
||||
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
|
||||
}
|
||||
if (!$this->canRead($pFilename)) {
|
||||
throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid Spreadsheet file.");
|
||||
}
|
||||
|
||||
$worksheetNames = array();
|
||||
|
||||
$xml = simplexml_load_file($pFilename, 'SimpleXMLElement', PHPExcel_Settings::getLibXmlLoaderOptions());
|
||||
$namespaces = $xml->getNamespaces(true);
|
||||
|
||||
$xml_ss = $xml->children($namespaces['ss']);
|
||||
foreach($xml_ss->Worksheet as $worksheet) {
|
||||
$worksheet_ss = $worksheet->attributes($namespaces['ss']);
|
||||
$worksheetNames[] = self::_convertStringEncoding((string) $worksheet_ss['Name'],$this->_charSet);
|
||||
}
|
||||
|
||||
return $worksheetNames;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns)
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function listWorksheetInfo($pFilename)
|
||||
{
|
||||
// Check if file exists
|
||||
if (!file_exists($pFilename)) {
|
||||
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
|
||||
}
|
||||
|
||||
$worksheetInfo = array();
|
||||
|
||||
$xml = simplexml_load_file($pFilename, 'SimpleXMLElement', PHPExcel_Settings::getLibXmlLoaderOptions());
|
||||
$namespaces = $xml->getNamespaces(true);
|
||||
|
||||
$worksheetID = 1;
|
||||
$xml_ss = $xml->children($namespaces['ss']);
|
||||
foreach($xml_ss->Worksheet as $worksheet) {
|
||||
$worksheet_ss = $worksheet->attributes($namespaces['ss']);
|
||||
|
||||
$tmpInfo = array();
|
||||
$tmpInfo['worksheetName'] = '';
|
||||
$tmpInfo['lastColumnLetter'] = 'A';
|
||||
$tmpInfo['lastColumnIndex'] = 0;
|
||||
$tmpInfo['totalRows'] = 0;
|
||||
$tmpInfo['totalColumns'] = 0;
|
||||
|
||||
if (isset($worksheet_ss['Name'])) {
|
||||
$tmpInfo['worksheetName'] = (string) $worksheet_ss['Name'];
|
||||
} else {
|
||||
$tmpInfo['worksheetName'] = "Worksheet_{$worksheetID}";
|
||||
}
|
||||
|
||||
if (isset($worksheet->Table->Row)) {
|
||||
$rowIndex = 0;
|
||||
|
||||
foreach($worksheet->Table->Row as $rowData) {
|
||||
$columnIndex = 0;
|
||||
$rowHasData = false;
|
||||
|
||||
foreach($rowData->Cell as $cell) {
|
||||
if (isset($cell->Data)) {
|
||||
$tmpInfo['lastColumnIndex'] = max($tmpInfo['lastColumnIndex'], $columnIndex);
|
||||
$rowHasData = true;
|
||||
}
|
||||
|
||||
++$columnIndex;
|
||||
}
|
||||
|
||||
++$rowIndex;
|
||||
|
||||
if ($rowHasData) {
|
||||
$tmpInfo['totalRows'] = max($tmpInfo['totalRows'], $rowIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$tmpInfo['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']);
|
||||
$tmpInfo['totalColumns'] = $tmpInfo['lastColumnIndex'] + 1;
|
||||
|
||||
$worksheetInfo[] = $tmpInfo;
|
||||
++$worksheetID;
|
||||
}
|
||||
|
||||
return $worksheetInfo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads PHPExcel from file
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @return PHPExcel
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function load($pFilename)
|
||||
{
|
||||
// Create new PHPExcel
|
||||
$objPHPExcel = new PHPExcel();
|
||||
|
||||
// Load into this instance
|
||||
return $this->loadIntoExisting($pFilename, $objPHPExcel);
|
||||
}
|
||||
|
||||
|
||||
private static function identifyFixedStyleValue($styleList,&$styleAttributeValue) {
|
||||
$styleAttributeValue = strtolower($styleAttributeValue);
|
||||
foreach($styleList as $style) {
|
||||
if ($styleAttributeValue == strtolower($style)) {
|
||||
$styleAttributeValue = $style;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* pixel units to excel width units(units of 1/256th of a character width)
|
||||
* @param pxs
|
||||
* @return
|
||||
*/
|
||||
private static function _pixel2WidthUnits($pxs) {
|
||||
$UNIT_OFFSET_MAP = array(0, 36, 73, 109, 146, 182, 219);
|
||||
|
||||
$widthUnits = 256 * ($pxs / 7);
|
||||
$widthUnits += $UNIT_OFFSET_MAP[($pxs % 7)];
|
||||
return $widthUnits;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* excel width units(units of 1/256th of a character width) to pixel units
|
||||
* @param widthUnits
|
||||
* @return
|
||||
*/
|
||||
private static function _widthUnits2Pixel($widthUnits) {
|
||||
$pixels = ($widthUnits / 256) * 7;
|
||||
$offsetWidthUnits = $widthUnits % 256;
|
||||
$pixels += round($offsetWidthUnits / (256 / 7));
|
||||
return $pixels;
|
||||
}
|
||||
|
||||
|
||||
private static function _hex2str($hex) {
|
||||
return chr(hexdec($hex[1]));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads PHPExcel from file into PHPExcel instance
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @param PHPExcel $objPHPExcel
|
||||
* @return PHPExcel
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
|
||||
{
|
||||
$fromFormats = array('\-', '\ ');
|
||||
$toFormats = array('-', ' ');
|
||||
|
||||
$underlineStyles = array (
|
||||
PHPExcel_Style_Font::UNDERLINE_NONE,
|
||||
PHPExcel_Style_Font::UNDERLINE_DOUBLE,
|
||||
PHPExcel_Style_Font::UNDERLINE_DOUBLEACCOUNTING,
|
||||
PHPExcel_Style_Font::UNDERLINE_SINGLE,
|
||||
PHPExcel_Style_Font::UNDERLINE_SINGLEACCOUNTING
|
||||
);
|
||||
$verticalAlignmentStyles = array (
|
||||
PHPExcel_Style_Alignment::VERTICAL_BOTTOM,
|
||||
PHPExcel_Style_Alignment::VERTICAL_TOP,
|
||||
PHPExcel_Style_Alignment::VERTICAL_CENTER,
|
||||
PHPExcel_Style_Alignment::VERTICAL_JUSTIFY
|
||||
);
|
||||
$horizontalAlignmentStyles = array (
|
||||
PHPExcel_Style_Alignment::HORIZONTAL_GENERAL,
|
||||
PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
|
||||
PHPExcel_Style_Alignment::HORIZONTAL_RIGHT,
|
||||
PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
|
||||
PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS,
|
||||
PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY
|
||||
);
|
||||
|
||||
$timezoneObj = new DateTimeZone('Europe/London');
|
||||
$GMT = new DateTimeZone('UTC');
|
||||
|
||||
|
||||
// Check if file exists
|
||||
if (!file_exists($pFilename)) {
|
||||
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
|
||||
}
|
||||
|
||||
if (!$this->canRead($pFilename)) {
|
||||
throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid Spreadsheet file.");
|
||||
}
|
||||
|
||||
$xml = simplexml_load_file($pFilename, 'SimpleXMLElement', PHPExcel_Settings::getLibXmlLoaderOptions());
|
||||
$namespaces = $xml->getNamespaces(true);
|
||||
|
||||
$docProps = $objPHPExcel->getProperties();
|
||||
if (isset($xml->DocumentProperties[0])) {
|
||||
foreach($xml->DocumentProperties[0] as $propertyName => $propertyValue) {
|
||||
switch ($propertyName) {
|
||||
case 'Title' :
|
||||
$docProps->setTitle(self::_convertStringEncoding($propertyValue,$this->_charSet));
|
||||
break;
|
||||
case 'Subject' :
|
||||
$docProps->setSubject(self::_convertStringEncoding($propertyValue,$this->_charSet));
|
||||
break;
|
||||
case 'Author' :
|
||||
$docProps->setCreator(self::_convertStringEncoding($propertyValue,$this->_charSet));
|
||||
break;
|
||||
case 'Created' :
|
||||
$creationDate = strtotime($propertyValue);
|
||||
$docProps->setCreated($creationDate);
|
||||
break;
|
||||
case 'LastAuthor' :
|
||||
$docProps->setLastModifiedBy(self::_convertStringEncoding($propertyValue,$this->_charSet));
|
||||
break;
|
||||
case 'LastSaved' :
|
||||
$lastSaveDate = strtotime($propertyValue);
|
||||
$docProps->setModified($lastSaveDate);
|
||||
break;
|
||||
case 'Company' :
|
||||
$docProps->setCompany(self::_convertStringEncoding($propertyValue,$this->_charSet));
|
||||
break;
|
||||
case 'Category' :
|
||||
$docProps->setCategory(self::_convertStringEncoding($propertyValue,$this->_charSet));
|
||||
break;
|
||||
case 'Manager' :
|
||||
$docProps->setManager(self::_convertStringEncoding($propertyValue,$this->_charSet));
|
||||
break;
|
||||
case 'Keywords' :
|
||||
$docProps->setKeywords(self::_convertStringEncoding($propertyValue,$this->_charSet));
|
||||
break;
|
||||
case 'Description' :
|
||||
$docProps->setDescription(self::_convertStringEncoding($propertyValue,$this->_charSet));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($xml->CustomDocumentProperties)) {
|
||||
foreach($xml->CustomDocumentProperties[0] as $propertyName => $propertyValue) {
|
||||
$propertyAttributes = $propertyValue->attributes($namespaces['dt']);
|
||||
$propertyName = preg_replace_callback('/_x([0-9a-z]{4})_/','PHPExcel_Reader_Excel2003XML::_hex2str',$propertyName);
|
||||
$propertyType = PHPExcel_DocumentProperties::PROPERTY_TYPE_UNKNOWN;
|
||||
switch((string) $propertyAttributes) {
|
||||
case 'string' :
|
||||
$propertyType = PHPExcel_DocumentProperties::PROPERTY_TYPE_STRING;
|
||||
$propertyValue = trim($propertyValue);
|
||||
break;
|
||||
case 'boolean' :
|
||||
$propertyType = PHPExcel_DocumentProperties::PROPERTY_TYPE_BOOLEAN;
|
||||
$propertyValue = (bool) $propertyValue;
|
||||
break;
|
||||
case 'integer' :
|
||||
$propertyType = PHPExcel_DocumentProperties::PROPERTY_TYPE_INTEGER;
|
||||
$propertyValue = intval($propertyValue);
|
||||
break;
|
||||
case 'float' :
|
||||
$propertyType = PHPExcel_DocumentProperties::PROPERTY_TYPE_FLOAT;
|
||||
$propertyValue = floatval($propertyValue);
|
||||
break;
|
||||
case 'dateTime.tz' :
|
||||
$propertyType = PHPExcel_DocumentProperties::PROPERTY_TYPE_DATE;
|
||||
$propertyValue = strtotime(trim($propertyValue));
|
||||
break;
|
||||
}
|
||||
$docProps->setCustomProperty($propertyName,$propertyValue,$propertyType);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($xml->Styles[0] as $style) {
|
||||
$style_ss = $style->attributes($namespaces['ss']);
|
||||
$styleID = (string) $style_ss['ID'];
|
||||
// echo 'Style ID = '.$styleID.'<br />';
|
||||
if ($styleID == 'Default') {
|
||||
$this->_styles['Default'] = array();
|
||||
} else {
|
||||
$this->_styles[$styleID] = $this->_styles['Default'];
|
||||
}
|
||||
foreach ($style as $styleType => $styleData) {
|
||||
$styleAttributes = $styleData->attributes($namespaces['ss']);
|
||||
// echo $styleType.'<br />';
|
||||
switch ($styleType) {
|
||||
case 'Alignment' :
|
||||
foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
|
||||
// echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
|
||||
$styleAttributeValue = (string) $styleAttributeValue;
|
||||
switch ($styleAttributeKey) {
|
||||
case 'Vertical' :
|
||||
if (self::identifyFixedStyleValue($verticalAlignmentStyles,$styleAttributeValue)) {
|
||||
$this->_styles[$styleID]['alignment']['vertical'] = $styleAttributeValue;
|
||||
}
|
||||
break;
|
||||
case 'Horizontal' :
|
||||
if (self::identifyFixedStyleValue($horizontalAlignmentStyles,$styleAttributeValue)) {
|
||||
$this->_styles[$styleID]['alignment']['horizontal'] = $styleAttributeValue;
|
||||
}
|
||||
break;
|
||||
case 'WrapText' :
|
||||
$this->_styles[$styleID]['alignment']['wrap'] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'Borders' :
|
||||
foreach($styleData->Border as $borderStyle) {
|
||||
$borderAttributes = $borderStyle->attributes($namespaces['ss']);
|
||||
$thisBorder = array();
|
||||
foreach($borderAttributes as $borderStyleKey => $borderStyleValue) {
|
||||
// echo $borderStyleKey.' = '.$borderStyleValue.'<br />';
|
||||
switch ($borderStyleKey) {
|
||||
case 'LineStyle' :
|
||||
$thisBorder['style'] = PHPExcel_Style_Border::BORDER_MEDIUM;
|
||||
// $thisBorder['style'] = $borderStyleValue;
|
||||
break;
|
||||
case 'Weight' :
|
||||
// $thisBorder['style'] = $borderStyleValue;
|
||||
break;
|
||||
case 'Position' :
|
||||
$borderPosition = strtolower($borderStyleValue);
|
||||
break;
|
||||
case 'Color' :
|
||||
$borderColour = substr($borderStyleValue,1);
|
||||
$thisBorder['color']['rgb'] = $borderColour;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!empty($thisBorder)) {
|
||||
if (($borderPosition == 'left') || ($borderPosition == 'right') || ($borderPosition == 'top') || ($borderPosition == 'bottom')) {
|
||||
$this->_styles[$styleID]['borders'][$borderPosition] = $thisBorder;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'Font' :
|
||||
foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
|
||||
// echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
|
||||
$styleAttributeValue = (string) $styleAttributeValue;
|
||||
switch ($styleAttributeKey) {
|
||||
case 'FontName' :
|
||||
$this->_styles[$styleID]['font']['name'] = $styleAttributeValue;
|
||||
break;
|
||||
case 'Size' :
|
||||
$this->_styles[$styleID]['font']['size'] = $styleAttributeValue;
|
||||
break;
|
||||
case 'Color' :
|
||||
$this->_styles[$styleID]['font']['color']['rgb'] = substr($styleAttributeValue,1);
|
||||
break;
|
||||
case 'Bold' :
|
||||
$this->_styles[$styleID]['font']['bold'] = true;
|
||||
break;
|
||||
case 'Italic' :
|
||||
$this->_styles[$styleID]['font']['italic'] = true;
|
||||
break;
|
||||
case 'Underline' :
|
||||
if (self::identifyFixedStyleValue($underlineStyles,$styleAttributeValue)) {
|
||||
$this->_styles[$styleID]['font']['underline'] = $styleAttributeValue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'Interior' :
|
||||
foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
|
||||
// echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
|
||||
switch ($styleAttributeKey) {
|
||||
case 'Color' :
|
||||
$this->_styles[$styleID]['fill']['color']['rgb'] = substr($styleAttributeValue,1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'NumberFormat' :
|
||||
foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
|
||||
// echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
|
||||
$styleAttributeValue = str_replace($fromFormats,$toFormats,$styleAttributeValue);
|
||||
switch ($styleAttributeValue) {
|
||||
case 'Short Date' :
|
||||
$styleAttributeValue = 'dd/mm/yyyy';
|
||||
break;
|
||||
}
|
||||
if ($styleAttributeValue > '') {
|
||||
$this->_styles[$styleID]['numberformat']['code'] = $styleAttributeValue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'Protection' :
|
||||
foreach($styleAttributes as $styleAttributeKey => $styleAttributeValue) {
|
||||
// echo $styleAttributeKey.' = '.$styleAttributeValue.'<br />';
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
// print_r($this->_styles[$styleID]);
|
||||
// echo '<hr />';
|
||||
}
|
||||
// echo '<hr />';
|
||||
|
||||
$worksheetID = 0;
|
||||
$xml_ss = $xml->children($namespaces['ss']);
|
||||
|
||||
foreach($xml_ss->Worksheet as $worksheet) {
|
||||
$worksheet_ss = $worksheet->attributes($namespaces['ss']);
|
||||
|
||||
if ((isset($this->_loadSheetsOnly)) && (isset($worksheet_ss['Name'])) &&
|
||||
(!in_array($worksheet_ss['Name'], $this->_loadSheetsOnly))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// echo '<h3>Worksheet: ',$worksheet_ss['Name'],'<h3>';
|
||||
//
|
||||
// Create new Worksheet
|
||||
$objPHPExcel->createSheet();
|
||||
$objPHPExcel->setActiveSheetIndex($worksheetID);
|
||||
if (isset($worksheet_ss['Name'])) {
|
||||
$worksheetName = self::_convertStringEncoding((string) $worksheet_ss['Name'],$this->_charSet);
|
||||
// Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in
|
||||
// formula cells... during the load, all formulae should be correct, and we're simply bringing
|
||||
// the worksheet name in line with the formula, not the reverse
|
||||
$objPHPExcel->getActiveSheet()->setTitle($worksheetName,false);
|
||||
}
|
||||
|
||||
$columnID = 'A';
|
||||
if (isset($worksheet->Table->Column)) {
|
||||
foreach($worksheet->Table->Column as $columnData) {
|
||||
$columnData_ss = $columnData->attributes($namespaces['ss']);
|
||||
if (isset($columnData_ss['Index'])) {
|
||||
$columnID = PHPExcel_Cell::stringFromColumnIndex($columnData_ss['Index']-1);
|
||||
}
|
||||
if (isset($columnData_ss['Width'])) {
|
||||
$columnWidth = $columnData_ss['Width'];
|
||||
// echo '<b>Setting column width for '.$columnID.' to '.$columnWidth.'</b><br />';
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension($columnID)->setWidth($columnWidth / 5.4);
|
||||
}
|
||||
++$columnID;
|
||||
}
|
||||
}
|
||||
|
||||
$rowID = 1;
|
||||
if (isset($worksheet->Table->Row)) {
|
||||
foreach($worksheet->Table->Row as $rowData) {
|
||||
$rowHasData = false;
|
||||
$row_ss = $rowData->attributes($namespaces['ss']);
|
||||
if (isset($row_ss['Index'])) {
|
||||
$rowID = (integer) $row_ss['Index'];
|
||||
}
|
||||
// echo '<b>Row '.$rowID.'</b><br />';
|
||||
|
||||
$columnID = 'A';
|
||||
foreach($rowData->Cell as $cell) {
|
||||
|
||||
$cell_ss = $cell->attributes($namespaces['ss']);
|
||||
if (isset($cell_ss['Index'])) {
|
||||
$columnID = PHPExcel_Cell::stringFromColumnIndex($cell_ss['Index']-1);
|
||||
}
|
||||
$cellRange = $columnID.$rowID;
|
||||
|
||||
if ($this->getReadFilter() !== NULL) {
|
||||
if (!$this->getReadFilter()->readCell($columnID, $rowID, $worksheetName)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ((isset($cell_ss['MergeAcross'])) || (isset($cell_ss['MergeDown']))) {
|
||||
$columnTo = $columnID;
|
||||
if (isset($cell_ss['MergeAcross'])) {
|
||||
$columnTo = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($columnID) + $cell_ss['MergeAcross'] -1);
|
||||
}
|
||||
$rowTo = $rowID;
|
||||
if (isset($cell_ss['MergeDown'])) {
|
||||
$rowTo = $rowTo + $cell_ss['MergeDown'];
|
||||
}
|
||||
$cellRange .= ':'.$columnTo.$rowTo;
|
||||
$objPHPExcel->getActiveSheet()->mergeCells($cellRange);
|
||||
}
|
||||
|
||||
$cellIsSet = $hasCalculatedValue = false;
|
||||
$cellDataFormula = '';
|
||||
if (isset($cell_ss['Formula'])) {
|
||||
$cellDataFormula = $cell_ss['Formula'];
|
||||
// added this as a check for array formulas
|
||||
if (isset($cell_ss['ArrayRange'])) {
|
||||
$cellDataCSEFormula = $cell_ss['ArrayRange'];
|
||||
// echo "found an array formula at ".$columnID.$rowID."<br />";
|
||||
}
|
||||
$hasCalculatedValue = true;
|
||||
}
|
||||
if (isset($cell->Data)) {
|
||||
$cellValue = $cellData = $cell->Data;
|
||||
$type = PHPExcel_Cell_DataType::TYPE_NULL;
|
||||
$cellData_ss = $cellData->attributes($namespaces['ss']);
|
||||
if (isset($cellData_ss['Type'])) {
|
||||
$cellDataType = $cellData_ss['Type'];
|
||||
switch ($cellDataType) {
|
||||
/*
|
||||
const TYPE_STRING = 's';
|
||||
const TYPE_FORMULA = 'f';
|
||||
const TYPE_NUMERIC = 'n';
|
||||
const TYPE_BOOL = 'b';
|
||||
const TYPE_NULL = 'null';
|
||||
const TYPE_INLINE = 'inlineStr';
|
||||
const TYPE_ERROR = 'e';
|
||||
*/
|
||||
case 'String' :
|
||||
$cellValue = self::_convertStringEncoding($cellValue,$this->_charSet);
|
||||
$type = PHPExcel_Cell_DataType::TYPE_STRING;
|
||||
break;
|
||||
case 'Number' :
|
||||
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
|
||||
$cellValue = (float) $cellValue;
|
||||
if (floor($cellValue) == $cellValue) {
|
||||
$cellValue = (integer) $cellValue;
|
||||
}
|
||||
break;
|
||||
case 'Boolean' :
|
||||
$type = PHPExcel_Cell_DataType::TYPE_BOOL;
|
||||
$cellValue = ($cellValue != 0);
|
||||
break;
|
||||
case 'DateTime' :
|
||||
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
|
||||
$cellValue = PHPExcel_Shared_Date::PHPToExcel(strtotime($cellValue));
|
||||
break;
|
||||
case 'Error' :
|
||||
$type = PHPExcel_Cell_DataType::TYPE_ERROR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($hasCalculatedValue) {
|
||||
// echo 'FORMULA<br />';
|
||||
$type = PHPExcel_Cell_DataType::TYPE_FORMULA;
|
||||
$columnNumber = PHPExcel_Cell::columnIndexFromString($columnID);
|
||||
if (substr($cellDataFormula,0,3) == 'of:') {
|
||||
$cellDataFormula = substr($cellDataFormula,3);
|
||||
// echo 'Before: ',$cellDataFormula,'<br />';
|
||||
$temp = explode('"',$cellDataFormula);
|
||||
$key = false;
|
||||
foreach($temp as &$value) {
|
||||
// Only replace in alternate array entries (i.e. non-quoted blocks)
|
||||
if ($key = !$key) {
|
||||
$value = str_replace(array('[.','.',']'),'',$value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Convert R1C1 style references to A1 style references (but only when not quoted)
|
||||
// echo 'Before: ',$cellDataFormula,'<br />';
|
||||
$temp = explode('"',$cellDataFormula);
|
||||
$key = false;
|
||||
foreach($temp as &$value) {
|
||||
// Only replace in alternate array entries (i.e. non-quoted blocks)
|
||||
if ($key = !$key) {
|
||||
preg_match_all('/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/',$value, $cellReferences,PREG_SET_ORDER+PREG_OFFSET_CAPTURE);
|
||||
// Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way
|
||||
// through the formula from left to right. Reversing means that we work right to left.through
|
||||
// the formula
|
||||
$cellReferences = array_reverse($cellReferences);
|
||||
// Loop through each R1C1 style reference in turn, converting it to its A1 style equivalent,
|
||||
// then modify the formula to use that new reference
|
||||
foreach($cellReferences as $cellReference) {
|
||||
$rowReference = $cellReference[2][0];
|
||||
// Empty R reference is the current row
|
||||
if ($rowReference == '') $rowReference = $rowID;
|
||||
// Bracketed R references are relative to the current row
|
||||
if ($rowReference{0} == '[') $rowReference = $rowID + trim($rowReference,'[]');
|
||||
$columnReference = $cellReference[4][0];
|
||||
// Empty C reference is the current column
|
||||
if ($columnReference == '') $columnReference = $columnNumber;
|
||||
// Bracketed C references are relative to the current column
|
||||
if ($columnReference{0} == '[') $columnReference = $columnNumber + trim($columnReference,'[]');
|
||||
$A1CellReference = PHPExcel_Cell::stringFromColumnIndex($columnReference-1).$rowReference;
|
||||
$value = substr_replace($value,$A1CellReference,$cellReference[0][1],strlen($cellReference[0][0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($value);
|
||||
// Then rebuild the formula string
|
||||
$cellDataFormula = implode('"',$temp);
|
||||
// echo 'After: ',$cellDataFormula,'<br />';
|
||||
}
|
||||
|
||||
// echo 'Cell '.$columnID.$rowID.' is a '.$type.' with a value of '.(($hasCalculatedValue) ? $cellDataFormula : $cellValue).'<br />';
|
||||
//
|
||||
$objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setValueExplicit((($hasCalculatedValue) ? $cellDataFormula : $cellValue),$type);
|
||||
if ($hasCalculatedValue) {
|
||||
// echo 'Formula result is '.$cellValue.'<br />';
|
||||
$objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setCalculatedValue($cellValue);
|
||||
}
|
||||
$cellIsSet = $rowHasData = true;
|
||||
}
|
||||
|
||||
if (isset($cell->Comment)) {
|
||||
// echo '<b>comment found</b><br />';
|
||||
$commentAttributes = $cell->Comment->attributes($namespaces['ss']);
|
||||
$author = 'unknown';
|
||||
if (isset($commentAttributes->Author)) {
|
||||
$author = (string)$commentAttributes->Author;
|
||||
// echo 'Author: ',$author,'<br />';
|
||||
}
|
||||
$node = $cell->Comment->Data->asXML();
|
||||
// $annotation = str_replace('html:','',substr($node,49,-10));
|
||||
// echo $annotation,'<br />';
|
||||
$annotation = strip_tags($node);
|
||||
// echo 'Annotation: ',$annotation,'<br />';
|
||||
$objPHPExcel->getActiveSheet()->getComment( $columnID.$rowID )
|
||||
->setAuthor(self::_convertStringEncoding($author ,$this->_charSet))
|
||||
->setText($this->_parseRichText($annotation) );
|
||||
}
|
||||
|
||||
if (($cellIsSet) && (isset($cell_ss['StyleID']))) {
|
||||
$style = (string) $cell_ss['StyleID'];
|
||||
// echo 'Cell style for '.$columnID.$rowID.' is '.$style.'<br />';
|
||||
if ((isset($this->_styles[$style])) && (!empty($this->_styles[$style]))) {
|
||||
// echo 'Cell '.$columnID.$rowID.'<br />';
|
||||
// print_r($this->_styles[$style]);
|
||||
// echo '<br />';
|
||||
if (!$objPHPExcel->getActiveSheet()->cellExists($columnID.$rowID)) {
|
||||
$objPHPExcel->getActiveSheet()->getCell($columnID.$rowID)->setValue(NULL);
|
||||
}
|
||||
$objPHPExcel->getActiveSheet()->getStyle($cellRange)->applyFromArray($this->_styles[$style]);
|
||||
}
|
||||
}
|
||||
++$columnID;
|
||||
}
|
||||
|
||||
if ($rowHasData) {
|
||||
if (isset($row_ss['StyleID'])) {
|
||||
$rowStyle = $row_ss['StyleID'];
|
||||
}
|
||||
if (isset($row_ss['Height'])) {
|
||||
$rowHeight = $row_ss['Height'];
|
||||
// echo '<b>Setting row height to '.$rowHeight.'</b><br />';
|
||||
$objPHPExcel->getActiveSheet()->getRowDimension($rowID)->setRowHeight($rowHeight);
|
||||
}
|
||||
}
|
||||
|
||||
++$rowID;
|
||||
}
|
||||
}
|
||||
++$worksheetID;
|
||||
}
|
||||
|
||||
// Return
|
||||
return $objPHPExcel;
|
||||
}
|
||||
|
||||
|
||||
private static function _convertStringEncoding($string,$charset) {
|
||||
if ($charset != 'UTF-8') {
|
||||
return PHPExcel_Shared_String::ConvertEncoding($string,'UTF-8',$charset);
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
|
||||
private function _parseRichText($is = '') {
|
||||
$value = new PHPExcel_RichText();
|
||||
|
||||
$value->createText(self::_convertStringEncoding($is,$this->_charSet));
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
2069
extend/phpexcel/PHPExcel/Reader/Excel2007.php
Executable file
2069
extend/phpexcel/PHPExcel/Reader/Excel2007.php
Executable file
File diff suppressed because it is too large
Load Diff
517
extend/phpexcel/PHPExcel/Reader/Excel2007/Chart.php
Executable file
517
extend/phpexcel/PHPExcel/Reader/Excel2007/Chart.php
Executable file
@ -0,0 +1,517 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2014 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_Excel2007
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version 1.8.0, 2014-03-02
|
||||
*/
|
||||
|
||||
/**
|
||||
* PHPExcel_Reader_Excel2007_Chart
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Reader_Excel2007
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class PHPExcel_Reader_Excel2007_Chart
|
||||
{
|
||||
private static function _getAttribute($component, $name, $format) {
|
||||
$attributes = $component->attributes();
|
||||
if (isset($attributes[$name])) {
|
||||
if ($format == 'string') {
|
||||
return (string) $attributes[$name];
|
||||
} elseif ($format == 'integer') {
|
||||
return (integer) $attributes[$name];
|
||||
} elseif ($format == 'boolean') {
|
||||
return (boolean) ($attributes[$name] === '0' || $attributes[$name] !== 'true') ? false : true;
|
||||
} else {
|
||||
return (float) $attributes[$name];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
} // function _getAttribute()
|
||||
|
||||
|
||||
private static function _readColor($color,$background=false) {
|
||||
if (isset($color["rgb"])) {
|
||||
return (string)$color["rgb"];
|
||||
} else if (isset($color["indexed"])) {
|
||||
return PHPExcel_Style_Color::indexedColor($color["indexed"]-7,$background)->getARGB();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static function readChart($chartElements,$chartName) {
|
||||
$namespacesChartMeta = $chartElements->getNamespaces(true);
|
||||
$chartElementsC = $chartElements->children($namespacesChartMeta['c']);
|
||||
|
||||
$XaxisLabel = $YaxisLabel = $legend = $title = NULL;
|
||||
$dispBlanksAs = $plotVisOnly = NULL;
|
||||
|
||||
foreach($chartElementsC as $chartElementKey => $chartElement) {
|
||||
switch ($chartElementKey) {
|
||||
case "chart":
|
||||
foreach($chartElement as $chartDetailsKey => $chartDetails) {
|
||||
$chartDetailsC = $chartDetails->children($namespacesChartMeta['c']);
|
||||
switch ($chartDetailsKey) {
|
||||
case "plotArea":
|
||||
$plotAreaLayout = $XaxisLable = $YaxisLable = null;
|
||||
$plotSeries = $plotAttributes = array();
|
||||
foreach($chartDetails as $chartDetailKey => $chartDetail) {
|
||||
switch ($chartDetailKey) {
|
||||
case "layout":
|
||||
$plotAreaLayout = self::_chartLayoutDetails($chartDetail,$namespacesChartMeta,'plotArea');
|
||||
break;
|
||||
case "catAx":
|
||||
if (isset($chartDetail->title)) {
|
||||
$XaxisLabel = self::_chartTitle($chartDetail->title->children($namespacesChartMeta['c']),$namespacesChartMeta,'cat');
|
||||
}
|
||||
break;
|
||||
case "dateAx":
|
||||
if (isset($chartDetail->title)) {
|
||||
$XaxisLabel = self::_chartTitle($chartDetail->title->children($namespacesChartMeta['c']),$namespacesChartMeta,'cat');
|
||||
}
|
||||
break;
|
||||
case "valAx":
|
||||
if (isset($chartDetail->title)) {
|
||||
$YaxisLabel = self::_chartTitle($chartDetail->title->children($namespacesChartMeta['c']),$namespacesChartMeta,'cat');
|
||||
}
|
||||
break;
|
||||
case "barChart":
|
||||
case "bar3DChart":
|
||||
$barDirection = self::_getAttribute($chartDetail->barDir, 'val', 'string');
|
||||
$plotSer = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey);
|
||||
$plotSer->setPlotDirection($barDirection);
|
||||
$plotSeries[] = $plotSer;
|
||||
$plotAttributes = self::_readChartAttributes($chartDetail);
|
||||
break;
|
||||
case "lineChart":
|
||||
case "line3DChart":
|
||||
$plotSeries[] = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey);
|
||||
$plotAttributes = self::_readChartAttributes($chartDetail);
|
||||
break;
|
||||
case "areaChart":
|
||||
case "area3DChart":
|
||||
$plotSeries[] = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey);
|
||||
$plotAttributes = self::_readChartAttributes($chartDetail);
|
||||
break;
|
||||
case "doughnutChart":
|
||||
case "pieChart":
|
||||
case "pie3DChart":
|
||||
$explosion = isset($chartDetail->ser->explosion);
|
||||
$plotSer = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey);
|
||||
$plotSer->setPlotStyle($explosion);
|
||||
$plotSeries[] = $plotSer;
|
||||
$plotAttributes = self::_readChartAttributes($chartDetail);
|
||||
break;
|
||||
case "scatterChart":
|
||||
$scatterStyle = self::_getAttribute($chartDetail->scatterStyle, 'val', 'string');
|
||||
$plotSer = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey);
|
||||
$plotSer->setPlotStyle($scatterStyle);
|
||||
$plotSeries[] = $plotSer;
|
||||
$plotAttributes = self::_readChartAttributes($chartDetail);
|
||||
break;
|
||||
case "bubbleChart":
|
||||
$bubbleScale = self::_getAttribute($chartDetail->bubbleScale, 'val', 'integer');
|
||||
$plotSer = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey);
|
||||
$plotSer->setPlotStyle($bubbleScale);
|
||||
$plotSeries[] = $plotSer;
|
||||
$plotAttributes = self::_readChartAttributes($chartDetail);
|
||||
break;
|
||||
case "radarChart":
|
||||
$radarStyle = self::_getAttribute($chartDetail->radarStyle, 'val', 'string');
|
||||
$plotSer = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey);
|
||||
$plotSer->setPlotStyle($radarStyle);
|
||||
$plotSeries[] = $plotSer;
|
||||
$plotAttributes = self::_readChartAttributes($chartDetail);
|
||||
break;
|
||||
case "surfaceChart":
|
||||
case "surface3DChart":
|
||||
$wireFrame = self::_getAttribute($chartDetail->wireframe, 'val', 'boolean');
|
||||
$plotSer = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey);
|
||||
$plotSer->setPlotStyle($wireFrame);
|
||||
$plotSeries[] = $plotSer;
|
||||
$plotAttributes = self::_readChartAttributes($chartDetail);
|
||||
break;
|
||||
case "stockChart":
|
||||
$plotSeries[] = self::_chartDataSeries($chartDetail,$namespacesChartMeta,$chartDetailKey);
|
||||
$plotAttributes = self::_readChartAttributes($plotAreaLayout);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($plotAreaLayout == NULL) {
|
||||
$plotAreaLayout = new PHPExcel_Chart_Layout();
|
||||
}
|
||||
$plotArea = new PHPExcel_Chart_PlotArea($plotAreaLayout,$plotSeries);
|
||||
self::_setChartAttributes($plotAreaLayout,$plotAttributes);
|
||||
break;
|
||||
case "plotVisOnly":
|
||||
$plotVisOnly = self::_getAttribute($chartDetails, 'val', 'string');
|
||||
break;
|
||||
case "dispBlanksAs":
|
||||
$dispBlanksAs = self::_getAttribute($chartDetails, 'val', 'string');
|
||||
break;
|
||||
case "title":
|
||||
$title = self::_chartTitle($chartDetails,$namespacesChartMeta,'title');
|
||||
break;
|
||||
case "legend":
|
||||
$legendPos = 'r';
|
||||
$legendLayout = null;
|
||||
$legendOverlay = false;
|
||||
foreach($chartDetails as $chartDetailKey => $chartDetail) {
|
||||
switch ($chartDetailKey) {
|
||||
case "legendPos":
|
||||
$legendPos = self::_getAttribute($chartDetail, 'val', 'string');
|
||||
break;
|
||||
case "overlay":
|
||||
$legendOverlay = self::_getAttribute($chartDetail, 'val', 'boolean');
|
||||
break;
|
||||
case "layout":
|
||||
$legendLayout = self::_chartLayoutDetails($chartDetail,$namespacesChartMeta,'legend');
|
||||
break;
|
||||
}
|
||||
}
|
||||
$legend = new PHPExcel_Chart_Legend($legendPos, $legendLayout, $legendOverlay);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$chart = new PHPExcel_Chart($chartName,$title,$legend,$plotArea,$plotVisOnly,$dispBlanksAs,$XaxisLabel,$YaxisLabel);
|
||||
|
||||
return $chart;
|
||||
} // function readChart()
|
||||
|
||||
|
||||
private static function _chartTitle($titleDetails,$namespacesChartMeta,$type) {
|
||||
$caption = array();
|
||||
$titleLayout = null;
|
||||
foreach($titleDetails as $titleDetailKey => $chartDetail) {
|
||||
switch ($titleDetailKey) {
|
||||
case "tx":
|
||||
$titleDetails = $chartDetail->rich->children($namespacesChartMeta['a']);
|
||||
foreach($titleDetails as $titleKey => $titleDetail) {
|
||||
switch ($titleKey) {
|
||||
case "p":
|
||||
$titleDetailPart = $titleDetail->children($namespacesChartMeta['a']);
|
||||
$caption[] = self::_parseRichText($titleDetailPart);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "layout":
|
||||
$titleLayout = self::_chartLayoutDetails($chartDetail,$namespacesChartMeta);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new PHPExcel_Chart_Title($caption, $titleLayout);
|
||||
} // function _chartTitle()
|
||||
|
||||
|
||||
private static function _chartLayoutDetails($chartDetail,$namespacesChartMeta) {
|
||||
if (!isset($chartDetail->manualLayout)) {
|
||||
return null;
|
||||
}
|
||||
$details = $chartDetail->manualLayout->children($namespacesChartMeta['c']);
|
||||
if (is_null($details)) {
|
||||
return null;
|
||||
}
|
||||
$layout = array();
|
||||
foreach($details as $detailKey => $detail) {
|
||||
// echo $detailKey,' => ',self::_getAttribute($detail, 'val', 'string'),PHP_EOL;
|
||||
$layout[$detailKey] = self::_getAttribute($detail, 'val', 'string');
|
||||
}
|
||||
return new PHPExcel_Chart_Layout($layout);
|
||||
} // function _chartLayoutDetails()
|
||||
|
||||
|
||||
private static function _chartDataSeries($chartDetail,$namespacesChartMeta,$plotType) {
|
||||
$multiSeriesType = NULL;
|
||||
$smoothLine = false;
|
||||
$seriesLabel = $seriesCategory = $seriesValues = $plotOrder = array();
|
||||
|
||||
$seriesDetailSet = $chartDetail->children($namespacesChartMeta['c']);
|
||||
foreach($seriesDetailSet as $seriesDetailKey => $seriesDetails) {
|
||||
switch ($seriesDetailKey) {
|
||||
case "grouping":
|
||||
$multiSeriesType = self::_getAttribute($chartDetail->grouping, 'val', 'string');
|
||||
break;
|
||||
case "ser":
|
||||
$marker = NULL;
|
||||
foreach($seriesDetails as $seriesKey => $seriesDetail) {
|
||||
switch ($seriesKey) {
|
||||
case "idx":
|
||||
$seriesIndex = self::_getAttribute($seriesDetail, 'val', 'integer');
|
||||
break;
|
||||
case "order":
|
||||
$seriesOrder = self::_getAttribute($seriesDetail, 'val', 'integer');
|
||||
$plotOrder[$seriesIndex] = $seriesOrder;
|
||||
break;
|
||||
case "tx":
|
||||
$seriesLabel[$seriesIndex] = self::_chartDataSeriesValueSet($seriesDetail,$namespacesChartMeta);
|
||||
break;
|
||||
case "marker":
|
||||
$marker = self::_getAttribute($seriesDetail->symbol, 'val', 'string');
|
||||
break;
|
||||
case "smooth":
|
||||
$smoothLine = self::_getAttribute($seriesDetail, 'val', 'boolean');
|
||||
break;
|
||||
case "cat":
|
||||
$seriesCategory[$seriesIndex] = self::_chartDataSeriesValueSet($seriesDetail,$namespacesChartMeta);
|
||||
break;
|
||||
case "val":
|
||||
$seriesValues[$seriesIndex] = self::_chartDataSeriesValueSet($seriesDetail,$namespacesChartMeta,$marker);
|
||||
break;
|
||||
case "xVal":
|
||||
$seriesCategory[$seriesIndex] = self::_chartDataSeriesValueSet($seriesDetail,$namespacesChartMeta,$marker);
|
||||
break;
|
||||
case "yVal":
|
||||
$seriesValues[$seriesIndex] = self::_chartDataSeriesValueSet($seriesDetail,$namespacesChartMeta,$marker);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new PHPExcel_Chart_DataSeries($plotType,$multiSeriesType,$plotOrder,$seriesLabel,$seriesCategory,$seriesValues,$smoothLine);
|
||||
} // function _chartDataSeries()
|
||||
|
||||
|
||||
private static function _chartDataSeriesValueSet($seriesDetail, $namespacesChartMeta, $marker = null, $smoothLine = false) {
|
||||
if (isset($seriesDetail->strRef)) {
|
||||
$seriesSource = (string) $seriesDetail->strRef->f;
|
||||
$seriesData = self::_chartDataSeriesValues($seriesDetail->strRef->strCache->children($namespacesChartMeta['c']),'s');
|
||||
|
||||
return new PHPExcel_Chart_DataSeriesValues('String',$seriesSource,$seriesData['formatCode'],$seriesData['pointCount'],$seriesData['dataValues'],$marker,$smoothLine);
|
||||
} elseif (isset($seriesDetail->numRef)) {
|
||||
$seriesSource = (string) $seriesDetail->numRef->f;
|
||||
$seriesData = self::_chartDataSeriesValues($seriesDetail->numRef->numCache->children($namespacesChartMeta['c']));
|
||||
|
||||
return new PHPExcel_Chart_DataSeriesValues('Number',$seriesSource,$seriesData['formatCode'],$seriesData['pointCount'],$seriesData['dataValues'],$marker,$smoothLine);
|
||||
} elseif (isset($seriesDetail->multiLvlStrRef)) {
|
||||
$seriesSource = (string) $seriesDetail->multiLvlStrRef->f;
|
||||
$seriesData = self::_chartDataSeriesValuesMultiLevel($seriesDetail->multiLvlStrRef->multiLvlStrCache->children($namespacesChartMeta['c']),'s');
|
||||
$seriesData['pointCount'] = count($seriesData['dataValues']);
|
||||
|
||||
return new PHPExcel_Chart_DataSeriesValues('String',$seriesSource,$seriesData['formatCode'],$seriesData['pointCount'],$seriesData['dataValues'],$marker,$smoothLine);
|
||||
} elseif (isset($seriesDetail->multiLvlNumRef)) {
|
||||
$seriesSource = (string) $seriesDetail->multiLvlNumRef->f;
|
||||
$seriesData = self::_chartDataSeriesValuesMultiLevel($seriesDetail->multiLvlNumRef->multiLvlNumCache->children($namespacesChartMeta['c']),'s');
|
||||
$seriesData['pointCount'] = count($seriesData['dataValues']);
|
||||
|
||||
return new PHPExcel_Chart_DataSeriesValues('String',$seriesSource,$seriesData['formatCode'],$seriesData['pointCount'],$seriesData['dataValues'],$marker,$smoothLine);
|
||||
}
|
||||
return null;
|
||||
} // function _chartDataSeriesValueSet()
|
||||
|
||||
|
||||
private static function _chartDataSeriesValues($seriesValueSet,$dataType='n') {
|
||||
$seriesVal = array();
|
||||
$formatCode = '';
|
||||
$pointCount = 0;
|
||||
|
||||
foreach($seriesValueSet as $seriesValueIdx => $seriesValue) {
|
||||
switch ($seriesValueIdx) {
|
||||
case 'ptCount':
|
||||
$pointCount = self::_getAttribute($seriesValue, 'val', 'integer');
|
||||
break;
|
||||
case 'formatCode':
|
||||
$formatCode = (string) $seriesValue;
|
||||
break;
|
||||
case 'pt':
|
||||
$pointVal = self::_getAttribute($seriesValue, 'idx', 'integer');
|
||||
if ($dataType == 's') {
|
||||
$seriesVal[$pointVal] = (string) $seriesValue->v;
|
||||
} else {
|
||||
$seriesVal[$pointVal] = (float) $seriesValue->v;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($seriesVal)) {
|
||||
$seriesVal = NULL;
|
||||
}
|
||||
|
||||
return array( 'formatCode' => $formatCode,
|
||||
'pointCount' => $pointCount,
|
||||
'dataValues' => $seriesVal
|
||||
);
|
||||
} // function _chartDataSeriesValues()
|
||||
|
||||
|
||||
private static function _chartDataSeriesValuesMultiLevel($seriesValueSet,$dataType='n') {
|
||||
$seriesVal = array();
|
||||
$formatCode = '';
|
||||
$pointCount = 0;
|
||||
|
||||
foreach($seriesValueSet->lvl as $seriesLevelIdx => $seriesLevel) {
|
||||
foreach($seriesLevel as $seriesValueIdx => $seriesValue) {
|
||||
switch ($seriesValueIdx) {
|
||||
case 'ptCount':
|
||||
$pointCount = self::_getAttribute($seriesValue, 'val', 'integer');
|
||||
break;
|
||||
case 'formatCode':
|
||||
$formatCode = (string) $seriesValue;
|
||||
break;
|
||||
case 'pt':
|
||||
$pointVal = self::_getAttribute($seriesValue, 'idx', 'integer');
|
||||
if ($dataType == 's') {
|
||||
$seriesVal[$pointVal][] = (string) $seriesValue->v;
|
||||
} else {
|
||||
$seriesVal[$pointVal][] = (float) $seriesValue->v;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array( 'formatCode' => $formatCode,
|
||||
'pointCount' => $pointCount,
|
||||
'dataValues' => $seriesVal
|
||||
);
|
||||
} // function _chartDataSeriesValuesMultiLevel()
|
||||
|
||||
private static function _parseRichText($titleDetailPart = null) {
|
||||
$value = new PHPExcel_RichText();
|
||||
|
||||
foreach($titleDetailPart as $titleDetailElementKey => $titleDetailElement) {
|
||||
if (isset($titleDetailElement->t)) {
|
||||
$objText = $value->createTextRun( (string) $titleDetailElement->t );
|
||||
}
|
||||
if (isset($titleDetailElement->rPr)) {
|
||||
if (isset($titleDetailElement->rPr->rFont["val"])) {
|
||||
$objText->getFont()->setName((string) $titleDetailElement->rPr->rFont["val"]);
|
||||
}
|
||||
|
||||
$fontSize = (self::_getAttribute($titleDetailElement->rPr, 'sz', 'integer'));
|
||||
if (!is_null($fontSize)) {
|
||||
$objText->getFont()->setSize(floor($fontSize / 100));
|
||||
}
|
||||
|
||||
$fontColor = (self::_getAttribute($titleDetailElement->rPr, 'color', 'string'));
|
||||
if (!is_null($fontColor)) {
|
||||
$objText->getFont()->setColor( new PHPExcel_Style_Color( self::_readColor($fontColor) ) );
|
||||
}
|
||||
|
||||
$bold = self::_getAttribute($titleDetailElement->rPr, 'b', 'boolean');
|
||||
if (!is_null($bold)) {
|
||||
$objText->getFont()->setBold($bold);
|
||||
}
|
||||
|
||||
$italic = self::_getAttribute($titleDetailElement->rPr, 'i', 'boolean');
|
||||
if (!is_null($italic)) {
|
||||
$objText->getFont()->setItalic($italic);
|
||||
}
|
||||
|
||||
$baseline = self::_getAttribute($titleDetailElement->rPr, 'baseline', 'integer');
|
||||
if (!is_null($baseline)) {
|
||||
if ($baseline > 0) {
|
||||
$objText->getFont()->setSuperScript(true);
|
||||
} elseif($baseline < 0) {
|
||||
$objText->getFont()->setSubScript(true);
|
||||
}
|
||||
}
|
||||
|
||||
$underscore = (self::_getAttribute($titleDetailElement->rPr, 'u', 'string'));
|
||||
if (!is_null($underscore)) {
|
||||
if ($underscore == 'sng') {
|
||||
$objText->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_SINGLE);
|
||||
} elseif($underscore == 'dbl') {
|
||||
$objText->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_DOUBLE);
|
||||
} else {
|
||||
$objText->getFont()->setUnderline(PHPExcel_Style_Font::UNDERLINE_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
$strikethrough = (self::_getAttribute($titleDetailElement->rPr, 's', 'string'));
|
||||
if (!is_null($strikethrough)) {
|
||||
if ($strikethrough == 'noStrike') {
|
||||
$objText->getFont()->setStrikethrough(false);
|
||||
} else {
|
||||
$objText->getFont()->setStrikethrough(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
private static function _readChartAttributes($chartDetail) {
|
||||
$plotAttributes = array();
|
||||
if (isset($chartDetail->dLbls)) {
|
||||
if (isset($chartDetail->dLbls->howLegendKey)) {
|
||||
$plotAttributes['showLegendKey'] = self::_getAttribute($chartDetail->dLbls->showLegendKey, 'val', 'string');
|
||||
}
|
||||
if (isset($chartDetail->dLbls->showVal)) {
|
||||
$plotAttributes['showVal'] = self::_getAttribute($chartDetail->dLbls->showVal, 'val', 'string');
|
||||
}
|
||||
if (isset($chartDetail->dLbls->showCatName)) {
|
||||
$plotAttributes['showCatName'] = self::_getAttribute($chartDetail->dLbls->showCatName, 'val', 'string');
|
||||
}
|
||||
if (isset($chartDetail->dLbls->showSerName)) {
|
||||
$plotAttributes['showSerName'] = self::_getAttribute($chartDetail->dLbls->showSerName, 'val', 'string');
|
||||
}
|
||||
if (isset($chartDetail->dLbls->showPercent)) {
|
||||
$plotAttributes['showPercent'] = self::_getAttribute($chartDetail->dLbls->showPercent, 'val', 'string');
|
||||
}
|
||||
if (isset($chartDetail->dLbls->showBubbleSize)) {
|
||||
$plotAttributes['showBubbleSize'] = self::_getAttribute($chartDetail->dLbls->showBubbleSize, 'val', 'string');
|
||||
}
|
||||
if (isset($chartDetail->dLbls->showLeaderLines)) {
|
||||
$plotAttributes['showLeaderLines'] = self::_getAttribute($chartDetail->dLbls->showLeaderLines, 'val', 'string');
|
||||
}
|
||||
}
|
||||
|
||||
return $plotAttributes;
|
||||
}
|
||||
|
||||
private static function _setChartAttributes($plotArea,$plotAttributes)
|
||||
{
|
||||
foreach($plotAttributes as $plotAttributeKey => $plotAttributeValue) {
|
||||
switch($plotAttributeKey) {
|
||||
case 'showLegendKey' :
|
||||
$plotArea->setShowLegendKey($plotAttributeValue);
|
||||
break;
|
||||
case 'showVal' :
|
||||
$plotArea->setShowVal($plotAttributeValue);
|
||||
break;
|
||||
case 'showCatName' :
|
||||
$plotArea->setShowCatName($plotAttributeValue);
|
||||
break;
|
||||
case 'showSerName' :
|
||||
$plotArea->setShowSerName($plotAttributeValue);
|
||||
break;
|
||||
case 'showPercent' :
|
||||
$plotArea->setShowPercent($plotAttributeValue);
|
||||
break;
|
||||
case 'showBubbleSize' :
|
||||
$plotArea->setShowBubbleSize($plotAttributeValue);
|
||||
break;
|
||||
case 'showLeaderLines' :
|
||||
$plotArea->setShowLeaderLines($plotAttributeValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
124
extend/phpexcel/PHPExcel/Reader/Excel2007/Theme.php
Executable file
124
extend/phpexcel/PHPExcel/Reader/Excel2007/Theme.php
Executable file
@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2014 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_Excel2007
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version 1.8.0, 2014-03-02
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* PHPExcel_Reader_Excel2007_Theme
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Reader_Excel2007
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class PHPExcel_Reader_Excel2007_Theme
|
||||
{
|
||||
/**
|
||||
* Theme Name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_themeName;
|
||||
|
||||
/**
|
||||
* Colour Scheme Name
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_colourSchemeName;
|
||||
|
||||
/**
|
||||
* Colour Map indexed by position
|
||||
*
|
||||
* @var array of string
|
||||
*/
|
||||
private $_colourMapValues;
|
||||
|
||||
|
||||
/**
|
||||
* Colour Map
|
||||
*
|
||||
* @var array of string
|
||||
*/
|
||||
private $_colourMap;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new PHPExcel_Theme
|
||||
*
|
||||
*/
|
||||
public function __construct($themeName,$colourSchemeName,$colourMap)
|
||||
{
|
||||
// Initialise values
|
||||
$this->_themeName = $themeName;
|
||||
$this->_colourSchemeName = $colourSchemeName;
|
||||
$this->_colourMap = $colourMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Theme Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getThemeName()
|
||||
{
|
||||
return $this->_themeName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get colour Scheme Name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getColourSchemeName() {
|
||||
return $this->_colourSchemeName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get colour Map Value by Position
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getColourByIndex($index=0) {
|
||||
if (isset($this->_colourMap[$index])) {
|
||||
return $this->_colourMap[$index];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement PHP __clone to create a deep clone, not just a shallow copy.
|
||||
*/
|
||||
public function __clone() {
|
||||
$vars = get_object_vars($this);
|
||||
foreach ($vars as $key => $value) {
|
||||
if ((is_object($value)) && ($key != '_parent')) {
|
||||
$this->$key = clone $value;
|
||||
} else {
|
||||
$this->$key = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
7084
extend/phpexcel/PHPExcel/Reader/Excel5.php
Executable file
7084
extend/phpexcel/PHPExcel/Reader/Excel5.php
Executable file
File diff suppressed because it is too large
Load Diff
640
extend/phpexcel/PHPExcel/Reader/Excel5/Escher.php
Executable file
640
extend/phpexcel/PHPExcel/Reader/Excel5/Escher.php
Executable file
@ -0,0 +1,640 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2014 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 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version 1.8.0, 2014-03-02
|
||||
*/
|
||||
|
||||
/**
|
||||
* PHPExcel_Reader_Excel5_Escher
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Reader_Excel5
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class PHPExcel_Reader_Excel5_Escher
|
||||
{
|
||||
const DGGCONTAINER = 0xF000;
|
||||
const BSTORECONTAINER = 0xF001;
|
||||
const DGCONTAINER = 0xF002;
|
||||
const SPGRCONTAINER = 0xF003;
|
||||
const SPCONTAINER = 0xF004;
|
||||
const DGG = 0xF006;
|
||||
const BSE = 0xF007;
|
||||
const DG = 0xF008;
|
||||
const SPGR = 0xF009;
|
||||
const SP = 0xF00A;
|
||||
const OPT = 0xF00B;
|
||||
const CLIENTTEXTBOX = 0xF00D;
|
||||
const CLIENTANCHOR = 0xF010;
|
||||
const CLIENTDATA = 0xF011;
|
||||
const BLIPJPEG = 0xF01D;
|
||||
const BLIPPNG = 0xF01E;
|
||||
const SPLITMENUCOLORS = 0xF11E;
|
||||
const TERTIARYOPT = 0xF122;
|
||||
|
||||
/**
|
||||
* Escher stream data (binary)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_data;
|
||||
|
||||
/**
|
||||
* Size in bytes of the Escher stream data
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_dataSize;
|
||||
|
||||
/**
|
||||
* Current position of stream pointer in Escher stream data
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_pos;
|
||||
|
||||
/**
|
||||
* The object to be returned by the reader. Modified during load.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
private $_object;
|
||||
|
||||
/**
|
||||
* Create a new PHPExcel_Reader_Excel5_Escher instance
|
||||
*
|
||||
* @param mixed $object
|
||||
*/
|
||||
public function __construct($object)
|
||||
{
|
||||
$this->_object = $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load Escher stream data. May be a partial Escher stream.
|
||||
*
|
||||
* @param string $data
|
||||
*/
|
||||
public function load($data)
|
||||
{
|
||||
$this->_data = $data;
|
||||
|
||||
// total byte size of Excel data (workbook global substream + sheet substreams)
|
||||
$this->_dataSize = strlen($this->_data);
|
||||
|
||||
$this->_pos = 0;
|
||||
|
||||
// Parse Escher stream
|
||||
while ($this->_pos < $this->_dataSize) {
|
||||
|
||||
// offset: 2; size: 2: Record Type
|
||||
$fbt = PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos + 2);
|
||||
|
||||
switch ($fbt) {
|
||||
case self::DGGCONTAINER: $this->_readDggContainer(); break;
|
||||
case self::DGG: $this->_readDgg(); break;
|
||||
case self::BSTORECONTAINER: $this->_readBstoreContainer(); break;
|
||||
case self::BSE: $this->_readBSE(); break;
|
||||
case self::BLIPJPEG: $this->_readBlipJPEG(); break;
|
||||
case self::BLIPPNG: $this->_readBlipPNG(); break;
|
||||
case self::OPT: $this->_readOPT(); break;
|
||||
case self::TERTIARYOPT: $this->_readTertiaryOPT(); break;
|
||||
case self::SPLITMENUCOLORS: $this->_readSplitMenuColors(); break;
|
||||
case self::DGCONTAINER: $this->_readDgContainer(); break;
|
||||
case self::DG: $this->_readDg(); break;
|
||||
case self::SPGRCONTAINER: $this->_readSpgrContainer(); break;
|
||||
case self::SPCONTAINER: $this->_readSpContainer(); break;
|
||||
case self::SPGR: $this->_readSpgr(); break;
|
||||
case self::SP: $this->_readSp(); break;
|
||||
case self::CLIENTTEXTBOX: $this->_readClientTextbox(); break;
|
||||
case self::CLIENTANCHOR: $this->_readClientAnchor(); break;
|
||||
case self::CLIENTDATA: $this->_readClientData(); break;
|
||||
default: $this->_readDefault(); break;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a generic record
|
||||
*/
|
||||
private function _readDefault()
|
||||
{
|
||||
// offset 0; size: 2; recVer and recInstance
|
||||
$verInstance = PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos);
|
||||
|
||||
// offset: 2; size: 2: Record Type
|
||||
$fbt = PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos + 2);
|
||||
|
||||
// bit: 0-3; mask: 0x000F; recVer
|
||||
$recVer = (0x000F & $verInstance) >> 0;
|
||||
|
||||
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read DggContainer record (Drawing Group Container)
|
||||
*/
|
||||
private function _readDggContainer()
|
||||
{
|
||||
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
|
||||
// record is a container, read contents
|
||||
$dggContainer = new PHPExcel_Shared_Escher_DggContainer();
|
||||
$this->_object->setDggContainer($dggContainer);
|
||||
$reader = new PHPExcel_Reader_Excel5_Escher($dggContainer);
|
||||
$reader->load($recordData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read Dgg record (Drawing Group)
|
||||
*/
|
||||
private function _readDgg()
|
||||
{
|
||||
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read BstoreContainer record (Blip Store Container)
|
||||
*/
|
||||
private function _readBstoreContainer()
|
||||
{
|
||||
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
|
||||
// record is a container, read contents
|
||||
$bstoreContainer = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer();
|
||||
$this->_object->setBstoreContainer($bstoreContainer);
|
||||
$reader = new PHPExcel_Reader_Excel5_Escher($bstoreContainer);
|
||||
$reader->load($recordData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read BSE record
|
||||
*/
|
||||
private function _readBSE()
|
||||
{
|
||||
// offset: 0; size: 2; recVer and recInstance
|
||||
|
||||
// bit: 4-15; mask: 0xFFF0; recInstance
|
||||
$recInstance = (0xFFF0 & PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos)) >> 4;
|
||||
|
||||
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
|
||||
// add BSE to BstoreContainer
|
||||
$BSE = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE();
|
||||
$this->_object->addBSE($BSE);
|
||||
|
||||
$BSE->setBLIPType($recInstance);
|
||||
|
||||
// offset: 0; size: 1; btWin32 (MSOBLIPTYPE)
|
||||
$btWin32 = ord($recordData[0]);
|
||||
|
||||
// offset: 1; size: 1; btWin32 (MSOBLIPTYPE)
|
||||
$btMacOS = ord($recordData[1]);
|
||||
|
||||
// offset: 2; size: 16; MD4 digest
|
||||
$rgbUid = substr($recordData, 2, 16);
|
||||
|
||||
// offset: 18; size: 2; tag
|
||||
$tag = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 18);
|
||||
|
||||
// offset: 20; size: 4; size of BLIP in bytes
|
||||
$size = PHPExcel_Reader_Excel5::_GetInt4d($recordData, 20);
|
||||
|
||||
// offset: 24; size: 4; number of references to this BLIP
|
||||
$cRef = PHPExcel_Reader_Excel5::_GetInt4d($recordData, 24);
|
||||
|
||||
// offset: 28; size: 4; MSOFO file offset
|
||||
$foDelay = PHPExcel_Reader_Excel5::_GetInt4d($recordData, 28);
|
||||
|
||||
// offset: 32; size: 1; unused1
|
||||
$unused1 = ord($recordData{32});
|
||||
|
||||
// offset: 33; size: 1; size of nameData in bytes (including null terminator)
|
||||
$cbName = ord($recordData{33});
|
||||
|
||||
// offset: 34; size: 1; unused2
|
||||
$unused2 = ord($recordData{34});
|
||||
|
||||
// offset: 35; size: 1; unused3
|
||||
$unused3 = ord($recordData{35});
|
||||
|
||||
// offset: 36; size: $cbName; nameData
|
||||
$nameData = substr($recordData, 36, $cbName);
|
||||
|
||||
// offset: 36 + $cbName, size: var; the BLIP data
|
||||
$blipData = substr($recordData, 36 + $cbName);
|
||||
|
||||
// record is a container, read contents
|
||||
$reader = new PHPExcel_Reader_Excel5_Escher($BSE);
|
||||
$reader->load($blipData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read BlipJPEG record. Holds raw JPEG image data
|
||||
*/
|
||||
private function _readBlipJPEG()
|
||||
{
|
||||
// offset: 0; size: 2; recVer and recInstance
|
||||
|
||||
// bit: 4-15; mask: 0xFFF0; recInstance
|
||||
$recInstance = (0xFFF0 & PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos)) >> 4;
|
||||
|
||||
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
|
||||
$pos = 0;
|
||||
|
||||
// offset: 0; size: 16; rgbUid1 (MD4 digest of)
|
||||
$rgbUid1 = substr($recordData, 0, 16);
|
||||
$pos += 16;
|
||||
|
||||
// offset: 16; size: 16; rgbUid2 (MD4 digest), only if $recInstance = 0x46B or 0x6E3
|
||||
if (in_array($recInstance, array(0x046B, 0x06E3))) {
|
||||
$rgbUid2 = substr($recordData, 16, 16);
|
||||
$pos += 16;
|
||||
}
|
||||
|
||||
// offset: var; size: 1; tag
|
||||
$tag = ord($recordData{$pos});
|
||||
$pos += 1;
|
||||
|
||||
// offset: var; size: var; the raw image data
|
||||
$data = substr($recordData, $pos);
|
||||
|
||||
$blip = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip();
|
||||
$blip->setData($data);
|
||||
|
||||
$this->_object->setBlip($blip);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read BlipPNG record. Holds raw PNG image data
|
||||
*/
|
||||
private function _readBlipPNG()
|
||||
{
|
||||
// offset: 0; size: 2; recVer and recInstance
|
||||
|
||||
// bit: 4-15; mask: 0xFFF0; recInstance
|
||||
$recInstance = (0xFFF0 & PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos)) >> 4;
|
||||
|
||||
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
|
||||
$pos = 0;
|
||||
|
||||
// offset: 0; size: 16; rgbUid1 (MD4 digest of)
|
||||
$rgbUid1 = substr($recordData, 0, 16);
|
||||
$pos += 16;
|
||||
|
||||
// offset: 16; size: 16; rgbUid2 (MD4 digest), only if $recInstance = 0x46B or 0x6E3
|
||||
if ($recInstance == 0x06E1) {
|
||||
$rgbUid2 = substr($recordData, 16, 16);
|
||||
$pos += 16;
|
||||
}
|
||||
|
||||
// offset: var; size: 1; tag
|
||||
$tag = ord($recordData{$pos});
|
||||
$pos += 1;
|
||||
|
||||
// offset: var; size: var; the raw image data
|
||||
$data = substr($recordData, $pos);
|
||||
|
||||
$blip = new PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE_Blip();
|
||||
$blip->setData($data);
|
||||
|
||||
$this->_object->setBlip($blip);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read OPT record. This record may occur within DggContainer record or SpContainer
|
||||
*/
|
||||
private function _readOPT()
|
||||
{
|
||||
// offset: 0; size: 2; recVer and recInstance
|
||||
|
||||
// bit: 4-15; mask: 0xFFF0; recInstance
|
||||
$recInstance = (0xFFF0 & PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos)) >> 4;
|
||||
|
||||
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
|
||||
$this->_readOfficeArtRGFOPTE($recordData, $recInstance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read TertiaryOPT record
|
||||
*/
|
||||
private function _readTertiaryOPT()
|
||||
{
|
||||
// offset: 0; size: 2; recVer and recInstance
|
||||
|
||||
// bit: 4-15; mask: 0xFFF0; recInstance
|
||||
$recInstance = (0xFFF0 & PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos)) >> 4;
|
||||
|
||||
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read SplitMenuColors record
|
||||
*/
|
||||
private function _readSplitMenuColors()
|
||||
{
|
||||
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read DgContainer record (Drawing Container)
|
||||
*/
|
||||
private function _readDgContainer()
|
||||
{
|
||||
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
|
||||
// record is a container, read contents
|
||||
$dgContainer = new PHPExcel_Shared_Escher_DgContainer();
|
||||
$this->_object->setDgContainer($dgContainer);
|
||||
$reader = new PHPExcel_Reader_Excel5_Escher($dgContainer);
|
||||
$escher = $reader->load($recordData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read Dg record (Drawing)
|
||||
*/
|
||||
private function _readDg()
|
||||
{
|
||||
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read SpgrContainer record (Shape Group Container)
|
||||
*/
|
||||
private function _readSpgrContainer()
|
||||
{
|
||||
// context is either context DgContainer or SpgrContainer
|
||||
|
||||
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
|
||||
// record is a container, read contents
|
||||
$spgrContainer = new PHPExcel_Shared_Escher_DgContainer_SpgrContainer();
|
||||
|
||||
if ($this->_object instanceof PHPExcel_Shared_Escher_DgContainer) {
|
||||
// DgContainer
|
||||
$this->_object->setSpgrContainer($spgrContainer);
|
||||
} else {
|
||||
// SpgrContainer
|
||||
$this->_object->addChild($spgrContainer);
|
||||
}
|
||||
|
||||
$reader = new PHPExcel_Reader_Excel5_Escher($spgrContainer);
|
||||
$escher = $reader->load($recordData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read SpContainer record (Shape Container)
|
||||
*/
|
||||
private function _readSpContainer()
|
||||
{
|
||||
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// add spContainer to spgrContainer
|
||||
$spContainer = new PHPExcel_Shared_Escher_DgContainer_SpgrContainer_SpContainer();
|
||||
$this->_object->addChild($spContainer);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
|
||||
// record is a container, read contents
|
||||
$reader = new PHPExcel_Reader_Excel5_Escher($spContainer);
|
||||
$escher = $reader->load($recordData);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read Spgr record (Shape Group)
|
||||
*/
|
||||
private function _readSpgr()
|
||||
{
|
||||
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read Sp record (Shape)
|
||||
*/
|
||||
private function _readSp()
|
||||
{
|
||||
// offset: 0; size: 2; recVer and recInstance
|
||||
|
||||
// bit: 4-15; mask: 0xFFF0; recInstance
|
||||
$recInstance = (0xFFF0 & PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos)) >> 4;
|
||||
|
||||
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read ClientTextbox record
|
||||
*/
|
||||
private function _readClientTextbox()
|
||||
{
|
||||
// offset: 0; size: 2; recVer and recInstance
|
||||
|
||||
// bit: 4-15; mask: 0xFFF0; recInstance
|
||||
$recInstance = (0xFFF0 & PHPExcel_Reader_Excel5::_GetInt2d($this->_data, $this->_pos)) >> 4;
|
||||
|
||||
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read ClientAnchor record. This record holds information about where the shape is anchored in worksheet
|
||||
*/
|
||||
private function _readClientAnchor()
|
||||
{
|
||||
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
|
||||
// offset: 2; size: 2; upper-left corner column index (0-based)
|
||||
$c1 = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 2);
|
||||
|
||||
// offset: 4; size: 2; upper-left corner horizontal offset in 1/1024 of column width
|
||||
$startOffsetX = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 4);
|
||||
|
||||
// offset: 6; size: 2; upper-left corner row index (0-based)
|
||||
$r1 = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 6);
|
||||
|
||||
// offset: 8; size: 2; upper-left corner vertical offset in 1/256 of row height
|
||||
$startOffsetY = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 8);
|
||||
|
||||
// offset: 10; size: 2; bottom-right corner column index (0-based)
|
||||
$c2 = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 10);
|
||||
|
||||
// offset: 12; size: 2; bottom-right corner horizontal offset in 1/1024 of column width
|
||||
$endOffsetX = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 12);
|
||||
|
||||
// offset: 14; size: 2; bottom-right corner row index (0-based)
|
||||
$r2 = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 14);
|
||||
|
||||
// offset: 16; size: 2; bottom-right corner vertical offset in 1/256 of row height
|
||||
$endOffsetY = PHPExcel_Reader_Excel5::_GetInt2d($recordData, 16);
|
||||
|
||||
// set the start coordinates
|
||||
$this->_object->setStartCoordinates(PHPExcel_Cell::stringFromColumnIndex($c1) . ($r1 + 1));
|
||||
|
||||
// set the start offsetX
|
||||
$this->_object->setStartOffsetX($startOffsetX);
|
||||
|
||||
// set the start offsetY
|
||||
$this->_object->setStartOffsetY($startOffsetY);
|
||||
|
||||
// set the end coordinates
|
||||
$this->_object->setEndCoordinates(PHPExcel_Cell::stringFromColumnIndex($c2) . ($r2 + 1));
|
||||
|
||||
// set the end offsetX
|
||||
$this->_object->setEndOffsetX($endOffsetX);
|
||||
|
||||
// set the end offsetY
|
||||
$this->_object->setEndOffsetY($endOffsetY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read ClientData record
|
||||
*/
|
||||
private function _readClientData()
|
||||
{
|
||||
$length = PHPExcel_Reader_Excel5::_GetInt4d($this->_data, $this->_pos + 4);
|
||||
$recordData = substr($this->_data, $this->_pos + 8, $length);
|
||||
|
||||
// move stream pointer to next record
|
||||
$this->_pos += 8 + $length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read OfficeArtRGFOPTE table of property-value pairs
|
||||
*
|
||||
* @param string $data Binary data
|
||||
* @param int $n Number of properties
|
||||
*/
|
||||
private function _readOfficeArtRGFOPTE($data, $n) {
|
||||
|
||||
$splicedComplexData = substr($data, 6 * $n);
|
||||
|
||||
// loop through property-value pairs
|
||||
for ($i = 0; $i < $n; ++$i) {
|
||||
// read 6 bytes at a time
|
||||
$fopte = substr($data, 6 * $i, 6);
|
||||
|
||||
// offset: 0; size: 2; opid
|
||||
$opid = PHPExcel_Reader_Excel5::_GetInt2d($fopte, 0);
|
||||
|
||||
// bit: 0-13; mask: 0x3FFF; opid.opid
|
||||
$opidOpid = (0x3FFF & $opid) >> 0;
|
||||
|
||||
// bit: 14; mask 0x4000; 1 = value in op field is BLIP identifier
|
||||
$opidFBid = (0x4000 & $opid) >> 14;
|
||||
|
||||
// bit: 15; mask 0x8000; 1 = this is a complex property, op field specifies size of complex data
|
||||
$opidFComplex = (0x8000 & $opid) >> 15;
|
||||
|
||||
// offset: 2; size: 4; the value for this property
|
||||
$op = PHPExcel_Reader_Excel5::_GetInt4d($fopte, 2);
|
||||
|
||||
if ($opidFComplex) {
|
||||
$complexData = substr($splicedComplexData, 0, $op);
|
||||
$splicedComplexData = substr($splicedComplexData, $op);
|
||||
|
||||
// we store string value with complex data
|
||||
$value = $complexData;
|
||||
} else {
|
||||
// we store integer value
|
||||
$value = $op;
|
||||
}
|
||||
|
||||
$this->_object->setOPT($opidOpid, $value);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
221
extend/phpexcel/PHPExcel/Reader/Excel5/MD5.php
Executable file
221
extend/phpexcel/PHPExcel/Reader/Excel5/MD5.php
Executable file
@ -0,0 +1,221 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2014 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 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version 1.8.0, 2014-03-02
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* PHPExcel_Reader_Excel5_MD5
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Reader_Excel5
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class PHPExcel_Reader_Excel5_MD5
|
||||
{
|
||||
// Context
|
||||
private $a;
|
||||
private $b;
|
||||
private $c;
|
||||
private $d;
|
||||
|
||||
|
||||
/**
|
||||
* MD5 stream constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->reset();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reset the MD5 stream context
|
||||
*/
|
||||
public function reset()
|
||||
{
|
||||
$this->a = 0x67452301;
|
||||
$this->b = 0xEFCDAB89;
|
||||
$this->c = 0x98BADCFE;
|
||||
$this->d = 0x10325476;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get MD5 stream context
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getContext()
|
||||
{
|
||||
$s = '';
|
||||
foreach (array('a', 'b', 'c', 'd') as $i) {
|
||||
$v = $this->{$i};
|
||||
$s .= chr($v & 0xff);
|
||||
$s .= chr(($v >> 8) & 0xff);
|
||||
$s .= chr(($v >> 16) & 0xff);
|
||||
$s .= chr(($v >> 24) & 0xff);
|
||||
}
|
||||
|
||||
return $s;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add data to context
|
||||
*
|
||||
* @param string $data Data to add
|
||||
*/
|
||||
public function add($data)
|
||||
{
|
||||
$words = array_values(unpack('V16', $data));
|
||||
|
||||
$A = $this->a;
|
||||
$B = $this->b;
|
||||
$C = $this->c;
|
||||
$D = $this->d;
|
||||
|
||||
$F = array('PHPExcel_Reader_Excel5_MD5','F');
|
||||
$G = array('PHPExcel_Reader_Excel5_MD5','G');
|
||||
$H = array('PHPExcel_Reader_Excel5_MD5','H');
|
||||
$I = array('PHPExcel_Reader_Excel5_MD5','I');
|
||||
|
||||
/* ROUND 1 */
|
||||
self::step($F, $A, $B, $C, $D, $words[0], 7, 0xd76aa478);
|
||||
self::step($F, $D, $A, $B, $C, $words[1], 12, 0xe8c7b756);
|
||||
self::step($F, $C, $D, $A, $B, $words[2], 17, 0x242070db);
|
||||
self::step($F, $B, $C, $D, $A, $words[3], 22, 0xc1bdceee);
|
||||
self::step($F, $A, $B, $C, $D, $words[4], 7, 0xf57c0faf);
|
||||
self::step($F, $D, $A, $B, $C, $words[5], 12, 0x4787c62a);
|
||||
self::step($F, $C, $D, $A, $B, $words[6], 17, 0xa8304613);
|
||||
self::step($F, $B, $C, $D, $A, $words[7], 22, 0xfd469501);
|
||||
self::step($F, $A, $B, $C, $D, $words[8], 7, 0x698098d8);
|
||||
self::step($F, $D, $A, $B, $C, $words[9], 12, 0x8b44f7af);
|
||||
self::step($F, $C, $D, $A, $B, $words[10], 17, 0xffff5bb1);
|
||||
self::step($F, $B, $C, $D, $A, $words[11], 22, 0x895cd7be);
|
||||
self::step($F, $A, $B, $C, $D, $words[12], 7, 0x6b901122);
|
||||
self::step($F, $D, $A, $B, $C, $words[13], 12, 0xfd987193);
|
||||
self::step($F, $C, $D, $A, $B, $words[14], 17, 0xa679438e);
|
||||
self::step($F, $B, $C, $D, $A, $words[15], 22, 0x49b40821);
|
||||
|
||||
/* ROUND 2 */
|
||||
self::step($G, $A, $B, $C, $D, $words[1], 5, 0xf61e2562);
|
||||
self::step($G, $D, $A, $B, $C, $words[6], 9, 0xc040b340);
|
||||
self::step($G, $C, $D, $A, $B, $words[11], 14, 0x265e5a51);
|
||||
self::step($G, $B, $C, $D, $A, $words[0], 20, 0xe9b6c7aa);
|
||||
self::step($G, $A, $B, $C, $D, $words[5], 5, 0xd62f105d);
|
||||
self::step($G, $D, $A, $B, $C, $words[10], 9, 0x02441453);
|
||||
self::step($G, $C, $D, $A, $B, $words[15], 14, 0xd8a1e681);
|
||||
self::step($G, $B, $C, $D, $A, $words[4], 20, 0xe7d3fbc8);
|
||||
self::step($G, $A, $B, $C, $D, $words[9], 5, 0x21e1cde6);
|
||||
self::step($G, $D, $A, $B, $C, $words[14], 9, 0xc33707d6);
|
||||
self::step($G, $C, $D, $A, $B, $words[3], 14, 0xf4d50d87);
|
||||
self::step($G, $B, $C, $D, $A, $words[8], 20, 0x455a14ed);
|
||||
self::step($G, $A, $B, $C, $D, $words[13], 5, 0xa9e3e905);
|
||||
self::step($G, $D, $A, $B, $C, $words[2], 9, 0xfcefa3f8);
|
||||
self::step($G, $C, $D, $A, $B, $words[7], 14, 0x676f02d9);
|
||||
self::step($G, $B, $C, $D, $A, $words[12], 20, 0x8d2a4c8a);
|
||||
|
||||
/* ROUND 3 */
|
||||
self::step($H, $A, $B, $C, $D, $words[5], 4, 0xfffa3942);
|
||||
self::step($H, $D, $A, $B, $C, $words[8], 11, 0x8771f681);
|
||||
self::step($H, $C, $D, $A, $B, $words[11], 16, 0x6d9d6122);
|
||||
self::step($H, $B, $C, $D, $A, $words[14], 23, 0xfde5380c);
|
||||
self::step($H, $A, $B, $C, $D, $words[1], 4, 0xa4beea44);
|
||||
self::step($H, $D, $A, $B, $C, $words[4], 11, 0x4bdecfa9);
|
||||
self::step($H, $C, $D, $A, $B, $words[7], 16, 0xf6bb4b60);
|
||||
self::step($H, $B, $C, $D, $A, $words[10], 23, 0xbebfbc70);
|
||||
self::step($H, $A, $B, $C, $D, $words[13], 4, 0x289b7ec6);
|
||||
self::step($H, $D, $A, $B, $C, $words[0], 11, 0xeaa127fa);
|
||||
self::step($H, $C, $D, $A, $B, $words[3], 16, 0xd4ef3085);
|
||||
self::step($H, $B, $C, $D, $A, $words[6], 23, 0x04881d05);
|
||||
self::step($H, $A, $B, $C, $D, $words[9], 4, 0xd9d4d039);
|
||||
self::step($H, $D, $A, $B, $C, $words[12], 11, 0xe6db99e5);
|
||||
self::step($H, $C, $D, $A, $B, $words[15], 16, 0x1fa27cf8);
|
||||
self::step($H, $B, $C, $D, $A, $words[2], 23, 0xc4ac5665);
|
||||
|
||||
/* ROUND 4 */
|
||||
self::step($I, $A, $B, $C, $D, $words[0], 6, 0xf4292244);
|
||||
self::step($I, $D, $A, $B, $C, $words[7], 10, 0x432aff97);
|
||||
self::step($I, $C, $D, $A, $B, $words[14], 15, 0xab9423a7);
|
||||
self::step($I, $B, $C, $D, $A, $words[5], 21, 0xfc93a039);
|
||||
self::step($I, $A, $B, $C, $D, $words[12], 6, 0x655b59c3);
|
||||
self::step($I, $D, $A, $B, $C, $words[3], 10, 0x8f0ccc92);
|
||||
self::step($I, $C, $D, $A, $B, $words[10], 15, 0xffeff47d);
|
||||
self::step($I, $B, $C, $D, $A, $words[1], 21, 0x85845dd1);
|
||||
self::step($I, $A, $B, $C, $D, $words[8], 6, 0x6fa87e4f);
|
||||
self::step($I, $D, $A, $B, $C, $words[15], 10, 0xfe2ce6e0);
|
||||
self::step($I, $C, $D, $A, $B, $words[6], 15, 0xa3014314);
|
||||
self::step($I, $B, $C, $D, $A, $words[13], 21, 0x4e0811a1);
|
||||
self::step($I, $A, $B, $C, $D, $words[4], 6, 0xf7537e82);
|
||||
self::step($I, $D, $A, $B, $C, $words[11], 10, 0xbd3af235);
|
||||
self::step($I, $C, $D, $A, $B, $words[2], 15, 0x2ad7d2bb);
|
||||
self::step($I, $B, $C, $D, $A, $words[9], 21, 0xeb86d391);
|
||||
|
||||
$this->a = ($this->a + $A) & 0xffffffff;
|
||||
$this->b = ($this->b + $B) & 0xffffffff;
|
||||
$this->c = ($this->c + $C) & 0xffffffff;
|
||||
$this->d = ($this->d + $D) & 0xffffffff;
|
||||
}
|
||||
|
||||
|
||||
private static function F($X, $Y, $Z)
|
||||
{
|
||||
return (($X & $Y) | ((~ $X) & $Z)); // X AND Y OR NOT X AND Z
|
||||
}
|
||||
|
||||
|
||||
private static function G($X, $Y, $Z)
|
||||
{
|
||||
return (($X & $Z) | ($Y & (~ $Z))); // X AND Z OR Y AND NOT Z
|
||||
}
|
||||
|
||||
|
||||
private static function H($X, $Y, $Z)
|
||||
{
|
||||
return ($X ^ $Y ^ $Z); // X XOR Y XOR Z
|
||||
}
|
||||
|
||||
|
||||
private static function I($X, $Y, $Z)
|
||||
{
|
||||
return ($Y ^ ($X | (~ $Z))) ; // Y XOR (X OR NOT Z)
|
||||
}
|
||||
|
||||
|
||||
private static function step($func, &$A, $B, $C, $D, $M, $s, $t)
|
||||
{
|
||||
$A = ($A + call_user_func($func, $B, $C, $D) + $M + $t) & 0xffffffff;
|
||||
$A = self::rotate($A, $s);
|
||||
$A = ($B + $A) & 0xffffffff;
|
||||
}
|
||||
|
||||
|
||||
private static function rotate($decimal, $bits)
|
||||
{
|
||||
$binary = str_pad(decbin($decimal), 32, "0", STR_PAD_LEFT);
|
||||
return bindec(substr($binary, $bits).substr($binary, 0, $bits));
|
||||
}
|
||||
}
|
88
extend/phpexcel/PHPExcel/Reader/Excel5/RC4.php
Executable file
88
extend/phpexcel/PHPExcel/Reader/Excel5/RC4.php
Executable file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2014 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 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version 1.8.0, 2014-03-02
|
||||
*/
|
||||
|
||||
/**
|
||||
* PHPExcel_Reader_Excel5_RC4
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Reader_Excel5
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class PHPExcel_Reader_Excel5_RC4
|
||||
{
|
||||
// Context
|
||||
var $s = array();
|
||||
var $i = 0;
|
||||
var $j = 0;
|
||||
|
||||
/**
|
||||
* RC4 stream decryption/encryption constrcutor
|
||||
*
|
||||
* @param string $key Encryption key/passphrase
|
||||
*/
|
||||
public function __construct($key)
|
||||
{
|
||||
$len = strlen($key);
|
||||
|
||||
for ($this->i = 0; $this->i < 256; $this->i++) {
|
||||
$this->s[$this->i] = $this->i;
|
||||
}
|
||||
|
||||
$this->j = 0;
|
||||
for ($this->i = 0; $this->i < 256; $this->i++) {
|
||||
$this->j = ($this->j + $this->s[$this->i] + ord($key[$this->i % $len])) % 256;
|
||||
$t = $this->s[$this->i];
|
||||
$this->s[$this->i] = $this->s[$this->j];
|
||||
$this->s[$this->j] = $t;
|
||||
}
|
||||
$this->i = $this->j = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Symmetric decryption/encryption function
|
||||
*
|
||||
* @param string $data Data to encrypt/decrypt
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function RC4($data)
|
||||
{
|
||||
$len = strlen($data);
|
||||
for ($c = 0; $c < $len; $c++) {
|
||||
$this->i = ($this->i + 1) % 256;
|
||||
$this->j = ($this->j + $this->s[$this->i]) % 256;
|
||||
$t = $this->s[$this->i];
|
||||
$this->s[$this->i] = $this->s[$this->j];
|
||||
$this->s[$this->j] = $t;
|
||||
|
||||
$t = ($this->s[$this->i] + $this->s[$this->j]) % 256;
|
||||
|
||||
$data[$c] = chr(ord($data[$c]) ^ $this->s[$t]);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
52
extend/phpexcel/PHPExcel/Reader/Exception.php
Executable file
52
extend/phpexcel/PHPExcel/Reader/Exception.php
Executable file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2014 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
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version 1.8.0, 2014-03-02
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* PHPExcel_Reader_Exception
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Reader
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class PHPExcel_Reader_Exception extends PHPExcel_Exception {
|
||||
/**
|
||||
* Error handler callback
|
||||
*
|
||||
* @param mixed $code
|
||||
* @param mixed $string
|
||||
* @param mixed $file
|
||||
* @param mixed $line
|
||||
* @param mixed $context
|
||||
*/
|
||||
public static function errorHandlerCallback($code, $string, $file, $line, $context) {
|
||||
$e = new self($string, $code);
|
||||
$e->line = $line;
|
||||
$e->file = $file;
|
||||
throw $e;
|
||||
}
|
||||
}
|
873
extend/phpexcel/PHPExcel/Reader/Gnumeric.php
Executable file
873
extend/phpexcel/PHPExcel/Reader/Gnumeric.php
Executable file
@ -0,0 +1,873 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2014 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
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version 1.8.0, 2014-03-02
|
||||
*/
|
||||
|
||||
|
||||
/** PHPExcel root directory */
|
||||
if (!defined('PHPEXCEL_ROOT')) {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
|
||||
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* PHPExcel_Reader_Gnumeric
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Reader
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class PHPExcel_Reader_Gnumeric extends PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
|
||||
{
|
||||
/**
|
||||
* Formats
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_styles = array();
|
||||
|
||||
/**
|
||||
* Shared Expressions
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_expressions = array();
|
||||
|
||||
private $_referenceHelper = null;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new PHPExcel_Reader_Gnumeric
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
|
||||
$this->_referenceHelper = PHPExcel_ReferenceHelper::getInstance();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Can the current PHPExcel_Reader_IReader read the file?
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @return boolean
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function canRead($pFilename)
|
||||
{
|
||||
// Check if file exists
|
||||
if (!file_exists($pFilename)) {
|
||||
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
|
||||
}
|
||||
|
||||
// Check if gzlib functions are available
|
||||
if (!function_exists('gzread')) {
|
||||
throw new PHPExcel_Reader_Exception("gzlib library is not enabled");
|
||||
}
|
||||
|
||||
// Read signature data (first 3 bytes)
|
||||
$fh = fopen($pFilename, 'r');
|
||||
$data = fread($fh, 2);
|
||||
fclose($fh);
|
||||
|
||||
if ($data != chr(0x1F).chr(0x8B)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function listWorksheetNames($pFilename)
|
||||
{
|
||||
// Check if file exists
|
||||
if (!file_exists($pFilename)) {
|
||||
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
|
||||
}
|
||||
|
||||
$xml = new XMLReader();
|
||||
$xml->open(
|
||||
'compress.zlib://'.realpath($pFilename), null, PHPExcel_Settings::getLibXmlLoaderOptions()
|
||||
);
|
||||
$xml->setParserProperty(2,true);
|
||||
|
||||
$worksheetNames = array();
|
||||
while ($xml->read()) {
|
||||
if ($xml->name == 'gnm:SheetName' && $xml->nodeType == XMLReader::ELEMENT) {
|
||||
$xml->read(); // Move onto the value node
|
||||
$worksheetNames[] = (string) $xml->value;
|
||||
} elseif ($xml->name == 'gnm:Sheets') {
|
||||
// break out of the loop once we've got our sheet names rather than parse the entire file
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $worksheetNames;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns)
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function listWorksheetInfo($pFilename)
|
||||
{
|
||||
// Check if file exists
|
||||
if (!file_exists($pFilename)) {
|
||||
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
|
||||
}
|
||||
|
||||
$xml = new XMLReader();
|
||||
$xml->open(
|
||||
'compress.zlib://'.realpath($pFilename), null, PHPExcel_Settings::getLibXmlLoaderOptions()
|
||||
);
|
||||
$xml->setParserProperty(2,true);
|
||||
|
||||
$worksheetInfo = array();
|
||||
while ($xml->read()) {
|
||||
if ($xml->name == 'gnm:Sheet' && $xml->nodeType == XMLReader::ELEMENT) {
|
||||
$tmpInfo = array(
|
||||
'worksheetName' => '',
|
||||
'lastColumnLetter' => 'A',
|
||||
'lastColumnIndex' => 0,
|
||||
'totalRows' => 0,
|
||||
'totalColumns' => 0,
|
||||
);
|
||||
|
||||
while ($xml->read()) {
|
||||
if ($xml->name == 'gnm:Name' && $xml->nodeType == XMLReader::ELEMENT) {
|
||||
$xml->read(); // Move onto the value node
|
||||
$tmpInfo['worksheetName'] = (string) $xml->value;
|
||||
} elseif ($xml->name == 'gnm:MaxCol' && $xml->nodeType == XMLReader::ELEMENT) {
|
||||
$xml->read(); // Move onto the value node
|
||||
$tmpInfo['lastColumnIndex'] = (int) $xml->value;
|
||||
$tmpInfo['totalColumns'] = (int) $xml->value + 1;
|
||||
} elseif ($xml->name == 'gnm:MaxRow' && $xml->nodeType == XMLReader::ELEMENT) {
|
||||
$xml->read(); // Move onto the value node
|
||||
$tmpInfo['totalRows'] = (int) $xml->value + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$tmpInfo['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']);
|
||||
$worksheetInfo[] = $tmpInfo;
|
||||
}
|
||||
}
|
||||
|
||||
return $worksheetInfo;
|
||||
}
|
||||
|
||||
|
||||
private function _gzfileGetContents($filename) {
|
||||
$file = @gzopen($filename, 'rb');
|
||||
if ($file !== false) {
|
||||
$data = '';
|
||||
while (!gzeof($file)) {
|
||||
$data .= gzread($file, 1024);
|
||||
}
|
||||
gzclose($file);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads PHPExcel from file
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @return PHPExcel
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function load($pFilename)
|
||||
{
|
||||
// Create new PHPExcel
|
||||
$objPHPExcel = new PHPExcel();
|
||||
|
||||
// Load into this instance
|
||||
return $this->loadIntoExisting($pFilename, $objPHPExcel);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads PHPExcel from file into PHPExcel instance
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @param PHPExcel $objPHPExcel
|
||||
* @return PHPExcel
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
|
||||
{
|
||||
// Check if file exists
|
||||
if (!file_exists($pFilename)) {
|
||||
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
|
||||
}
|
||||
|
||||
$timezoneObj = new DateTimeZone('Europe/London');
|
||||
$GMT = new DateTimeZone('UTC');
|
||||
|
||||
$gFileData = $this->_gzfileGetContents($pFilename);
|
||||
|
||||
// echo '<pre>';
|
||||
// echo htmlentities($gFileData,ENT_QUOTES,'UTF-8');
|
||||
// echo '</pre><hr />';
|
||||
//
|
||||
$xml = simplexml_load_string($gFileData, 'SimpleXMLElement', PHPExcel_Settings::getLibXmlLoaderOptions());
|
||||
$namespacesMeta = $xml->getNamespaces(true);
|
||||
|
||||
// var_dump($namespacesMeta);
|
||||
//
|
||||
$gnmXML = $xml->children($namespacesMeta['gnm']);
|
||||
|
||||
$docProps = $objPHPExcel->getProperties();
|
||||
// Document Properties are held differently, depending on the version of Gnumeric
|
||||
if (isset($namespacesMeta['office'])) {
|
||||
$officeXML = $xml->children($namespacesMeta['office']);
|
||||
$officeDocXML = $officeXML->{'document-meta'};
|
||||
$officeDocMetaXML = $officeDocXML->meta;
|
||||
|
||||
foreach($officeDocMetaXML as $officePropertyData) {
|
||||
|
||||
$officePropertyDC = array();
|
||||
if (isset($namespacesMeta['dc'])) {
|
||||
$officePropertyDC = $officePropertyData->children($namespacesMeta['dc']);
|
||||
}
|
||||
foreach($officePropertyDC as $propertyName => $propertyValue) {
|
||||
$propertyValue = (string) $propertyValue;
|
||||
switch ($propertyName) {
|
||||
case 'title' :
|
||||
$docProps->setTitle(trim($propertyValue));
|
||||
break;
|
||||
case 'subject' :
|
||||
$docProps->setSubject(trim($propertyValue));
|
||||
break;
|
||||
case 'creator' :
|
||||
$docProps->setCreator(trim($propertyValue));
|
||||
$docProps->setLastModifiedBy(trim($propertyValue));
|
||||
break;
|
||||
case 'date' :
|
||||
$creationDate = strtotime(trim($propertyValue));
|
||||
$docProps->setCreated($creationDate);
|
||||
$docProps->setModified($creationDate);
|
||||
break;
|
||||
case 'description' :
|
||||
$docProps->setDescription(trim($propertyValue));
|
||||
break;
|
||||
}
|
||||
}
|
||||
$officePropertyMeta = array();
|
||||
if (isset($namespacesMeta['meta'])) {
|
||||
$officePropertyMeta = $officePropertyData->children($namespacesMeta['meta']);
|
||||
}
|
||||
foreach($officePropertyMeta as $propertyName => $propertyValue) {
|
||||
$attributes = $propertyValue->attributes($namespacesMeta['meta']);
|
||||
$propertyValue = (string) $propertyValue;
|
||||
switch ($propertyName) {
|
||||
case 'keyword' :
|
||||
$docProps->setKeywords(trim($propertyValue));
|
||||
break;
|
||||
case 'initial-creator' :
|
||||
$docProps->setCreator(trim($propertyValue));
|
||||
$docProps->setLastModifiedBy(trim($propertyValue));
|
||||
break;
|
||||
case 'creation-date' :
|
||||
$creationDate = strtotime(trim($propertyValue));
|
||||
$docProps->setCreated($creationDate);
|
||||
$docProps->setModified($creationDate);
|
||||
break;
|
||||
case 'user-defined' :
|
||||
list(,$attrName) = explode(':',$attributes['name']);
|
||||
switch ($attrName) {
|
||||
case 'publisher' :
|
||||
$docProps->setCompany(trim($propertyValue));
|
||||
break;
|
||||
case 'category' :
|
||||
$docProps->setCategory(trim($propertyValue));
|
||||
break;
|
||||
case 'manager' :
|
||||
$docProps->setManager(trim($propertyValue));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif (isset($gnmXML->Summary)) {
|
||||
foreach($gnmXML->Summary->Item as $summaryItem) {
|
||||
$propertyName = $summaryItem->name;
|
||||
$propertyValue = $summaryItem->{'val-string'};
|
||||
switch ($propertyName) {
|
||||
case 'title' :
|
||||
$docProps->setTitle(trim($propertyValue));
|
||||
break;
|
||||
case 'comments' :
|
||||
$docProps->setDescription(trim($propertyValue));
|
||||
break;
|
||||
case 'keywords' :
|
||||
$docProps->setKeywords(trim($propertyValue));
|
||||
break;
|
||||
case 'category' :
|
||||
$docProps->setCategory(trim($propertyValue));
|
||||
break;
|
||||
case 'manager' :
|
||||
$docProps->setManager(trim($propertyValue));
|
||||
break;
|
||||
case 'author' :
|
||||
$docProps->setCreator(trim($propertyValue));
|
||||
$docProps->setLastModifiedBy(trim($propertyValue));
|
||||
break;
|
||||
case 'company' :
|
||||
$docProps->setCompany(trim($propertyValue));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$worksheetID = 0;
|
||||
foreach($gnmXML->Sheets->Sheet as $sheet) {
|
||||
$worksheetName = (string) $sheet->Name;
|
||||
// echo '<b>Worksheet: ',$worksheetName,'</b><br />';
|
||||
if ((isset($this->_loadSheetsOnly)) && (!in_array($worksheetName, $this->_loadSheetsOnly))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$maxRow = $maxCol = 0;
|
||||
|
||||
// Create new Worksheet
|
||||
$objPHPExcel->createSheet();
|
||||
$objPHPExcel->setActiveSheetIndex($worksheetID);
|
||||
// Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in formula
|
||||
// cells... during the load, all formulae should be correct, and we're simply bringing the worksheet
|
||||
// name in line with the formula, not the reverse
|
||||
$objPHPExcel->getActiveSheet()->setTitle($worksheetName,false);
|
||||
|
||||
if ((!$this->_readDataOnly) && (isset($sheet->PrintInformation))) {
|
||||
if (isset($sheet->PrintInformation->Margins)) {
|
||||
foreach($sheet->PrintInformation->Margins->children('gnm',TRUE) as $key => $margin) {
|
||||
$marginAttributes = $margin->attributes();
|
||||
$marginSize = 72 / 100; // Default
|
||||
switch($marginAttributes['PrefUnit']) {
|
||||
case 'mm' :
|
||||
$marginSize = intval($marginAttributes['Points']) / 100;
|
||||
break;
|
||||
}
|
||||
switch($key) {
|
||||
case 'top' :
|
||||
$objPHPExcel->getActiveSheet()->getPageMargins()->setTop($marginSize);
|
||||
break;
|
||||
case 'bottom' :
|
||||
$objPHPExcel->getActiveSheet()->getPageMargins()->setBottom($marginSize);
|
||||
break;
|
||||
case 'left' :
|
||||
$objPHPExcel->getActiveSheet()->getPageMargins()->setLeft($marginSize);
|
||||
break;
|
||||
case 'right' :
|
||||
$objPHPExcel->getActiveSheet()->getPageMargins()->setRight($marginSize);
|
||||
break;
|
||||
case 'header' :
|
||||
$objPHPExcel->getActiveSheet()->getPageMargins()->setHeader($marginSize);
|
||||
break;
|
||||
case 'footer' :
|
||||
$objPHPExcel->getActiveSheet()->getPageMargins()->setFooter($marginSize);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach($sheet->Cells->Cell as $cell) {
|
||||
$cellAttributes = $cell->attributes();
|
||||
$row = (int) $cellAttributes->Row + 1;
|
||||
$column = (int) $cellAttributes->Col;
|
||||
|
||||
if ($row > $maxRow) $maxRow = $row;
|
||||
if ($column > $maxCol) $maxCol = $column;
|
||||
|
||||
$column = PHPExcel_Cell::stringFromColumnIndex($column);
|
||||
|
||||
// Read cell?
|
||||
if ($this->getReadFilter() !== NULL) {
|
||||
if (!$this->getReadFilter()->readCell($column, $row, $worksheetName)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$ValueType = $cellAttributes->ValueType;
|
||||
$ExprID = (string) $cellAttributes->ExprID;
|
||||
// echo 'Cell ',$column,$row,'<br />';
|
||||
// echo 'Type is ',$ValueType,'<br />';
|
||||
// echo 'Value is ',$cell,'<br />';
|
||||
$type = PHPExcel_Cell_DataType::TYPE_FORMULA;
|
||||
if ($ExprID > '') {
|
||||
if (((string) $cell) > '') {
|
||||
|
||||
$this->_expressions[$ExprID] = array( 'column' => $cellAttributes->Col,
|
||||
'row' => $cellAttributes->Row,
|
||||
'formula' => (string) $cell
|
||||
);
|
||||
// echo 'NEW EXPRESSION ',$ExprID,'<br />';
|
||||
} else {
|
||||
$expression = $this->_expressions[$ExprID];
|
||||
|
||||
$cell = $this->_referenceHelper->updateFormulaReferences( $expression['formula'],
|
||||
'A1',
|
||||
$cellAttributes->Col - $expression['column'],
|
||||
$cellAttributes->Row - $expression['row'],
|
||||
$worksheetName
|
||||
);
|
||||
// echo 'SHARED EXPRESSION ',$ExprID,'<br />';
|
||||
// echo 'New Value is ',$cell,'<br />';
|
||||
}
|
||||
$type = PHPExcel_Cell_DataType::TYPE_FORMULA;
|
||||
} else {
|
||||
switch($ValueType) {
|
||||
case '10' : // NULL
|
||||
$type = PHPExcel_Cell_DataType::TYPE_NULL;
|
||||
break;
|
||||
case '20' : // Boolean
|
||||
$type = PHPExcel_Cell_DataType::TYPE_BOOL;
|
||||
$cell = ($cell == 'TRUE') ? True : False;
|
||||
break;
|
||||
case '30' : // Integer
|
||||
$cell = intval($cell);
|
||||
case '40' : // Float
|
||||
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
|
||||
break;
|
||||
case '50' : // Error
|
||||
$type = PHPExcel_Cell_DataType::TYPE_ERROR;
|
||||
break;
|
||||
case '60' : // String
|
||||
$type = PHPExcel_Cell_DataType::TYPE_STRING;
|
||||
break;
|
||||
case '70' : // Cell Range
|
||||
case '80' : // Array
|
||||
}
|
||||
}
|
||||
$objPHPExcel->getActiveSheet()->getCell($column.$row)->setValueExplicit($cell,$type);
|
||||
}
|
||||
|
||||
if ((!$this->_readDataOnly) && (isset($sheet->Objects))) {
|
||||
foreach($sheet->Objects->children('gnm',TRUE) as $key => $comment) {
|
||||
$commentAttributes = $comment->attributes();
|
||||
// Only comment objects are handled at the moment
|
||||
if ($commentAttributes->Text) {
|
||||
$objPHPExcel->getActiveSheet()->getComment( (string)$commentAttributes->ObjectBound )
|
||||
->setAuthor( (string)$commentAttributes->Author )
|
||||
->setText($this->_parseRichText((string)$commentAttributes->Text) );
|
||||
}
|
||||
}
|
||||
}
|
||||
// echo '$maxCol=',$maxCol,'; $maxRow=',$maxRow,'<br />';
|
||||
//
|
||||
foreach($sheet->Styles->StyleRegion as $styleRegion) {
|
||||
$styleAttributes = $styleRegion->attributes();
|
||||
if (($styleAttributes['startRow'] <= $maxRow) &&
|
||||
($styleAttributes['startCol'] <= $maxCol)) {
|
||||
|
||||
$startColumn = PHPExcel_Cell::stringFromColumnIndex((int) $styleAttributes['startCol']);
|
||||
$startRow = $styleAttributes['startRow'] + 1;
|
||||
|
||||
$endColumn = ($styleAttributes['endCol'] > $maxCol) ? $maxCol : (int) $styleAttributes['endCol'];
|
||||
$endColumn = PHPExcel_Cell::stringFromColumnIndex($endColumn);
|
||||
$endRow = ($styleAttributes['endRow'] > $maxRow) ? $maxRow : $styleAttributes['endRow'];
|
||||
$endRow += 1;
|
||||
$cellRange = $startColumn.$startRow.':'.$endColumn.$endRow;
|
||||
// echo $cellRange,'<br />';
|
||||
|
||||
$styleAttributes = $styleRegion->Style->attributes();
|
||||
// var_dump($styleAttributes);
|
||||
// echo '<br />';
|
||||
|
||||
// We still set the number format mask for date/time values, even if _readDataOnly is true
|
||||
if ((!$this->_readDataOnly) ||
|
||||
(PHPExcel_Shared_Date::isDateTimeFormatCode((string) $styleAttributes['Format']))) {
|
||||
$styleArray = array();
|
||||
$styleArray['numberformat']['code'] = (string) $styleAttributes['Format'];
|
||||
// If _readDataOnly is false, we set all formatting information
|
||||
if (!$this->_readDataOnly) {
|
||||
switch($styleAttributes['HAlign']) {
|
||||
case '1' :
|
||||
$styleArray['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL;
|
||||
break;
|
||||
case '2' :
|
||||
$styleArray['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_LEFT;
|
||||
break;
|
||||
case '4' :
|
||||
$styleArray['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_RIGHT;
|
||||
break;
|
||||
case '8' :
|
||||
$styleArray['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_CENTER;
|
||||
break;
|
||||
case '16' :
|
||||
case '64' :
|
||||
$styleArray['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS;
|
||||
break;
|
||||
case '32' :
|
||||
$styleArray['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY;
|
||||
break;
|
||||
}
|
||||
|
||||
switch($styleAttributes['VAlign']) {
|
||||
case '1' :
|
||||
$styleArray['alignment']['vertical'] = PHPExcel_Style_Alignment::VERTICAL_TOP;
|
||||
break;
|
||||
case '2' :
|
||||
$styleArray['alignment']['vertical'] = PHPExcel_Style_Alignment::VERTICAL_BOTTOM;
|
||||
break;
|
||||
case '4' :
|
||||
$styleArray['alignment']['vertical'] = PHPExcel_Style_Alignment::VERTICAL_CENTER;
|
||||
break;
|
||||
case '8' :
|
||||
$styleArray['alignment']['vertical'] = PHPExcel_Style_Alignment::VERTICAL_JUSTIFY;
|
||||
break;
|
||||
}
|
||||
|
||||
$styleArray['alignment']['wrap'] = ($styleAttributes['WrapText'] == '1') ? True : False;
|
||||
$styleArray['alignment']['shrinkToFit'] = ($styleAttributes['ShrinkToFit'] == '1') ? True : False;
|
||||
$styleArray['alignment']['indent'] = (intval($styleAttributes["Indent"]) > 0) ? $styleAttributes["indent"] : 0;
|
||||
|
||||
$RGB = self::_parseGnumericColour($styleAttributes["Fore"]);
|
||||
$styleArray['font']['color']['rgb'] = $RGB;
|
||||
$RGB = self::_parseGnumericColour($styleAttributes["Back"]);
|
||||
$shade = $styleAttributes["Shade"];
|
||||
if (($RGB != '000000') || ($shade != '0')) {
|
||||
$styleArray['fill']['color']['rgb'] = $styleArray['fill']['startcolor']['rgb'] = $RGB;
|
||||
$RGB2 = self::_parseGnumericColour($styleAttributes["PatternColor"]);
|
||||
$styleArray['fill']['endcolor']['rgb'] = $RGB2;
|
||||
switch($shade) {
|
||||
case '1' :
|
||||
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_SOLID;
|
||||
break;
|
||||
case '2' :
|
||||
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR;
|
||||
break;
|
||||
case '3' :
|
||||
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_GRADIENT_PATH;
|
||||
break;
|
||||
case '4' :
|
||||
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_DARKDOWN;
|
||||
break;
|
||||
case '5' :
|
||||
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_DARKGRAY;
|
||||
break;
|
||||
case '6' :
|
||||
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_DARKGRID;
|
||||
break;
|
||||
case '7' :
|
||||
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_DARKHORIZONTAL;
|
||||
break;
|
||||
case '8' :
|
||||
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_DARKTRELLIS;
|
||||
break;
|
||||
case '9' :
|
||||
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_DARKUP;
|
||||
break;
|
||||
case '10' :
|
||||
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_DARKVERTICAL;
|
||||
break;
|
||||
case '11' :
|
||||
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_GRAY0625;
|
||||
break;
|
||||
case '12' :
|
||||
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_GRAY125;
|
||||
break;
|
||||
case '13' :
|
||||
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_LIGHTDOWN;
|
||||
break;
|
||||
case '14' :
|
||||
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_LIGHTGRAY;
|
||||
break;
|
||||
case '15' :
|
||||
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_LIGHTGRID;
|
||||
break;
|
||||
case '16' :
|
||||
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_LIGHTHORIZONTAL;
|
||||
break;
|
||||
case '17' :
|
||||
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_LIGHTTRELLIS;
|
||||
break;
|
||||
case '18' :
|
||||
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_LIGHTUP;
|
||||
break;
|
||||
case '19' :
|
||||
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_LIGHTVERTICAL;
|
||||
break;
|
||||
case '20' :
|
||||
$styleArray['fill']['type'] = PHPExcel_Style_Fill::FILL_PATTERN_MEDIUMGRAY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$fontAttributes = $styleRegion->Style->Font->attributes();
|
||||
// var_dump($fontAttributes);
|
||||
// echo '<br />';
|
||||
$styleArray['font']['name'] = (string) $styleRegion->Style->Font;
|
||||
$styleArray['font']['size'] = intval($fontAttributes['Unit']);
|
||||
$styleArray['font']['bold'] = ($fontAttributes['Bold'] == '1') ? True : False;
|
||||
$styleArray['font']['italic'] = ($fontAttributes['Italic'] == '1') ? True : False;
|
||||
$styleArray['font']['strike'] = ($fontAttributes['StrikeThrough'] == '1') ? True : False;
|
||||
switch($fontAttributes['Underline']) {
|
||||
case '1' :
|
||||
$styleArray['font']['underline'] = PHPExcel_Style_Font::UNDERLINE_SINGLE;
|
||||
break;
|
||||
case '2' :
|
||||
$styleArray['font']['underline'] = PHPExcel_Style_Font::UNDERLINE_DOUBLE;
|
||||
break;
|
||||
case '3' :
|
||||
$styleArray['font']['underline'] = PHPExcel_Style_Font::UNDERLINE_SINGLEACCOUNTING;
|
||||
break;
|
||||
case '4' :
|
||||
$styleArray['font']['underline'] = PHPExcel_Style_Font::UNDERLINE_DOUBLEACCOUNTING;
|
||||
break;
|
||||
default :
|
||||
$styleArray['font']['underline'] = PHPExcel_Style_Font::UNDERLINE_NONE;
|
||||
break;
|
||||
}
|
||||
switch($fontAttributes['Script']) {
|
||||
case '1' :
|
||||
$styleArray['font']['superScript'] = True;
|
||||
break;
|
||||
case '-1' :
|
||||
$styleArray['font']['subScript'] = True;
|
||||
break;
|
||||
}
|
||||
|
||||
if (isset($styleRegion->Style->StyleBorder)) {
|
||||
if (isset($styleRegion->Style->StyleBorder->Top)) {
|
||||
$styleArray['borders']['top'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->Top->attributes());
|
||||
}
|
||||
if (isset($styleRegion->Style->StyleBorder->Bottom)) {
|
||||
$styleArray['borders']['bottom'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->Bottom->attributes());
|
||||
}
|
||||
if (isset($styleRegion->Style->StyleBorder->Left)) {
|
||||
$styleArray['borders']['left'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->Left->attributes());
|
||||
}
|
||||
if (isset($styleRegion->Style->StyleBorder->Right)) {
|
||||
$styleArray['borders']['right'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->Right->attributes());
|
||||
}
|
||||
if ((isset($styleRegion->Style->StyleBorder->Diagonal)) && (isset($styleRegion->Style->StyleBorder->{'Rev-Diagonal'}))) {
|
||||
$styleArray['borders']['diagonal'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->Diagonal->attributes());
|
||||
$styleArray['borders']['diagonaldirection'] = PHPExcel_Style_Borders::DIAGONAL_BOTH;
|
||||
} elseif (isset($styleRegion->Style->StyleBorder->Diagonal)) {
|
||||
$styleArray['borders']['diagonal'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->Diagonal->attributes());
|
||||
$styleArray['borders']['diagonaldirection'] = PHPExcel_Style_Borders::DIAGONAL_UP;
|
||||
} elseif (isset($styleRegion->Style->StyleBorder->{'Rev-Diagonal'})) {
|
||||
$styleArray['borders']['diagonal'] = self::_parseBorderAttributes($styleRegion->Style->StyleBorder->{'Rev-Diagonal'}->attributes());
|
||||
$styleArray['borders']['diagonaldirection'] = PHPExcel_Style_Borders::DIAGONAL_DOWN;
|
||||
}
|
||||
}
|
||||
if (isset($styleRegion->Style->HyperLink)) {
|
||||
// TO DO
|
||||
$hyperlink = $styleRegion->Style->HyperLink->attributes();
|
||||
}
|
||||
}
|
||||
// var_dump($styleArray);
|
||||
// echo '<br />';
|
||||
$objPHPExcel->getActiveSheet()->getStyle($cellRange)->applyFromArray($styleArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((!$this->_readDataOnly) && (isset($sheet->Cols))) {
|
||||
// Column Widths
|
||||
$columnAttributes = $sheet->Cols->attributes();
|
||||
$defaultWidth = $columnAttributes['DefaultSizePts'] / 5.4;
|
||||
$c = 0;
|
||||
foreach($sheet->Cols->ColInfo as $columnOverride) {
|
||||
$columnAttributes = $columnOverride->attributes();
|
||||
$column = $columnAttributes['No'];
|
||||
$columnWidth = $columnAttributes['Unit'] / 5.4;
|
||||
$hidden = ((isset($columnAttributes['Hidden'])) && ($columnAttributes['Hidden'] == '1')) ? true : false;
|
||||
$columnCount = (isset($columnAttributes['Count'])) ? $columnAttributes['Count'] : 1;
|
||||
while ($c < $column) {
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($c))->setWidth($defaultWidth);
|
||||
++$c;
|
||||
}
|
||||
while (($c < ($column+$columnCount)) && ($c <= $maxCol)) {
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($c))->setWidth($columnWidth);
|
||||
if ($hidden) {
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($c))->setVisible(false);
|
||||
}
|
||||
++$c;
|
||||
}
|
||||
}
|
||||
while ($c <= $maxCol) {
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension(PHPExcel_Cell::stringFromColumnIndex($c))->setWidth($defaultWidth);
|
||||
++$c;
|
||||
}
|
||||
}
|
||||
|
||||
if ((!$this->_readDataOnly) && (isset($sheet->Rows))) {
|
||||
// Row Heights
|
||||
$rowAttributes = $sheet->Rows->attributes();
|
||||
$defaultHeight = $rowAttributes['DefaultSizePts'];
|
||||
$r = 0;
|
||||
|
||||
foreach($sheet->Rows->RowInfo as $rowOverride) {
|
||||
$rowAttributes = $rowOverride->attributes();
|
||||
$row = $rowAttributes['No'];
|
||||
$rowHeight = $rowAttributes['Unit'];
|
||||
$hidden = ((isset($rowAttributes['Hidden'])) && ($rowAttributes['Hidden'] == '1')) ? true : false;
|
||||
$rowCount = (isset($rowAttributes['Count'])) ? $rowAttributes['Count'] : 1;
|
||||
while ($r < $row) {
|
||||
++$r;
|
||||
$objPHPExcel->getActiveSheet()->getRowDimension($r)->setRowHeight($defaultHeight);
|
||||
}
|
||||
while (($r < ($row+$rowCount)) && ($r < $maxRow)) {
|
||||
++$r;
|
||||
$objPHPExcel->getActiveSheet()->getRowDimension($r)->setRowHeight($rowHeight);
|
||||
if ($hidden) {
|
||||
$objPHPExcel->getActiveSheet()->getRowDimension($r)->setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
while ($r < $maxRow) {
|
||||
++$r;
|
||||
$objPHPExcel->getActiveSheet()->getRowDimension($r)->setRowHeight($defaultHeight);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle Merged Cells in this worksheet
|
||||
if (isset($sheet->MergedRegions)) {
|
||||
foreach($sheet->MergedRegions->Merge as $mergeCells) {
|
||||
if (strpos($mergeCells,':') !== FALSE) {
|
||||
$objPHPExcel->getActiveSheet()->mergeCells($mergeCells);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$worksheetID++;
|
||||
}
|
||||
|
||||
// Loop through definedNames (global named ranges)
|
||||
if (isset($gnmXML->Names)) {
|
||||
foreach($gnmXML->Names->Name as $namedRange) {
|
||||
$name = (string) $namedRange->name;
|
||||
$range = (string) $namedRange->value;
|
||||
if (stripos($range, '#REF!') !== false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$range = explode('!',$range);
|
||||
$range[0] = trim($range[0],"'");;
|
||||
if ($worksheet = $objPHPExcel->getSheetByName($range[0])) {
|
||||
$extractedRange = str_replace('$', '', $range[1]);
|
||||
$objPHPExcel->addNamedRange( new PHPExcel_NamedRange($name, $worksheet, $extractedRange) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Return
|
||||
return $objPHPExcel;
|
||||
}
|
||||
|
||||
|
||||
private static function _parseBorderAttributes($borderAttributes)
|
||||
{
|
||||
$styleArray = array();
|
||||
|
||||
if (isset($borderAttributes["Color"])) {
|
||||
$RGB = self::_parseGnumericColour($borderAttributes["Color"]);
|
||||
$styleArray['color']['rgb'] = $RGB;
|
||||
}
|
||||
|
||||
switch ($borderAttributes["Style"]) {
|
||||
case '0' :
|
||||
$styleArray['style'] = PHPExcel_Style_Border::BORDER_NONE;
|
||||
break;
|
||||
case '1' :
|
||||
$styleArray['style'] = PHPExcel_Style_Border::BORDER_THIN;
|
||||
break;
|
||||
case '2' :
|
||||
$styleArray['style'] = PHPExcel_Style_Border::BORDER_MEDIUM;
|
||||
break;
|
||||
case '4' :
|
||||
$styleArray['style'] = PHPExcel_Style_Border::BORDER_DASHED;
|
||||
break;
|
||||
case '5' :
|
||||
$styleArray['style'] = PHPExcel_Style_Border::BORDER_THICK;
|
||||
break;
|
||||
case '6' :
|
||||
$styleArray['style'] = PHPExcel_Style_Border::BORDER_DOUBLE;
|
||||
break;
|
||||
case '7' :
|
||||
$styleArray['style'] = PHPExcel_Style_Border::BORDER_DOTTED;
|
||||
break;
|
||||
case '9' :
|
||||
$styleArray['style'] = PHPExcel_Style_Border::BORDER_DASHDOT;
|
||||
break;
|
||||
case '10' :
|
||||
$styleArray['style'] = PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT;
|
||||
break;
|
||||
case '11' :
|
||||
$styleArray['style'] = PHPExcel_Style_Border::BORDER_DASHDOTDOT;
|
||||
break;
|
||||
case '12' :
|
||||
$styleArray['style'] = PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT;
|
||||
break;
|
||||
case '13' :
|
||||
$styleArray['style'] = PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT;
|
||||
break;
|
||||
case '3' :
|
||||
$styleArray['style'] = PHPExcel_Style_Border::BORDER_SLANTDASHDOT;
|
||||
break;
|
||||
case '8' :
|
||||
$styleArray['style'] = PHPExcel_Style_Border::BORDER_MEDIUMDASHED;
|
||||
break;
|
||||
}
|
||||
return $styleArray;
|
||||
}
|
||||
|
||||
|
||||
private function _parseRichText($is = '') {
|
||||
$value = new PHPExcel_RichText();
|
||||
|
||||
$value->createText($is);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
private static function _parseGnumericColour($gnmColour) {
|
||||
list($gnmR,$gnmG,$gnmB) = explode(':',$gnmColour);
|
||||
$gnmR = substr(str_pad($gnmR,4,'0',STR_PAD_RIGHT),0,2);
|
||||
$gnmG = substr(str_pad($gnmG,4,'0',STR_PAD_RIGHT),0,2);
|
||||
$gnmB = substr(str_pad($gnmB,4,'0',STR_PAD_RIGHT),0,2);
|
||||
$RGB = $gnmR.$gnmG.$gnmB;
|
||||
// echo 'Excel Colour: ',$RGB,'<br />';
|
||||
return $RGB;
|
||||
}
|
||||
|
||||
}
|
468
extend/phpexcel/PHPExcel/Reader/HTML.php
Executable file
468
extend/phpexcel/PHPExcel/Reader/HTML.php
Executable file
@ -0,0 +1,468 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2014 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
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version 1.8.0, 2014-03-02
|
||||
*/
|
||||
|
||||
|
||||
/** PHPExcel root directory */
|
||||
if (!defined('PHPEXCEL_ROOT')) {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
|
||||
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* PHPExcel_Reader_HTML
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Reader
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class PHPExcel_Reader_HTML extends PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
|
||||
{
|
||||
/**
|
||||
* Input encoding
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_inputEncoding = 'ANSI';
|
||||
|
||||
/**
|
||||
* Sheet index to read
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_sheetIndex = 0;
|
||||
|
||||
/**
|
||||
* Formats
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_formats = array( 'h1' => array( 'font' => array( 'bold' => true,
|
||||
'size' => 24,
|
||||
),
|
||||
), // Bold, 24pt
|
||||
'h2' => array( 'font' => array( 'bold' => true,
|
||||
'size' => 18,
|
||||
),
|
||||
), // Bold, 18pt
|
||||
'h3' => array( 'font' => array( 'bold' => true,
|
||||
'size' => 13.5,
|
||||
),
|
||||
), // Bold, 13.5pt
|
||||
'h4' => array( 'font' => array( 'bold' => true,
|
||||
'size' => 12,
|
||||
),
|
||||
), // Bold, 12pt
|
||||
'h5' => array( 'font' => array( 'bold' => true,
|
||||
'size' => 10,
|
||||
),
|
||||
), // Bold, 10pt
|
||||
'h6' => array( 'font' => array( 'bold' => true,
|
||||
'size' => 7.5,
|
||||
),
|
||||
), // Bold, 7.5pt
|
||||
'a' => array( 'font' => array( 'underline' => true,
|
||||
'color' => array( 'argb' => PHPExcel_Style_Color::COLOR_BLUE,
|
||||
),
|
||||
),
|
||||
), // Blue underlined
|
||||
'hr' => array( 'borders' => array( 'bottom' => array( 'style' => PHPExcel_Style_Border::BORDER_THIN,
|
||||
'color' => array( PHPExcel_Style_Color::COLOR_BLACK,
|
||||
),
|
||||
),
|
||||
),
|
||||
), // Bottom border
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Create a new PHPExcel_Reader_HTML
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that the current file is an HTML file
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function _isValidFormat()
|
||||
{
|
||||
// Reading 2048 bytes should be enough to validate that the format is HTML
|
||||
$data = fread($this->_fileHandle, 2048);
|
||||
if ((strpos($data, '<') !== FALSE) &&
|
||||
(strlen($data) !== strlen(strip_tags($data)))) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads PHPExcel from file
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @return PHPExcel
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function load($pFilename)
|
||||
{
|
||||
// Create new PHPExcel
|
||||
$objPHPExcel = new PHPExcel();
|
||||
|
||||
// Load into this instance
|
||||
return $this->loadIntoExisting($pFilename, $objPHPExcel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set input encoding
|
||||
*
|
||||
* @param string $pValue Input encoding
|
||||
*/
|
||||
public function setInputEncoding($pValue = 'ANSI')
|
||||
{
|
||||
$this->_inputEncoding = $pValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get input encoding
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getInputEncoding()
|
||||
{
|
||||
return $this->_inputEncoding;
|
||||
}
|
||||
|
||||
// Data Array used for testing only, should write to PHPExcel object on completion of tests
|
||||
private $_dataArray = array();
|
||||
|
||||
private $_tableLevel = 0;
|
||||
private $_nestedColumn = array('A');
|
||||
|
||||
private function _setTableStartColumn($column) {
|
||||
if ($this->_tableLevel == 0)
|
||||
$column = 'A';
|
||||
++$this->_tableLevel;
|
||||
$this->_nestedColumn[$this->_tableLevel] = $column;
|
||||
|
||||
return $this->_nestedColumn[$this->_tableLevel];
|
||||
}
|
||||
|
||||
private function _getTableStartColumn() {
|
||||
return $this->_nestedColumn[$this->_tableLevel];
|
||||
}
|
||||
|
||||
private function _releaseTableStartColumn() {
|
||||
--$this->_tableLevel;
|
||||
return array_pop($this->_nestedColumn);
|
||||
}
|
||||
|
||||
private function _flushCell($sheet,$column,$row,&$cellContent) {
|
||||
if (is_string($cellContent)) {
|
||||
// Simple String content
|
||||
if (trim($cellContent) > '') {
|
||||
// Only actually write it if there's content in the string
|
||||
// echo 'FLUSH CELL: ' , $column , $row , ' => ' , $cellContent , '<br />';
|
||||
// Write to worksheet to be done here...
|
||||
// ... we return the cell so we can mess about with styles more easily
|
||||
$cell = $sheet->setCellValue($column.$row,$cellContent,true);
|
||||
$this->_dataArray[$row][$column] = $cellContent;
|
||||
}
|
||||
} else {
|
||||
// We have a Rich Text run
|
||||
// TODO
|
||||
$this->_dataArray[$row][$column] = 'RICH TEXT: ' . $cellContent;
|
||||
}
|
||||
$cellContent = (string) '';
|
||||
}
|
||||
|
||||
private function _processDomElement(DOMNode $element, $sheet, &$row, &$column, &$cellContent){
|
||||
foreach($element->childNodes as $child){
|
||||
if ($child instanceof DOMText) {
|
||||
$domText = preg_replace('/\s+/',' ',trim($child->nodeValue));
|
||||
if (is_string($cellContent)) {
|
||||
// simply append the text if the cell content is a plain text string
|
||||
$cellContent .= $domText;
|
||||
} else {
|
||||
// but if we have a rich text run instead, we need to append it correctly
|
||||
// TODO
|
||||
}
|
||||
} elseif($child instanceof DOMElement) {
|
||||
// echo '<b>DOM ELEMENT: </b>' , strtoupper($child->nodeName) , '<br />';
|
||||
|
||||
$attributeArray = array();
|
||||
foreach($child->attributes as $attribute) {
|
||||
// echo '<b>ATTRIBUTE: </b>' , $attribute->name , ' => ' , $attribute->value , '<br />';
|
||||
$attributeArray[$attribute->name] = $attribute->value;
|
||||
}
|
||||
|
||||
switch($child->nodeName) {
|
||||
case 'meta' :
|
||||
foreach($attributeArray as $attributeName => $attributeValue) {
|
||||
switch($attributeName) {
|
||||
case 'content':
|
||||
// TODO
|
||||
// Extract character set, so we can convert to UTF-8 if required
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->_processDomElement($child,$sheet,$row,$column,$cellContent);
|
||||
break;
|
||||
case 'title' :
|
||||
$this->_processDomElement($child,$sheet,$row,$column,$cellContent);
|
||||
$sheet->setTitle($cellContent);
|
||||
$cellContent = '';
|
||||
break;
|
||||
case 'span' :
|
||||
case 'div' :
|
||||
case 'font' :
|
||||
case 'i' :
|
||||
case 'em' :
|
||||
case 'strong':
|
||||
case 'b' :
|
||||
// echo 'STYLING, SPAN OR DIV<br />';
|
||||
if ($cellContent > '')
|
||||
$cellContent .= ' ';
|
||||
$this->_processDomElement($child,$sheet,$row,$column,$cellContent);
|
||||
if ($cellContent > '')
|
||||
$cellContent .= ' ';
|
||||
// echo 'END OF STYLING, SPAN OR DIV<br />';
|
||||
break;
|
||||
case 'hr' :
|
||||
$this->_flushCell($sheet,$column,$row,$cellContent);
|
||||
++$row;
|
||||
if (isset($this->_formats[$child->nodeName])) {
|
||||
$sheet->getStyle($column.$row)->applyFromArray($this->_formats[$child->nodeName]);
|
||||
} else {
|
||||
$cellContent = '----------';
|
||||
$this->_flushCell($sheet,$column,$row,$cellContent);
|
||||
}
|
||||
++$row;
|
||||
case 'br' :
|
||||
if ($this->_tableLevel > 0) {
|
||||
// If we're inside a table, replace with a \n
|
||||
$cellContent .= "\n";
|
||||
} else {
|
||||
// Otherwise flush our existing content and move the row cursor on
|
||||
$this->_flushCell($sheet,$column,$row,$cellContent);
|
||||
++$row;
|
||||
}
|
||||
// echo 'HARD LINE BREAK: ' , '<br />';
|
||||
break;
|
||||
case 'a' :
|
||||
// echo 'START OF HYPERLINK: ' , '<br />';
|
||||
foreach($attributeArray as $attributeName => $attributeValue) {
|
||||
switch($attributeName) {
|
||||
case 'href':
|
||||
// echo 'Link to ' , $attributeValue , '<br />';
|
||||
$sheet->getCell($column.$row)->getHyperlink()->setUrl($attributeValue);
|
||||
if (isset($this->_formats[$child->nodeName])) {
|
||||
$sheet->getStyle($column.$row)->applyFromArray($this->_formats[$child->nodeName]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
$cellContent .= ' ';
|
||||
$this->_processDomElement($child,$sheet,$row,$column,$cellContent);
|
||||
// echo 'END OF HYPERLINK:' , '<br />';
|
||||
break;
|
||||
case 'h1' :
|
||||
case 'h2' :
|
||||
case 'h3' :
|
||||
case 'h4' :
|
||||
case 'h5' :
|
||||
case 'h6' :
|
||||
case 'ol' :
|
||||
case 'ul' :
|
||||
case 'p' :
|
||||
if ($this->_tableLevel > 0) {
|
||||
// If we're inside a table, replace with a \n
|
||||
$cellContent .= "\n";
|
||||
// echo 'LIST ENTRY: ' , '<br />';
|
||||
$this->_processDomElement($child,$sheet,$row,$column,$cellContent);
|
||||
// echo 'END OF LIST ENTRY:' , '<br />';
|
||||
} else {
|
||||
if ($cellContent > '') {
|
||||
$this->_flushCell($sheet,$column,$row,$cellContent);
|
||||
$row += 2;
|
||||
}
|
||||
// echo 'START OF PARAGRAPH: ' , '<br />';
|
||||
$this->_processDomElement($child,$sheet,$row,$column,$cellContent);
|
||||
// echo 'END OF PARAGRAPH:' , '<br />';
|
||||
$this->_flushCell($sheet,$column,$row,$cellContent);
|
||||
|
||||
if (isset($this->_formats[$child->nodeName])) {
|
||||
$sheet->getStyle($column.$row)->applyFromArray($this->_formats[$child->nodeName]);
|
||||
}
|
||||
|
||||
$row += 2;
|
||||
$column = 'A';
|
||||
}
|
||||
break;
|
||||
case 'li' :
|
||||
if ($this->_tableLevel > 0) {
|
||||
// If we're inside a table, replace with a \n
|
||||
$cellContent .= "\n";
|
||||
// echo 'LIST ENTRY: ' , '<br />';
|
||||
$this->_processDomElement($child,$sheet,$row,$column,$cellContent);
|
||||
// echo 'END OF LIST ENTRY:' , '<br />';
|
||||
} else {
|
||||
if ($cellContent > '') {
|
||||
$this->_flushCell($sheet,$column,$row,$cellContent);
|
||||
}
|
||||
++$row;
|
||||
// echo 'LIST ENTRY: ' , '<br />';
|
||||
$this->_processDomElement($child,$sheet,$row,$column,$cellContent);
|
||||
// echo 'END OF LIST ENTRY:' , '<br />';
|
||||
$this->_flushCell($sheet,$column,$row,$cellContent);
|
||||
$column = 'A';
|
||||
}
|
||||
break;
|
||||
case 'table' :
|
||||
$this->_flushCell($sheet,$column,$row,$cellContent);
|
||||
$column = $this->_setTableStartColumn($column);
|
||||
// echo 'START OF TABLE LEVEL ' , $this->_tableLevel , '<br />';
|
||||
if ($this->_tableLevel > 1)
|
||||
--$row;
|
||||
$this->_processDomElement($child,$sheet,$row,$column,$cellContent);
|
||||
// echo 'END OF TABLE LEVEL ' , $this->_tableLevel , '<br />';
|
||||
$column = $this->_releaseTableStartColumn();
|
||||
if ($this->_tableLevel > 1) {
|
||||
++$column;
|
||||
} else {
|
||||
++$row;
|
||||
}
|
||||
break;
|
||||
case 'thead' :
|
||||
case 'tbody' :
|
||||
$this->_processDomElement($child,$sheet,$row,$column,$cellContent);
|
||||
break;
|
||||
case 'tr' :
|
||||
++$row;
|
||||
$column = $this->_getTableStartColumn();
|
||||
$cellContent = '';
|
||||
// echo 'START OF TABLE ' , $this->_tableLevel , ' ROW<br />';
|
||||
$this->_processDomElement($child,$sheet,$row,$column,$cellContent);
|
||||
// echo 'END OF TABLE ' , $this->_tableLevel , ' ROW<br />';
|
||||
break;
|
||||
case 'th' :
|
||||
case 'td' :
|
||||
// echo 'START OF TABLE ' , $this->_tableLevel , ' CELL<br />';
|
||||
$this->_processDomElement($child,$sheet,$row,$column,$cellContent);
|
||||
// echo 'END OF TABLE ' , $this->_tableLevel , ' CELL<br />';
|
||||
$this->_flushCell($sheet,$column,$row,$cellContent);
|
||||
++$column;
|
||||
break;
|
||||
case 'body' :
|
||||
$row = 1;
|
||||
$column = 'A';
|
||||
$content = '';
|
||||
$this->_tableLevel = 0;
|
||||
$this->_processDomElement($child,$sheet,$row,$column,$cellContent);
|
||||
break;
|
||||
default:
|
||||
$this->_processDomElement($child,$sheet,$row,$column,$cellContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads PHPExcel from file into PHPExcel instance
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @param PHPExcel $objPHPExcel
|
||||
* @return PHPExcel
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
|
||||
{
|
||||
// Open file to validate
|
||||
$this->_openFile($pFilename);
|
||||
if (!$this->_isValidFormat()) {
|
||||
fclose ($this->_fileHandle);
|
||||
throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid HTML file.");
|
||||
}
|
||||
// Close after validating
|
||||
fclose ($this->_fileHandle);
|
||||
|
||||
// Create new PHPExcel
|
||||
while ($objPHPExcel->getSheetCount() <= $this->_sheetIndex) {
|
||||
$objPHPExcel->createSheet();
|
||||
}
|
||||
$objPHPExcel->setActiveSheetIndex( $this->_sheetIndex );
|
||||
|
||||
// Create a new DOM object
|
||||
$dom = new domDocument;
|
||||
// Reload the HTML file into the DOM object
|
||||
$loaded = $dom->loadHTMLFile($pFilename, PHPExcel_Settings::getLibXmlLoaderOptions());
|
||||
if ($loaded === FALSE) {
|
||||
throw new PHPExcel_Reader_Exception('Failed to load ',$pFilename,' as a DOM Document');
|
||||
}
|
||||
|
||||
// Discard white space
|
||||
$dom->preserveWhiteSpace = false;
|
||||
|
||||
|
||||
$row = 0;
|
||||
$column = 'A';
|
||||
$content = '';
|
||||
$this->_processDomElement($dom,$objPHPExcel->getActiveSheet(),$row,$column,$content);
|
||||
|
||||
// echo '<hr />';
|
||||
// var_dump($this->_dataArray);
|
||||
|
||||
// Return
|
||||
return $objPHPExcel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sheet index
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getSheetIndex() {
|
||||
return $this->_sheetIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set sheet index
|
||||
*
|
||||
* @param int $pValue Sheet index
|
||||
* @return PHPExcel_Reader_HTML
|
||||
*/
|
||||
public function setSheetIndex($pValue = 0) {
|
||||
$this->_sheetIndex = $pValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
47
extend/phpexcel/PHPExcel/Reader/IReadFilter.php
Executable file
47
extend/phpexcel/PHPExcel/Reader/IReadFilter.php
Executable file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2014 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
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version 1.8.0, 2014-03-02
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* PHPExcel_Reader_IReadFilter
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Reader
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
interface PHPExcel_Reader_IReadFilter
|
||||
{
|
||||
/**
|
||||
* Should this cell be read?
|
||||
*
|
||||
* @param $column String column index
|
||||
* @param $row Row index
|
||||
* @param $worksheetName Optional worksheet name
|
||||
* @return boolean
|
||||
*/
|
||||
public function readCell($column, $row, $worksheetName = '');
|
||||
}
|
53
extend/phpexcel/PHPExcel/Reader/IReader.php
Executable file
53
extend/phpexcel/PHPExcel/Reader/IReader.php
Executable file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2014 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
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version 1.8.0, 2014-03-02
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* PHPExcel_Reader_IReader
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Reader
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
interface PHPExcel_Reader_IReader
|
||||
{
|
||||
/**
|
||||
* Can the current PHPExcel_Reader_IReader read the file?
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @return boolean
|
||||
*/
|
||||
public function canRead($pFilename);
|
||||
|
||||
/**
|
||||
* Loads PHPExcel from file
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function load($pFilename);
|
||||
}
|
707
extend/phpexcel/PHPExcel/Reader/OOCalc.php
Executable file
707
extend/phpexcel/PHPExcel/Reader/OOCalc.php
Executable file
@ -0,0 +1,707 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2014 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
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version 1.8.0, 2014-03-02
|
||||
*/
|
||||
|
||||
|
||||
/** PHPExcel root directory */
|
||||
if (!defined('PHPEXCEL_ROOT')) {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
|
||||
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* PHPExcel_Reader_OOCalc
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Reader
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class PHPExcel_Reader_OOCalc extends PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
|
||||
{
|
||||
/**
|
||||
* Formats
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_styles = array();
|
||||
|
||||
|
||||
/**
|
||||
* Create a new PHPExcel_Reader_OOCalc
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Can the current PHPExcel_Reader_IReader read the file?
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @return boolean
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function canRead($pFilename)
|
||||
{
|
||||
// Check if file exists
|
||||
if (!file_exists($pFilename)) {
|
||||
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
|
||||
}
|
||||
|
||||
$zipClass = PHPExcel_Settings::getZipClass();
|
||||
|
||||
// Check if zip class exists
|
||||
// if (!class_exists($zipClass, FALSE)) {
|
||||
// throw new PHPExcel_Reader_Exception($zipClass . " library is not enabled");
|
||||
// }
|
||||
|
||||
$mimeType = 'UNKNOWN';
|
||||
// Load file
|
||||
$zip = new $zipClass;
|
||||
if ($zip->open($pFilename) === true) {
|
||||
// check if it is an OOXML archive
|
||||
$stat = $zip->statName('mimetype');
|
||||
if ($stat && ($stat['size'] <= 255)) {
|
||||
$mimeType = $zip->getFromName($stat['name']);
|
||||
} elseif($stat = $zip->statName('META-INF/manifest.xml')) {
|
||||
$xml = simplexml_load_string($zip->getFromName('META-INF/manifest.xml'), 'SimpleXMLElement', PHPExcel_Settings::getLibXmlLoaderOptions());
|
||||
$namespacesContent = $xml->getNamespaces(true);
|
||||
if (isset($namespacesContent['manifest'])) {
|
||||
$manifest = $xml->children($namespacesContent['manifest']);
|
||||
foreach($manifest as $manifestDataSet) {
|
||||
$manifestAttributes = $manifestDataSet->attributes($namespacesContent['manifest']);
|
||||
if ($manifestAttributes->{'full-path'} == '/') {
|
||||
$mimeType = (string) $manifestAttributes->{'media-type'};
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$zip->close();
|
||||
|
||||
return ($mimeType === 'application/vnd.oasis.opendocument.spreadsheet');
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function listWorksheetNames($pFilename)
|
||||
{
|
||||
// Check if file exists
|
||||
if (!file_exists($pFilename)) {
|
||||
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
|
||||
}
|
||||
|
||||
$zipClass = PHPExcel_Settings::getZipClass();
|
||||
|
||||
$zip = new $zipClass;
|
||||
if (!$zip->open($pFilename)) {
|
||||
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! Error opening file.");
|
||||
}
|
||||
|
||||
$worksheetNames = array();
|
||||
|
||||
$xml = new XMLReader();
|
||||
$res = $xml->open('zip://'.realpath($pFilename).'#content.xml', null, PHPExcel_Settings::getLibXmlLoaderOptions());
|
||||
$xml->setParserProperty(2,true);
|
||||
|
||||
// Step into the first level of content of the XML
|
||||
$xml->read();
|
||||
while ($xml->read()) {
|
||||
// Quickly jump through to the office:body node
|
||||
while ($xml->name !== 'office:body') {
|
||||
if ($xml->isEmptyElement)
|
||||
$xml->read();
|
||||
else
|
||||
$xml->next();
|
||||
}
|
||||
// Now read each node until we find our first table:table node
|
||||
while ($xml->read()) {
|
||||
if ($xml->name == 'table:table' && $xml->nodeType == XMLReader::ELEMENT) {
|
||||
// Loop through each table:table node reading the table:name attribute for each worksheet name
|
||||
do {
|
||||
$worksheetNames[] = $xml->getAttribute('table:name');
|
||||
$xml->next();
|
||||
} while ($xml->name == 'table:table' && $xml->nodeType == XMLReader::ELEMENT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $worksheetNames;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns)
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function listWorksheetInfo($pFilename)
|
||||
{
|
||||
// Check if file exists
|
||||
if (!file_exists($pFilename)) {
|
||||
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
|
||||
}
|
||||
|
||||
$worksheetInfo = array();
|
||||
|
||||
$zipClass = PHPExcel_Settings::getZipClass();
|
||||
|
||||
$zip = new $zipClass;
|
||||
if (!$zip->open($pFilename)) {
|
||||
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! Error opening file.");
|
||||
}
|
||||
|
||||
$xml = new XMLReader();
|
||||
$res = $xml->open('zip://'.realpath($pFilename).'#content.xml', null, PHPExcel_Settings::getLibXmlLoaderOptions());
|
||||
$xml->setParserProperty(2,true);
|
||||
|
||||
// Step into the first level of content of the XML
|
||||
$xml->read();
|
||||
while ($xml->read()) {
|
||||
// Quickly jump through to the office:body node
|
||||
while ($xml->name !== 'office:body') {
|
||||
if ($xml->isEmptyElement)
|
||||
$xml->read();
|
||||
else
|
||||
$xml->next();
|
||||
}
|
||||
// Now read each node until we find our first table:table node
|
||||
while ($xml->read()) {
|
||||
if ($xml->name == 'table:table' && $xml->nodeType == XMLReader::ELEMENT) {
|
||||
$worksheetNames[] = $xml->getAttribute('table:name');
|
||||
|
||||
$tmpInfo = array(
|
||||
'worksheetName' => $xml->getAttribute('table:name'),
|
||||
'lastColumnLetter' => 'A',
|
||||
'lastColumnIndex' => 0,
|
||||
'totalRows' => 0,
|
||||
'totalColumns' => 0,
|
||||
);
|
||||
|
||||
// Loop through each child node of the table:table element reading
|
||||
$currCells = 0;
|
||||
do {
|
||||
$xml->read();
|
||||
if ($xml->name == 'table:table-row' && $xml->nodeType == XMLReader::ELEMENT) {
|
||||
$rowspan = $xml->getAttribute('table:number-rows-repeated');
|
||||
$rowspan = empty($rowspan) ? 1 : $rowspan;
|
||||
$tmpInfo['totalRows'] += $rowspan;
|
||||
$tmpInfo['totalColumns'] = max($tmpInfo['totalColumns'],$currCells);
|
||||
$currCells = 0;
|
||||
// Step into the row
|
||||
$xml->read();
|
||||
do {
|
||||
if ($xml->name == 'table:table-cell' && $xml->nodeType == XMLReader::ELEMENT) {
|
||||
if (!$xml->isEmptyElement) {
|
||||
$currCells++;
|
||||
$xml->next();
|
||||
} else {
|
||||
$xml->read();
|
||||
}
|
||||
} elseif ($xml->name == 'table:covered-table-cell' && $xml->nodeType == XMLReader::ELEMENT) {
|
||||
$mergeSize = $xml->getAttribute('table:number-columns-repeated');
|
||||
$currCells += $mergeSize;
|
||||
$xml->read();
|
||||
}
|
||||
} while ($xml->name != 'table:table-row');
|
||||
}
|
||||
} while ($xml->name != 'table:table');
|
||||
|
||||
$tmpInfo['totalColumns'] = max($tmpInfo['totalColumns'],$currCells);
|
||||
$tmpInfo['lastColumnIndex'] = $tmpInfo['totalColumns'] - 1;
|
||||
$tmpInfo['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']);
|
||||
$worksheetInfo[] = $tmpInfo;
|
||||
}
|
||||
}
|
||||
|
||||
// foreach($workbookData->table as $worksheetDataSet) {
|
||||
// $worksheetData = $worksheetDataSet->children($namespacesContent['table']);
|
||||
// $worksheetDataAttributes = $worksheetDataSet->attributes($namespacesContent['table']);
|
||||
//
|
||||
// $rowIndex = 0;
|
||||
// foreach ($worksheetData as $key => $rowData) {
|
||||
// switch ($key) {
|
||||
// case 'table-row' :
|
||||
// $rowDataTableAttributes = $rowData->attributes($namespacesContent['table']);
|
||||
// $rowRepeats = (isset($rowDataTableAttributes['number-rows-repeated'])) ?
|
||||
// $rowDataTableAttributes['number-rows-repeated'] : 1;
|
||||
// $columnIndex = 0;
|
||||
//
|
||||
// foreach ($rowData as $key => $cellData) {
|
||||
// $cellDataTableAttributes = $cellData->attributes($namespacesContent['table']);
|
||||
// $colRepeats = (isset($cellDataTableAttributes['number-columns-repeated'])) ?
|
||||
// $cellDataTableAttributes['number-columns-repeated'] : 1;
|
||||
// $cellDataOfficeAttributes = $cellData->attributes($namespacesContent['office']);
|
||||
// if (isset($cellDataOfficeAttributes['value-type'])) {
|
||||
// $tmpInfo['lastColumnIndex'] = max($tmpInfo['lastColumnIndex'], $columnIndex + $colRepeats - 1);
|
||||
// $tmpInfo['totalRows'] = max($tmpInfo['totalRows'], $rowIndex + $rowRepeats);
|
||||
// }
|
||||
// $columnIndex += $colRepeats;
|
||||
// }
|
||||
// $rowIndex += $rowRepeats;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// $tmpInfo['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']);
|
||||
// $tmpInfo['totalColumns'] = $tmpInfo['lastColumnIndex'] + 1;
|
||||
//
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
return $worksheetInfo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads PHPExcel from file
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @return PHPExcel
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function load($pFilename)
|
||||
{
|
||||
// Create new PHPExcel
|
||||
$objPHPExcel = new PHPExcel();
|
||||
|
||||
// Load into this instance
|
||||
return $this->loadIntoExisting($pFilename, $objPHPExcel);
|
||||
}
|
||||
|
||||
|
||||
private static function identifyFixedStyleValue($styleList,&$styleAttributeValue) {
|
||||
$styleAttributeValue = strtolower($styleAttributeValue);
|
||||
foreach($styleList as $style) {
|
||||
if ($styleAttributeValue == strtolower($style)) {
|
||||
$styleAttributeValue = $style;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Loads PHPExcel from file into PHPExcel instance
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @param PHPExcel $objPHPExcel
|
||||
* @return PHPExcel
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
|
||||
{
|
||||
// Check if file exists
|
||||
if (!file_exists($pFilename)) {
|
||||
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! File does not exist.");
|
||||
}
|
||||
|
||||
$timezoneObj = new DateTimeZone('Europe/London');
|
||||
$GMT = new DateTimeZone('UTC');
|
||||
|
||||
$zipClass = PHPExcel_Settings::getZipClass();
|
||||
|
||||
$zip = new $zipClass;
|
||||
if (!$zip->open($pFilename)) {
|
||||
throw new PHPExcel_Reader_Exception("Could not open " . $pFilename . " for reading! Error opening file.");
|
||||
}
|
||||
|
||||
// echo '<h1>Meta Information</h1>';
|
||||
$xml = simplexml_load_string($zip->getFromName("meta.xml"), 'SimpleXMLElement', PHPExcel_Settings::getLibXmlLoaderOptions());
|
||||
$namespacesMeta = $xml->getNamespaces(true);
|
||||
// echo '<pre>';
|
||||
// print_r($namespacesMeta);
|
||||
// echo '</pre><hr />';
|
||||
|
||||
$docProps = $objPHPExcel->getProperties();
|
||||
$officeProperty = $xml->children($namespacesMeta['office']);
|
||||
foreach($officeProperty as $officePropertyData) {
|
||||
$officePropertyDC = array();
|
||||
if (isset($namespacesMeta['dc'])) {
|
||||
$officePropertyDC = $officePropertyData->children($namespacesMeta['dc']);
|
||||
}
|
||||
foreach($officePropertyDC as $propertyName => $propertyValue) {
|
||||
$propertyValue = (string) $propertyValue;
|
||||
switch ($propertyName) {
|
||||
case 'title' :
|
||||
$docProps->setTitle($propertyValue);
|
||||
break;
|
||||
case 'subject' :
|
||||
$docProps->setSubject($propertyValue);
|
||||
break;
|
||||
case 'creator' :
|
||||
$docProps->setCreator($propertyValue);
|
||||
$docProps->setLastModifiedBy($propertyValue);
|
||||
break;
|
||||
case 'date' :
|
||||
$creationDate = strtotime($propertyValue);
|
||||
$docProps->setCreated($creationDate);
|
||||
$docProps->setModified($creationDate);
|
||||
break;
|
||||
case 'description' :
|
||||
$docProps->setDescription($propertyValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
$officePropertyMeta = array();
|
||||
if (isset($namespacesMeta['dc'])) {
|
||||
$officePropertyMeta = $officePropertyData->children($namespacesMeta['meta']);
|
||||
}
|
||||
foreach($officePropertyMeta as $propertyName => $propertyValue) {
|
||||
$propertyValueAttributes = $propertyValue->attributes($namespacesMeta['meta']);
|
||||
$propertyValue = (string) $propertyValue;
|
||||
switch ($propertyName) {
|
||||
case 'initial-creator' :
|
||||
$docProps->setCreator($propertyValue);
|
||||
break;
|
||||
case 'keyword' :
|
||||
$docProps->setKeywords($propertyValue);
|
||||
break;
|
||||
case 'creation-date' :
|
||||
$creationDate = strtotime($propertyValue);
|
||||
$docProps->setCreated($creationDate);
|
||||
break;
|
||||
case 'user-defined' :
|
||||
$propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_STRING;
|
||||
foreach ($propertyValueAttributes as $key => $value) {
|
||||
if ($key == 'name') {
|
||||
$propertyValueName = (string) $value;
|
||||
} elseif($key == 'value-type') {
|
||||
switch ($value) {
|
||||
case 'date' :
|
||||
$propertyValue = PHPExcel_DocumentProperties::convertProperty($propertyValue,'date');
|
||||
$propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_DATE;
|
||||
break;
|
||||
case 'boolean' :
|
||||
$propertyValue = PHPExcel_DocumentProperties::convertProperty($propertyValue,'bool');
|
||||
$propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_BOOLEAN;
|
||||
break;
|
||||
case 'float' :
|
||||
$propertyValue = PHPExcel_DocumentProperties::convertProperty($propertyValue,'r4');
|
||||
$propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_FLOAT;
|
||||
break;
|
||||
default :
|
||||
$propertyValueType = PHPExcel_DocumentProperties::PROPERTY_TYPE_STRING;
|
||||
}
|
||||
}
|
||||
}
|
||||
$docProps->setCustomProperty($propertyValueName,$propertyValue,$propertyValueType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// echo '<h1>Workbook Content</h1>';
|
||||
$xml = simplexml_load_string($zip->getFromName("content.xml"), 'SimpleXMLElement', PHPExcel_Settings::getLibXmlLoaderOptions());
|
||||
$namespacesContent = $xml->getNamespaces(true);
|
||||
// echo '<pre>';
|
||||
// print_r($namespacesContent);
|
||||
// echo '</pre><hr />';
|
||||
|
||||
$workbook = $xml->children($namespacesContent['office']);
|
||||
foreach($workbook->body->spreadsheet as $workbookData) {
|
||||
$workbookData = $workbookData->children($namespacesContent['table']);
|
||||
$worksheetID = 0;
|
||||
foreach($workbookData->table as $worksheetDataSet) {
|
||||
$worksheetData = $worksheetDataSet->children($namespacesContent['table']);
|
||||
// print_r($worksheetData);
|
||||
// echo '<br />';
|
||||
$worksheetDataAttributes = $worksheetDataSet->attributes($namespacesContent['table']);
|
||||
// print_r($worksheetDataAttributes);
|
||||
// echo '<br />';
|
||||
if ((isset($this->_loadSheetsOnly)) && (isset($worksheetDataAttributes['name'])) &&
|
||||
(!in_array($worksheetDataAttributes['name'], $this->_loadSheetsOnly))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// echo '<h2>Worksheet '.$worksheetDataAttributes['name'].'</h2>';
|
||||
// Create new Worksheet
|
||||
$objPHPExcel->createSheet();
|
||||
$objPHPExcel->setActiveSheetIndex($worksheetID);
|
||||
if (isset($worksheetDataAttributes['name'])) {
|
||||
$worksheetName = (string) $worksheetDataAttributes['name'];
|
||||
// Use false for $updateFormulaCellReferences to prevent adjustment of worksheet references in
|
||||
// formula cells... during the load, all formulae should be correct, and we're simply
|
||||
// bringing the worksheet name in line with the formula, not the reverse
|
||||
$objPHPExcel->getActiveSheet()->setTitle($worksheetName,false);
|
||||
}
|
||||
|
||||
$rowID = 1;
|
||||
foreach($worksheetData as $key => $rowData) {
|
||||
// echo '<b>'.$key.'</b><br />';
|
||||
switch ($key) {
|
||||
case 'table-header-rows':
|
||||
foreach ($rowData as $key=>$cellData) {
|
||||
$rowData = $cellData;
|
||||
break;
|
||||
}
|
||||
case 'table-row' :
|
||||
$rowDataTableAttributes = $rowData->attributes($namespacesContent['table']);
|
||||
$rowRepeats = (isset($rowDataTableAttributes['number-rows-repeated'])) ?
|
||||
$rowDataTableAttributes['number-rows-repeated'] : 1;
|
||||
$columnID = 'A';
|
||||
foreach($rowData as $key => $cellData) {
|
||||
if ($this->getReadFilter() !== NULL) {
|
||||
if (!$this->getReadFilter()->readCell($columnID, $rowID, $worksheetName)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// echo '<b>'.$columnID.$rowID.'</b><br />';
|
||||
$cellDataText = (isset($namespacesContent['text'])) ?
|
||||
$cellData->children($namespacesContent['text']) :
|
||||
'';
|
||||
$cellDataOffice = $cellData->children($namespacesContent['office']);
|
||||
$cellDataOfficeAttributes = $cellData->attributes($namespacesContent['office']);
|
||||
$cellDataTableAttributes = $cellData->attributes($namespacesContent['table']);
|
||||
|
||||
// echo 'Office Attributes: ';
|
||||
// print_r($cellDataOfficeAttributes);
|
||||
// echo '<br />Table Attributes: ';
|
||||
// print_r($cellDataTableAttributes);
|
||||
// echo '<br />Cell Data Text';
|
||||
// print_r($cellDataText);
|
||||
// echo '<br />';
|
||||
//
|
||||
$type = $formatting = $hyperlink = null;
|
||||
$hasCalculatedValue = false;
|
||||
$cellDataFormula = '';
|
||||
if (isset($cellDataTableAttributes['formula'])) {
|
||||
$cellDataFormula = $cellDataTableAttributes['formula'];
|
||||
$hasCalculatedValue = true;
|
||||
}
|
||||
|
||||
if (isset($cellDataOffice->annotation)) {
|
||||
// echo 'Cell has comment<br />';
|
||||
$annotationText = $cellDataOffice->annotation->children($namespacesContent['text']);
|
||||
$textArray = array();
|
||||
foreach($annotationText as $t) {
|
||||
foreach($t->span as $text) {
|
||||
$textArray[] = (string)$text;
|
||||
}
|
||||
}
|
||||
$text = implode("\n",$textArray);
|
||||
// echo $text,'<br />';
|
||||
$objPHPExcel->getActiveSheet()->getComment( $columnID.$rowID )
|
||||
// ->setAuthor( $author )
|
||||
->setText($this->_parseRichText($text) );
|
||||
}
|
||||
|
||||
if (isset($cellDataText->p)) {
|
||||
// Consolidate if there are multiple p records (maybe with spans as well)
|
||||
$dataArray = array();
|
||||
// Text can have multiple text:p and within those, multiple text:span.
|
||||
// text:p newlines, but text:span does not.
|
||||
// Also, here we assume there is no text data is span fields are specified, since
|
||||
// we have no way of knowing proper positioning anyway.
|
||||
foreach ($cellDataText->p as $pData) {
|
||||
if (isset($pData->span)) {
|
||||
// span sections do not newline, so we just create one large string here
|
||||
$spanSection = "";
|
||||
foreach ($pData->span as $spanData) {
|
||||
$spanSection .= $spanData;
|
||||
}
|
||||
array_push($dataArray, $spanSection);
|
||||
} else {
|
||||
array_push($dataArray, $pData);
|
||||
}
|
||||
}
|
||||
$allCellDataText = implode($dataArray, "\n");
|
||||
|
||||
// echo 'Value Type is '.$cellDataOfficeAttributes['value-type'].'<br />';
|
||||
switch ($cellDataOfficeAttributes['value-type']) {
|
||||
case 'string' :
|
||||
$type = PHPExcel_Cell_DataType::TYPE_STRING;
|
||||
$dataValue = $allCellDataText;
|
||||
if (isset($dataValue->a)) {
|
||||
$dataValue = $dataValue->a;
|
||||
$cellXLinkAttributes = $dataValue->attributes($namespacesContent['xlink']);
|
||||
$hyperlink = $cellXLinkAttributes['href'];
|
||||
}
|
||||
break;
|
||||
case 'boolean' :
|
||||
$type = PHPExcel_Cell_DataType::TYPE_BOOL;
|
||||
$dataValue = ($allCellDataText == 'TRUE') ? True : False;
|
||||
break;
|
||||
case 'percentage' :
|
||||
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
|
||||
$dataValue = (float) $cellDataOfficeAttributes['value'];
|
||||
if (floor($dataValue) == $dataValue) {
|
||||
$dataValue = (integer) $dataValue;
|
||||
}
|
||||
$formatting = PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE_00;
|
||||
break;
|
||||
case 'currency' :
|
||||
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
|
||||
$dataValue = (float) $cellDataOfficeAttributes['value'];
|
||||
if (floor($dataValue) == $dataValue) {
|
||||
$dataValue = (integer) $dataValue;
|
||||
}
|
||||
$formatting = PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE;
|
||||
break;
|
||||
case 'float' :
|
||||
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
|
||||
$dataValue = (float) $cellDataOfficeAttributes['value'];
|
||||
if (floor($dataValue) == $dataValue) {
|
||||
if ($dataValue == (integer) $dataValue)
|
||||
$dataValue = (integer) $dataValue;
|
||||
else
|
||||
$dataValue = (float) $dataValue;
|
||||
}
|
||||
break;
|
||||
case 'date' :
|
||||
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
|
||||
$dateObj = new DateTime($cellDataOfficeAttributes['date-value'], $GMT);
|
||||
$dateObj->setTimeZone($timezoneObj);
|
||||
list($year,$month,$day,$hour,$minute,$second) = explode(' ',$dateObj->format('Y m d H i s'));
|
||||
$dataValue = PHPExcel_Shared_Date::FormattedPHPToExcel($year,$month,$day,$hour,$minute,$second);
|
||||
if ($dataValue != floor($dataValue)) {
|
||||
$formatting = PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15.' '.PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4;
|
||||
} else {
|
||||
$formatting = PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX15;
|
||||
}
|
||||
break;
|
||||
case 'time' :
|
||||
$type = PHPExcel_Cell_DataType::TYPE_NUMERIC;
|
||||
$dataValue = PHPExcel_Shared_Date::PHPToExcel(strtotime('01-01-1970 '.implode(':',sscanf($cellDataOfficeAttributes['time-value'],'PT%dH%dM%dS'))));
|
||||
$formatting = PHPExcel_Style_NumberFormat::FORMAT_DATE_TIME4;
|
||||
break;
|
||||
}
|
||||
// echo 'Data value is '.$dataValue.'<br />';
|
||||
// if ($hyperlink !== NULL) {
|
||||
// echo 'Hyperlink is '.$hyperlink.'<br />';
|
||||
// }
|
||||
} else {
|
||||
$type = PHPExcel_Cell_DataType::TYPE_NULL;
|
||||
$dataValue = NULL;
|
||||
}
|
||||
|
||||
if ($hasCalculatedValue) {
|
||||
$type = PHPExcel_Cell_DataType::TYPE_FORMULA;
|
||||
// echo 'Formula: ', $cellDataFormula, PHP_EOL;
|
||||
$cellDataFormula = substr($cellDataFormula,strpos($cellDataFormula,':=')+1);
|
||||
$temp = explode('"',$cellDataFormula);
|
||||
$tKey = false;
|
||||
foreach($temp as &$value) {
|
||||
// Only replace in alternate array entries (i.e. non-quoted blocks)
|
||||
if ($tKey = !$tKey) {
|
||||
$value = preg_replace('/\[([^\.]+)\.([^\.]+):\.([^\.]+)\]/Ui','$1!$2:$3',$value); // Cell range reference in another sheet
|
||||
$value = preg_replace('/\[([^\.]+)\.([^\.]+)\]/Ui','$1!$2',$value); // Cell reference in another sheet
|
||||
$value = preg_replace('/\[\.([^\.]+):\.([^\.]+)\]/Ui','$1:$2',$value); // Cell range reference
|
||||
$value = preg_replace('/\[\.([^\.]+)\]/Ui','$1',$value); // Simple cell reference
|
||||
$value = PHPExcel_Calculation::_translateSeparator(';',',',$value,$inBraces);
|
||||
}
|
||||
}
|
||||
unset($value);
|
||||
// Then rebuild the formula string
|
||||
$cellDataFormula = implode('"',$temp);
|
||||
// echo 'Adjusted Formula: ', $cellDataFormula, PHP_EOL;
|
||||
}
|
||||
|
||||
$colRepeats = (isset($cellDataTableAttributes['number-columns-repeated'])) ?
|
||||
$cellDataTableAttributes['number-columns-repeated'] : 1;
|
||||
if ($type !== NULL) {
|
||||
for ($i = 0; $i < $colRepeats; ++$i) {
|
||||
if ($i > 0) {
|
||||
++$columnID;
|
||||
}
|
||||
if ($type !== PHPExcel_Cell_DataType::TYPE_NULL) {
|
||||
for ($rowAdjust = 0; $rowAdjust < $rowRepeats; ++$rowAdjust) {
|
||||
$rID = $rowID + $rowAdjust;
|
||||
$objPHPExcel->getActiveSheet()->getCell($columnID.$rID)->setValueExplicit((($hasCalculatedValue) ? $cellDataFormula : $dataValue),$type);
|
||||
if ($hasCalculatedValue) {
|
||||
// echo 'Forumla result is '.$dataValue.'<br />';
|
||||
$objPHPExcel->getActiveSheet()->getCell($columnID.$rID)->setCalculatedValue($dataValue);
|
||||
}
|
||||
if ($formatting !== NULL) {
|
||||
$objPHPExcel->getActiveSheet()->getStyle($columnID.$rID)->getNumberFormat()->setFormatCode($formatting);
|
||||
} else {
|
||||
$objPHPExcel->getActiveSheet()->getStyle($columnID.$rID)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_GENERAL);
|
||||
}
|
||||
if ($hyperlink !== NULL) {
|
||||
$objPHPExcel->getActiveSheet()->getCell($columnID.$rID)->getHyperlink()->setUrl($hyperlink);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Merged cells
|
||||
if ((isset($cellDataTableAttributes['number-columns-spanned'])) || (isset($cellDataTableAttributes['number-rows-spanned']))) {
|
||||
if (($type !== PHPExcel_Cell_DataType::TYPE_NULL) || (!$this->_readDataOnly)) {
|
||||
$columnTo = $columnID;
|
||||
if (isset($cellDataTableAttributes['number-columns-spanned'])) {
|
||||
$columnTo = PHPExcel_Cell::stringFromColumnIndex(PHPExcel_Cell::columnIndexFromString($columnID) + $cellDataTableAttributes['number-columns-spanned'] -2);
|
||||
}
|
||||
$rowTo = $rowID;
|
||||
if (isset($cellDataTableAttributes['number-rows-spanned'])) {
|
||||
$rowTo = $rowTo + $cellDataTableAttributes['number-rows-spanned'] - 1;
|
||||
}
|
||||
$cellRange = $columnID.$rowID.':'.$columnTo.$rowTo;
|
||||
$objPHPExcel->getActiveSheet()->mergeCells($cellRange);
|
||||
}
|
||||
}
|
||||
|
||||
++$columnID;
|
||||
}
|
||||
$rowID += $rowRepeats;
|
||||
break;
|
||||
}
|
||||
}
|
||||
++$worksheetID;
|
||||
}
|
||||
}
|
||||
|
||||
// Return
|
||||
return $objPHPExcel;
|
||||
}
|
||||
|
||||
|
||||
private function _parseRichText($is = '') {
|
||||
$value = new PHPExcel_RichText();
|
||||
|
||||
$value->createText($is);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
}
|
450
extend/phpexcel/PHPExcel/Reader/SYLK.php
Executable file
450
extend/phpexcel/PHPExcel/Reader/SYLK.php
Executable file
@ -0,0 +1,450 @@
|
||||
<?php
|
||||
/**
|
||||
* PHPExcel
|
||||
*
|
||||
* Copyright (c) 2006 - 2014 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
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
|
||||
* @version 1.8.0, 2014-03-02
|
||||
*/
|
||||
|
||||
|
||||
/** PHPExcel root directory */
|
||||
if (!defined('PHPEXCEL_ROOT')) {
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../../');
|
||||
require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* PHPExcel_Reader_SYLK
|
||||
*
|
||||
* @category PHPExcel
|
||||
* @package PHPExcel_Reader
|
||||
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
|
||||
*/
|
||||
class PHPExcel_Reader_SYLK extends PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
|
||||
{
|
||||
/**
|
||||
* Input encoding
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_inputEncoding = 'ANSI';
|
||||
|
||||
/**
|
||||
* Sheet index to read
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_sheetIndex = 0;
|
||||
|
||||
/**
|
||||
* Formats
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_formats = array();
|
||||
|
||||
/**
|
||||
* Format Count
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_format = 0;
|
||||
|
||||
/**
|
||||
* Create a new PHPExcel_Reader_SYLK
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that the current file is a SYLK file
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
protected function _isValidFormat()
|
||||
{
|
||||
// Read sample data (first 2 KB will do)
|
||||
$data = fread($this->_fileHandle, 2048);
|
||||
|
||||
// Count delimiters in file
|
||||
$delimiterCount = substr_count($data, ';');
|
||||
if ($delimiterCount < 1) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Analyze first line looking for ID; signature
|
||||
$lines = explode("\n", $data);
|
||||
if (substr($lines[0],0,4) != 'ID;P') {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set input encoding
|
||||
*
|
||||
* @param string $pValue Input encoding
|
||||
*/
|
||||
public function setInputEncoding($pValue = 'ANSI')
|
||||
{
|
||||
$this->_inputEncoding = $pValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get input encoding
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getInputEncoding()
|
||||
{
|
||||
return $this->_inputEncoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns)
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function listWorksheetInfo($pFilename)
|
||||
{
|
||||
// Open file
|
||||
$this->_openFile($pFilename);
|
||||
if (!$this->_isValidFormat()) {
|
||||
fclose ($this->_fileHandle);
|
||||
throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid Spreadsheet file.");
|
||||
}
|
||||
$fileHandle = $this->_fileHandle;
|
||||
rewind($fileHandle);
|
||||
|
||||
$worksheetInfo = array();
|
||||
$worksheetInfo[0]['worksheetName'] = 'Worksheet';
|
||||
$worksheetInfo[0]['lastColumnLetter'] = 'A';
|
||||
$worksheetInfo[0]['lastColumnIndex'] = 0;
|
||||
$worksheetInfo[0]['totalRows'] = 0;
|
||||
$worksheetInfo[0]['totalColumns'] = 0;
|
||||
|
||||
// Loop through file
|
||||
$rowData = array();
|
||||
|
||||
// loop through one row (line) at a time in the file
|
||||
$rowIndex = 0;
|
||||
while (($rowData = fgets($fileHandle)) !== FALSE) {
|
||||
$columnIndex = 0;
|
||||
|
||||
// convert SYLK encoded $rowData to UTF-8
|
||||
$rowData = PHPExcel_Shared_String::SYLKtoUTF8($rowData);
|
||||
|
||||
// explode each row at semicolons while taking into account that literal semicolon (;)
|
||||
// is escaped like this (;;)
|
||||
$rowData = explode("\t",str_replace('¤',';',str_replace(';',"\t",str_replace(';;','¤',rtrim($rowData)))));
|
||||
|
||||
$dataType = array_shift($rowData);
|
||||
if ($dataType == 'C') {
|
||||
// Read cell value data
|
||||
foreach($rowData as $rowDatum) {
|
||||
switch($rowDatum{0}) {
|
||||
case 'C' :
|
||||
case 'X' :
|
||||
$columnIndex = substr($rowDatum,1) - 1;
|
||||
break;
|
||||
case 'R' :
|
||||
case 'Y' :
|
||||
$rowIndex = substr($rowDatum,1);
|
||||
break;
|
||||
}
|
||||
|
||||
$worksheetInfo[0]['totalRows'] = max($worksheetInfo[0]['totalRows'], $rowIndex);
|
||||
$worksheetInfo[0]['lastColumnIndex'] = max($worksheetInfo[0]['lastColumnIndex'], $columnIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$worksheetInfo[0]['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($worksheetInfo[0]['lastColumnIndex']);
|
||||
$worksheetInfo[0]['totalColumns'] = $worksheetInfo[0]['lastColumnIndex'] + 1;
|
||||
|
||||
// Close file
|
||||
fclose($fileHandle);
|
||||
|
||||
return $worksheetInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads PHPExcel from file
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @return PHPExcel
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function load($pFilename)
|
||||
{
|
||||
// Create new PHPExcel
|
||||
$objPHPExcel = new PHPExcel();
|
||||
|
||||
// Load into this instance
|
||||
return $this->loadIntoExisting($pFilename, $objPHPExcel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads PHPExcel from file into PHPExcel instance
|
||||
*
|
||||
* @param string $pFilename
|
||||
* @param PHPExcel $objPHPExcel
|
||||
* @return PHPExcel
|
||||
* @throws PHPExcel_Reader_Exception
|
||||
*/
|
||||
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
|
||||
{
|
||||
// Open file
|
||||
$this->_openFile($pFilename);
|
||||
if (!$this->_isValidFormat()) {
|
||||
fclose ($this->_fileHandle);
|
||||
throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid Spreadsheet file.");
|
||||
}
|
||||
$fileHandle = $this->_fileHandle;
|
||||
rewind($fileHandle);
|
||||
|
||||
// Create new PHPExcel
|
||||
while ($objPHPExcel->getSheetCount() <= $this->_sheetIndex) {
|
||||
$objPHPExcel->createSheet();
|
||||
}
|
||||
$objPHPExcel->setActiveSheetIndex( $this->_sheetIndex );
|
||||
|
||||
$fromFormats = array('\-', '\ ');
|
||||
$toFormats = array('-', ' ');
|
||||
|
||||
// Loop through file
|
||||
$rowData = array();
|
||||
$column = $row = '';
|
||||
|
||||
// loop through one row (line) at a time in the file
|
||||
while (($rowData = fgets($fileHandle)) !== FALSE) {
|
||||
|
||||
// convert SYLK encoded $rowData to UTF-8
|
||||
$rowData = PHPExcel_Shared_String::SYLKtoUTF8($rowData);
|
||||
|
||||
// explode each row at semicolons while taking into account that literal semicolon (;)
|
||||
// is escaped like this (;;)
|
||||
$rowData = explode("\t",str_replace('¤',';',str_replace(';',"\t",str_replace(';;','¤',rtrim($rowData)))));
|
||||
|
||||
$dataType = array_shift($rowData);
|
||||
// Read shared styles
|
||||
if ($dataType == 'P') {
|
||||
$formatArray = array();
|
||||
foreach($rowData as $rowDatum) {
|
||||
switch($rowDatum{0}) {
|
||||
case 'P' : $formatArray['numberformat']['code'] = str_replace($fromFormats,$toFormats,substr($rowDatum,1));
|
||||
break;
|
||||
case 'E' :
|
||||
case 'F' : $formatArray['font']['name'] = substr($rowDatum,1);
|
||||
break;
|
||||
case 'L' : $formatArray['font']['size'] = substr($rowDatum,1);
|
||||
break;
|
||||
case 'S' : $styleSettings = substr($rowDatum,1);
|
||||
for ($i=0;$i<strlen($styleSettings);++$i) {
|
||||
switch ($styleSettings{$i}) {
|
||||
case 'I' : $formatArray['font']['italic'] = true;
|
||||
break;
|
||||
case 'D' : $formatArray['font']['bold'] = true;
|
||||
break;
|
||||
case 'T' : $formatArray['borders']['top']['style'] = PHPExcel_Style_Border::BORDER_THIN;
|
||||
break;
|
||||
case 'B' : $formatArray['borders']['bottom']['style'] = PHPExcel_Style_Border::BORDER_THIN;
|
||||
break;
|
||||
case 'L' : $formatArray['borders']['left']['style'] = PHPExcel_Style_Border::BORDER_THIN;
|
||||
break;
|
||||
case 'R' : $formatArray['borders']['right']['style'] = PHPExcel_Style_Border::BORDER_THIN;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->_formats['P'.$this->_format++] = $formatArray;
|
||||
// Read cell value data
|
||||
} elseif ($dataType == 'C') {
|
||||
$hasCalculatedValue = false;
|
||||
$cellData = $cellDataFormula = '';
|
||||
foreach($rowData as $rowDatum) {
|
||||
switch($rowDatum{0}) {
|
||||
case 'C' :
|
||||
case 'X' : $column = substr($rowDatum,1);
|
||||
break;
|
||||
case 'R' :
|
||||
case 'Y' : $row = substr($rowDatum,1);
|
||||
break;
|
||||
case 'K' : $cellData = substr($rowDatum,1);
|
||||
break;
|
||||
case 'E' : $cellDataFormula = '='.substr($rowDatum,1);
|
||||
// Convert R1C1 style references to A1 style references (but only when not quoted)
|
||||
$temp = explode('"',$cellDataFormula);
|
||||
$key = false;
|
||||
foreach($temp as &$value) {
|
||||
// Only count/replace in alternate array entries
|
||||
if ($key = !$key) {
|
||||
preg_match_all('/(R(\[?-?\d*\]?))(C(\[?-?\d*\]?))/',$value, $cellReferences,PREG_SET_ORDER+PREG_OFFSET_CAPTURE);
|
||||
// Reverse the matches array, otherwise all our offsets will become incorrect if we modify our way
|
||||
// through the formula from left to right. Reversing means that we work right to left.through
|
||||
// the formula
|
||||
$cellReferences = array_reverse($cellReferences);
|
||||
// Loop through each R1C1 style reference in turn, converting it to its A1 style equivalent,
|
||||
// then modify the formula to use that new reference
|
||||
foreach($cellReferences as $cellReference) {
|
||||
$rowReference = $cellReference[2][0];
|
||||
// Empty R reference is the current row
|
||||
if ($rowReference == '') $rowReference = $row;
|
||||
// Bracketed R references are relative to the current row
|
||||
if ($rowReference{0} == '[') $rowReference = $row + trim($rowReference,'[]');
|
||||
$columnReference = $cellReference[4][0];
|
||||
// Empty C reference is the current column
|
||||
if ($columnReference == '') $columnReference = $column;
|
||||
// Bracketed C references are relative to the current column
|
||||
if ($columnReference{0} == '[') $columnReference = $column + trim($columnReference,'[]');
|
||||
$A1CellReference = PHPExcel_Cell::stringFromColumnIndex($columnReference-1).$rowReference;
|
||||
|
||||
$value = substr_replace($value,$A1CellReference,$cellReference[0][1],strlen($cellReference[0][0]));
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($value);
|
||||
// Then rebuild the formula string
|
||||
$cellDataFormula = implode('"',$temp);
|
||||
$hasCalculatedValue = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$columnLetter = PHPExcel_Cell::stringFromColumnIndex($column-1);
|
||||
$cellData = PHPExcel_Calculation::_unwrapResult($cellData);
|
||||
|
||||
// Set cell value
|
||||
$objPHPExcel->getActiveSheet()->getCell($columnLetter.$row)->setValue(($hasCalculatedValue) ? $cellDataFormula : $cellData);
|
||||
if ($hasCalculatedValue) {
|
||||
$cellData = PHPExcel_Calculation::_unwrapResult($cellData);
|
||||
$objPHPExcel->getActiveSheet()->getCell($columnLetter.$row)->setCalculatedValue($cellData);
|
||||
}
|
||||
// Read cell formatting
|
||||
} elseif ($dataType == 'F') {
|
||||
$formatStyle = $columnWidth = $styleSettings = '';
|
||||
$styleData = array();
|
||||
foreach($rowData as $rowDatum) {
|
||||
switch($rowDatum{0}) {
|
||||
case 'C' :
|
||||
case 'X' : $column = substr($rowDatum,1);
|
||||
break;
|
||||
case 'R' :
|
||||
case 'Y' : $row = substr($rowDatum,1);
|
||||
break;
|
||||
case 'P' : $formatStyle = $rowDatum;
|
||||
break;
|
||||
case 'W' : list($startCol,$endCol,$columnWidth) = explode(' ',substr($rowDatum,1));
|
||||
break;
|
||||
case 'S' : $styleSettings = substr($rowDatum,1);
|
||||
for ($i=0;$i<strlen($styleSettings);++$i) {
|
||||
switch ($styleSettings{$i}) {
|
||||
case 'I' : $styleData['font']['italic'] = true;
|
||||
break;
|
||||
case 'D' : $styleData['font']['bold'] = true;
|
||||
break;
|
||||
case 'T' : $styleData['borders']['top']['style'] = PHPExcel_Style_Border::BORDER_THIN;
|
||||
break;
|
||||
case 'B' : $styleData['borders']['bottom']['style'] = PHPExcel_Style_Border::BORDER_THIN;
|
||||
break;
|
||||
case 'L' : $styleData['borders']['left']['style'] = PHPExcel_Style_Border::BORDER_THIN;
|
||||
break;
|
||||
case 'R' : $styleData['borders']['right']['style'] = PHPExcel_Style_Border::BORDER_THIN;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (($formatStyle > '') && ($column > '') && ($row > '')) {
|
||||
$columnLetter = PHPExcel_Cell::stringFromColumnIndex($column-1);
|
||||
if (isset($this->_formats[$formatStyle])) {
|
||||
$objPHPExcel->getActiveSheet()->getStyle($columnLetter.$row)->applyFromArray($this->_formats[$formatStyle]);
|
||||
}
|
||||
}
|
||||
if ((!empty($styleData)) && ($column > '') && ($row > '')) {
|
||||
$columnLetter = PHPExcel_Cell::stringFromColumnIndex($column-1);
|
||||
$objPHPExcel->getActiveSheet()->getStyle($columnLetter.$row)->applyFromArray($styleData);
|
||||
}
|
||||
if ($columnWidth > '') {
|
||||
if ($startCol == $endCol) {
|
||||
$startCol = PHPExcel_Cell::stringFromColumnIndex($startCol-1);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension($startCol)->setWidth($columnWidth);
|
||||
} else {
|
||||
$startCol = PHPExcel_Cell::stringFromColumnIndex($startCol-1);
|
||||
$endCol = PHPExcel_Cell::stringFromColumnIndex($endCol-1);
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension($startCol)->setWidth($columnWidth);
|
||||
do {
|
||||
$objPHPExcel->getActiveSheet()->getColumnDimension(++$startCol)->setWidth($columnWidth);
|
||||
} while ($startCol != $endCol);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach($rowData as $rowDatum) {
|
||||
switch($rowDatum{0}) {
|
||||
case 'C' :
|
||||
case 'X' : $column = substr($rowDatum,1);
|
||||
break;
|
||||
case 'R' :
|
||||
case 'Y' : $row = substr($rowDatum,1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Close file
|
||||
fclose($fileHandle);
|
||||
|
||||
// Return
|
||||
return $objPHPExcel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sheet index
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getSheetIndex() {
|
||||
return $this->_sheetIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set sheet index
|
||||
*
|
||||
* @param int $pValue Sheet index
|
||||
* @return PHPExcel_Reader_SYLK
|
||||
*/
|
||||
public function setSheetIndex($pValue = 0) {
|
||||
$this->_sheetIndex = $pValue;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user