I am creating a CSV file which containts special characters. So I set it to UTF-8 in order to display those characters.
The problem is, in Excel all data is displayed in a single column. It ignores the separator.
public static function exportCSV($month) {
$file = fopen("../export/test_csv.csv","w");
fputs($file, $bom =( chr(0xEF) . chr(0xBB) . chr(0xBF) ));
$header = 'Beløb;Valørdato;Status';
fputcsv($file,explode(';',$header), ';');
fclose($file);
}
The file is generated, I can read it with no issue in Libre Office. But I need to make it working in Excel.
The special characters are displayed, but they are all in one column. Is it possible to separate them by tabs?
Desired result should be:
Column 1 Column 2 Column 3
Beløb Valørdato Status
I have read a solution here saying if you use '/t' it will do the job. But it doesn't seem to work, maybe I did something wrong? I used /t instead of ; but no luck
Can anyone please help me with this?
EDIT: I just managed to fix this thanks to RiggsFolly I separated the values within $header with , (comma)
Then in fputcsv function I added t as a separator and it worked ;)
fputcsv($file,explode("\t",$header), "\t");