我希望在浏览器上下载生成的Xlsx文件,但当我执行此代码时,请求启动时没有错误,但什么也没有发生
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header('Content-Disposition: attachment; filename='.basename($pathfile).'');
header('Cache-Control: max-age=0');
File::setUseUploadTempDirectory(true);
$objWriter = IOFactory::createWriter($objWorkBookExcel, 'Xlsx');
$objWriter->save("php://output");
当我使用这个的时候:
$objWriter->save($pathfile);
我的文件在我的服务器上生成
发布于 2020-06-09 21:09:00
我推荐使用PHPOffice的进化版PHPspreedsheet!
试一试:
$objWriter = io_factory::createWriter($objPHPExcel, 'Xlsx');
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=nameoffile.xlsx");
header("Content-Transfer-Encoding: binary ");
ob_end_clean();
ob_start();
$objWriter->save('php://output');
exit;
如果您使用PHPExcel:
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="' . $filename . '.xlsx"');
$objWriter->save('php://output');
die();
发布于 2020-06-09 21:35:00
现在我在这里
$objWriter = IOFactory::createWriter($objWorkBookExcel, 'Xlsx');
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename='nameoffile.xlsx'");
header("Content-Transfer-Encoding: binary ");
ob_end_clean();
ob_start();
File::setUseUploadTempDirectory(true);
$objWriter->save('php://output');
exit;
但是没有下载的文件
https://stackoverflow.com/questions/62283244
复制相似问题