SQL查询结果写入Excel [英] SQL queries results write to Excel
本文介绍了SQL查询结果写入Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
OK,所以我没有想法如何做,除了安装PHPexcel
OK so I have no Idea how to do this except install PHPexcel
但说我有一个查询在数组中的结果
But say I have the results of a query in an array
$mysqli = new mysqli('server', 'user1', 'pass', 'users');
if ($mysqli->connect_error)
die(connect error ('.$mysqli->connect_error.') '.$mysqli->connect_error);
$date = date("Y-m-d");
$query = "SELECT * from usr WHERE date = '$date'";
while($row = $query->fetch_array()) {
//EXCEL STUFF???
}
然后我将如何将其写入excel电子表格?
任何帮助赞赏
And then how would I write this to an excel spreadsheet? Any help appreciated
推荐答案
第一:你有一个语法错误:
1st: you have a syntax error:
$mysqli = new mysqli('server', 'user1', 'pass', 'users');
if ($mysqli->connect_error)
die('Connect Error: ' . $mysqli->connect_error);
$date = date("Y-m-d");
$query = "SELECT * from usr WHERE date = '$date'";
while($row = $query->fetch_array()) {
//EXCEL STUFF???
}
第二,您可以将其作为普通表输出,并将其添加到标题中:
2nd, you can output it as a normal table and add this in the header:
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-Disposition: attachment; filename=abc.xls");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
此脚本将自动允许您下载名为 abc.xls
与您的内容。
This script will automatically allow you to download a file named abc.xls
with your content.
这篇关于SQL查询结果写入Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文