微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PHP批量导出数据为excel表格

//$teacherList 是从数据库查出来的二维数组  $execlname是要导出的文件

if(is_array($teacherList)){

  foreach($teacherList as $k=>$val){

    $strTable .= '<tr 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();

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐