如何安装 maatwebsite/excel?

Posted

技术标签:

【中文标题】如何安装 maatwebsite/excel?【英文标题】:How do I install maatwebsite/excel? 【发布时间】:2020-01-30 09:59:29 【问题描述】:

我正在尝试安装maatwebsite/excel;但是,我无法让它工作。

我尝试删除composer.lock 文件并运行:

composer install
composer update

我也试过了:

composer require maatwebsite/excel --update-with-dependencies

这两种方法都不起作用。

我收到的错误是:

Problem 1
- maatwebsite/excel 3.1.10 requires phpoffice/phpspreadsheet ^1.6 -> satisfiable by phpoffice/phpspreadsheet[1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
- maatwebsite/excel 3.1.11 requires phpoffice/phpspreadsheet ^1.6 -> satisfiable by phpoffice/phpspreadsheet[1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
- maatwebsite/excel 3.1.12 requires phpoffice/phpspreadsheet ^1.6 -> satisfiable by phpoffice/phpspreadsheet[1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
- maatwebsite/excel 3.1.13 requires phpoffice/phpspreadsheet ^1.6 -> satisfiable by phpoffice/phpspreadsheet[1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
 .
 .
 .
 .

- maatwebsite/excel 3.1.14 requires phpoffice/phpspreadsheet ^1.6 -> satisfiable by phpoffice/phpspreadsheet[1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].
- maatwebsite/excel 3.1.15 requires phpoffice/phpspreadsheet ^1.6 -> satisfiable by phpoffice/phpspreadsheet[1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0].   
- Installation request for maatwebsite/excel ^3.1 -> satisfiable by maatwebsite/excel[3.1.0, 3.1.1, 3.1.10, 3.1.11, 3.1.12, 3.1.13, 3.1.14, 3.1.15, 3.1.16, 3.1.17, 3.1.2, 3.1.3, 3.1.4, 3.1.5, 3.1.6, 3.1.7, 3.1.8, 3.1.9, 3.1.x-dev, 3.2.x-dev].

To enable extensions, verify that they are enabled in your .ini files:
- C:\Users\user\Downloads\php-7.3.8-nts-Win32-VC15-x64\php.ini
You can also run `php --ini` inside terminal to see which files are used 
by PHP in CLI mode.

Installation failed, reverting ./composer.json to its original content.

【问题讨论】:

【参考方案1】:

此软件包需要 GD (GIF Draw) 扩展。 您需要从 php.ini 文件中启用 gd 扩展。

在 php.ini 中搜索这个文件:extension=gd

【讨论】:

这才是真正的答案!【参考方案2】:

在我的情况下,发生错误是因为作曲家无法加载 phpoffice/phpspreadsheet 包。通常,composer 能够安装依赖项。但是,服务器上缺少一些 php 扩展——比如 php zip。一旦我安装了这些扩展,问题就解决了。

我建议你不要忽视需求,而是去寻找问题的根源。

【讨论】:

【参考方案3】:

我尝试了很多东西,但这对我有用。

sudo apt-get install php-zip&&sudo apt-get install php-gd 我得到了。 maatwebsite/excel 3.1.10 需要 phpoffice/phpspreadsheet ^1.6 -> 可由 phpoffice/phpspreadsheet[1.6.0, 1.7.0, 1.8.0, 1.8.1, 1.8.2, 1.9.0] 满足。

正如 Teoman Tıngır 所说,Composer 应该更新依赖项,但有时由于缺少一些扩展,它无法做到这一点,这就是出现这些错误的原因。

【讨论】:

【参考方案4】:

转到您的 php.ini 文件并查找该行 **;extension=gd** 并将其更改为 **extension=gd**

如果此行不存在,则仅查找 **gd** 并取消注释。

【讨论】:

【参考方案5】:
sudo apt-get install php-zip&&sudo apt-get install php-gd

它帮助了我

【讨论】:

【参考方案6】:

显然,这是一个依赖错误。要忽略此依赖项要求,请运行:

composer require maatwebsite/excel --ignore-platform-reqs

【讨论】:

maatwebsite/excel 3.1.10 requires phpoffice/phpspreadsheet,所以你不应该需要'maatwebsite/excel',而是需要'phpoffice/phpspreadsheet'。 非常感谢它对我有用 laravel 8

以上是关于如何安装 maatwebsite/excel?的主要内容,如果未能解决你的问题,请参考以下文章

laravel-excel maatwebsite/excel 新版中文文档

laravel maatwebsite/excel 数字显示科学技术法怎么解决

Maatwebsite\Excel\Sheet::mapArraybleRow()的返回值必须是数组类型,返回null

Laravel Excel 实现 Excel-CSV 文件导入导出功能

laravel安装Excel安装不上

如何在 Laravel 项目中处理 Excel 文件 | 扣钉·实栗