我想实现这样的功能,从数据库查询出的数据展现在一个新的页面上,在页面上显示为一个有若干行的表格,在表格下方设置一个按钮(按钮与查询出的数据在一个页面上),点击按钮,弹出提示下载框,将查询出的数据保存到excel,这个如何实现,望高手不吝赐教,主要是这个按钮和按钮触发的东西怎么做。 

解决方案 »

  1.   

    <?php
    if ($_REQUEST['opt'] == "export")
    {
    //导出的操作
    echo "exporting...";
    }
    ?><script>
    function exportcsv()
    {
        if(confirm('确认导出吗?')){
            f_export.opt.value='export';
        }
        else{
            f_export.opt.value='search';
        }
        f_export.submit();
    }
    </script>
    <form name="f_export" method="post">
    <table border="1">
    <tr>
    <td>id</td>
    <td>name</td>
    <td>date</td>
    </tr>
    <?php
    for ($i=0; $i<10; $i++)
    {
    ?><tr><td><?php echo $i;?></td><td>aa</td><td>2009-09-09</td></tr>
    <?php
    }
    ?><tr><input type="button" onclick="exportcsv();" value="export"></tr>
    </table>
    <input type="hidden" name="opt" value="">
    </form>
      

  2.   

    http://www.rsywx.net/misc/lakers.php先看看是不是你想要的……
      

  3.   

    做过相关开发,并不复杂,你可以直接向浏览器输出header信息:$file_type = "vnd.ms-excel";
    $file_ending = "xls";
    header("Content-Type: application/$file_type;charset=utf-8");
    header("Content-Disposition: attachment; filename=mydowns.$file_ending");
    header("Pragma: no-cache");
    header("Expires: 0");
    echo 'test    test2    test3';//用tab键分开好了
    也可以用一些较成熟的类,下面这个是我用过的,还可以:http://search.cpan.org/dist/Spreadsheet-WriteExcel/