From 85ff71fd185076da5ab60d234c4a89861bc8ea09 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Wed, 11 May 2011 22:36:47 +0000 Subject: [PATCH] General: Improved memory usage in CSV Writer git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@73146 2327b42d-5241-43d6-9e2a-de5ac946f064 --- Classes/PHPExcel/Writer/CSV.php | 12 ++++++++---- changelog.txt | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Classes/PHPExcel/Writer/CSV.php b/Classes/PHPExcel/Writer/CSV.php index cd536fbc..17daf678 100644 --- a/Classes/PHPExcel/Writer/CSV.php +++ b/Classes/PHPExcel/Writer/CSV.php @@ -118,12 +118,16 @@ class PHPExcel_Writer_CSV implements PHPExcel_Writer_IWriter { fwrite($fileHandle, "\xEF\xBB\xBF"); } - // Convert sheet to array - $cellsArray = $sheet->toArray('', $this->_preCalculateFormulas); + // Identify the range that we need to extract from the worksheet + $maxCol = $sheet->getHighestColumn(); + $maxRow = $sheet->getHighestRow(); // Write rows to file - foreach ($cellsArray as $row) { - $this->_writeLine($fileHandle, $row); + for($row = 1; $row <= $maxRow; ++$row) { + // Convert the row to an array... + $cellsArray = $sheet->rangeToArray('A'.$row.':'.$maxCol.$row,'', $this->_preCalculateFormulas); + // ... and write to the file + $this->_writeLine($fileHandle, $cellsArray[0]); } // Close file diff --git a/changelog.txt b/changelog.txt index 75185b78..d48f107d 100644 --- a/changelog.txt +++ b/changelog.txt @@ -26,6 +26,7 @@ Fixed in SVN: - General: (MBaker) Fix to build to ensure that Examples are included with the documentation - General: (MBaker) Reduce cell caching overhead using dirty flag to ensure that cells are only rewritten to the cache if they have actually been changed +- General: (MBaker) Improved memory usage in CSV Writer - Bugfix: (MBaker) Work item 15459 - Invalid cell coordinate in Autofilter for Excel2007 Writer - Bugfix: (MBaker) Work item 15518 - PCLZip library issue - Bugfix: (MBaker) Work item 15537 - Excel2007 Reader canRead function bug