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
csv column width
Moderator: General Moderators
Re: csv column width
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
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:
There's no need to be concatenating like that.
I'd suggest simplifying your code:
Code: Select all
$data = 'January, Jancap, Feb, Febcap...etc';Real programmers don't comment their code. If it was hard to write, it should be hard to understand.