1
Vote

getCalculatedValue() doesn't work with readfilter

description

There seems to be a bug when using getCalculatedValue() with a PHPExcel_Reader_IReadFilter to read the file in chunks. I'm reading a file in a double loop with a chunk size of 10,000 - when it gets to the second loop values pulled in with getCalculatedValue() are returned as 0 when they shouldn't be. I've reduced the chunk size and confirmed that the issue occurs at the start of the second loop when a new chunk is set.

Formulas in the cells being read are of the format:

=F1160%
=F12
60%
etc

My filter is like this:
class chunkReadFilter implements PHPExcel_Reader_IReadFilter 
    { 
        private $_startRow = 0; 
        private $_endRow = 0; 
        
        /**  Set the list of rows that we want to read  */ 
        public function setRows($startRow, $chunkSize) { 
            $this->_startRow    = $startRow; 
            $this->_endRow      = $startRow + $chunkSize; 
        } 
        public function readCell($column, $row, $worksheetName = '') { 
            //  Only read the heading row, and the rows that are configured in $this->_startRow and $this->_endRow 
            if (($row == 1) || ($row >= $this->_startRow && $row < $this->_endRow)) { 
                return true; 
            } 
            return false; 
        } 
    } 
Outline of my loop looks like this:
for ($startRow = 1; $startRow <= $highestRow; $startRow += $chunkSize) { 

        $chunkFilter->setRows($startRow,$chunkSize); 
        $excelObj = $reader->load($filename);
        $worksheet = $excelObj->getSheet(0); 
        
        // Process each row of the spreadsheet    
        for($z=$startRow; $z<= min(array($startRow + $chunkSize, $highestRow)); $z++) 
        {       
                        ...
                        PHPExcel_Calculation::getInstance( $worksheet->getParent() )->flushInstance();
                                $params[$cols[$i]] = $worksheet->getCellByColumnAndRow($i, $z)->getCalculatedValue();
 ...
            }
}
I added the flushInstance as recommended in another post but it had no affect.

Is this a known issue and is there a way to fix it?

comments