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.
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
You can achieve that using array_shift this:
$toArray = $worksheet->toArray()
array_shift($toArray);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With