我正在使用 PhpSpreadsheet 修改现有文件并将其发送到浏览器,但每次下载文件 excel 时都会出现以下错误:
我们发现 filename.xlsx 中的某些内容存在问题。您希望我们尽可能多地尝试恢复吗?如果您信任此工作簿的来源,请单击是。
我已将所有内容剥离为以下代码。我打开的模板文件是一个全新的 excel 文件,没有对其进行任何编辑(以避免模板中已经存在错误的可能性)。我可以从驱动器打开这个文件,没有任何问题。
$spreadsheet = IOFactory::load(storage_path() ."\Template - English.xlsx");
// Redirect output to a client’s web browser (Xlsx)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="filename.xlsx"');
header('Cache-Control: max-age=0');
// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: ' . gmdate('D, d M Y …Run Code Online (Sandbox Code Playgroud)