微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

前言

在大家工作中做导出的时候,需要导出自定义的表格或嫌弃导出的Excel格式太难看了。这时候就需要设置颜色、字号大小、加粗、合并单元格等等。这篇文章通过实例告诉大家怎么做,下面来一起看看。

先来看看效果图:

实例代码

PHP代码

  • 导出文件

  • @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();

    }

    HTML代码

    rush:xhtml;"> xmlns:x="urn:schemas-microsoft-com:office:excel"

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

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

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

    <tr>

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

    成绩单

    </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>

    以上就是本文的全部内容,本文通过实例介绍的非常详细,希望对大家的学习和工作能有所帮助,如果有疑问可以留言,谢谢大家对编程之家的支持

    原文地址:https://www.jb51.cc/php/19108.html

    版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

    相关推荐