源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

PHP导出带样式的Excel示例代码

  • 时间:2021-08-31 20:32 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:PHP导出带样式的Excel示例代码
[b]前言[/b] 在大家工作中做导出的时候,需要导出自定义的表格或嫌弃导出的Excel格式太难看了。这时候就需要设置颜色、字号大小、加粗、合并单元格等等。这篇文章通过实例告诉大家怎么做,下面来一起看看。 [b]先来看看效果图:[/b] [img]http://files.jb51.net/file_images/article/201608/2016828102814251.png?2016728102824[/img] [b]实例代码[/b] [b]PHP代码:[/b]
/**

* 导出文件

* @return string

*/

public function export()

{

$file_name = "成绩单-".date("Y-m-d H:i:s",time());

$file_suffix = "xls";

header("Content-Type: application/vnd.ms-excel");

header("Content-Disposition: attachment; filename=$file_name.$file_suffix");

//根据业务,自己进行模板赋值。

$this->display();

}
[b]HTML代码:[/b]
<html xmlns:o="urn:schemas-microsoft-com:office:office"

xmlns:x="urn:schemas-microsoft-com:office:excel"

xmlns="http://www.w3.org/TR/REC-html40">

<head>

<meta http-equiv=Content-Type content="text/html; charset=utf-8">

<meta name=ProgId content=Excel.Sheet>

<meta name=Generator content="Microsoft Excel 11">

</head>

<body>

<table border=1 cellpadding=0 cellspacing=0 width="100%" >

<tr>

<td colspan="5" align="center">

<h2>成绩单</h2>

</td>

</tr>

<tr>

<td style='width:54pt' align="center">编号</td>

<td style='width:54pt' align="center">姓名</td>

<td style='width:54pt' align="center">语文</td>

<td style='width:54pt' align="center">数学</td>

<td style='width:54pt' align="center">英语</td>

</tr>

<tr>

<td align="center">1</td>

<td style="background-color: #00CC00;" align="center">Jone</td>

<td style="background-color: #00adee;" align="center">90</td>

<td style="background-color: #00CC00;" align="center">85</td>

<td style="background-color: #00adee;" align="center">100</td>

</tr>

<tr>

<td align="center">2</td>

<td style="background-color: #00CC00;" align="center">Tom</td>

<td style="background-color: #00adee;" align="center">99</td>

<td style="background-color: #00CC00;" align="center">85</td>

<td style="background-color: #00adee;" align="center">80</td>

</tr>

</table>

</body>

</html>
以上就是本文的全部内容,本文通过实例介绍的非常详细,希望对大家的学习和工作能有所帮助,如果有疑问可以留言,谢谢大家对编程素材网的支持。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部