30Apr/09Off
PHP Export to Excel
Here is some code I found that will allow you from PHP code to export data directly into an excel file. I haven't personally tested this but the source I had for it was no longer available online so I'm reposting it here.
< ?php session_start();
$ID=$_SESSION["ReportData"];
?>
< ?php
$line = '';
foreach($ID as $line) {
foreach($line as $key => $value) {
$data .= $value . "\t";
}
$data .= "\n";
}
$data = str_replace("\r","",$data);
?>
< ?php
if ($data == "") {
$data = "\n(0) Records Found!\n";
}
?>
< ?php
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=extraction.xls");
header("Pragma: no-cache");
header("Expires: 0");
echo "$data";
?>