Home > php教程 > php手册 > 实现导出表格为xls的简单方法

实现导出表格为xls的简单方法

WBOY
Release: 2016-06-07 11:44:03
Original
1662 people have browsed it

很多时候,我们需要输出到网页上的表格内容提供导出为excel的功能。这是一个最省事,最简单的方法。重点只需两行代码!
function xls()<br>     {<br>         //$this->getpoview();//此处是数据获得方法<br>         $filename=$_GET['id'];<br>         header('application/vnd.ms-excel');<br>         header('Content-Disposition: attachment; filename="'.$filename.'.xls"');<br>         $this->display();<br>     }模板文件如下:<br> <br> <meta> <br> <style><br /> table{border-collapse:collapse;width:1000px;}<br /> .title th{border:1px solid #ccc;padding:5px;background:#eee;}<br /> tbody td{border:1px solid #ccc;padding:5px;}<br /> </style> <br> <br> <br> <table> <br> <thead> <br> <tr> <br>     <th></th> <br>     <th></th> <br>     <th></th> <br>     <th></th> <br>     <th></th> <br>     <th></th> <br> </tr> <br> <tr> <br>     <th><h1> <eq>{$Think.lang.buypo}</eq><br>     <eq>{$Think.lang.sellpo}</eq> </h1></th> <br> </tr> <br> <tr> <br>     <th>{$Think.lang.no}</th> <br>     <td>{$list.guid}</td> <br>     <th>{$Think.lang.date}</th> <br>     <td>{$list.tdate}</td> <br> </tr> <br> <tr> <br>     <th>{$Think.lang.company}</th> <br>     <td>{$list.company}</td> <br>     <th>{$Think.lang.telphone}</th> <br>     <td>{$list.phone}</td> <br> </tr> <br> <tr> <br>     <th>{$Think.lang.mobi}</th> <br>     <td>{$list.mb}</td> <br>     <th>{$Think.lang.email}</th> <br>     <td>{$list.email}</td> <br> </tr> <br> <tr> <br>     <th>{$Think.lang.qq}</th> <br>     <td>{$list.qq}</td> <br>     <th>{$Think.lang.address}</th> <br>     <td>{$list.address}</td> <br> </tr> <br> <tr> <br>     <th>{$Think.lang.pic}</th> <br>     <th>{$Think.lang.info}</th> <br>     <th>{$Think.lang.desc}</th> <br>     <th>{$Think.lang.usefor}</th> <br>     <th>{$Think.lang.price}</th> <br>     <th>{$Think.lang.num}</th> <br> </tr> </thead> <tbody> <br> <volist><br>     <tr>class="ajax tr" url="__APP__/Ajax/getpd" func="showtd"><br>         <td><a><img alt="实现导出表格为xls的简单方法" ></a></td> <br>         <td> <br>             <b>{$v.name}</b><br><br>             {$v.search_fac}:{$v.search_num}<br><br>             {$Think.lang.numoth}<br><br>             {$v.othernum|excelbr}<br>         </td> <br>         <td>{$v.desc|excelbr}</td> <br>         <td>{$v.userfor|excelbr}</td> <br>         <td>{$v.price}</td> <br>         <td>{$v.num}</td> <br>     </tr> <br> </volist><br> </tbody> <br> <tfoot> <br> <tr> <br>     <br>     <td></td> <br>     <td>{$list.totalprice}</td> <br>     <td>{$list.totalnum}</td> <br> </tr> <br> <tr> <br>     <td></td> <br>     <td>{$Think.lang.total}{$list.total} </td> <br> </tr> <br> </tfoot> <br> </table> <br> <br> <br>  具体示例,请参看以下网址:http://tou.mobi/v/21cd67390173f6a5

实现导出表格为xls的简单方法

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template