thinkphp 后台控制器写Excel导出html形式,html混合php

本人一开始想要做excel导出,用phpexcel,可是在本地环境里可以用,代码放在阿里云服务器上就不行。好像是linux系统和windows的区别。linux读取文件需要权限。

所以只好改用excel导出html形式,在thinkphp框架里面写。

 

//数据
$AjaxController = new AjaxController();
$list = $AjaxController->TeacherInfoData($time);//二维数组的数据
header("Content-type:application/vnd.ms-excel");
header("Pragma:public");
header("Expires:0");
header("Cache-Control:must-revalidate,post-check=0,pre-check=0");
header("Cache-Control:private",false);
header("Content-Type:application/force-download");
header("Content-Type:application/download");
header("Content-Description:File Transfer");
header("Content-type:application/vnd.ms-excel");

 

 

$data ="";
$data .="<html>";
$data .="<body>";
$data .= "<table width='1000' border='1'>";
$data .="<tr>";
$data .="<td colspan='17' style='font-size:20px' align='center'>外教信息总表 筛选日期</td>";
$data .="</tr>";
$data .="<tr>";
$data .="<td align='center'>外教姓名</td>";
$data .="<td align='center'>skype</td>";
$data .="<td align='center'>电话</td>";
$data .="<td align='center'>邮箱</td>";
$data .="<td align='center'>入职日期</td>";
$data .="<td align='center'>国家</td>";
$data .="<td align='center'>证书</td>";
$data .="<td align='center'>学历</td>";
$data .="<td align='center'>教学经验</td>";
$data .="<td align='center'>适合产品名称</td>";
$data .="<td align='center'>任职状态</td>";
$data .="<td align='center'>出席率</td>";
$data .="<td align='center'>报名数</td>";
$data .="<td align='center'>报名金额</td>";
$data .="<td align='center'>正课续费率</td>";
$data .="<td align='center'>续费总人数</td>";
$data .="<td align='center'>续费总金额</td>";

$data .="</tr><tr>";
for($i=0;$i<count($list);$i++){
    $tea=$list[$i]['teacher_name'];
    $skype=$list[$i]['skype'];
    $tel=$list[$i]['phone'];
    $email=$list[$i]['email'];
    $entry_date=$list[$i]['entry_date'];
    $country=$list[$i]['country'];
    $certificate=$list[$i]['certificate'];
    $education=$list[$i]['education'];
    $teach_experience=$list[$i]['teach_experience'];
    $suitable_producte=$list[$i]['suitable_product'];
    $type=$list[$i]['type'];
    $attendance_rate=$list[$i]['attendance_rate'];
    $enter_num=$list[$i]['enter_num'];
    $enter_amount=$list[$i]['enter_amount'];
    $class_renew_rate=$list[$i]['class_renew_rate'];
    $renew_num=$list[$i]['renew_num'];
    $renew_contract_amount=$list[$i]['renew_contract_amount'];
    $data .="<td> $tea</td>";
    $data .="<td> $skype</td>";
    $data .="<td> $tel</td>";
    $data .="<td> $email</td>";
    $data .="<td> $entry_date</td>";
    $data .="<td> $country</td>";
    $data .="<td> $certificate</td>";
    $data .="<td> $education</td>";
    $data .="<td> $teach_experience</td>";
    $data .="<td> $suitable_producte</td>";
    $data .="<td> $type</td>";
    $data .="<td> $attendance_rate</td>";
    $data .="<td> $enter_num</td>";
    $data .="<td> $enter_amount</td>";
    $data .="<td> $class_renew_rate</td>";
    $data .="<td> $renew_num</td>";
    $data .="<td> $renew_contract_amount</td>";
    $data .="</tr>";
}

$data .="</table>";
$data .="</body></html>";
header("Content-type: application/vnd.ms-excel;charset=utf8");
$file="外教表.xls";
header("Content-Disposition: attachment; filename=$file");
echo $data.'<br>';

 

 

 

 

最后导出的样式:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值