1
votes

I'm trying to use PHPExcel to create a website that checks consistency of data in excel files. I manage to load the excels but now I need to pass some checks on the data, and I can't figure out how. For example some of the checks would be:

  • Count number of empty cells in a specific column
  • Count number of non integer values in a specific column
  • Check that a column only has values that are contained in another one of the excels.

Are there some functions that do a kind of count where on the columns? Or some way to iterate through the values to achieve this goals?

Thank you

1
PHPExcel doesn't provide this functionality: you'll need to write code to do this yourself; but there's certainly functions for iterating through worksheets, rows and columns - Mark Baker
Thanks Mark, I realized and it's working. I'll add the example as a reply. - Kal

1 Answers

1
votes

Like Mark said, once I used PHPExcel to put the data into arrays I managed to do the checks myself. Here is an example of logging the empty cells of a column:

$n_row=0;
$divisasNull=0;
foreach ($sheetdata as $row) {
    $n_column=0;
    foreach ($row as $cell) {       
        if($n_column==6)
        {
            if($cell==null)
            {
                echo 'Error. Empty currency at row: '.$n_row.'<br>';
                $divisasNull++;
            }
        }
        $n_column++;
    }
    $n_row++;
}
echo 'Total errors: '.$divisasNull;