27

我想使用包 Phpspreadsheet 编写一个脚本。我没有php经验。我正在尝试通过 sudo composer require phpoffice/phpspreadsheet 添加对我的脚本的引用。但它不起作用。我收到错误消息:安装失败,删除 composer.json....如果不知道它为什么不工作。任何想法?

详细错误:

Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for phpoffice/phpspreadsheet ^1.0 -> satisfiable by phpoffice/phpspreadsheet[1.0.0].
- phpoffice/phpspreadsheet 1.0.0 requires ext-dom * -> the requested PHP extension dom is missing from your system.

To enable extensions, verify that they are enabled in those .ini files:
- /etc/php/7.0/cli/php.ini
- /etc/php/7.0/cli/conf.d/10-mysqlnd.ini
- /etc/php/7.0/cli/conf.d/10-opcache.ini
- /etc/php/7.0/cli/conf.d/10-pdo.ini
- /etc/php/7.0/cli/conf.d/20-calendar.ini
- /etc/php/7.0/cli/conf.d/20-ctype.ini
- /etc/php/7.0/cli/conf.d/20-exif.ini
- /etc/php/7.0/cli/conf.d/20-fileinfo.ini
- /etc/php/7.0/cli/conf.d/20-ftp.ini
- /etc/php/7.0/cli/conf.d/20-gettext.ini
- /etc/php/7.0/cli/conf.d/20-iconv.ini
- /etc/php/7.0/cli/conf.d/20-json.ini
- /etc/php/7.0/cli/conf.d/20-mcrypt.ini
- /etc/php/7.0/cli/conf.d/20-mysqli.ini
- /etc/php/7.0/cli/conf.d/20-pdo_mysql.ini
- /etc/php/7.0/cli/conf.d/20-phar.ini
- /etc/php/7.0/cli/conf.d/20-posix.ini
- /etc/php/7.0/cli/conf.d/20-readline.ini
- /etc/php/7.0/cli/conf.d/20-shmop.ini
- /etc/php/7.0/cli/conf.d/20-sockets.ini
- /etc/php/7.0/cli/conf.d/20-sysvmsg.ini
- /etc/php/7.0/cli/conf.d/20-sysvsem.ini
- /etc/php/7.0/cli/conf.d/20-sysvshm.ini
- /etc/php/7.0/cli/conf.d/20-tokenizer.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.
4

11 回答 11

79

所以我应该安装

sudo apt install php-xml

sudo apt install php7.0-gd

sudo apt install php7.0-mbstring

sudo apt install php-zip

于 2018-01-13T15:28:14.043 回答
9

我有同样的问题,我通过这样做来解决它

composer install --ignore-platform-reqs
于 2021-08-10T00:27:39.993 回答
8

在运行 composer install/update 或安装新包时也会添加

--ignore-platform-reqs

在命令结束时,为不同的环境添加/安装成功。

于 2021-03-29T14:31:47.373 回答
3

sudo apt install php-xml

sudo apt install php7.0-gd

sudo apt install php7.0-mbstring

sudo apt install php-zip

于 2020-10-24T07:53:28.907 回答
2

在 Centos 中:

sudo yum install gd gd-devel php-gd

于 2019-03-14T01:54:21.100 回答
1

请阅读错误信息“需要 ext-dom”。它抱怨缺少包或在这种情况下是 php 扩展。通常,当您无法安装软件包时,您可以查看其 composer.json 中所需的软件包以查看完整列表。

phpoffice(在这种情况下为 1.1.0)需要以下内容:

   "require": {
        "php": "^5.6|^7.0",
        "ext-ctype": "*",
        "ext-dom": "*",
        "ext-gd": "*",
        "ext-iconv": "*",
        "ext-libxml": "*",
        "ext-mbstring": "*",
        "ext-SimpleXML": "*",
        "ext-xml": "*",
        "ext-xmlreader": "*",
        "ext-xmlwriter": "*",
        "ext-zip": "*",
        "ext-zlib": "*",
        "psr/simple-cache": "^1.0"
    },
    "require-dev": {
        "tecnickcom/tcpdf": "^6.2",
        "squizlabs/php_codesniffer": "^2.7",
        "phpunit/phpunit": "^5.7",
        "dompdf/dompdf": "^0.8.0",
        "mpdf/mpdf": "^7.0.0",
        "jpgraph/jpgraph": "^4.0",
        "friendsofphp/php-cs-fixer": "@stable"
    },
于 2018-02-11T03:22:52.937 回答
1

类型

 php -v

如果 php7 类型

sudo apt install php-xml
sudo apt install php7.0-gd
sudo apt install php7.0-mbstring
sudo apt install php-zip

如果 php8 类型

sudo apt install php-xml
sudo apt install php8.0-gd
sudo apt install php8.0-mbstring
sudo apt install php-zip
于 2021-06-13T10:37:33.537 回答
1

错误信息显示未命中。我有同样的问题,通过这样做解决它。请阅读错误信息“需要 ext-dom”。

请安装php7.1-dom

就我而言,PHP 是 7.1 以下是我所做的并且现在正在工作。

sudo apt-get install php7.1 php7.1-cli php7.1-common php7.1-json php7.1-opcache php7.1-mysql php7.1-mbstring php7.1-mcrypt php7.1-zip php7。 1-fpm sudo apt install php-xml php7.1-gd php7.1-dom

于 2019-08-26T06:10:49.763 回答
0

如果您是 Arch 用户编辑/etc/php74/php.ini或您使用的任何版本。确保已安装扩展并且未注释 gd 扩展。

extension=gd
于 2022-01-07T16:42:41.300 回答
0

我遇到了同样的问题,我用命令解决了composer install --ignore-platform-reqs

于 2021-11-05T14:27:52.250 回答
0

如果你正在使用

$sheet->setAutoFilter(); 

尝试对此发表评论以进行测试

//$sheet->setAutoFilter();

为我工作

于 2018-04-04T11:24:49.670 回答