分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

php 根据html table生成excel文件

发布时间:2023-09-06 01:07责任编辑:董明明关键词:excel
 1 <?php 2 ?3 /* 4 *处理Excel导出 5 *@param $datas array 设置表格数据 6 *@param $titlename string 设置head 7 *@param $title string 设置表头 8 */ 9 function excelData($datas, $titlename, $title, $filename) {10 ????$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>";11 ????$str .= "<table border=1><head>" . $titlename . "</head>";12 ????$str .= $title;13 ????foreach ($datas as $key => $rt) {14 ????????$str .= "<tr>";15 ????????foreach ($rt as $k => $v) {16 ????????????$str .= "<td>{$v}</td>";17 ????????}18 ????????$str .= "</tr>\n";19 ????}20 ????$str .= "</table></body></html>";21 ????echo $str;22 ????header("Content-Type: application/vnd.ms-excel; name=‘excel‘");23 ????header("Content-type: application/octet-stream");24 ????header("Content-Disposition: attachment; filename=" . $filename);25 ????header("Cache-Control: must-revalidate, post-check=0, pre-check=0");26 ????header("Pragma: no-cache");27 ????header("Expires: 0");28 ????exit($str);29 }30 31 32 $dataResult = array(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11));33 $headTitle = "XX保险公司 优惠券赠送记录";34 $title = "优惠券记录";35 $headtitle = "<tr style=‘height:50px;border-style:none;><th border=\"0\" style=‘height:60px;width:270px;font-size:22px;‘ colspan=‘11‘ >{$headTitle}</th></tr>";36 $titlename = "<tr> 37 ???????????????<th style=‘width:70px;‘ >合作商户</th> 38 ???????????????<th style=‘width:70px;‘ >会员卡号</th> 39 ???????????????<th style=‘width:70px;‘>车主姓名</th> 40 ???????????????<th style=‘width:150px;‘>手机号</th> 41 ???????????????<th style=‘width:70px;‘>车牌号</th> 42 ???????????????<th style=‘width:100px;‘>优惠券类型</th> 43 ???????????????<th style=‘width:70px;‘>优惠券名称</th> 44 ???????????????<th style=‘width:70px;‘>优惠券面值</th> 45 ???????????????<th style=‘width:70px;‘>优惠券数量</th> 46 ???????????????<th style=‘width:70px;‘>赠送时间</th> 47 ???????????????<th style=‘width:90px;‘>截至有效期</th> 48 ???????????</tr>";49 $filename = $title . ".xls";50 excelData($dataResult, $titlename, $headtitle, $filename);51 echo ‘success‘;

php 根据html table生成excel文件

原文地址:http://www.cnblogs.com/dannywang/p/7644729.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved