Speed boost and memory reduction in the Worksheet toArray() method.

git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@66403 2327b42d-5241-43d6-9e2a-de5ac946f064
This commit is contained in:
Mark Baker 2011-01-04 13:52:05 +00:00
parent b321f33fed
commit 59b831c4f1
2 changed files with 39 additions and 32 deletions

View File

@ -2150,20 +2150,24 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
// Garbage collect... // Garbage collect...
$this->garbageCollect(); $this->garbageCollect();
// Identify the range that we need to extract from the worksheet
$maxCol = $this->getHighestColumn();
$maxRow = $this->getHighestRow();
$maxCol++;
// Loop through rows // Loop through rows
$r = -1; for ($row = 1; $row <= $maxRow; ++$row) {
$rowIterator = $this->getRowIterator();
foreach ($rowIterator as $row) {
++$r;
$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(true); // Loop through each cell in the current row
$c = -1; $c = -1;
foreach ($cellIterator as $cell) { // Loop through columns in the current row
++$c; for ($col = 'A'; $col != $maxCol; ++$col) {
$rRef = ($returnCellRef) ? $cell->getRow() : $r; $rRef = ($returnCellRef) ? $row : $row-1;
$cRef = ($returnCellRef) ? $cell->getColumn() : $c; $cRef = ($returnCellRef) ? $col : ++$c;
if (!is_null($cell)) { // Using getCell() will create a new cell if it doesn't already exist. We don't want that to happen
// Cell exists? // so we test and retrieve directly against _cellCollection
if ($this->_cellCollection->isDataSet($col.$row)) {
// Cell exists
$cell = $this->_cellCollection->getCacheData($col.$row);
if ($cell->getValue() !== null) {
if ($cell->getValue() instanceof PHPExcel_RichText) { if ($cell->getValue() instanceof PHPExcel_RichText) {
$returnValue[$rRef][$cRef] = $cell->getValue()->getPlainText(); $returnValue[$rRef][$cRef] = $cell->getValue()->getPlainText();
} else { } else {
@ -2176,13 +2180,15 @@ class PHPExcel_Worksheet implements PHPExcel_IComparable
if ($formatData) { if ($formatData) {
$style = $this->_parent->getCellXfByIndex($cell->getXfIndex()); $style = $this->_parent->getCellXfByIndex($cell->getXfIndex());
$returnValue[$rRef][$cRef] = PHPExcel_Style_NumberFormat::toFormattedString($returnValue[$rRef][$cRef], $style->getNumberFormat()->getFormatCode()); $returnValue[$row][$cRef] = PHPExcel_Style_NumberFormat::toFormattedString($returnValue[$rRef][$cRef], $style->getNumberFormat()->getFormatCode());
} }
} else { } else {
// Cell doesn't exist
$returnValue[$rRef][$cRef] = $nullValue; $returnValue[$rRef][$cRef] = $nullValue;
} }
} }
} }
}
// Return // Return
return $returnValue; return $returnValue;

View File

@ -27,6 +27,7 @@ Fixed in SVN:
- Feature: (MBaker) Provide option to use PCLZip as an alternative to ZipArchive. - Feature: (MBaker) Provide option to use PCLZip as an alternative to ZipArchive.
This allows the writing of Excel2007 files, even without ZipArchive enabled (it does require zlib), or when php_zip is one of the buggy PHP 5.2.6 or 5.2.8 versions This allows the writing of Excel2007 files, even without ZipArchive enabled (it does require zlib), or when php_zip is one of the buggy PHP 5.2.6 or 5.2.8 versions
- Feature: (MBaker) Work item 14979 - Added listWorksheetNames() method to Readers that support multiple worksheets in a workbook, allowing a user to extract a list of all the worksheet names from a file without parsing/loading the whole file. - Feature: (MBaker) Work item 14979 - Added listWorksheetNames() method to Readers that support multiple worksheets in a workbook, allowing a user to extract a list of all the worksheet names from a file without parsing/loading the whole file.
- Feature: (MBaker) Speed boost and memory reduction in the Worksheet toArray() method.
- Bugfix: (MBaker) Work item 14888 - Simple =IF() formula disappears - Bugfix: (MBaker) Work item 14888 - Simple =IF() formula disappears
- Bugfix: (MBaker) Work item 14898 - PHP Warning: preg_match(): Compilation failed: PCRE does not support \\L, \\l, \\N, \\P, \\p, \\U, \\u, or \\X - Bugfix: (MBaker) Work item 14898 - PHP Warning: preg_match(): Compilation failed: PCRE does not support \\L, \\l, \\N, \\P, \\p, \\U, \\u, or \\X
- Bugfix: (MBaker) Work item 14901 - VLOOKUP choking on parameters in PHPExcel.1.7.5/PHPExcel_Writer_Excel2007 - Bugfix: (MBaker) Work item 14901 - VLOOKUP choking on parameters in PHPExcel.1.7.5/PHPExcel_Writer_Excel2007