Getting errors while reading decimal number values

Topics: Developer Forum
Jun 21, 2012 at 3:14 PM
Edited Jun 21, 2012 at 3:17 PM

I'm using PHPExcel to update an eshop's items prices and stock, passing the data to a mysql query and updating the DB. I'm having a problem with some of the cells containing numbers with the format of 123,45 (using comma as a decimal separator). Although all cells contain the same format, only some are being read correctly. Please have a look for yourselves and let me know what I'm missing.

And finally, my code:

    
    $objPHPExcel = PHPExcel_IOFactory::load($path);
    $objWorksheet = $objPHPExcel->setActiveSheetIndex(0);

        $highestRow = $objWorksheet->getHighestRow();
        $highestColumn = $objWorksheet->getHighestColumn();
        $highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);
        $nrColumns = ord($highestColumn) - 64;
       
        $rowsadded=0;
        $begin_row=2; // 1st line of data in excel file
        for ($row = $begin_row; $row <= $highestRow; ++ $row) {
            $val=array();
            for ($col=0; $col < $highestColumnIndex; $col++) {
                $cell = $objWorksheet->getCellByColumnAndRow($col, $row);
                $val[] = $cell->getCalculatedValue();
            }
           
            if (($val[0]<>'') && ($val[6]>0)) { //check that row contains data before inserting
                $rowsadded++;
                $sql = sprintf("update productsizes set price=%s, stock=%s where auxcode=%s",
                       GetSQLValueString($val[6], "float"),
                       GetSQLValueString($val[4], "int"),
                       GetSQLValueString($val[0], "int"));
                $result = mysql_query($sql) or die(mysql_error());
            } //end of checking that row contains data before inserting
           
        } echo '<h2>'.$rowsadded. ' rows updated successfully</h2>';