I have a CSV file where the data is in landscape orientation.ex:
name, test name
age, 20
gender,Male
where the first column is the headers and the second the data, i tried using laravel maatwebsite/Excel
and the response after reading the file, the first row is taken as the headers. (name
and test name
).
is there any method to read this type of CSV files in laravel using maatwebsite/Excel
You can use this function
public function readCSV($csvFile, $array)
{
$file_handle = fopen($csvFile, 'r');
while (!feof($file_handle)) {
$line_of_text[] = fgetcsv($file_handle, 0, $array['delimiter']);
}
fclose($file_handle);
return $line_of_text;
}
$csvFileName = "test.csv";
$csvFile = public_path('csv/' . $csvFileName);
$this->readCSV($csvFile,array('delimiter' => ','))
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