1. 程式人生 > >PHP批量導出數據為excel表格

PHP批量導出數據為excel表格

pub .cn force center 導出表 echo xlsx nload exec

之前用插件phoexcel寫過批量導入數據,現在用到了批量導出,就記錄一下,這次批量導出沒用插件,是寫出一個表格,直接輸出

//$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();
}

這個是之前寫的批量導入表格數據到數據庫 使用PHPExcel實現數據批量導入到數據庫

PHP批量導出數據為excel表格