PHP Microsoft Excel文件生成/导出类 [英] PHP Microsoft Excel file generation / export class

查看:177
本文介绍了PHP Microsoft Excel文件生成/导出类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一个很好的Excel文件生成类,还没有找到一个 - 我的第一个问题是,虽然我可以得到导出的文件在Excel中运行(运行2007),我总是得到一个警告

I've been looking for a good Excel file generation class and have yet to find one - my number one issue is that I although I can get the exported file to open in Excel (running 2007), I always get a warning saying "the file is in a different format to the file extension".

我注意到phpMyAdmin中的Excel导出甚至会生成上述警告消息。

I noticed that the Excel export in phpMyAdmin even generates the aforementioned warning message.

其他用户在此常见要求中使用了哪些代码?

What code do other users use for this common requirement?

快速更新扩展我生成的Excel文件作为xml它在浏览器中打开(即使我发送正确的标题),但如果我选择保存xml文件,然后从Excel打开它,它的工作没有任何警告!不幸的是,这比用户点击仍然继续和我收到的警告更麻烦。更多想法?

Quick update If I set the file extension of my generated Excel file as xml it opens in the browser (even though I'm sending the correct headers), but if I choose to save the xml file and then open it from Excel, it works without any warnings! Unfortunately, that's more hassle for the users than simply clicking 'Proceed anyway' with the warning I'm getting. Any more ideas?

推荐答案

我发现在我生成的Excel文件的xml声明下添加以下内容,使用xml文件扩展名(而不是网络浏览器)打开文件:

I've discovered that adding the following, under the xml declaration in my generated Excel file, ensures Excel opens the file with an xml file extension (rather than the web browser):

 <?mso-application progid=\"Excel.Sheet\"?>

我还在php中设置以下标题:

I'm also setting the following headers in php:

// deliver header (as recommended in php manual)
header('Content-Type: application/vnd.ms-excel; charset=UTF-8');
header('Content-Disposition: attachment; filename="' . $filename . '.xml"');

这篇关于PHP Microsoft Excel文件生成/导出类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆