php 如何在 Laravel 中安装 PHPExcel 库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23764375/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:55:17  来源:igfitidea点击:

How I can install the PHPExcel library in laravel?

phpexcellaravellaravel-4

提问by TuGordoBello

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/wikipage?title=Examples) but also do not know what folder should I place it. How I can install?

我正在尝试使用这个库来创建 excel 文件,但不是如何安装它。我正在考虑从其主页(http://phpexcel.codeplex.com/wikipage?title=Examples)下载该库,但也不知道应该将它放在哪个文件夹中。我该如何安装?

回答by Razor

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

您应该使用作曲家:添加"phpexcel/phpexcel": "dev-master"到您的composer.json

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

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

然后执行composer update。所以你可以正常使用它:

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));
    }

}

回答by Vipul

For install PhpExcel in laravel 5.

用于在 Laravel 5 中安装 PhpExcel。

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

请访问此链接以获取包 - https://packagist.org/packages/phpoffice/phpexcel

Please follow the instruction --

请按照说明——

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

1:- 添加"phpoffice/phpexcel": "dev-master"到您的 composer.json。

2:- execute "composer update"on terminal.

2:-"composer update"在终端上执行。

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

3:- 打开文件“/vendor/composer/autoload_namespaces.php”。将以下行粘贴到文件中。

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

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

4:- 现在您可以在控制器或中间件或库中使用 PHPEXCEL 库。

use PHPExcel; 
use PHPExcel_IOFactory;

回答by ceejayoz

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/

实际上有一个专门为 Laravel 制作的整洁的新 PHPExcel 库。易于安装,看起来易于使用(我没有附属关系)。https://laravel-excel.com/

回答by Dean Chiu

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

如果您使用的是Laravel 5。这很容易。

check this linkfor configuration

检查此链接以进行配置

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

您可能需要输入以下命令才能继续下载软件包

composer require maatwebsite/excel

作曲家需要 maatwebsite/excel

check this linkfor 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');
}

回答by user3415926

For future readers:

对于未来的读者:

PHPExcell is no more maintained. Rather use:

PHPExcell不再维护。而是使用:

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

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.

因为所有的努力都转移到了 PhpSpreadsheet,PHPExcel 将不再维护。PHPExcel、补丁和新功能的所有贡献都应针对 PhpSpreadsheet 开发分支。