本人一开始想要做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>';
最后导出的样式: