如何用 phpoffice/phpspreadsheet 替换 phpoffice/phpexcel

How to replace phpoffice/phpexcel with phpoffice/phpspreadsheet

执行composer install时的主要错误:

Package phpoffice/phpexcel is abandoned, you should avoid using it. Use phpoffice/phpspreadsheet instead.

我正在使用 "maatwebsite/excel": "~2.1.0" 并且 Laravel 5.5

我想避免将 excel 迁移到 3.0。我已经尝试迁移它,但它不适合。

您可以尝试以下指南,或提到的“自动化工具”

Migration from PHPExcel

在此期间,您可以指定 Excel 的完整版本号以继续 运行 更新。

Discalimer:我编写了一个工具来处理从 CLI 的自动迁移,称为 Rector,因此人们不必再手动升级 PHP 代码。 It's free, open-source, on GitHub.


官方 "Automated tool" 仅修复 class 个名称。还有 24 个案例需要更改。我们需要升级庞大的 PHP 项目,手动更改会花费太多时间,而且可能会让我们停滞数周。

相反,我制作了一个包含所有 25 个案例的 升级集,这为我们更改了代码:

composer require rector/rector --dev
vendor/bin/rector process src --set phpexcel-to-phpspreadsheet


您想了解更多吗?检查 How to Migrate From PHPExcel to PHPSpreadsheet with Rector in 30 minutes post