开发者

html to excel problem!

I am printing excel like this:

header("Content-Type:   application/vnd.ms-excel; charset=utf-8");
header("Content-type:   application/x-msexcel; charset=utf-8");
header("Content-Disposition: attachment; filename=".str_replace(' ', '_', $title).".xls"); 
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); 

The content is plain html. The problem, when I download this, I get an initial confirmation box written

The file you are trying to open 'File_name.xls', is in a different开发者_如何学C format than specified by the file extension. Verified that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?

When I do 'yes', I get this. Bit strange, any input here friends please ?

html to excel problem!


Well, that is pretty strange. I doubt this will help, but try renaming it to .xlsx. It might just be that it's not getting the proper (newer) file extension.


I always use content type = "application/ms-excel"


I have an application that does the same thing; it sets ContentType = "application/vnd.xls" and it works correctly (you still get the warning about that it's in the wrong format, but it opens after that).

I suspect the problem is not the content type, but the actual html content you are sending. Can you post an example of the file you are sending that causes the error?


Well, this one suddenly got solved, I don't know how.

This is what I did. I copied and pasted codes of a different page where the excel thing was working. Then, I changed the variables manually to adapt this with the 2nd page.

After some hit and try, it suddenly worked.

Thanks for all the answers anyway.

PS. By solved, I mean that excel is not crushing anymore, though I am still getting the confirm box about incorrect format.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜