how to add PHPExcel library in laravel?

两盒软妹~` 提交于 2019-12-06 01:34:01

问题


i want to create new module in laravel which include PHPExcel library. where to put library. how to access it.

i have put the PHPExcel library at below location

laravel\project\application\libraries\PHPEXCEL

it give me error PHP Fatal error: Class 'PHPExcel' not found.


回答1:


You can use the PHPExcel Composer package. Just add "phpoffice/phpexcel": "dev-master" to your composer.json and enter composer update. This way the library will be "installed" and you can use it as normal (for example $objPHPExcel = new PHPExcel();) No need for manual includes etc.

Update may 2016

Instead of editing your composer.json, please use the 'official' command:

composer require phpoffice/phpexcel




回答2:


Below are the step to use PHPEXCEL Library with laravel 5

1:- Install "phpoffice" Package in Laravel 5. Below is the link for the packages

2:- Add "phpexcel/phpexcel": "dev-master" to your composer.json. Ex:- "require": { "phpexcel/phpexcel": "dev-master" }

3:- Then execute "composer update".

4:- Open the file "/vendor/composer/autoload_namespaces.php". Paste the below line in the file.

// Include PHPEXCEL Library with Laravel 5
'PHPExcel' => array($vendorDir . '/phpoffice/phpexcel/Classes'),

5:- Now you can use PHPEXCEL library in your controllers or middleware or library. use PHPExcel; use PHPExcel_IOFactory;

For more details you can access "https://github.com/pantlavanya/export-to-excel-using-phpoffice-phpexcel-in-laravel-5" link.



来源:https://stackoverflow.com/questions/22130008/how-to-add-phpexcel-library-in-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!