登录  /  注册

php 通过html-table形式完成excel下载的功能实现

不言
发布: 2023-04-02 15:12:01
原创
1512人浏览过

这篇文章主要介绍了关于php 通过html-table形式完成excel下载的功能实现,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下

/** 
* @param $datas  具体数据 
* @param $titles 列名 
* @param $filename 文件名 
* @param $extraMessage 额外信息 
*/
public static function createExcel($datas, $titles, $filename, $extraMessage = ''){    
$str = "<html xmlns:o=\"urn:schemas-microsoft-com:office:office\"\r\nxmlns:x=\"urn:schemas-microsoft-com:office:excel\"\r\nxmlns=\"http://www.w3.org/TR/REC-html40\">\r\n<head>\r\n<meta http-equiv=Content-Type content=\"text/html; charset=utf-8\">\r\n</head>\r\n<body>";    
$str .= "<table border=1>";    
//表头    
$str .= "<tr>";    foreach ($titles as $title)
 {        
$str .= "<td style='width: 60px;'>{$title}</tdw>";    
}    
$str .= "</tr>\n";    
//具体数据    
foreach ($datas as $key => $rt)
 {        
$str .= "<tr>";        
foreach ($rt as $k => $v)
 {            
$str .= "<td>{$v}</td>";        
}        
$str .= "</tr>\n";    
}    
//额外信息    
if (!empty($extraMessage))
 {        
$str .= "<tr style='height:50px;border-style:none;'><th border=\"0\" style='height:60px;width:270px;font-size:22px;' colspan='19' >{$extraMessage}</th></tr>";    
}    
$str .= "</table></body></html>";    
header("Content-Type: application/vnd.ms-excel; name='excel'");    
header("Content-type: application/octet-stream");    
header("Content-Disposition: attachment; filename=" . $filename);    
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");    
header("Content-Type:application/download");;    
header("Pragma: no-cache");    
header("Expires: 0");    
exit($str);
}
登录后复制

最下方本次导出合计为额外信息

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!

相关推荐:

PHP实现中文圆形印章的特效

PHP导入进度条类

php打包zip图片下载的方法

以上就是php 通过html-table形式完成excel下载的功能实现的详细内容,更多请关注php中文网其它相关文章!

相关标签:
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 技术文章
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2023 //m.sbmmt.com/ All Rights Reserved | 苏州跃动光标网络科技有限公司 | 苏ICP备2020058653号-1

 | 本站CDN由 数掘科技 提供

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