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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

PHP 导出excel

發布時間:2023/12/20 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PHP 导出excel 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原文鏈接

**
? ? ?* 導出
? ? ?*/
? ? function download_exit() {
? ? ? ? $mod=new Mysqli_model();
? ? ? ? $mod->linkmysql(DB_K_WEIXIN_WAP);
? ? ? ? //獲取當前時間的18歲
? ? ? ? $sql='SELECT uid,mreal_idcard,YEAR (NOW()) - substring(idcard, 7, 4) as n,substring(idcard, 11,2) as month FROM ims_mc_members where mreal_mobile != "" and mreal_idcard != ""'
? ? ? ? ? ? ? ? . ' HAVING n < 18';
? ? ? ? $dataResult=$mod->query($sql);
? ? ? ? if (empty($dataResult)) {
? ? ? ? ? ? $this->load->view('page/ok', '沒有數據可導出');
? ? ? ? ? ? die;
? ? ? ? }
? ? ? ? foreach ($dataResult as $key => $val) {
? ? ? ? }?
? ? ? ? $title = '導出頁';
? ? ? ? $headtitle='導出頁';
// ? ? ? ?$headTitle = '導出頁';
// ? ? ? ?$headtitle = "<tr><th ?colspan='7'>{$headTitle}</th></tr>";
? ? ? ? $titlename = "<tr>
? ? ? ? ? ? ? ?<th>UID</th>
? ? ? ? ? ? ? ?<th>身份證號</th>
? ? ? ? ? ? ? ?<th>年齡</th>
? ? ? ? ? ? ? ?<th>月份</th>
? ? ? ? ? ?</tr>";
? ? ? ? $filename = $title . ".xls";
? ? ? ? $this->excelData($dataResult, $titlename, $headtitle, $filename);
? ? }
?
?
?
/*
? ? ?* 處理Excel導出
? ? ?* @param $datas array 設置表格數據
? ? ?* @param $titlename string 設置head
? ? ?* @param $title string 設置表頭
? ? ?*/
?
? ? public function excelData($datas, $titlename, $title, $filename) {
? ? ? ? $str = "<html xmlns:o=\"urn:schemas-microsoft-com:office:office\"\r\nxmlns:x=\"urn:schemas-microsoft-com:office:excel\"\r\nxmlns=\"http://www.w3.org/TR/REC-html40\">\r\n<head>\r\n<meta http-equiv=Content-Type content=\"text/html; charset=utf-8\">\r\n</head>\r\n<body>";
? ? ? ? $str .="<table border=1>" . $titlename . "";
? ? ? ? $str .= $title;
? ? ? ? foreach ($datas as $key => $rt) {
? ? ? ? ? ? $str .= "<tr>";
? ? ? ? ? ? foreach ($rt as $k => $v) {
? ? ? ? ? ? ? ? $str .= "<td>{$v}</td>";
? ? ? ? ? ? }
? ? ? ? ? ? $str .= "</tr>\n";
? ? ? ? }
? ? ? ? $str .= "</table></body></html>

function Uploads() {$data = I();$mod = M("label");$dataResult = array(); //todo:導出數據(自行設置)$res = M($this->mod)->find($data['logid']);if (empty($res)) {$this->error("沒有數據可導出");die;}$dataResult = $mod->where("logid = {$data['logid']}")->field("id,addtime,lname,lcode,money,starttime,endtime,state,employ")->select();foreach ($dataResult as $key => $val) {$dataResult[$key]['addtime']=date("Y-m-d H:i",$val['addtime']);$dataResult[$key]['starttime']=date("Y-m-d H:i",$val['starttime']);$dataResult[$key]['endtime']=date("Y-m-d H:i",$val['endtime']);} $headTitle = $res['lname'];$title = $res['lname'];$headtitle=''; // $headtitle = "<tr><th colspan='7'>{$headTitle}</th></tr>";$titlename = "<tr><th>ID</th><th>添加時間</th><th>標簽名稱</th><th>標簽代碼</th><th>代表金額</th><th>有效期開始時間</th><th>有效期結束時間</th><th>是否啟用</th><th>是否使用</th></tr>";$filename = $title . ".xls";$this->excelData($dataResult, $titlename, $headtitle, $filename);}/** 處理Excel導出* @param $datas array 設置表格數據* @param $titlename string 設置head* @param $title string 設置表頭*/public function excelData($datas, $titlename, $title, $filename) {$str = "<html xmlns:o=\"urn:schemas-microsoft-com:office:office\"\r\nxmlns:x=\"urn:schemas-microsoft-com:office:excel\"\r\nxmlns=\"http://www.w3.org/TR/REC-html40\">\r\n<head>\r\n<meta http-equiv=Content-Type content=\"text/html; charset=utf-8\">\r\n</head>\r\n<body>";$str .="<table border=1>" . $titlename . "";$str .= $title;foreach ($datas as $key => $rt) {$str .= "<tr>";foreach ($rt as $k => $v) {$str .= "<td>{$v}</td>";}$str .= "</tr>\n";}$str .= "</table></body></html>";header("Content-Type: application/vnd.ms-excel; name='excel'");header("Content-type: application/octet-stream");header("Content-Disposition: attachment; filename=" . $filename);header("Cache-Control: must-revalidate, post-check=0, pre-check=0");header("Pragma: no-cache");header("Expires: 0");exit($str);}

總結:

1.查找數據

2.設置表頭列

3.調用方法瀏覽器輸出

測試可用

總結

以上是生活随笔為你收集整理的PHP 导出excel的全部內容,希望文章能夠幫你解決所遇到的問題。

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