最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2016年11月19日 08:49:11   投稿:jingxian  
下面小編就為大家?guī)硪黄猵hp原生導出excel文件的兩種方法(推薦)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

第一種方法:

$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";
    // 計數(shù)器 
    $cnt = 0;
    // 每隔$limit行,刷新一下輸出buffer,節(jié)約資源 
    $limit = 100000;
    // 逐行取出數(shù)據(jù),節(jié)約內(nèi)存
    while ($res = mysql_fetch_assoc($query)) {
      $cnt ++;
      if ($limit == $cnt) { //刷新一下輸出buffer,防止由于數(shù)據(jù)過多造成問題 
        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>";
    // 逐行取出數(shù)據(jù),節(jié)約內(nèi)存
    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文件的兩種方法(推薦)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

最新評論

贡嘎县| 闽侯县| 乐陵市| 莱州市| 嘉义县| 嘉善县| 东安县| 遂宁市| 荔波县| 平乡县| 华安县| 蓬莱市| 内乡县| 竹溪县| 乡城县| 米脂县| 兰州市| 卢龙县| 绥棱县| 镶黄旗| 壶关县| 平安县| 巴南区| 六枝特区| 泽库县| 石屏县| 平武县| 宜昌市| 祁门县| 葵青区| 德江县| 长兴县| 镇安县| 望江县| 赤峰市| 察雅县| 金寨县| 陵川县| 宜城市| 苗栗县| 仙居县|