First method:
$filename = ' file name ';
$filetitle = ' your title ';
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 file Handle, Php://output represents direct output to the browser $fp = fopen (' php://output ', ' a ');
Output Excel column header information $head = Array (' ID '); Character substitution $p _new_lines = Array ("\ r \ n", "\ n", "T", "\ 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";
Counter $cnt = 0;
Every $limit line, refresh the output buffer, save resources $limit = 100000;
Fetching data line by row, saving memory while ($res = Mysql_fetch_assoc ($query)) {$cnt + +; if ($limit = = $cnt) {//Refresh output BuffeR to prevent problems caused by excessive data ob_flush ();
Flush ();
$cnt = 0; echo Trim ($res [' ID ']).
"T";
echo "\ n"; }
}
Second method:
$filename = ' file name ';
$filetitle = ' your title ';
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 '
The above PHP native to export Excel file two methods (recommended) is a small series to share all the content, I hope to give you a reference, but also hope that we support the cloud-dwelling community.