如题,小弟新手,想在WEB中实现这个功能,网上搜PHP导出EXCEL的方法不少,下载了PHPEXCEL这个库,但不知道怎么用它从MYSQL里面读取数据来导出,特此求教。
直接上PHP程序就可,当然知道利用上PHPEXCEL更好~THANKS
直接上PHP程序就可,当然知道利用上PHPEXCEL更好~THANKS
解决方案 »
- linux下如何扩展curl?
- php里如何把字符串转换成字节数组
- php投票的问题
- PHPAMIN就是不正常,iis+php+mysql+ZendOptimizer都正常
- session_start(): Failed to initialize storage module.
- 邮件发送失败,那位有成功的DEMO?
- 各位大侠,帮个忙一个很菜的问题!
- 使用 header("Location: $url");无法重定向网页
- 紧急求助,分不够随便加,请各位高手赐教!!!
- 服务器端的PHP代码如何直接操作客户端的文件?有可能吗?
- 怎么让OUTLOOK通过POP3接收OA的内部邮件呢?
- 编辑器提交后取值问题
或者直接生成表头,然后将数据填入表内在导出
把写入的内容那一块换成你从数据库取出的数据即可。
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=example.xls");mysql查询结果到数组
输出数据echo $data1."\t".$data2."\n"; \t 换列,\n换行
<?php
function exportHeader($filename="export.xls") {
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/download");
header("Content-Disposition: attachment;filename=$filename");
header("Content-Transfer-Encoding: binary ");
}exportHeader("test.xls");
?>
<meta content="text/html; charset='utf-8'" http-equiv="content-type">
<table id="mainTable" class="tablesorter">
<thead>
<tr>
<th width="200">Title</th>
<th width="300">Description</th>
<th width="100">Status</th>
</tr>
</thead>
<tbody>
<tr class="selected">
<td>Row 1</td>
<td>Description 1</td>
<td>Status 1</td>
</tr>
<tr>
<td>Row 2</td>
<td>Description 2</td>
<td>Status 2</td>
</tr>
</tbody>
</table>
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/download");
header("Content-Disposition: attachment;filename=$filename");
header("Content-Transfer-Encoding: binary ");
$result=mysql_query("/*执行数据库命令*/");
$row=mysql_fetch_array($result);
/*你的那个把数据库内容转换为XLS的代码*/
echo "输出XLS";
或者输出文件:
header("Pragma: public");
header("Expires: 0");
header("Content-Type: application/force-download");
header("Content-Type: application/download");
header("Content-Disposition: attachment;filename=$fn");
header("Content-Transfer-Encoding: binary ");//二进制
readfile("$fn");//读取文件内容