从PHP页面保存mysql查询到excel文件 [英] Save mysql query to excel file from php webpage

查看:95
本文介绍了从PHP页面保存mysql查询到excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在mysql数据库中有一个表。我想做的是在php页面中运行一个select语句并将结果输出到一个excel文件中。



我已经看到了很多教程,并尝试过,但是这些教程将网页的内容输出到Excel文件中。我只是想要mysql表的数据和头。



有没有办法这样做?

解决方案

你可以使用可用的PHP库之一。 一个 two



有一件事是开发非常快,但不像使用LIBRARY那样整洁:



  1. 执行您的MySQL查询

  2. 创建一个HTML表格,结果

  3. 将响应的内容类型设置为: 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:

  1. Perform your MySQL query
  2. Create an HTML table with the results
  3. 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屋!

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