看到许多类似的问题,但没有任何帮助。我使用PHPExcel。 我试过了
$filename = "report.xls";
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-Disposition: attachment; filename=".$filename);
header("Cache-Control: max-age=0");
header("Content-Type: application/octet-stream");
header("Content-Description: File Transfer");
header("Content-Transfer-Encoding: Binary");
$objWriter = PHPExcel_IOFactory::createWriter($pExcel, 'Excel5');
$objWriter->save("php://output");
和这个
$filename = "report.xlsx";
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header("Content-Disposition: attachment; filename=\"".$filename."\"");
header("Cache-Control: max-age=0");
header("Content-Type: application/octet-stream");
header("Content-Description: File Transfer");
header("Content-Transfer-Encoding: Binary");
$objWriter = PHPExcel_IOFactory::createWriter($pExcel, 'Excel2007');
$objWriter->save("php://output");
但它在浏览器"PKoCjKG�D�X�[Content_Types].xml��MN�0���""像这样,并没有强行下载。
答案 0 :(得分:0)
如果您之前确定,请将文件名更改为$ filename。 例如:
require_once 'Classes/PHPExcel.php';
$objPHPExcel = new PHPExcel();
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename='.$filename);
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
答案 1 :(得分:0)
它为我工作。
header("Content-Type: application/vnd.ms-excel; charset=UTF-8");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=output.xls");
答案 2 :(得分:0)
尝试替换
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
使用
header('Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
我遇到了类似(不完全)的问题,并从上面提到的代码修复了它,我还使用了它Here。