mirror of
https://github.com/retailcrm/PHPExcel.git
synced 2024-11-26 07:16:03 +03:00
Performance improvements to the CSV Reader and Writer
git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@64769 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
parent
5917b8c9b0
commit
f1e413bcc1
@ -31,6 +31,7 @@ PHPExcel_Shared_ZipStreamWrapper::register();
|
||||
if (ini_get('mbstring.func_overload') & 2) {
|
||||
throw new Exception('Multibyte function overloading in PHP must be disabled for string functions (2).');
|
||||
}
|
||||
PHPExcel_Shared_String::buildCharacterSets();
|
||||
|
||||
|
||||
class PHPExcel_Autoloader
|
||||
|
@ -230,20 +230,22 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
|
||||
break;
|
||||
}
|
||||
|
||||
$escapeEnclosures = array( "\\" . $this->_enclosure,
|
||||
$this->_enclosure . $this->_enclosure
|
||||
);
|
||||
|
||||
// Loop through file
|
||||
$currentRow = $contiguousRow = 0;
|
||||
$rowData = array();
|
||||
while (($rowData = fgetcsv($fileHandle, 0, $this->_delimiter, $this->_enclosure)) !== FALSE) {
|
||||
++$currentRow;
|
||||
$crset = false;
|
||||
$ccRef = 0;
|
||||
$rowDataCount = count($rowData);
|
||||
$columnLetter = 'A';
|
||||
for ($i = 0; $i < $rowDataCount; ++$i) {
|
||||
$columnLetter = PHPExcel_Cell::stringFromColumnIndex($i);
|
||||
if ($rowData[$i] != '' && $this->_readFilter->readCell($columnLetter, $currentRow)) {
|
||||
// Unescape enclosures
|
||||
$rowData[$i] = str_replace("\\" . $this->_enclosure, $this->_enclosure, $rowData[$i]);
|
||||
$rowData[$i] = str_replace($this->_enclosure . $this->_enclosure, $this->_enclosure, $rowData[$i]);
|
||||
$rowData[$i] = str_replace($escapeEnclosures, $this->_enclosure, $rowData[$i]);
|
||||
|
||||
// Convert encoding if necessary
|
||||
if ($this->_inputEncoding !== 'UTF-8') {
|
||||
@ -256,12 +258,13 @@ class PHPExcel_Reader_CSV implements PHPExcel_Reader_IReader
|
||||
$crset = true;
|
||||
}
|
||||
// Set cell value
|
||||
$objPHPExcel->getActiveSheet()->getCell(PHPExcel_Cell::stringFromColumnIndex($ccRef++) . $contiguousRow)->setValue($rowData[$i]);
|
||||
$objPHPExcel->getActiveSheet()->getCell($columnLetter . $contiguousRow)->setValue($rowData[$i]);
|
||||
} else {
|
||||
// Set cell value
|
||||
$objPHPExcel->getActiveSheet()->getCell($columnLetter . $currentRow)->setValue($rowData[$i]);
|
||||
}
|
||||
}
|
||||
++$columnLetter;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -194,11 +194,11 @@ class PHPExcel_Reader_Excel2007 implements PHPExcel_Reader_IReader
|
||||
// echo 'Initial Cast to Boolean<br />';
|
||||
$value = isset($c->v) ? (string) $c->v : null;
|
||||
if ($value == '0') {
|
||||
$value = false;
|
||||
return false;
|
||||
} elseif ($value == '1') {
|
||||
$value = true;
|
||||
return true;
|
||||
} else {
|
||||
$value = (bool)$c->v;
|
||||
return (bool)$c->v;
|
||||
}
|
||||
return $value;
|
||||
} // function _castToBool()
|
||||
|
@ -322,6 +322,15 @@ class PHPExcel_Shared_String
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function buildCharacterSets() {
|
||||
if(empty(self::$_controlCharacters)) {
|
||||
self::_buildControlCharacters();
|
||||
}
|
||||
if(empty(self::$_SYLKCharacters)) {
|
||||
self::_buildSYLKCharacters();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert from OpenXML escaped control character to PHP control character
|
||||
*
|
||||
@ -337,10 +346,6 @@ class PHPExcel_Shared_String
|
||||
* @return string
|
||||
*/
|
||||
public static function ControlCharacterOOXML2PHP($value = '') {
|
||||
if(empty(self::$_controlCharacters)) {
|
||||
self::_buildControlCharacters();
|
||||
}
|
||||
|
||||
return str_replace( array_keys(self::$_controlCharacters), array_values(self::$_controlCharacters), $value );
|
||||
}
|
||||
|
||||
@ -359,10 +364,6 @@ class PHPExcel_Shared_String
|
||||
* @return string
|
||||
*/
|
||||
public static function ControlCharacterPHP2OOXML($value = '') {
|
||||
if(empty(self::$_controlCharacters)) {
|
||||
self::_buildControlCharacters();
|
||||
}
|
||||
|
||||
return str_replace( array_values(self::$_controlCharacters), array_keys(self::$_controlCharacters), $value );
|
||||
}
|
||||
|
||||
@ -657,10 +658,6 @@ class PHPExcel_Shared_String
|
||||
return $pValue;
|
||||
}
|
||||
|
||||
if(empty(self::$_SYLKCharacters)) {
|
||||
self::_buildSYLKCharacters();
|
||||
}
|
||||
|
||||
foreach (self::$_SYLKCharacters as $k => $v) {
|
||||
$pValue = str_replace($k, $v, $pValue);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user