search
Homephp教程php手册三行代码实现ThinkPHP导出Excle方法,不依赖第三方库

Excle导出方法
ThinkPHP最简单的Excle导出方法,不依赖第三方库,三行代码就能实现。虽然ThinkPHP用过很多年、但是在导出Excle方式还是新手,下面的代码仅供参考。如果大神们发现本方法有什么不妥之处,请多多指教,大家一起探讨,一起进步,谢谢各位啦。
此方法比较简单就直接上代码了。
首先是Action里的代码    /**<br>      *<br>      * 导出Excel<br>      */<br>     public function expExcel(){//导出Excel<br>         $fileName = $_SESSION['loginUserName'].date('_YmdHis');<br>         $xlsModel = D('Gyjyl');<br>         $xlsData  = $xlsModel->where($map)->select();<br>         $this->assign('list',$xlsData);<br>         header('pragma:public');<br>         header('Content-type:application/vnd.ms-excel;charset=utf-8;name="'.$fileName.'.xls"');<br>         header("Content-Disposition:attachment;filename=$fileName.xls");//attachment新窗口打印inline本窗口打印<br>         $this->display();<br>          <br>     }把上面控制器的数据输出到expExcel.html 模板里
expExcel.html:    <table> <br>         <tbody> <br>             <th>{$Think.session.loginUserName}-{$vo['jyrq']|date="Y-m-d",###}-柜员交易量</th> <br>         </tbody> <br>         <thead> <br>         <tr> <br>             <th>class="{$_REQUEST._sort}">网点名称</th> <br>             <th>柜员号</th> <br>             <th>柜员名</th> <br>             <th>网银笔数</th> <br>             <th>短信笔数</th> <br>             <th>活期笔数/金额</th> <br>             <th>定期笔数/金额</th> <br>             <th>交易日期</th> <br>         </tr> <br>         </thead> <br>         <tbody> <br>         <volist><br>             <tr> <br>                 <td>{$vo['gyjg']|getDepartmentNameToJgh}</td> <br>                 <td>{$vo['gybh']}</td> <br>                 <td>{$vo['gybh']}</td> <br>                 <td>{$vo['wybs']}</td> <br>                 <td>{$vo['dxbs']}</td> <br>                 <td>{$vo['hqbs']}/{$vo['hqje']}</td> <br>                 <td>{$vo['dqbs']}/{$vo['dqje']}</td> <br>                 <td>{$vo['jyrq']|date="Y-m-d",###}</td> <br>             </tr> <br>         </volist><br>         </tbody> <br>     </table>最后就是前台调用的代码了<a><span>导出EXCEL</span></a>最后说几句:本方法的重点是 用Html的header属性 把Html格式重置为Excle文件。

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

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor