从PHP页面保存mysql查询到excel文件 [英] Save mysql query to excel file from php webpage
问题描述
我已经看到了很多教程,并尝试过,但是这些教程将网页的内容输出到Excel文件中。我只是想要mysql表的数据和头。
有没有办法这样做?
有一件事是开发非常快,但不像使用LIBRARY那样整洁:
- 执行您的MySQL查询
- 创建一个HTML表格,结果
- 将响应的内容类型设置为:
application / vnd.ms-excel
在大多数浏览器中,使用该页面将在Excel中以HTML表格的形式打开电子表格。您可以使用其他HTTP标头来建议该文件的文件名。
I have a table within a mysql database. What i want to do, is in a php page, run a select statement and output the result into an excel file.
I've seen quite a few tutorials out there and tried them, however these output the contents of the webpage into the excel file. I just want the mysql table data and headers.
Is there a way to do this?
You can use one of the available PHP libraries for that. One, two.
One thing that is pretty fast to develop but not as neat as using a LIBRARY for that is:
- Perform your MySQL query
- Create an HTML table with the results
- Set content type of the response to:
application/vnd.ms-excel
In most browsers, using that page will open the HTML table as a spreadsheet in Excel. You can use other HTTP headers to suggest file name for that file.
这篇关于从PHP页面保存mysql查询到excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!