How I can install the PHPExcel library in laravel?

前端 未结 5 415
伪装坚强ぢ
伪装坚强ぢ 2020-12-29 08:18

I\'m trying to use this library to create excel files but not how to install it. I was considering to download the library from its home page (http://phpexcel.codeplex.com/w

相关标签:
5条回答
  • 2020-12-29 09:00

    If you are using Laravel 5. It is very easy.

    check this link for configuration

    you may need to type in the following command to proceed with the package download

    composer require maatwebsite/excel

    check this link for usage

    my might want to look at my example code:

    public function testexcel(){
    
        Excel::create('testfile', function($excel) {
            // Set the title
            $excel->setTitle('no title');
            $excel->setCreator('no no creator')->setCompany('no company');
            $excel->setDescription('report file');
    
            $excel->sheet('sheet1', function($sheet) {
                $data = array(
                    array('header1', 'header2','header3','header4','header5','header6','header7'),
                    array('data1', 'data2', 300, 400, 500, 0, 100),
                    array('data1', 'data2', 300, 400, 500, 0, 100),
                    array('data1', 'data2', 300, 400, 500, 0, 100),
                    array('data1', 'data2', 300, 400, 500, 0, 100),
                    array('data1', 'data2', 300, 400, 500, 0, 100),
                    array('data1', 'data2', 300, 400, 500, 0, 100)
                );
                $sheet->fromArray($data, null, 'A1', false, false);
                $sheet->cells('A1:G1', function($cells) {
                $cells->setBackground('#AAAAFF');
    
                });
            });
        })->download('xlsx');
    }
    
    0 讨论(0)
  • 2020-12-29 09:12

    For install PhpExcel in laravel 5.

    Please visit this link for pakage -https://packagist.org/packages/phpoffice/phpexcel.

    Please follow the instruction --

    1:- Add "phpoffice/phpexcel": "dev-master" to your composer.json.

    2:- execute "composer update" on terminal.

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

    'PHPExcel' => array($vendorDir . '/phpoffice/phpexcel/Classes'),
    

    4:- Now you can use PHPEXCEL library in your controllers or middleware or library.

    use PHPExcel; 
    use PHPExcel_IOFactory;
    
    0 讨论(0)
  • 2020-12-29 09:13

    There's actually a neat new PHPExcel library specifically made for Laravel. Easy installation and it looks easy to use (I'm unaffiliated). https://laravel-excel.com/

    0 讨论(0)
  • 2020-12-29 09:19

    For future readers:

    PHPExcell is no more maintained. Rather use:

    https://github.com/PHPOffice/PhpSpreadsheet http://phpspreadsheet.readthedocs.io/en/develop/#installation

    Because all efforts have shifted to PhpSpreadsheet, PHPExcel will no longer be maintained. All contributions for PHPExcel, patches and new features, should target PhpSpreadsheet develop branch.

    0 讨论(0)
  • 2020-12-29 09:20

    You should use composer: Add "phpexcel/phpexcel": "dev-master" to your composer.json

    "require": {
        "phpexcel/phpexcel": "dev-master"
    }
    

    Then execute composer update. So you can use it as normal:

    public function import($path){
    
        $objPHPExcel = PHPExcel_IOFactory::load($path);
        $objWorksheet = $objPHPExcel->getActiveSheet();
        $highestRow = $objWorksheet->getHighestRow();
        for ($row = 1; $row <= $highestRow; ++$row) {
             var_dump($objWorksheet->getCellByColumnAndRow(1, $row));
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题