PHPExcel icon indicating copy to clipboard operation
PHPExcel copied to clipboard

Stream/callback to process large files

Open daniel-adlantic opened this issue 11 years ago • 0 comments

Hello,

I am wondering if it is possible to add support for some kind of row based callback. This would be specially useful to me when handling 10,000+ rows excel documents. Loading the entire sheet uses up a lot of memory, and my current work-around using a chunk filter seems very inefficient in processing. My thoughts are currently that it would work similar to ReadFilters. For example:

The interface:

interface PHPExcel_Reader_IRowHandler {
    public function handleRow(PHPExcel_Worksheet_Row $row);
}

An implementation:

class MyExcelRowHandler implements PHPExcel_Reader_IRowHandler {
    public function handleCell(PHPExcel_Worksheet_Row $row) {
        // Read cells, update database's etc.
    }
}

And bringing it all together

$objReader = PHPExcel_IOFactory::createReaderForFile($strPath);
$objRowHandler = new MyExcelRowHandler();
$objReader->setRowHandler($objRowHandler);
$objReader->run();

I realize this could get complicated when it comes to handling files with multiple sheets etc., but I'm still curious what your thoughts are on this?

daniel-adlantic avatar Jul 15 '15 16:07 daniel-adlantic