Ash*_*sha 2 php excel google-sheets google-apps-script
我正在尝试使用 PHP 创建 Excel 工作表。当我从本地主机调用 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.
Run Code Online (Sandbox Code Playgroud)
这是我的文件:
<?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');
?>
Run Code Online (Sandbox Code Playgroud)
更新 :
我创建了另一个名为 Trail 的文件夹并安装了 Composer 并替换了 Trail/vendor/ 中的代码,
<?php
require 'vendor/autoload.php';
?>
Run Code Online (Sandbox Code Playgroud)
我的文件夹结构
当我从本地主机调用该文件时,它给了我
`` 警告:require(vendor/autoload.php):无法打开流:第 3 行 /var/www/html/trail/vendor/sheet.php 中没有此类文件或目录
致命错误:require():无法在第 3 行的 /var/www/html/trail/vendor/sheet.php 中打开所需的 'vendor/autoload.php' (include_path='.:/usr/share/php') ` ` 错误
尝试取消注释您注释的第一行
require_once('vendor/autoload.php');
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$spreadsheet = new \PhpOffice\PhpSpreadsheet\Spreadsheet();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12018 次 |
| 最近记录: |