Am I missing something? Reader

Feb 19, 2009 at 11:53 PM
Edited Feb 19, 2009 at 11:55 PM
The code below and variations are for the most part working. That is, I get the values expected on most cells. Ive also tried, $sheet_rows = $objPHPExcel->getActiveSheet()->toArray(NULL, TRUE); (loop throught).  $objReader->setReadDataOnly(FALSE) and a few other things, but I need the value of cell H21 (should be 246) but it comes back as 0 or =SUM(I10). Its reading an xlsx created from PHPExcel as well.

include 'PHPExcel.php';
        /** PHPExcel_IOFactory */
        include 'PHPExcel/IOFactory.php';
         /** PHPExcel_Reader_IReadFilter */
        require_once 'PHPExcel/Reader/IReadFilter.php';
        //error_reporting(E_COMPILE_ERROR);
        $ext = substr($file, strrpos($file, '.') + 1);
        
        if($ext == 'xls') $objReader = PHPExcel_IOFactory::createReader('Excel5');
        elseif($ext == 'xlsx') $objReader = PHPExcel_IOFactory::createReader('Excel2007');
        $objReader->setReadDataOnly(FALSE); //PROBLEM?
        $this->benchmark->mark('read_start');
        $objPHPExcel = $objReader->load($file);
     
        $sheet_count = $objPHPExcel->getSheetCount();
        $sheets = array_reverse($objPHPExcel->getSheetNames(), true);
        sort($sheets);
        foreach ($sheets as $k => $sheet_title){
            $sheet_index = $objPHPExcel->getIndex($objPHPExcel->getSheetByName($sheet_title));
            
            $objPHPExcel->setActiveSheetIndex($sheet_index);


           

            $objWorksheet = $objPHPExcel->getActiveSheet();
echo '<table border="1">' . "\n";
foreach ($objWorksheet->getRowIterator() as $row) {
echo '<tr>' . "\n";

$cellIterator = $row->getCellIterator();
$cellIterator->setIterateOnlyExistingCells(false); // This loops all cells,
// even if it is not set.
// By default, only cells
// that are set will be
// iterated.
foreach ($cellIterator as $cell) {
echo '<td>' . $cell->getCalculatedValue() . '</td>' . "\n";
}

echo '</tr>' . "\n";
}
echo '</table>' . "\n";
Feb 19, 2009 at 11:57 PM
I references a cell that has another formula, that's probably the problem right? =IF(ISERROR(G10+H10),0,G10+H10)


Feb 20, 2009 at 12:06 AM
Ha! It was becuase I stored the cells as varchars in the DB and it was trying to do calcs on $123.00.

I appreciate the hard work, but maybe a suggestion, make a debug mode or something?
$objReader->setDebug(TRUE);

And have it dump table to the screen with errors on screwed up cells?

Anyways Love the code thanks for the hard work!