PHP8.0版本导出excel失败

环境:fastadmin框架,不是原版接手的项目。PHP8.0,mysql5.7.

code

php 复制代码
// 创建一个新的 Spreadsheet 对象
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();

// 设置表头
$worksheet->setCellValue('A1', 'ID');
$worksheet->setCellValue('B1', 'Name');
$worksheet->setCellValue('C1', 'Email');
$worksheet->setCellValue('D1', 'Created At');

$rowIndex=2;

$worksheet->setCellValue('A' . $rowIndex, 'id');
$worksheet->setCellValue('B' . $rowIndex, 'name');
$worksheet->setCellValue('C' . $rowIndex, 'email');
$worksheet->setCellValue('D' . $rowIndex, 'created_at');

// 设置 HTTP 头信息
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="exported_data.xlsx"');
header('Cache-Control: max-age=0');

// 保存到输出流
$writer = new Xlsx($spreadsheet);
$writer->save('php://output');

失败原因分析:只有最后一步$writer->save 失败,由于php8.0版本缺少8.2版本的一些新特性导致失败,可以尝试升级或者回退版本

相关推荐
jwn9995 分钟前
Laravel6.x核心特性全解析
开发语言·php·laravel
星辰徐哥1 小时前
5G的行业应用:工业互联网、车联网、智慧医疗中的网络支撑
网络·5g·php
三道渊2 小时前
进程通信与网络协议
开发语言·数据库·php
流觞 无依2 小时前
DedeCMS plus/download.php SQL注入漏洞修复教程
sql·php
Freak嵌入式3 小时前
MicroPython LVGL基础知识和概念:显示与多屏管理
开发语言·python·github·php·gui·lvgl·micropython
Freak嵌入式4 小时前
MicroPython LVGL基础知识和概念:时序与动态效果
开发语言·python·github·php·gui·lvgl·micropython
2501_930707784 小时前
使用C#代码在 Excel 中添加或设置批注格式
excel
fengci.6 小时前
php反序列化(复习)(第三章)
android·开发语言·学习·php
说实话起个名字真难啊6 小时前
Docker 入门之网络基础
网络·docker·php
竹之却6 小时前
【Agent-阿程】openclaw v2026.4.9更新内容介绍
开发语言·php·openclaw·openclaw 更新