PHP批量导出数据为excel表格php

/ / 2019-07-08   阅读:2487
//$teacherList 是从数据库查出来的二维数组  $execlname是要导出的文件名 if(is_array($teacherList)){   foreach($teacherList as $k=>$val){     $strTable .= '<tr style="text-al...
//$teacherList 是从数据库查出来的二维数组  $execlname是要导出的文件名
if(is_array($teacherList)){
  foreach($teacherList as $k=>$val){
    $strTable .= '<tr style="text-align:center;font-size:12px;">';
    $strTable .= '<td >'.$val['username'].'</td>';
    $strTable .= '<td >'.$val['school'].'</td>';
    $strTable .= '<td >'.$val['tel'].'</td>';
    $strTable .= '<td >'.$val['email'].'</td>';
    $strTable .= '<td >'.$val['teacher_name'].'</td>';
    $strTable .= '<td >'.$val['create_time'].'</td>';
    $strTable .= '<td >'.$val['status'].'</td>';
    $strTable .= '</tr>';
  }
  //释放$teacherList
  unset($teacherList);
}
$strTable .='</table>';
//excel表格名  对中文转码
$filename = iconv("utf-8", "GB2312", $excelname);
//导出表格  strTable表格内容   filename表格名
header("Content-type: application/vnd.ms-excel");
header("Content-Type: application/force-download");
header('Content-Disposition: attachment;filename="'.$excelname.'.xlsx"');
header('Expires:0');
header('Pragma:public');
echo '<html><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'.$strTable.'</html>';
exit();
}

我要评论

昵称:
验证码:

最新评论

共0条 共0页 10条/页 首页 上一页 下一页 尾页
意见反馈