php導(dǎo)出中文內(nèi)容excel文件類實(shí)例
本文實(shí)例講述了php導(dǎo)出中文內(nèi)容excel文件類。分享給大家供大家參考。具體如下:
<?php class toExcel{ public $link = null; function __construct(){ } /*************************************************************************** * $mapping:數(shù)組格式頭信息$map=array('No','Name','Email','Age'); * $datalist:數(shù)據(jù)庫(kù)查出來(lái)的結(jié)果集 * $fileName:Excel文件名稱 * return:Excel格式文件 **************************************************************************/ public function toExcel($mapping,$datalist,$fileName) { header("Content-type:application/vnd.ms-excel"); header("Content-Disposition:filename=".iconv('utf-8', 'gb2312', $fileName).".xls"); echo'<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="[url=http://www.w3.org/TR/REC-html40]http://www.w3.org/TR/REC-html40[/url]"> <head> <meta http-equiv="expires" content="Mon, 06 Jan 1999 00:00:01 GMT"> <meta http-equiv=Content-Type content="text/html; charset=UTF-8"> <!--[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> <body link=blue vlink=purple leftmargin=0 topmargin=0>'; echo'<table border="0" cellspacing="0" cellpadding="0">'; echo'<tr>'; if(is_array($mapping)) { foreach($mapping as $key=>$val) echo"<td style='background-color:#09F;font-weight:bold;'>".$val."</td>"; } echo'</tr>'; foreach($datalist as $k=>$v){ echo'<tr>'; foreach($v as $key=>$val){ if(is_numeric($val) && strlen($val)>=14){ echo"<td style='vnd.ms-excel.numberformat:@'>".$val."</td>"; //大于14位的數(shù)字轉(zhuǎn)換成字符串輸出(如身份證) }else{ echo"<td>".$val."</td>"; } } echo'</tr>'; } echo'</table>'; echo'</body>'; echo'</html>'; } } $map=array('No','Name','Email'); $datal=array(array(1, '管理員', 'admin@163.com'), array(2, 'member', 'member@163.com'));; $csv=new toExcel; $csv->toExcel($map,$datal,"dataexport"); ?>
方法二
<?php header("Content-Type: application/vnd.ms-execl"); header("Content-Disposition: attachment; filename=myExcel.xls"); header("Pragma: no-cache"); header("Expires: 0"); /*first line*/ $data1= "中文測(cè)試"; $data1=mb_convert_encoding($data1,"GB2312","UTF-8"); echo $data1."\t"; echo "world"."\t"; echo "\t\n"; /*start of second line*/ echo "this is second line"."\t"; echo "Hi,pretty girl"."\t"; echo "\t\n"; ?>
希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。
- php excel類 phpExcel使用方法介紹
- thinkPHP導(dǎo)出csv文件及用表格輸出excel的方法
- PHP使用PHPexcel導(dǎo)入導(dǎo)出數(shù)據(jù)的方法
- PHP導(dǎo)入導(dǎo)出Excel代碼
- 用PHP生成excel文件到指定目錄
- PHPExcel中的一些常用方法匯總
- php導(dǎo)入excel文件到mysql數(shù)據(jù)庫(kù)的方法
- php生成excel列名超過(guò)26列大于Z時(shí)的解決方法
- Yii中使用PHPExcel導(dǎo)出Excel的方法
- ThinkPHP基于PHPExcel導(dǎo)入Excel文件的方法
- php實(shí)現(xiàn)的操作excel類詳解
相關(guān)文章
利用phpexcel對(duì)數(shù)據(jù)庫(kù)數(shù)據(jù)的導(dǎo)入excel(excel篩選)、導(dǎo)出excel
本篇文章主要介紹了利用phpexcel對(duì)數(shù)據(jù)庫(kù)數(shù)據(jù)的導(dǎo)入excel(excel篩選)、導(dǎo)出excel的相關(guān)知識(shí)。具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧2017-04-04Admin generator, filters and I18n
You need to modify your EntityFormFilter (where Entity is your object class - Article, Book, etc.).2011-10-10echo, print, printf 和 sprintf 區(qū)別
echo, print, printf 和 sprintf 區(qū)別...2006-12-12php Sql Server連接失敗問(wèn)題及解決辦法
本人在鏈接sql2005的時(shí)候遇到的問(wèn)題,經(jīng)過(guò)仔細(xì)排查和搜索找到解決辦法,希望對(duì)大家有用。2009-08-08PHP中實(shí)現(xiàn)Bloom Filter算法
這篇文章主要介紹了PHP中實(shí)現(xiàn)Bloom Filter算法,本文直接給出實(shí)現(xiàn)代碼,代碼中給出詳細(xì)注釋,Bloom Filter算法介紹等內(nèi)容,需要的朋友可以參考下2015-03-03PHP利用func_get_args和func_num_args函數(shù)實(shí)現(xiàn)函數(shù)重載實(shí)例
這篇文章主要介紹了PHP利用func_get_args和func_num_args函數(shù)實(shí)現(xiàn)函數(shù)重載的方法,實(shí)例展示了PHP實(shí)現(xiàn)重載的具體方法,是非常實(shí)用的技巧,需要的朋友可以參考下2014-11-11