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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools