samedi 5 novembre 2016

PHPExcel how to generate excel file via controller of Laravel 5

I use the library PHPExcel included in Classes directory. I do a simple test in my controller. In my controller, i placed this code:

    `include(app_path().'/Classes/PHPExcel.php');`
    `include(app_path().'/Classes/PHPExcel/Writer/Excel2007.php');`

Then I instantiate the object PHPExcel :

    `$workbook = new PHPExcel;`

I activate the sheet on which I work (the default form), with method ->getActiveSheet().

    `$sheet = $workbook->getActiveSheet();`

I filled my first cell with the method ->setCellValue().

    `$sheet->setCellValue('A1','MaitrePylos');`

Finally to create the file, I need to instantiate an object writer, specific to the type of picture I want to generate.

    `$writer = new PHPExcel_Writer_Excel2007($workbook);`

I give a name to my file, and save :

    `$records = 'storage/app/sampleData/fichier.xlsx';`
    `$writer->save($records);`

Result: I have a generated error Class 'App\Http\Controllers\PHPExcel_Writer_Excel2007' not found

Who can help me to better organize my code and fix my error problem?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire