thinkphp导出Excel方法,可以使用

编程入门 行业动态 更新时间:2024-10-25 10:28:01

thinkphp导出Excel方法,<a href=https://www.elefans.com/category/jswz/34/1771306.html style=可以使用"/>

thinkphp导出Excel方法,可以使用

先在程序里把要导出的数据读出到前台,之后做成模板,再导出,

程序:

function exportexcel(){           
         //查询的一张表
$db=M('Existingcompanies','cn_');
$channelid['channelid'] = array('not in','86');
$where=$channelid;
$data = $db->where($where)->order('id desc')->select();

import("@.ORG.Page_cn"); //导入分页类
$count = $db->field('id')->where($where)->count();// 查询满足要求的总记录数
$Page = new Page($count,16);// 实例化分页类 传入总记录数和每页显示的记录数
$Page->setConfig('theme', '%nextPage% %upPage% %downPage% %prePage%');
$show = $Page->show();// 分页显示输出
$data = $db->where($where)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
$this->data=$data;
$this->artlist=$data;
$this->show=$show;
 header("Content-type:application/octet-stream");
              header("Accept-Ranges:bytes");
              header("Content-type:application/vnd.ms-excel"); 
              header("Content-Disposition:attachment;filename=现成公司信息表".date("Y-m-d").".xls");
              header("Pragma: no-cache");
              header("Expires: 0");    
 $this->display();          
        }


前台模板:

<script>
$(document).ready(function(){
  //行效果
  $(".trhover").mouseover(function(){
  $(this).css({ "background-color": "#FFFFCC"});
  });
  $(".trhover").mouseout(function(){
  $(this).css({ "background-color": "#FFF"});
  });
});
</script>
<!---------------------------------------------------------------------------------------->
<!---头部AD----->
<!---头部AD----->
<div id="PagesMain">
<div class="Pagesmain">
  <div style="clear:both"></div>
  <!----------左边内容--------------------><!----------左边内容--------------------> 
  <!----------右边内容-------------------->
  <div class="Pagesmainright">
    <div class="Pagesmainright_Middle_content">
    <div style="font-size:18px; font-weight:bold; text-align:center; width:100%">香港环宇-现成公司列表</div>
      <!-----------------------------提示START-------------------------->
      <div class="alert alert-warning alert-dismissible" role="alert" style="margin-top:8px;">
          "现成公司"也叫空壳公司(readymade company)。最早是根据英国公司法确立的一种公司法律形式。是发起人根据香港或英国的法律成立的有限公司,但是没有任命第一任董事,也没有投资者认购股份,不会发生经营及债权债务。需要公司时,投资者只需要将董事和股东交给公司秘书,由他制作相关文件。一般在数小时便可完成。<br />
   因为公司注册成立需时,但部分人士可能急需注册成立公司,然后以公司名义签订合同或办理其它业务。因此,专业的咨询服务机构,预先注册成立大量公司,以供购买。此类公司既属现成公司(shelf company),也叫做空壳公司(readymade company)。 </div>
      <!-----------------------------提示END--------------------------> 
    </div>
<empty name="data">
        <div class="nodata">暂时还没有相关文章!</div>
        <else/>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>


    <table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#DDD" style="background:#DDD">
  <tr style="font-weight:bold; background-color:#EBEBEB">
    <td width="10%" height="25" align="center">注册编号</td>
    <td width="34%" align="left">公司中文名称</td>
    <td width="43%" align="left">公司英文名称</td>
    <td width="13%" align="center">注册日期</td>
    </tr>
 <volist  name="data" id="vo">  
  <tr bgcolor="#FFFFFF"  class="trhover">
    <td  align="center" style="border-bottom:1px #eee solid">{$vo['registrationnumber']}</td>
    <td style="border-bottom:1px #eee solid">{$vo['title']}</td>
    <td style="border-bottom:1px #eee solid">{$vo['entitle']}</td>
    <td align="left" style="border-bottom:1px #eee solid">{$vo['registrationdate']|date='Y-m-d',###}</td>
    </tr>
  </volist> 
</table>
</empty>


    <!----------右边内容--------------------> 
  </div>
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td valign="top" bgcolor="#F2DEDE">首先您要为你将来的公司起名,我们免费查册,您可以把公司名称传真到指定的办事处
24小时:</span><span style="padding-top:12px; background-color:#F2DEDE"><br />
Mobile:13802215157      E-mail:icr@icr.hk      QQ:178816877 网址:;/span></td>
    <td valign="top" bgcolor="#F2DEDE"><span style="padding-top:12px; background-color:#F2DEDE">香港总部:Tel:(852) 2575 5755      Fax: (852) 3576 3539 <br />
深圳福田:Tel:86-755-3322 2298     Fax:86-755-3322 2297 <br />
深圳福田:Tel:86-755-6128 6655     Fax:86-755-6128 6565 <br /></td>
    <td valign="top" bgcolor="#F2DEDE">北京朝阳:Tel:86-10-6591 8829      Fax:86-10-6591 9929 <br />
北京海淀:Tel:86-10-5166 9188       Fax:86-10-5162 6939</td>
    <td valign="top" bgcolor="#F2DEDE">&nbsp;</td>
  </tr>
</table>
<!---------------------------------------------------------------------------------------->
<div style="clear:both"></div>

之后直接导出即可,挺好用。

更多推荐

thinkphp导出Excel方法,可以使用

本文发布于:2024-03-09 14:56:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1725298.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以使用   方法   thinkphp   Excel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!