直接以xsl格式输出ecshop的数据

2009-08-12 15:16 来源:www.chinab4c.com 作者:ecshop专家

      最近要帮朋友把ecshop中的一些数据给导成xls格式。还真麻烦。不过找了段代码,还着好用,下面贴出来。

     <?

header("Content-type:application/vnd.ms-excel");  
header("Content-Disposition:filename=test.xls");  
/*
$ip ="localhost";
$db = "uc";
$user = "root";
$pwd = "root";
*/
$ip ="localhost";
$db = "shopuc";
$user = "shopuc";
$pwd = "##RFV##uc";
$con = mysql_connect($ip,$user,$pwd);
mysql_query("set names 'GBK'");
mysql_select_db($db);
$re = mysql_query("select * from uc_members order by uid desc");
$str = '';

while ($r = mysql_fetch_array($re)) {
 echo iconv("UTF-8","GBK",$r['username'])."\t";
 echo iconv("UTF-8","GBK",$r['email'])."\t\n";
 
}


?>

 

 

<?php

$ip ="localhost";
$db = "shopuc";
$user = "shopuc";
$pwd = "##RFV##uc";
$con = mysql_connect($ip,$user,$pwd);
mysql_query('set names "utf8"');
mysql_select_db($db);
$re = mysql_query("select * from uc_members order by uid desc");

mysql_query("set names 'UTF8'");
$fp = fopen('file.csv', 'w');
while ($v = mysql_fetch_array($re)) {
   fputcsv($fp, array(iconv("UTF-8","GBK",$v['username']),$v['email']));
 
}

fclose($fp);

?>
<A href="file.csv">x</a>

来源:中国B4C电子商务