如题,小弟新手,想在WEB中实现这个功能,网上搜PHP导出EXCEL的方法不少,下载了PHPEXCEL这个库,但不知道怎么用它从MYSQL里面读取数据来导出,特此求教。
直接上PHP程序就可,当然知道利用上PHPEXCEL更好~THANKS

解决方案 »

  1.   

    方法很多的,我常用的方法是先把数据库的内容做成html表格,在将html表格导出到excel
    或者直接生成表头,然后将数据填入表内在导出
      

  2.   

    参见:http://topic.csdn.net/u/20081210/13/7736b231-bf17-499c-af88-459bb53f4bc7.html
    把写入的内容那一块换成你从数据库取出的数据即可。
      

  3.   

    头部加这个
    header("Content-type:application/vnd.ms-excel");     
    header("Content-Disposition:filename=example.xls");mysql查询结果到数组
    输出数据echo $data1."\t".$data2."\n";   \t 换列,\n换行
      

  4.   


    <?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>
      

  5.   

    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 ");
    $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");//读取文件内容