首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在PHPOffice PHPSpreadSheet和Composer上安装错误

在PHPOffice PHPSpreadSheet和Composer上安装错误
EN

Stack Overflow用户
提问于 2022-04-11 23:44:05
回答 1查看 901关注 0票数 0

我使用的是Windows 10和Laragon 5.0 WAMP (PHP 7.4.19和Apache2.4.47)。

使用以下命令尝试用Composer安装PHPOffice/PHPSpreadSheet:

编写器需要phpoffice/phpoffice电子表格

Composer安装没有任何问题,但是在尝试运行以下PHP代码时:

代码语言:javascript
复制
<?php
$spreadsheet = \PhpSpreadsheet\IOFactory::load('template.xlsx');

$worksheet = $spreadsheet->getActiveSheet();

$worksheet->getCell('A1')->setValue('John');
$worksheet->getCell('A2')->setValue('Smith');

$writer = \PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls');
$writer->save('write.xls');
?>

它会出错:

致命错误:未捕获错误:在C:\laragon\www\excel.php:2堆栈跟踪中找不到'PhpSpreadsheet\IOFactory‘类:#0

作曲家表演:

代码语言:javascript
复制
C:\Users\wieb>composer show
ezyang/htmlpurifier       v4.14.0 Standards compliant HTML filter written in PHP
maennchen/zipstream-php   2.1.0   ZipStream is a library for dynamically streaming dynamic zip files from PHP without writing to the disk at all on the server.
markbaker/complex         3.0.1   PHP Class for working with complex numbers
markbaker/matrix          3.0.0   PHP Class for working with matrices
myclabs/php-enum          1.8.3   PHP Enum implementation
phpoffice/phpspreadsheet  1.22.0  PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine
psr/http-client           1.0.1   Common interface for HTTP clients
psr/http-factory          1.0.1   Common interfaces for PSR-7 HTTP message factories
psr/http-message          1.0.1   Common interface for HTTP messages
psr/simple-cache          1.0.1   Common interfaces for simple caching
symfony/polyfill-mbstring v1.25.0 Symfony polyfill for the Mbstring extension

作曲家诊断:

代码语言:javascript
复制
C:\Users\wieb>composer diagnose
Checking composer.json: WARNING
No license specified, it is recommended to do so. For closed-source software you may use "proprietary" as license.
Checking platform settings: OK
Checking git settings: OK
Checking http connectivity to packagist: OK
Checking https connectivity to packagist: OK
Checking github.com rate limit: OK
Checking disk free space: OK
Checking pubkeys:
Tags Public Key Fingerprint: 57815BA2 7E54DC31 7ECC7CC5 573090D0  87719BA6 8F3BB723 4E5D42D0 84A14642
Dev Public Key Fingerprint: 4AC45767 E5EC2265 2F0C1167 CBBB8A2B  0C708369 153E328C AD90147D AFE50952
OK
Checking composer version: OK
Composer version: 2.3.4
PHP version: 7.4.19
PHP binary path: C:\laragon\bin\php\php-7.4.19-Win32-vc15-x64\php.exe
OpenSSL version: OpenSSL 1.1.1k  25 Mar 2021
cURL version: 7.70.0 libz 1.2.11 ssl OpenSSL/1.1.1k
zip: extension present, unzip not available, 7-Zip not available

我哪里做错了?

请帮忙,谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-12 03:22:19

正确的代码:

代码语言:javascript
复制
<?php

require __DIR__ .  '/vendor/autoload.php'; /* will vary depending upon your environment */
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load('template.xlsx');

$worksheet = $spreadsheet->getActiveSheet();

$worksheet->getCell('A1')->setValue('John');
$worksheet->getCell('A2')->setValue('Smith');

$writer = \PhpOffice\PhpSpreadsheet\IOFactory::createWriter($spreadsheet, 'Xls');
$writer->save('write.xls');

?>

使用、安装在C上的PHPOffice文件夹和autoload.php文件进行搜索:\user\user\ folder

拉贡Apache htdocs文件夹中的C:\拉里角\www

require __DIR__ . '/vendor/autoload.php';更改require "C:/Users/user/vendor/autoload.php";,它最终会工作

感谢oleibman on PHPOffice/PhpSpreadsheet Github

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71835456

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档