您好,欢迎访问一九零五行业门户网

php导出CSV方法 (转)

制作网站时,经常会遇到检索数据列表的情况。通常用户希望下载这些列表数据并存储到客户端。当然下载这些数据的时候是需要固定的格式,以便于用excel等软件阅览。说的简单一些就是csv/excel数据导出 。
注意事项:
输出文档的基本格式为:列1,列2,列3,……,列nn
格式化数据的同时要对特殊的字符进行过滤。譬如“,”如果不转换为全角“,”会导致数据格式的混乱。
实现方法:
举例:检索数据库表,将结果保存为字符串,进行格式和特殊字符的过滤后,导出到客户端的csv文件。 
ordersearchedit_savecsv.php
php
include($_server[''document_root''] . /ftcart/orderinfomanager.class.php);
include($_server[''document_root''] . /ftcart/commonutil.php);
include($_server[''document_root''] . /ftcart/commonconst.php);
include($_server[''document_root''] . /ftcart/commonerrormsg.php);
include($_server[''document_root''] . /webadmin.php);
$searchcase = new orderinfomanager();
$nowtime = microtime_float();
$searchcase = unserialize($_session[order_search_case]);
$listcsv = $searchcase->docsv();// 调用docsv()方法
$filename = $nowtime;
//$filename = str_replace(:,,$nowtime);
//$filename = trim($filename);
//echo $filename;
header(content-disposition: attachment; filename=.$filename..csv);
header(''content-type:application/octet-stream'');
echo 注文no.,注文日,氏名,住所,支
其它类似信息

推荐信息