搜索
系统检测到您的用户名不符合规范:

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

浏览:2524 发布日期:2013年08月23日 分类:功能实现 关键字: xls 导入excel
很多时候,我们需要输出到网页上的表格内容提供导出为excel的功能。这是一个最省事,最简单的方法。重点只需两行代码!
function xls()
{
//$this->getpoview();//此处是数据获得方法
$filename=$_GET['id'];
header('application/vnd.ms-excel');
header('Content-Disposition: attachment; filename="'.$filename.'.xls"');
$this->display();
}
模板文件如下:<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
table{border-collapse:collapse;width:1000px;}
.title th{border:1px solid #ccc;padding:5px;background:#eee;}
tbody td{border:1px solid #ccc;padding:5px;}
</style>
</head>
<body>
<TABLE cellpadding="2" cellspacing="0">
<thead>
<TR>
<th width="200px"></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</TR>
<TR>
<th colspan="6"><h1 class="text-center"><eq name="list.style" value="0">{$Think.lang.buypo}</eq>
<eq name="list.style" value="1">{$Think.lang.sellpo}</eq></h1></th>
</TR>
<TR>
<th align="right" width="120px">{$Think.lang.no}</th>
<td colspan="2">{$list.guid}</td>
<th align="right">{$Think.lang.date}</th>
<td colspan="2">{$list.tdate}</td>
</TR>
<TR>
<th align="right">{$Think.lang.company}</th>
<td colspan="2">{$list.company}</td>
<th align="right">{$Think.lang.telphone}</th>
<td colspan="2">{$list.phone}</td>
</TR>
<TR>
<th align="right">{$Think.lang.mobi}</th>
<td colspan="2">{$list.mb}</td>
<th align="right">{$Think.lang.email}</th>
<td colspan="2">{$list.email}</td>
</TR>
<TR>
<th align="right">{$Think.lang.qq}</th>
<td colspan="2">{$list.qq}</td>
<th align="right">{$Think.lang.address}</th>
<td colspan="2">{$list.address}</td>
</TR>
<TR class="title">
<th width="120px" bgcolor="#CCCCCC">{$Think.lang.pic}</th>
<th bgcolor="#CCCCCC">{$Think.lang.info}</th>
<th bgcolor="#CCCCCC">{$Think.lang.desc}</th>
<th bgcolor="#CCCCCC">{$Think.lang.usefor}</th>
<th bgcolor="#CCCCCC">{$Think.lang.price}</th>
<th bgcolor="#CCCCCC">{$Think.lang.num}</th>
</TR></thead><tbody>
<volist name="row" id="v">
<TR val="{$v.id}" <eq name='v["status"]' value='0'>class="ajax tr" url="__APP__/Ajax/getpd" func="showtd"</eq>>
<TD class="pic"><a href="{$v.href}" target="_blank"><img src="{$v.pic|picpath}"></a></TD>
<TD class="info">
<b>{$v.name}</b><br style="mso-data-placement:same-cell;"/>
{$v.search_fac}:{$v.search_num}<br style="mso-data-placement:same-cell;"/>
{$Think.lang.numoth}<br style="mso-data-placement:same-cell;"/>
{$v.othernum|excelbr}
</TD>
<TD class="desc pre">{$v.desc|excelbr}</TD>
<TD class="usefor pre">{$v.userfor|excelbr}</TD>
<TD class="price">{$v.price}</TD>
<TD class="num">{$v.num}</TD>
</TR>
</volist>
</tbody>
<tfoot>
<TR>

<td colspan="4"></td>
<td>{$list.totalprice}</td>
<td>{$list.totalnum}</td>
</TR>
<TR>
<td colspan="4"></td>
<td colspan="2">{$Think.lang.total}{$list.total} </td>
</TR>
</tfoot>
</TABLE>
</body>
</html>
具体示例,请参看以下网址:http://tou.mobi/v/21cd67390173f6a5

评论() 相关
收藏
ufomail
积分:499 等级:LV2
热点推荐
(追記) (追記ここまで)
最新更新

我们

合作

网站

信息

ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。

AltStyle によって変換されたページ (->オリジナル) /