此代码创建一个xlsx文件:
$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
我想让访问者在选择“打开或保存”时访问并获取文件
你知道我怎么能得到这个?
提前致谢。
答案 0 :(得分:3)
01simple-download-xlsx.php
文件夹中/Examples
的代码显示了如何执行此操作:
// Redirect output to a client’s web browser (Excel2007)
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="01simple.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
答案 1 :(得分:0)
// Redirect output to a client’s web browser (Excel5)
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('Template.xls');
header('location:Template.xls');