Xatenev Xatenev - 3 months ago 8
PHP Question

Date string while creating Excel CSV File outputs ###### ##### instead of the value

I wanna create a simple CSV file without

PHPExcel


I have the following code:

header('Content-Type: text/csv');
header('Content-Disposition: attachement; filename="Bestellungen_Export.csv";');
$f = fopen('php://output', 'w');
foreach ($list as $fields) {
fputcsv($f, $fields, ';');
}


now I have a datetime string
29.10.2012 12:20:02 (d.m.Y H:i:s)
. Now its inserted into the excel and looks like that:
##########
. Obviously Excel doesn't find the correct date format for that string. If I double click the
column
, the correct value is displayed. Now my questions:


  • What is the exact error here that it displays ########

  • How can I make it show the correct date?


Answer

A CSV-File is a text file witch contains only text in comma separated format. When you open your CSV and you see only ### in a column, the width is too small.

You can't solve that problem without building a Excel-file with style informations. So if you have to declare the with or the type of the column you have to use PHPExcel and specify them for that col.

Comments