這篇文章主要介紹php原生匯出excel檔案的兩種方法,有興趣的朋友參考下,希望對大家有幫助。
第一種方法:
#$filename='文件名称'; $filetitle='你的标题'; if($_POST){ set_time_limit(10000); $title = ''; ini_set('memory_limit','300M'); header('Content-Type: application/vnd.ms-excel;charset=utf-8'); $name = $title.".xls"; header('Content-Disposition: attachment;filename='.$name.''); header('Cache-Control: max-age=0'); $where = "1=1"; $sql = ""; $query = DB::Query($sql); // PHP文件句柄,php://output 表示直接输出到浏览器 $fp = fopen('php://output', 'a'); // 输出Excel列头信息 $head = array('ID'); //字符替换 $p_new_lines = array("\r\n", "\n","\t","\r","\r\n", "<pre class="brush:php;toolbar:false">","","
第二種方法:
$filename='文件名称'; $filetitle='你的标题'; if($_POST){ $title = ''; ini_set('memory_limit','300M'); header('Content-Type: application/vnd.ms-excel;charset=utf-8'); $name = $title.".xls"; header('Content-Disposition: attachment;filename='.$name.''); header('Cache-Control: max-age=0'); echo '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"> <head> <meta http-equiv="expires" content="Mon, 06 Jan 1999 00:00:01 GMT"> <meta http-equiv=Content-Type content="text/html; charset=gb2312"> <!--[if gte mso 9]><xml> <x:ExcelWorkbook> <x:ExcelWorksheets> <x:ExcelWorksheet> <x:Name></x:Name> <x:WorksheetOptions> <x:DisplayGridlines/> </x:WorksheetOptions> </x:ExcelWorksheet> </x:ExcelWorksheets> </x:ExcelWorkbook> </xml><![endif]--> </head>'; $where = "1=1"; $sql = " "; mysql_query('set names "utf8"'); mysql_set_charset('utf8'); $query = DB::Query($sql); // PHP文件句柄,php://output 表示直接输出到浏览器 $fp = fopen('php://output', 'a'); // 输出Excel列头信息 $head = array('ID','xxx'); //字符替换 $p_new_lines = array("\r\n", "\n","\t","\r","\r\n", "<pre class="brush:php;toolbar:false">","","
".iconv('utf-8','gb2312',$v)." | "; } echo "|
".$res['id']." | "; echo "".iconv('utf-8', 'gb2312', $res['xxx']." | "; echo"
以上就是本文的全部內容,希望對大家的學習有幫助。
相關推薦:
#
以上是php原生匯出excel檔案的兩種方法詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章!