3
I want to create an XSV file from PHP. What I want is to be able to create columns and give background color to an element for example. I have the following:
<?php
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=file.csv");
header("Pragma: no-cache");
header("Expires: 0");
outputCSV(array(
array("name 1", "age 1", "city 1"),
array("name 2", "age 2", "city 2"),
array("name 3", "age 3", "city 3")
));
function outputCSV($data) {
$output = fopen("php://output", "w");
foreach ($data as $row) {
fputcsv($output, $row); // here you can change delimiter/enclosure
}
fclose($output);
}
?>
The file is well generated. What is generated looks like this:
And I want it to stay that way (all divided by column and if possible a background color):
Is there an API you can use?
I tested with libreoffice 4.x the values came in the right columns without the background color. Soen has a list of other libs who manipulate
.xls
– rray
@lost phpexcel would be a good option, but I have to even create the file in CSV
– pc_oc
Have you tried to remove Enclosure?
fputcsv($output, $row, ',', '');
– Jader A. Wagner
@Can Jader explain it better? How he got it wrong
– pc_oc
@pc_oc look at the comment I put in your reply.
– gmsantos