html转excel问题!

发布于 2024-11-03 09:33:34 字数 655 浏览 5 评论 0原文

我像这样打印Excel:

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); 

内容是纯html。问题是,当我下载此文件时,我收到一个初始确认框,上面写着

您尝试打开“File_name.xls”的文件的格式与文件扩展名指定的格式不同。打开文件之前已验证该文件未损坏且来自受信任的来源。您想现在打开该文件吗?

当我选择“是”时,我得到了这个。有点奇怪,请问朋友们有什么意见吗?

在此处输入图像描述

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 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 ?

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

半边脸i 2024-11-10 09:33:34

嗯,这很奇怪。我怀疑这会有帮助,但尝试将其重命名为 .xlsx。可能只是因为它没有获得正确的(较新的)文件扩展名。

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.

转身以后 2024-11-10 09:33:34

我总是使用内容类型 =“application/ms-excel”

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

凡尘雨 2024-11-10 09:33:34

我有一个应用程序可以做同样的事情;它设置了 ContentType = "application/vnd.xls" 并且它可以正常工作(您仍然会收到有关其格式错误的警告,但之后会打开)。

我怀疑问题不在于内容类型,而在于您发送的实际 html 内容。您可以发布导致错误的发送文件的示例吗?

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?

·深蓝 2024-11-10 09:33:34

嗯,这个问题突然就解决了,不知道怎么解决的。

这就是我所做的。我复制并粘贴了 Excel 正在运行的不同页面的代码。然后,我手动更改了变量以适应第二页。

经过一番尝试后,它突然奏效了。

无论如何,感谢所有的答案。

附言。通过解决,我的意思是 Excel 不再令人沮丧,尽管我仍然收到有关格式不正确的确认框。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文