MDL-44515 import latest PHPExcel 1.8.0

This commit is contained in:
Petr Škoda
2014-03-14 12:10:52 +08:00
parent c0e88129d1
commit 7ec0e0629c
229 changed files with 15154 additions and 14964 deletions
+31 -79
View File
@@ -2,7 +2,7 @@
/**
* PHPExcel
*
* Copyright (c) 2006 - 2012 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
@@ -20,7 +20,7 @@
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
* @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 ##VERSION##, ##DATE##
*/
@@ -40,9 +40,9 @@ if (!defined('PHPEXCEL_ROOT')) {
*
* @category PHPExcel
* @package PHPExcel_Reader
* @copyright Copyright (c) 2006 - 2012 PHPExcel (http://www.codeplex.com/PHPExcel)
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader
class PHPExcel_Reader_SYLK extends PHPExcel_Reader_Abstract implements PHPExcel_Reader_IReader
{
/**
* Input encoding
@@ -72,14 +72,6 @@ class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader
*/
private $_format = 0;
/**
* PHPExcel_Reader_IReadFilter instance
*
* @var PHPExcel_Reader_IReadFilter
*/
private $_readFilter = null;
/**
* Create a new PHPExcel_Reader_SYLK
*/
@@ -87,63 +79,31 @@ class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader
$this->_readFilter = new PHPExcel_Reader_DefaultReadFilter();
}
/**
* Can the current PHPExcel_Reader_IReader read the file?
* Validate that the current file is a SYLK file
*
* @param string $pFileName
* @return boolean
* @throws Exception
* @return boolean
*/
public function canRead($pFilename)
protected function _isValidFormat()
{
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
}
// Read sample data (first 2 KB will do)
$fh = fopen($pFilename, 'r');
$data = fread($fh, 2048);
fclose($fh);
$data = fread($this->_fileHandle, 2048);
// Count delimiters in file
$delimiterCount = substr_count($data, ';');
if ($delimiterCount < 1) {
return false;
return FALSE;
}
// Analyze first line looking for ID; signature
$lines = explode("\n", $data);
if (substr($lines[0],0,4) != 'ID;P') {
return false;
return FALSE;
}
return true;
return TRUE;
}
/**
* Read filter
*
* @return PHPExcel_Reader_IReadFilter
*/
public function getReadFilter() {
return $this->_readFilter;
}
/**
* Set read filter
*
* @param PHPExcel_Reader_IReadFilter $pValue
*/
public function setReadFilter(PHPExcel_Reader_IReadFilter $pValue) {
$this->_readFilter = $pValue;
return $this;
}
/**
* Set input encoding
*
@@ -155,7 +115,6 @@ class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader
return $this;
}
/**
* Get input encoding
*
@@ -166,25 +125,22 @@ class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader
return $this->_inputEncoding;
}
/**
* Return worksheet info (Name, Last Column Letter, Last Column Index, Total Rows, Total Columns)
*
* @param string $pFilename
* @throws Exception
* @throws PHPExcel_Reader_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.");
}
// Open file
$fileHandle = fopen($pFilename, 'r');
if ($fileHandle === false) {
throw new Exception("Could not open file " . $pFilename . " for reading.");
$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';
@@ -206,7 +162,7 @@ class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader
// 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)))));
$rowData = explode("\t",str_replace('¤',';',str_replace(';',"\t",str_replace(';;','¤',rtrim($rowData)))));
$dataType = array_shift($rowData);
if ($dataType == 'C') {
@@ -238,13 +194,12 @@ class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader
return $worksheetInfo;
}
/**
* Loads PHPExcel from file
*
* @param string $pFilename
* @return PHPExcel
* @throws Exception
* @throws PHPExcel_Reader_Exception
*/
public function load($pFilename)
{
@@ -255,21 +210,24 @@ class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader
return $this->loadIntoExisting($pFilename, $objPHPExcel);
}
/**
* Loads PHPExcel from file into PHPExcel instance
*
* @param string $pFilename
* @param PHPExcel $objPHPExcel
* @return PHPExcel
* @throws Exception
* @throws PHPExcel_Reader_Exception
*/
public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
{
// Check if file exists
if (!file_exists($pFilename)) {
throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
// 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) {
@@ -280,12 +238,6 @@ class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader
$fromFormats = array('\-', '\ ');
$toFormats = array('-', ' ');
// Open file
$fileHandle = fopen($pFilename, 'r');
if ($fileHandle === false) {
throw new Exception("Could not open file $pFilename for reading.");
}
// Loop through file
$rowData = array();
$column = $row = '';
@@ -433,7 +385,9 @@ class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader
}
if (($formatStyle > '') && ($column > '') && ($row > '')) {
$columnLetter = PHPExcel_Cell::stringFromColumnIndex($column-1);
$objPHPExcel->getActiveSheet()->getStyle($columnLetter.$row)->applyFromArray($this->_formats[$formatStyle]);
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);
@@ -473,7 +427,6 @@ class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader
return $objPHPExcel;
}
/**
* Get sheet index
*
@@ -483,7 +436,6 @@ class PHPExcel_Reader_SYLK implements PHPExcel_Reader_IReader
return $this->_sheetIndex;
}
/**
* Set sheet index
*