not reading data from cell

Topics: Developer Forum
Jun 8, 2014 at 4:25 PM
I can't figure out what I am doing wrong. But I can't read any data from a cell in my spreadsheet.
Here is the code:
/** Include PHPExcel */
    require_once dirname(__FILE__) . '/../Classes/PHPExcel.php';
    
    $inputFileName = 'CCCStocks.xls';
    
    /**  Identify the type of $inputFileName  **/
    //$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
    
    /**  Create a new Reader of the type defined in $inputFileType  **/ 
    //$objReader = PHPExcel_IOFactory::createReader($inputFileType); 
    $objReader = new PHPExcel_Reader_Excel5();
    
    /**  Advise the Reader that we only want to load cell data  **/
    $objReader->setReadDataOnly(true);

    $worksheetNames = $objReader->listWorksheetNames($inputFileName);

    echo "<h3>Reading $inputFileName</h3>";
    echo "<ol>";
    
    /**  Set a sheet index  **/ 
    $sheet = 0; 
    $query = "SELECT Category FROM ccccategories";
    $result = mysqli_query($con, $query);
    $cats = array();
    while($row = mysqli_fetch_array($result, MYSQLI_NUM)) {
        $cats[] = $row[0];
    }
    print_r($cats);
    //$objReader->setLoadSheetsOnly(0);
    
    /**  Load $inputFileName to a PHPExcel Object  **/
    $objPHPExcel = $objReader->load($inputFileName);
    $objWorksheet = $objPHPExcel->setActiveSheetIndex('0');
        $cat = $cats[0];
        echo "<li>$cat</li>";
        //$objPHPExcel->setActiveSheetIndexByName("Champions");
        $col = 0;
        $row = 0;
        $cell = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
        echo "<ol>";
        echo "<li>$cell</li>";
        while($cell != null && $cell != "") {
            echo "<li>$cell</li>";
            $cell = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow($col, $row)->getValue();
            $row++;
        }
    echo '</ol></ol>';
Jun 13, 2014 at 9:15 PM
So this line:
echo "<li>$cell</li>";
output nothing. Any ideas what I am doing wrong?
Thanks
Mike
Coordinator
Jun 13, 2014 at 9:58 PM
There isn't a $row = 0 in an Excel spreadsheet, row numbers start at 1
Jun 13, 2014 at 10:14 PM
Heh, figured it's be something simple like that. So rows start at 1 and columns start at 0?