PHP導出Excel案列
$data = array();
$data = $app->getStatisApp(2,$username,$whereDepartment,$status,$level,$time);
$str = mb_convert_encoding ("姓名,一級部門,所在部門,直屬上級,入職時間\n", 'GBK', 'UTF8' );
$filename = "轉正申請表審核進度統計";
$filename = mb_convert_encoding ( $filename, 'GBK', 'UTF8' );
ob_end_clean ();
header ( "HTTP/1.1 200 OK" );
header ( 'Content-Encoding: none' );
header ( 'Content-type:text/csv' );
header ( "Content-Disposition:attachment;filename={$filename}.csv" );
header ( 'Cache-Control:must-revalidate,post-check=0,pre-check=0,max-age=31536000' );
header ( 'Expires:0' );
header ( 'Pragma:public' );
foreach ( $data as $value ) {
$str .= mb_convert_encoding ( "{$value['truename']},{$value['oneDepartment']},{$value['twoDepartment']},{$value['leaderTruename']},{$value['entry_time']},{$value['formal_time']}\n", 'GBK', 'UTF8');
}
echo $str;