Mã: [COLOR=#000000][FONT=monospace]<?php function xlsBOF() { [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]return; [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]} [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]function xlsEOF() { [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]echo pack("ss", 0x0A, 0x00); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]return; [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]} [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]function xlsWriteNumber($Row, $Col, $Value) { [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]echo pack("sssss", 0x203, 14, $Row, $Col, 0x0); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]echo pack("d", $Value); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]return; [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]} [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]function xlsWriteLabel($Row, $Col, $Value ) { [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]$L = strlen($Value); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]echo $Value; [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]return; [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]} [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]header("Pragma: public"); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]header("Expires: 0"); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]header("Content-Type: application/force-download"); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]header("Content-Type: application/octet-stream"); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]header("Content-Type: application/download");; [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]header("Content-Disposition: attachment;filename=php2xls.xls "); // à¹à¸¥à¹‰à¸§à¸™à¸µà¹ˆà¸à¹‡à¸Šà¸·à¹ˆà¸ ไฟล์ [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]header("Content-Transfer-Encoding: binary "); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]// XLS Data Cell [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]xlsBOF(); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]xlsWriteLabel(1,0,"PHP Group VN"); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]xlsWriteLabel(2,0,"Website : "); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]xlsWriteLabel(2,1,"http://phpbasic.com"); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]xlsWriteLabel(3,0,"TITLE : "); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]xlsWriteLabel(3,1,"Dien dan thao luan PHP"); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]xlsWriteLabel(4,0,"Copyright @ "); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]xlsWriteLabel(4,1,"PHP Group VN"); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]xlsWriteLabel(6,0,"NO"); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]xlsWriteLabel(7,0,"1"); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]xlsWriteLabel(6,1,"ID"); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]xlsWriteLabel(7,1,"2104"); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]xlsWriteLabel(6,2,"Gender"); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]xlsWriteLabel(7,2,"Male"); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]xlsWriteLabel(6,3,"Name"); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]xlsWriteLabel(7,3,"TG"); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]xlsEOF(); [/FONT][/COLOR] [COLOR=#000000][FONT=monospace]?>[/FONT][/COLOR] Code sưu tầm. Hi vọng giúp ích cho các lập trình viên