Exporting to Excel format
Submitted by Pujan on Thu, 02/19/2009 - 13:22
Tagged:
This simple function here checks whether the given file with the filename that we retrieved through GET method exists and prints the output in excel format by printing suitable headers to the page.
function xls_export($file)
{
if ((isset($file))&&(file_exists($file))) {
header("Content-Type: application/vnd.ms-excel");
header("Content-disposition: attachment; filename=export.xls");
readfile("$file");
} else {
echo "No file selected";
}
}
$filename=$_GET['file'];
xls_export($filename);