可以使用"/>
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> </td>
<td> </td>
<td> </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> </td>
<td> </td>
<td> </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"> </td>
</tr>
</table>
<!---------------------------------------------------------------------------------------->
<div style="clear:both"></div>
之后直接导出即可,挺好用。
更多推荐
thinkphp导出Excel方法,可以使用
发布评论