Getting started with PHP using phpSpredsheet. Testing basic code returns the error Fatal error: Uncaught Error: Class "PhpOffice\PhpSpreadsheet\Spreadsheet" not found. The composer.json file includes:
使用phpSpredSheet开始使用PHP。测试基本代码会返回错误FATAL ERROR:UNAUCAT ERROR:CLASS“PhpOffice\PhpSpreadSheet\SpreadSheet”Not Found。Composer.json文件包括:
"require": {
"phpoffice/phpspreadsheet": "^1.29"
},
The path to the files: .\vendor\phpoffice\phpspreadsheet
文件的路径:.\Vendor\phpoffice\phpspadsheet
The below php script in Visual Studio appears to pickup the references to Speadsheet and Xlsx, as a mouseover provides tooltip information.
由于鼠标悬停提供了工具提示信息,因此在Visual Studio中,下面的php脚本似乎选择了SpeadSheet和xlsx的引用。
// require_once('vendor/autoload.php');
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use phpoffice\PhpSpreadsheet\Writer\Xlsx;
// Creates New Spreadsheet
$spreadsheet = new Spreadsheet();
// Retrieve the current active worksheet
$sheet = $spreadsheet->getActiveSheet();
// Set the value of cell A1
$sheet->setCellValue('A1', 'This is a test!');
// Sets the value of cell B1
$sheet->setCellValue('B1', 'This is only a test');
// Write an .xlsx file
$writer = new Xlsx($spreadsheet);
// Save .xlsx file to the current directory
$writer->save('/test.xlsx');
Remark out open_basedir
Restart IIS
Remove ./vendor
Remove ./composer.lock
Reinstall Composer
重新启动IIS REMOVE。/VADVER REMOVE。/Composer.lock重新安装Composer
更多回答
Is the require_once()
really commented out in your code?
您的代码中是否真的注释掉了RequireOnce()?
Without the autoloader it won't find the class. Uncomment the first line.
没有自动装载机,它就找不到班级了。取消对第一行的注释。
OMG, that was a stupid mistake. Thank you for pointing that out. It was left after commenting out all php code to test resolution of HTML on the page. But I am back to the error when opening the page after removing the comment on autoload: Fatal error: Uncaught Error: Class "phpoffice\PhpSpreadsheet\Writer\Xlsx" not found
天哪,那是个愚蠢的错误。谢谢你指出这一点。它是在注释掉所有php代码以测试页面上的HTML解析后留下的。但我在删除autoload上的评论后打开页面时返回错误:致命错误:未捕获错误:找不到类“phpoffice\PhpSpreadSheet\Writer\xlsx”
The second use
statement should be use PhpOffice\...
, not use phpoffice\...
.
第二个USE语句应该是Use PhpOffice\...,而不是Use Phpoffice\...
我是一名优秀的程序员,十分优秀!