Phoenix Bird
Phoenix Bird

Reputation: 1247

How to eliminate empty rows in excel upload from PHP using PHPExcel upload?

i am in the middle of the development. i want to eliminate the empty rows while upload a excel from PHP using PHP excel plugin.

while($x<=$excel->sheets[0]['numRows']){
    $y=1;
    while($y<=$excel->sheets[0]['numCols']){
        $cell = isset($excel->sheets[0]['cells'][$x][$y])
            ? $excel->sheets[0]['cells'][$x][$y] 
            : '';
        if($excel->sheets[0]['cells'][$x][$y] == $excel->sheets[0]['cells'][$x][1] ){
            echo $cell;
        } else { 
            echo $cell; 
        }
        $y++;
    } 
    $x++;
} 

i used this code to get the values from excel to PHP, but if the excel has empty record the result will be modified something like extra cells. how can i fix this.

Upvotes: 2

Views: 2335

Answers (1)

Mark Baker
Mark Baker

Reputation: 212412

if (!array_reduce(
    $excel->sheets[0]['cells'][$x],
    function ($state, $value) {
        return $state && !($value > '');
    },
    TRUE
)) {
// execute your while($y<=$excel->sheets[0]['numCols']) loop here
}

Upvotes: 1

Related Questions