PhpSpreadsheet 通过引入命名空间和重命名一些类引入了许多破坏性更改。为了帮助您迁移现有项目,编写了一个工具来替换所有对 PHPExcel 类的引用到它们新名称。但是还需要进行手动更改。
自动化工具
RectorPHP 可用于自动迁移您的代码库。假设要迁移的文件位于 src/
目录下,可以按照如下方式运行迁移:
composer require rector/rector rector/rector-phpoffice phpoffice/phpspreadsheet --dev
# this creates rector.php config
vendor/bin/rector init
在 rector.php
中设置 PHPOfficeSetList
declare(strict_types=1);
use Rector\Config\RectorConfig;
use Rector\PHPOffice\Set\PHPOfficeSetList;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([
PHPOfficeSetList::PHPEXCEL_TO_PHPSPREADSHEET
]);
};
在代码中执行 Rector 代码
vendor/bin/rector process src
有关更多详细信息,请参阅 rector-phpoffice。