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

相关推荐
catchadmin1 天前
Laravel AI SDK 在 Laracon India 2026 首次亮相
人工智能·php·laravel
一晌小贪欢1 天前
Python 操作 Excel 高阶技巧:用 openpyxl 玩转循环与 Decimal 精度控制
开发语言·python·excel·openpyxl·python办公·python读取excel
云游云记1 天前
php 高精度数学扩展 bcmath 知识笔记
笔记·php·bcmath
金书世界1 天前
使用PHP+html+MySQL实现用户的注册和登录(源码)
开发语言·mysql·php
darkb1rd1 天前
三、PHP字符串处理与编码安全
android·安全·php
day day day ...1 天前
easyExcel和poi分别处理不同标准的excel
java·服务器·excel
骆驼爱记录1 天前
Word侧边页码设置全攻略
前端·自动化·word·excel·wps·新人首发
toooooop81 天前
php BC MATH扩展函数巧妙进行财务金额四舍五入
开发语言·php
云游云记2 天前
PHP 汉字转拼音扩展包:overtrue/pinyin 全面指南
php·overtrue/pinyin
有代理ip2 天前
成功请求的密码:HTTP 2 开头响应码深度解析
java·大数据·python·算法·php