2017-07-08 55 views
-2

你好朋友我有文本數組與逗號與雙coutes selerated但當我推csv記錄逗號分隔值轉換爲兩個頭可以請你幫我解決這個問題。是否可以在csv中上傳標題逗號?

請找到波紋管串。 例如:我需要「西南,倫敦&支持辦公室L1」在一個colume

$datestr ='First Name,Last Name,Company,Type,Email,Attendance Status,Invited By,Payroll  No,Pharmacy No,Pharmacy Name,RM,RSM,Accomodation Friday,Accomodation Saturday,Job_Title,"Business Partner Session","Awards Evening","North & Central L1","North & Central L2","South East L1","South East & Warehouse L2","South West, London & Support Office L1","South West, London and Support Office L2'; 

$sessstr = "First Name,"."Last Name,"."Company,"."Type,"."Email,"."Attendance Status,"."Invited By,"."Payroll No,"."Pharmacy No,"."Pharmacy Name,"."RM,"."RSM,"."Accomodation Friday,"."Accomodation Saturday,"."Job_Title,"; 
     $datestr = "Jaikishan, Keswani,Day Lewis,[email protected],Yes,Colin,,,1,,,,Yes,Yes,PHP Developer,"; 
     foreach($sessions as $k=>$ses){ 
      $sessstr .= '"'.$ses['session_name'].'",'; 
      $datestr .= 'Yes,'; 
     } 
     $datestr = substr($datestr,0,-1); 
     $sessstr = substr($sessstr,0,-1); 

     $sessstr = $sessstr.",European Welcome Dinner,"."Accommodation By Invitation Letter,"."Notes,"."Awards Evening Food Option,"."Dietary Requirements"; 
     $datestr = $datestr.",,,,,"; 

     header('Content-Type: application/excel'); 
     header('Content-Disposition: attachment; filename="sample.csv"'); 
     $data = array(
       $sessstr, 
       $datestr 
     ); 

     $fp = fopen('php://output', 'w'); 

     foreach ($data as $line) { 
      $val = explode(",", $line); 

      fputcsv($fp, $val); 
     } 
     fclose($fp); 
+1

您需要提供您正在使用的代碼來執行此操作。如果你使用PHP本地fputcsv和fgetcsv函數,它不應該出現這個問題。 – apokryfos

+0

但是,當我打開csv,「西南,倫敦&支持辦公室L1」轉入西南和倫敦&支持辦公室L1。你能幫我解決這個問題嗎 –

+0

你是怎麼寫這一行的? – apokryfos

回答

0

如果您使用PHP的CSV功能,你應該把你的數據在陣列:

$datestr =['First Name','Last Name','Company','Type','Email','Attendance Status','Invited By','Payroll  No','Pharmacy No','Pharmacy Name','RM','RSM','Accomodation Friday','Accomodation Saturday','Job_Title','Business Partner Session',"Awards Evening","North & Central L1","North & Central L2","South East L1","South East & Warehouse L2","South West, London & Support Office L1","South West, London and Support Office L2"]; 

$sessstr = ["First Name","Last Name","Company","Type","Email","Attendance Status","Invited By","Payroll No","Pharmacy No","Pharmacy Name","RM","RSM","Accomodation Friday","Accomodation Saturday","Job_Title" ]; 
$datestr = ["Jaikishan", "Keswani","Day Lewis","[email protected]","Yes","Colin","","","1","","","","Yes","Yes","PHP Developer"]; 
foreach($sessions as $k=>$ses){ 
     $sessstr[] = $ses['session_name']; 
     $datestr[] = 'Yes'; 
    } 
    //$datestr = substr($datestr,0,-1); 
    //$sessstr = substr($sessstr,0,-1); 

    $sessstr = array_merge($sessstr,["European Welcome Dinner","Accommodation By Invitation Letter","Notes","Awards Evening Food Option","Dietary Requirements" ]; 
    $datestr = array_merge($datestr,[ "","","","","","" ]); 

    header('Content-Type: application/excel'); 
    header('Content-Disposition: attachment; filename="sample.csv"'); 
    $data = array(
      $sessstr, 
      $datestr 
    ); 

    $fp = fopen('php://output', 'w'); 

    foreach ($data as $line) { 
     fputcsv($fp, $val); 
    } 
    fclose($fp);