
前提
PHPでExcelのデータを取得したいのでPhpSpreadsheetを使いたいです。
composerもインストール済みです。
~windows cmdのログ~
C:\Users\myname>composer require phpoffice/phpspreadsheet Using version ^1.24 for phpoffice/phpspreadsheet ./composer.json has been updated Running composer update phpoffice/phpspreadsheet Loading composer repositories with package information Updating dependencies Lock file operations: 11 installs, 0 updates, 0 removals - Locking ezyang/htmlpurifier (v4.14.0) - Locking maennchen/zipstream-php (2.2.1) - Locking markbaker/complex (3.0.1) - Locking markbaker/matrix (3.0.0) - Locking myclabs/php-enum (1.8.3) - Locking phpoffice/phpspreadsheet (1.24.1) - Locking psr/http-client (1.0.1) - Locking psr/http-factory (1.0.1) - Locking psr/http-message (1.0.1) - Locking psr/simple-cache (2.0.0) - Locking symfony/polyfill-mbstring (v1.26.0) Writing lock file Installing dependencies from lock file (including require-dev) Package operations: 11 installs, 0 updates, 0 removals - Downloading myclabs/php-enum (1.8.3) - Downloading psr/simple-cache (2.0.0) - Downloading markbaker/matrix (3.0.0) - Downloading markbaker/complex (3.0.1) - Downloading symfony/polyfill-mbstring (v1.26.0) - Downloading maennchen/zipstream-php (2.2.1) - Downloading ezyang/htmlpurifier (v4.14.0) - Downloading phpoffice/phpspreadsheet (1.24.1) - Installing myclabs/php-enum (1.8.3): Extracting archive - Installing psr/simple-cache (2.0.0): Extracting archive - Installing psr/http-message (1.0.1): Extracting archive - Installing psr/http-factory (1.0.1): Extracting archive - Installing psr/http-client (1.0.1): Extracting archive - Installing markbaker/matrix (3.0.0): Extracting archive - Installing markbaker/complex (3.0.1): Extracting archive - Installing symfony/polyfill-mbstring (v1.26.0): Extracting archive - Installing maennchen/zipstream-php (2.2.1): Extracting archive - Installing ezyang/htmlpurifier (v4.14.0): Extracting archive - Installing phpoffice/phpspreadsheet (1.24.1): Extracting archive 4 package suggestions were added by new dependencies, use `composer suggest` to see details. Generating autoload files 3 packages you are using are looking for funding. Use the `composer fund` command to find out more!
発生している問題・エラーメッセージ
$reader = new XlsxReader();の時点で
"PhpOffice\PhpSpreadsheet\Reader\Xlsx" not found
になってしまします。
PHP Fatal error: Uncaught Error: Class "PhpOffice\PhpSpreadsheet\Reader\Xlsx" not found in C:\xampp\htdocs\xxxx\index.php
該当のソースコード
PHP
1<?php 2include('./vendor/autoload.php'); 3//require './vendor/autoload.php'; 4use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader; 5//use phpoffice\phpspreadsheet\src\PhpSpreadsheet\Reader\Xlsx as XlsxReader; 6 7~略~ 8 9function XXX($aaa){ 10 11 $reader = new XlsxReader(); ←ここでエラー
試したこと
①includeやrequireの部分を変える
include('./vendor/autoload.php');の部分を
require './vendor/autoload.php';に変えても同じエラーが出ました。
②use コマンドの引数を変える
PHP Fatal error: Uncaught Error: Class "PhpOffice\PhpSpreadsheet\Reader\Xlsx" not found in C:\xampp\htdocs\xxxx\index.php
というエラーなので、vendor以下のフルパスを確認しました。
フルパスは以下です。
C:\Users\myname\vendor\phpoffice\phpspreadsheet\src\PhpSpreadsheet\Reader\Xlsx
そこで、
use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader;
ではなく
use phpoffice\phpspreadsheet\src\PhpSpreadsheet\Reader\Xlsx as XlsxReader;
でも試しましたが、
同様のエラーが出ました。
PHP Fatal error: Uncaught Error: Class "phpoffice\phpspreadsheet\src\PhpSpreadsheet\Reader\Xlsx" not found in C:\xampp\htdocs\xxxx\index.php
補足情報(FW/ツールのバージョンなど)
PHP 8.0.8
PHP初心者で、cmdのコマンドも至らない状況ですが、
ご教授いただければ幸いです。
回答1件
あなたの回答
tips
プレビュー