Forum Moderators: coopster
I have a good working code for making a excel doc. on the fly. He send the file to the screen and you can save it directly. But I dont want it to send it to the screen but that he save it on the server and EMAILS it to someone. I'm searching and trying to get it work for 3 days, but no luck. I hope you guys can help me out.
This is the code I use the make an excel doc.
$select = "SELECT * FROM dagrapport WHERE dagrapportid='$dagrapportid'"; $result = mysql_query($select);
$datum = mysql_result($result,0,'datum');
$medewerkernummer = mysql_result($result,0,'medewerkernummer');
$export = mysql_query($select);
$fields = mysql_num_fields($export);
$kop = "";
$data = "";
for ($i = 0; $i < $fields; $i++) {
$kop .= mysql_field_name($export, $i) . "\t";
}
while($row = mysql_fetch_row($export)) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
}
$data = str_replace("\r","",$data);
if ($data == "") {
$data = "\n(0) Records Found!\n";
}
header("Content-type: application/x-msexcel");
header("Content-Disposition: attachment; filename=dagrapport-$datum-$medewerkernummer.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$kop\n$data";
All the best,
Jasper