我尝试下载一个csv文件,但是当我下载它时,我的数据只在一列中。
我有
[1,2,3,4,5] [] [] [] []
我需要
[1] [2] [3] [4] [5]
我的代码:
function to_csv($tab){
$Allarray=array();
foreach ($tab as $tableau){
$Allarray[]=$tableau;
}
$separateur = "\t";
$entete = array('firstname', 'name', 'mail', 'rate','review','review_date','order_ref', 'oder_date', 'source');
$file = implode($separateur, $entete) . "\r\n";
foreach ($Allarray as $ligne) {
$file .= implode($separateur, $ligne) . "\r\n";
}
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename=ebay_export_'.date("dmYHis").'.csv');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
print chr(239) . chr(187) . chr(191) .($file);
exit;
}
编辑: tab的值是foreach列的数据:
array (size=36)
0 =>
array (size=9)
'firstname' =>
object(SimpleXMLElement)[9]
public 0 => string 'mywifemademe' (length=12)
'name' => string ' ' (length=1)
'mail' => string 'anonymous@anonymous.com' (length=23)
'rate' => int 5
'review' =>
object(SimpleXMLElement)[12]
public 0 => string 'WONDERFUL-FAST PAYMENT-GREAT COMMUNICATION-FIRST CLASS! A+A+' (length=60)
'review_date' =>
object(SimpleXMLElement)[13]
public 0 => string '2002-06-08T18:29:31.000Z' (length=24)
'order_ref' => string '1539157020_EBAY_2018-03-13 15:21:40_0' (length=37)
'order_date' =>
object(SimpleXMLElement)[19]
public 0 => string '2002-06-08T18:29:31.000Z' (length=24)
'source' => string '12' (length=2)
1 =>
...
但是当我下载.csv时,在我的Excel中,所有这些数据都在“A”列中:
firstname name mail rate review review_date order_ref order_date source
mywifemademe anonymous@anonymous.com WONDERFUL-FAST PAYMENT-GREAT COMMUNICATION-FIRST CLASS! A+A+ ...
答案 0 :(得分:0)
将分隔符更改为';&#39 ;;之前我遇到过同样的问题,因为你很擅长阅读它。