在iPad上将PHP导出为Excel [英] PHP Exporting to Excel, on iPad
问题描述
我有一个脚本将mysql结果输出到excel,在所有浏览器中都可以正常工作. 但是,我需要该脚本也可以在iPad上运行,以在Safari中打开excel.这时,脚本只是在iPad上挂起",并且一直在加载.这是标题问题吗? 此时的代码头:
I have a script to output a mysql result to excel, which is working just fine in all browsers. However, I need the script to also work on iPad, opening the excel in Safari. At this moment, the script just "hangs" on the iPad, it keeps loading. Is this a headers problem? The code headers at this moment:
header( 'Content-Transfer-Encoding: binary' );
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Content-Type: application/vnd.ms-excel');
//header("Content-Type: application/octet-stream");
header('Content-Disposition: attachment;filename="' . $_POST['Client_FirstName'] . ' ' . $_POST['Client_LastName'] . ' ' . $_POST['month'] . '-' . $_POST['year'] . '.xlsx"');
header('Cache-Control: max-age=0');
header("Pragma: public");
header("Expires: 0");
推荐答案
显然是导致问题的原因是application/vnd.ms-excel标头. 将其设置为八位字节流可解决此问题,但随后在IE8中引起了问题. 所以我用下面的代码完全解决了这个问题:
Apparently it was the application/vnd.ms-excel header that caused the problem. Setting it to octet-stream solved the issue, but then caused problems in IE8. So I used this code to totally solve the problem:
if(stristr($_SERVER['HTTP_USER_AGENT'], 'ipad') OR stristr($_SERVER['HTTP_USER_AGENT'], 'iphone') OR stristr($_SERVER['HTTP_USER_AGENT'], 'ipod'))
{
header("Content-Type: application/octet-stream");
}else{
header('Content-Type: application/vnd.ms-excel');
}
这篇关于在iPad上将PHP导出为Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!