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版本的一些新特性导致失败,可以尝试升级或者回退版本

相关推荐
疯狂打码的少年12 小时前
【计算机网络】子网掩码与子网划分计算(含CIDR表示法)
服务器·笔记·计算机网络·php
cc_yy_zh15 小时前
学习使用kali抓包
服务器·学习·php
ao-weilai16 小时前
Linux网络编程:网络知识基础
linux·网络·php
鲲穹AI种草20 小时前
Excel 表格批量处理与数据整理,多款表格工具能力客观记录
excel·表格处理
clz131452121 小时前
设备反欺诈的四大支柱:从设备指纹到关联图谱
开发语言·php
cspttty1 天前
2026秋招供应链分析师技能栈:SQL、Excel、BI与业务分析
数据库·sql·excel
PHP实战开发录1 天前
PHP脚本手动能跑定时任务却失败
开发语言·php·开发
彧azz1 天前
图的存储结构详解:邻接矩阵的原理、实现与应用
开发语言·数据结构·学习·php
CRMEB系统商城1 天前
CRMEB标准版系统(Java)v3.1正式发布
java·spring·微信小程序·php·教育电商
hui-梦苑2 天前
[PHP]轻量主题函数WordPress 集成 KaTeX 数学公式渲染
开发语言·php·wordpress·katex