【发布时间】:2019-12-20 08:16:34
【问题描述】:
我正在尝试使用 PHP 创建一个 Excel 工作表。当我从 localhost 调用 API 时,它给了我
Fatal error: Uncaught Error: Class 'vendor\PhpOffice\PhpSpreadsheet\Spreadsheet' not found in /var/www/html/sti/svr/excel/sheet.php:8 Stack trace: #0 {main} thrown in /var/www/html/sti/svr/excel/sheet.php on line 8` error.
这是我的文件:
<?php
// require_once('vendor/autoload.php');
use vendor\PhpOffice\PhpSpreadsheet\Spreadsheet;
use vendor\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', 'GeeksForGeeks!');
// Sets the value of cell B1
$sheet->setCellValue('B1', 'A Computer Science Portal For Geeks');
// Write an .xlsx file
$writer = new Xlsx($spreadsheet);
// Save .xlsx file to the current directory
$writer->save('gfg.xlsx');
?>
更新:
我创建了另一个名为 trail 的文件夹并安装了 composer 并在 trail/vendor/ 中替换了这段代码,
<?php
require 'vendor/autoload.php';
?>
我的文件夹结构
当我从本地主机调用文件时,它给了我
``警告:需要(供应商/autoload.php):无法打开流:第3行的/var/www/html/trail/vendor/sheet.php中没有这样的文件或目录
致命错误:require():无法在 /var/www/html/trail/vendor/sheet.php 中打开所需的 'vendor/autoload.php' (include_path='.:/usr/share/php')第 3 行``错误
【问题讨论】:
标签: php excel google-apps-script google-sheets