博主信息
博文 33
粉丝 0
评论 1
访问量 50379
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
PHP将HTML表格导出为Excel文件
萝卜温的博客
原创
3977人浏览过
/**
 * 把html table内容导出到xls文件
 * @param  [type] $filename 文件名
 * @param  [type] $table    html table代码
 * @return [type]           file
 */
function export_xls($filename,$table){
    //可以修改样式,控制字号、字体、表格线、对齐方式、表格宽度、单元格padding等,在下边的<style></style>
    $header="<html xmlns:o=\"urn:schemas-microsoft-com:office:office\"\nxmlns:x=\"urn:schemas-microsoft-com:office:excel\"\nxmlns=\"http://www.w3.org/TR/REC-html40\">\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html>\n<head>\n<meta http-equiv=\"Content-type\" content=\"text/html;charset=utf-8\" />\n<style>\ntd{padding:4px;mso-ignore:padding;color:windowtext;font-size:10.0pt;font-weight:400;font-style:normal;text-decoration:none;font-family:Arial;mso-generic-font-family:auto;mso-font-charset:134;mso-number-format:General;text-align:general;vertical-align:middle;border:.5pt solid windowtext;mso-background-source:auto;mso-pattern:auto;mso-protection:locked visible;white-space:nowrap;mso-rotate:0;}\n</style>\n</head><body>\n";
    $footer="\n</body></html>";
    $exportString=$header.$table.$footer;
 
    header("Cache-Control:public");
    header("Pragma:public");
    header("Content-type: Content-type:application/vnd.ms-excel");
    header("Accept-Ranges: bytes");
    header("Content-Disposition:attachment; filename=".$filename);
    header("Content-length:".strlen($exportString));
    echo $exportString;
    exit;
}


本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学