Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPExcel toArray skip first header row

I'm uploading an excel file to website and process it for database use.

I'm using toArray() function to get all rows in a php array.

But I want to skip the first row ( header title row). The rest of rows will be stored in array.

How can I skip the first row.

Note : I can't use rangeToArray() function since there is not fixed range to get rows into array. It is dynamic. All i want is get all rows except first.

like image 376
Sohan Patel Avatar asked Apr 05 '15 10:04

Sohan Patel


2 Answers

Eko answers half the problem, you can use rangeToArray(); but you don't need to use a loop at all:

$highestRow = $sheet->getHighestRow(); 
$highestColumn = $sheet->getHighestColumn();

$sheetData = $sheet->rangeToArray(
    'A2:' . $highestColumn . $highestRow,
    NULL,TRUE,FALSE
);

Alternatively, use toArray() and then just unset the first element from the returned array

like image 95
Mark Baker Avatar answered Oct 14 '22 06:10

Mark Baker


You can achieve that using array_shift this:

$toArray = $worksheet->toArray() 
array_shift($toArray);
like image 20
Pablo Rodriguez V. Avatar answered Oct 14 '22 07:10

Pablo Rodriguez V.