最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

php table如何转excel

来源:动视网 责编:小采 时间:2020-11-02 18:23:37
文档

php table如何转excel

php table如何转excel:php table转excel的实现方法:首先定义一个excelData方法;然后设置表格数据、head以及表头;最后通过excelData($dataResult, $titlename, $headtitle...;方式生成excel文件即可。推荐:《PHP视频教程》php 根据html table生成e
推荐度:
导读php table如何转excel:php table转excel的实现方法:首先定义一个excelData方法;然后设置表格数据、head以及表头;最后通过excelData($dataResult, $titlename, $headtitle...;方式生成excel文件即可。推荐:《PHP视频教程》php 根据html table生成e


php table转excel的实现方法:首先定义一个“excelData”方法;然后设置表格数据、head以及表头;最后通过“excelData($dataResult, $titlename, $headtitle...;”方式生成excel文件即可。

推荐:《PHP视频教程》

php 根据html table生成excel文件

<?php

/*
*处理Excel导出
*@param $datas array 设置表格数据
*@param $titlename string 设置head
*@param $title string 设置表头
*/
function excelData($datas, $titlename, $title, $filename) {
 $str = "<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">
</head>
<body>";
 $str .= "<table border=1><head>" . $titlename . "</head>";
 $str .= $title;
 foreach ($datas as $key => $rt) {
 $str .= "<tr>";
 foreach ($rt as $k => $v) {
 $str .= "<td>{$v}</td>";
 }
 $str .= "</tr>
";
 }
 $str .= "</table></body></html>";
 echo $str;
 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("Pragma: no-cache");
 header("Expires: 0");
 exit($str);
}


$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));
$headTitle = "XX保险公司 优惠券赠送记录";
$title = "优惠券记录";
$headtitle = "<tr style='height:50px;border-style:none;><th border="0" style='height:60px;width:270px;font-size:22px;' colspan='11' >{$headTitle}</th></tr>";
$titlename = "<tr>
 <th style='width:70px;' >合作商户</th>
 <th style='width:70px;' >会员卡号</th>
 <th style='width:70px;'>车主姓名</th>
 <th style='width:150px;'>手机号</th>
 <th style='width:70px;'>车牌号</th>
 <th style='width:100px;'>优惠券类型</th>
 <th style='width:70px;'>优惠券名称</th>
 <th style='width:70px;'>优惠券面值</th>
 <th style='width:70px;'>优惠券数量</th>
 <th style='width:70px;'>赠送时间</th>
 <th style='width:90px;'>截至有效期</th>
 </tr>";
$filename = $title . ".xls";
excelData($dataResult, $titlename, $headtitle, $filename);
echo 'success';

文档

php table如何转excel

php table如何转excel:php table转excel的实现方法:首先定义一个excelData方法;然后设置表格数据、head以及表头;最后通过excelData($dataResult, $titlename, $headtitle...;方式生成excel文件即可。推荐:《PHP视频教程》php 根据html table生成e
推荐度:
标签: excel php 转换excel
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top