2
0
forked from Wavyzz/dolibarr

Upgrade phpexcel lib to 1.7.8

This commit is contained in:
Laurent Destailleur
2014-09-07 12:12:30 +02:00
parent 9d2d165cfc
commit 789427b75d
370 changed files with 35980 additions and 211021 deletions

View File

@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2011 PHPExcel
* Copyright (c) 2006 - 2012 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -20,9 +20,9 @@
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.6, 2011-02-27
* @version 1.7.8, 2012-10-12
*/
@@ -36,28 +36,28 @@ if (!defined('PHPEXCEL_ROOT')) {
}
/**
* PHPExcel_Reader_Gnumeric
* PHPExcel_Reader_Gnumeric
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
{
/**
* Read data only?
* Identifies whether the Reader should only read data values for cells, and ignore any formatting information;
* 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
* @var boolean
*/
private $_readDataOnly = 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.
* 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
* @var array of string
*/
private $_loadSheetsOnly = null;
@@ -86,50 +86,62 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
/**
* Read data only?
* Create a new PHPExcel_Reader_Gnumeric
*/
public function __construct() {
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
$this->_referenceHelper = PHPExcel_ReferenceHelper::getInstance();
}
/**
* 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
* @return boolean
*/
public function getReadDataOnly() {
return $this->_readDataOnly;
}
/**
* Set read data only
* 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
* @param boolean $pValue
*
* @return PHPExcel_Reader_Gnumeric
* @return PHPExcel_Reader_Gnumeric
*/
public function setReadDataOnly($pValue = false) {
$this->_readDataOnly = $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.
* 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
* @return mixed
*/
public function getLoadSheetsOnly()
{
return $this->_loadSheetsOnly;
}
/**
* Set which sheets to load
* Set which sheets to load
*
* @param mixed $value
* @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_Gnumeric
* @return PHPExcel_Reader_Gnumeric
*/
public function setLoadSheetsOnly($value = null)
{
@@ -138,11 +150,12 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
return $this;
}
/**
* Set all sheets to load
* Set all sheets to load
* Tells the Reader to load all worksheets from the workbook.
*
* @return PHPExcel_Reader_Gnumeric
* @return PHPExcel_Reader_Gnumeric
*/
public function setLoadAllSheets()
{
@@ -150,6 +163,7 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
return $this;
}
/**
* Read filter
*
@@ -159,6 +173,7 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
return $this->_readFilter;
}
/**
* Set read filter
*
@@ -170,32 +185,26 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
return $this;
}
/**
* 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 Exception
*/
public function canRead($pFilename)
{
// Check if gzlib functions are available
if (!function_exists('gzread')) {
return false;
}
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
// Check if gzlib functions are available
if (!function_exists('gzread')) {
throw new Exception("gzlib library is not enabled");
}
// Read signature data (first 3 bytes)
$fh = fopen($pFilename, 'r');
$data = fread($fh, 2);
@@ -208,6 +217,70 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
return true;
}
/**
* Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns)
*
* @param string $pFilename
* @throws Exception
*/
public function listWorksheetInfo($pFilename)
{
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
$gFileData = $this->_gzfileGetContents($pFilename);
$xml = simplexml_load_string($gFileData);
$namespacesMeta = $xml->getNamespaces(true);
$gnmXML = $xml->children($namespacesMeta['gnm']);
$worksheetInfo = array();
foreach ($gnmXML->Sheets->Sheet as $sheet) {
$tmpInfo = array();
$tmpInfo['worksheetName'] = (string) $sheet->Name;
$tmpInfo['lastColumnLetter'] = 'A';
$tmpInfo['lastColumnIndex'] = 0;
$tmpInfo['totalRows'] = 0;
$tmpInfo['totalColumns'] = 0;
foreach ($sheet->Cells->Cell as $cell) {
$cellAttributes = $cell->attributes();
$rowIndex = (int) $cellAttributes->Row + 1;
$columnIndex = (int) $cellAttributes->Col;
$tmpInfo['totalRows'] = max($tmpInfo['totalRows'], $rowIndex);
$tmpInfo['lastColumnIndex'] = max($tmpInfo['lastColumnIndex'], $columnIndex);
}
$tmpInfo['lastColumnLetter'] = PHPExcel_Cell::stringFromColumnIndex($tmpInfo['lastColumnIndex']);
$tmpInfo['totalColumns'] = $tmpInfo['lastColumnIndex'] + 1;
$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
*
@@ -224,17 +297,6 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
return $this->loadIntoExisting($pFilename, $objPHPExcel);
}
private function _gzfileGetContents($filename) {
$file = @gzopen($filename, 'rb');
if ($file !== false) {
$data = '';
while (!gzeof($file)) {
$data .= gzread($file, 1024);
}
gzclose($file);
}
return $data;
}
/**
* Reads names of the worksheets from a file, without parsing the whole file to a PHPExcel object
@@ -414,7 +476,10 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
// Create new Worksheet
$objPHPExcel->createSheet();
$objPHPExcel->setActiveSheetIndex($worksheetID);
$objPHPExcel->getActiveSheet()->setTitle($worksheetName);
// 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)) {
@@ -461,7 +526,7 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
$column = PHPExcel_Cell::stringFromColumnIndex($column);
// Read cell?
if (!is_null($this->getReadFilter())) {
if ($this->getReadFilter() !== NULL) {
if (!$this->getReadFilter()->readCell($column, $row, $worksheetName)) {
continue;
}
@@ -536,16 +601,13 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
//
foreach($sheet->Styles->StyleRegion as $styleRegion) {
$styleAttributes = $styleRegion->attributes();
// var_dump($styleAttributes);
// echo '<br />';
if (($styleAttributes['startRow'] <= $maxRow) &&
($styleAttributes['startCol'] <= $maxCol)) {
$startColumn = PHPExcel_Cell::stringFromColumnIndex($styleAttributes['startCol']);
$startColumn = PHPExcel_Cell::stringFromColumnIndex((int) $styleAttributes['startCol']);
$startRow = $styleAttributes['startRow'] + 1;
$endColumn = ($styleAttributes['endCol'] > $maxCol) ? $maxCol : $styleAttributes['endCol'];
$endColumn = ($styleAttributes['endCol'] > $maxCol) ? $maxCol : (int) $styleAttributes['endCol'];
$endColumn = PHPExcel_Cell::stringFromColumnIndex($endColumn);
$endRow = ($styleAttributes['endRow'] > $maxRow) ? $maxRow : $styleAttributes['endRow'];
$endRow += 1;
@@ -808,7 +870,9 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
// Handle Merged Cells in this worksheet
if (isset($sheet->MergedRegions)) {
foreach($sheet->MergedRegions->Merge as $mergeCells) {
$objPHPExcel->getActiveSheet()->mergeCells($mergeCells);
if (strpos($mergeCells,':') !== FALSE) {
$objPHPExcel->getActiveSheet()->mergeCells($mergeCells);
}
}
}
@@ -838,7 +902,9 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
return $objPHPExcel;
}
private static function _parseBorderAttributes($borderAttributes) {
private static function _parseBorderAttributes($borderAttributes)
{
$styleArray = array();
if (isset($borderAttributes["Color"])) {
@@ -893,6 +959,7 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
return $styleArray;
}
private function _parseRichText($is = '') {
$value = new PHPExcel_RichText();
@@ -901,6 +968,7 @@ class PHPExcel_Reader_Gnumeric implements PHPExcel_Reader_IReader
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);