PHP批量导出数据为excel表格php
//$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();
}
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();
}
上一篇:php无限分类方法类
最新评论
热门推荐
我要评论