lghaman123
asked on
Simple Export to Excel with PHP
I wrote the following code to export a multi-dimensional array to rows in an excel spreadsheet for the user to download. But in the fields where the data is "" or Null, it doesn't tab over to a new row so my columns are getting all jumbled. Attached is a sample file of what I'm getting. There must be something small that I am missing but I'm not sure what. Any help would be appreciated, thanks!
<?php
header("Content-type: application/x-msexcel");
header("Content-Disposition: attachment; filename=report.xls");
header("Pragma: no-cache");
header("Expires: 0");
for ($x=1; $x<count($resultArray); $x++) {
for ($y=0; $y<count($resultArray[$x]); $y++) {
echo $resultArray[$x][$y]."\t";
}
echo "\n";
}
?>
sample.xls
You will have to create ROWS + Columns through HTML and export to excel .. just try
logudotcom is right.
excel is pretty thick, unless you give it more to work on as a delimiter. so either use |'s or comma's or do the html method.
but not tab's.
not even swearing at excel works.
excel is pretty thick, unless you give it more to work on as a delimiter. so either use |'s or comma's or do the html method.
but not tab's.
not even swearing at excel works.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks guys, I appreciate the help.
echo $resultArray[$x][$y]."\t";
to:
echo $resultArray[$x][$y];
echo "\t";
I'm thinking it might have something to do with trying to append the tab to a null value