Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Inquisitive's avatar

PHP Spreadsheet Sample Example

Well, I was using maatwebsite/excel package but I just received a warning

"Package phpoffice/phpexcel is abandoned, you should avoid using it. Use phpoffice/phpspreadsheet instead."

So, is there any sample example parsing CSV/excel file using phpspreadsheet. My requirements is to parse CSV file and dump it to a database. I could do that with maatwebste/excel package. But, I am thinking about doing it with phpoffice/phpspreadsheet.

So, is there any tutorial related to this in laracasts. If not in laracasts, link to any other external resources will be appreciated. Or full details of step on the reply is another better option.

0 likes
4 replies
usamarauf93's avatar

i will upload use of php spreadsheet in laravel here soon

usamarauf93's avatar

use these artisan comands first 1)composer require maatwebsite/excel:2.*

2)add this into cmd

3)composer dumpautoload

4)php artisan clear-compiled

use Maatwebsite\Excel\Facades\Excel; class FileCdrController extends Controller { public function import(){

  $file_path="sample file.xlsx";
  // getting excel file data into array
  $data=Excel::load($file_path, function($reader) {})->get();
  $count=0;
  //looping out data of excel rows
  foreach ($data as $key => $value) {
      $count++;
      $array['promotion_name'] = isset($value->promotion_name) ? (string)$value->promotion_name:'';

// saving records of each row in database $fileCdrData = new FileCdrData($array); $fileCdrData->save();

      echo "$count record successfully saved. <br>";
  }
   
}

}

Please or to participate in this conversation.