日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

一个简单易用的导出Excel类

發布時間:2023/11/30 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 一个简单易用的导出Excel类 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
轉載自:http://www.umtry.com/201105/%E4%B8%80%E4%B8%AA%E7%AE%80%E5%8D%95%E6%98%93%E7%94%A8%E7%9A%84%E5%AF%BC%E5%87%BAexcel%E7%B1%BB.html5 <?php class toExcel{ public $link = null; function __construct(){ } function conndb($confdb){ $this->link = pg_connect($confdb); return $this->link; } /*************************************************************************** * $table:表名 * $mapping:數組格式頭信息$map=array(‘No’,'Name’,'Email’,'Age’); * $sql:sql語句 * $fileName:Excel文件名稱 * return:Excel格式文件 **************************************************************************/ public function toExcel($mapping,$sql,$fileName) { header(“Content-type:application/vnd.ms-excel”); header(“Content-Disposition:filename=”.$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>’; //數據庫連接 if(!is_resource($this->link)) { $this->conndb(DBCONF); } $query=pg_query($this->link,$sql); while($rows=pg_fetch_assoc($query)){ echo’<tr>’; foreach($rows as $key=>$val){ if(is_numeric($val) && strlen($val)>=14){ echo”<td style=’vnd.ms-excel.numberformat:@’>”.$val.”</td>”; //大于14位的數字轉換成字符串輸出(如身份證) }else{ echo”<td>”.$val.”</td>”; } } echo’</tr>’; }echo’</table>’; echo’</body>’; echo’</html>’; } } ?>
使用
$toexcel = new toExcel();
$toexcel->conndb(“host=localhost port=5432 dbname=super user=super password=super”);
$toexcel->toExcel($lable_arr,$sql,$excel_name);

轉載于:https://www.cnblogs.com/fcode/archive/2011/06/29/execl.html

總結

以上是生活随笔為你收集整理的一个简单易用的导出Excel类的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。