Page 1 of 1

csv column width

Posted: Thu Nov 06, 2008 1:50 am
by sailu_mvn
I am generating a csv using php code below.

$cr = "\n";

$data = "Jan" . ',' . "Jancap" . ',' . "Feb" . ',' . "Febcap" . ','."Mar".','."Marcap".','."April".','."Aprilcap".','."May".','."MayCap".','."June".',
'."Junecap".','."July".','."Julycap".','."August".','."Augustcap".','."September".','."Septembercap".','."October".','."Octobercap".','."November".','."Novembercap".','."December".','."Decembercap".$cr;

$data .= jan.jpg . ',' .$image_name_january . ',' . feb.jpg . ',' . $image_name_january .march.jpg . ',' .$image_name_january . ',' . april.jpg . ',' . $image_name_january . may.jpg . ',' .$image_name_january . ',' . june.jpg . ',' . $image_name_january .july.jpg . ',' .$image_name_january . ',' . august . ',' . $image_name_january .','.september.jpg . ',' .$image_name_january . ',' . october.jpg . ',' . $image_name_january .','.november.jpg . ',' .$image_name_january . ',' . december.jpg . ',' . $image_name_january .$cr;

$csv_contents .= $data;

function write_to_file($filename, $stringtowrite, $writetype)
{
$filesession = fopen($filename,$writetype);
fwrite($filesession,"$stringtowrite");
fclose($filesession);
}
write_to_file('exportfile.csv',$csv_contents, 'w');


Everything is working fine..but when it comes to columns in csv, from June on, they are printed in the next line. I want them as headings.How can I sort this problem?

Pls advice.

Sailaja

Re: csv column width

Posted: Thu Nov 06, 2008 2:57 am
by onion2k
CSV files have no formatting capability. They're just displayed however the application you're viewing it in wants. If you need to format the data in a specific way you'll need to convert it to a different format (eg HTML, PDF, Excel, etc).

Re: csv column width

Posted: Thu Nov 06, 2008 10:04 am
by pickle
They're on a new line because you've got a newline character in your first $data assignment, right after the comma after June.

I'd suggest simplifying your code:

Code: Select all

$data = 'January, Jancap, Feb, Febcap...etc';
There's no need to be concatenating like that.