$query = mysql_query("SELECT * FROM ".$prefix."product")or die(mysql_error());
$num = @mysql_num_rows($query);
$n = 0;
$proname="AllProduct-List.xls";
// Functions for export to excel.
function xlsBOF() {
echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
return;
}
function xlsEOF() {
echo pack("ss", 0x0A, 0x00);
return;
}
function xlsWriteNumber($Row, $Col, $Value) {
echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
echo pack("d", $Value);
return;
}
function xlsWriteLabel($Row, $Col, $Value ) {
$L = strlen($Value);
echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
echo $Value;
return;
}
header("Content-type: application/vnd.ms-excel; charset=UTF-8");
header("Content-Disposition: attachment; filename=$filename" );
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
header("Pragma: public");
header("Content-Transfer-Encoding: binary ");
xlsBOF();
/*
Make a top line on your excel sheet at line 1 (starting at 0).
The first number is the row number and the second number is the column, both are start at '0'
*/
xlsWriteLabel(0,0,"List of product.");
// Make column labels. (at line 3)
xlsWriteLabel(2,0,"STT");
xlsWriteLabel(2,1,"Product name");
xlsWriteLabel(2,2,"Product count");
$xlsRow = 3;
// Put data records from mysql by while loop.
while($row=mysql_fetch_array($query)){
$n++;
//utf8_encode($str);
xlsWriteNumber($xlsRow,0,$n);
xlsWriteLabel($xlsRow,1,$row['name']);
xlsWriteLabel($xlsRow,2,$row['num']);
$xlsRow++;
}
xlsEOF();
exit();