banner

[Rule] Rules  [Home] Main Forum  [Portal] Portal  
[Members] Member Listing  [Statistics] Statistics  [Search] Search  [Reading Room] Reading Room 
[Register] Register  
[Login] Loginhttp  | https  ]
 
Forum Index Thảo luận hệ điều hành Windows Lỗi font chữ khi export từ mysql ra excel. Help!  XML
  [Question]   Lỗi font chữ khi export từ mysql ra excel. Help! 01/06/2007 07:11:01 (+0700) | #1 | 62660
[Avatar]
canh_nguyen
Elite Member

[Minus]    0    [Plus]
Joined: 23/08/2004 18:55:09
Messages: 775
Location: Broken dream
Offline
[Profile] [PM] [WWW] [Yahoo!] [MSN] [ICQ]
Mình dùng PHP để export data từ MySql ra excel (xls).

Code:
$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();



Vấn đề là khi export xong thì bị lỗi font khi em bằng MSExcel. Pro nào biết cách giải quyết xin cho ý kiến. Thanks.
[Up] [Print Copy]
[digg] [delicious] [google] [yahoo] [technorati] [reddit] [stumbleupon]
Go to: 
 Users currently in here 
1 Anonymous

Powered by JForum - Extended by HVAOnline
 hvaonline.net  |  hvaforum.net  |  hvazone.net  |  hvanews.net  |  vnhacker.org
1999 - 2013 © v2012|0504|218|