You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Yii2中PhpOffice库识别异常求助:同仓库两台电脑表现不一致

Troubleshooting "PhpOffice\Phpspreadsheet\Reader\Xlsx" Not Found Error on Second Machine

Hey there, let's break down why your second machine is hitting this error even though the vendor library exists and your composer files match the working machine. The key difference here is how the library was installed—Yii's Composer integration vs manual vendor addition—so we'll focus on closing that gap.

1. Regenerate Composer Autoload Files

When you manually copy the vendor folder, you skip the critical step where Composer generates its autoload mappings. Yii's Composer mechanism handles this automatically, but manual copies don't. Run this command in your project root to fix it:

composer dump-autoload

This refreshes the vendor/autoload.php file and class maps, ensuring PHP can locate the PhpSpreadsheet classes correctly.

2. Verify Yii's Autoloader Configuration

Yii has its own autoload setup that hooks into Composer's autoloader. Check if your second machine's Yii config is properly referencing it:

  • Open your main config file (like config/web.php or config/console.php)
  • Ensure the autoloader component (if configured) isn't overriding or missing the Composer autoload include.
  • Double-check that Yii.php (in vendor/yiisoft/yii2/) correctly includes vendor/autoload.php at the top. It should look like this:
    require(__DIR__ . '/../../autoload.php');
    

3. Check Permissions and Case Sensitivity

  • Permissions: Make sure your web server or CLI user has read access to the vendor/phpoffice/phpspreadsheet directory. On Linux/macOS, run:
    chmod -R 755 vendor/phpoffice/
    
  • Case Sensitivity: If your first machine is Windows (case-insensitive) and the second is Linux/macOS (case-sensitive), double-check the class path spelling. For example, confirm it's PhpOffice\PhpSpreadsheet\Reader\Xlsx (note the capital S in PhpSpreadsheet—typos here will break things on case-sensitive systems).

4. Clear Yii and PHP Caches

Cached class mappings can keep old, missing references active:

  • Yii Cache: Delete all files in your project's runtime/cache directory.
  • OPcache: If your PHP setup uses OPcache, restart your PHP service (Apache/Nginx/FPM) to clear cached class data. You can also temporarily disable OPcache in php.ini to test if this is the root cause.

5. Validate Vendor Directory Integrity

Even if the folder exists, manual copies might miss files or have corrupted data. Compare the vendor/phpoffice/phpspreadsheet/src/Reader/Xlsx.php file between both machines—ensure it exists and has the correct content. If anything's off, run composer install on the second machine (since your composer.json and lock are identical) to re-install the library properly instead of relying on manual copies.


内容的提问来源于stack exchange,提问作者Zoe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:00:21