国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

php原生導出excel文件的兩種方法(推薦)

2024-05-04 23:52:37
字體:
來源:轉載
供稿:網友

第一種方法:

$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>","</pre>","<br>","</br>","<br/>");    $p_change_line_in_excel_cell = '';    foreach($head as $v){      echo iconv('utf-8','gb2312',$v) . "/t";    }    echo "/n";    // 計數器     $cnt = 0;    // 每隔$limit行,刷新一下輸出buffer,節約資源     $limit = 100000;    // 逐行取出數據,節約內存    while ($res = mysql_fetch_assoc($query)) {      $cnt ++;      if ($limit == $cnt) { //刷新一下輸出buffer,防止由于數據過多造成問題         ob_flush();        flush();        $cnt = 0;      }       echo trim($res['id']). "/t";      echo "/n";    }  }

第二種方法:

$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>","</pre>","<br>","</br>","<br/>");    $p_change_line_in_excel_cell = '';    echo "<table>";    echo "<tr>";    foreach($head as $v){      echo "<td>".iconv('utf-8','gb2312',$v)."</td>";    }    echo "</tr>";    // 逐行取出數據,節約內存    while ($res = mysql_fetch_assoc($query)) {      echo "<tr>";      echo "<td style='vnd.ms-excel.numberformat:@'>".$res['id']."</td>";      echo "<td>".iconv('utf-8', 'gb2312', $res['xxx']."</td>";      echo"</tr>";    }    echo "</table>";  }

以上這篇php原生導出excel文件的兩種方法(推薦)就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持VeVb武林網。


注:相關教程知識閱讀請移步到PHP教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 通化县| 崇义县| 宜春市| 杂多县| 洛隆县| 鹤庆县| 定日县| 甘泉县| 黎平县| 南靖县| 广饶县| 夏邑县| 济阳县| 滨州市| 海盐县| 葫芦岛市| 尼玛县| 正阳县| 周口市| 河津市| 武鸣县| 磐安县| 阳江市| 屏东县| 深州市| 济阳县| 兴化市| 资中县| 赤水市| 隆子县| 乡城县| 自治县| 岱山县| 宁乡县| 大英县| 木里| 文登市| 华蓥市| 大邑县| 大方县| 乐安县|