Tuesday, 11 October 2011

Really really simple method to export data from php to excel or another other spreadsheet.


<?php
// Excel export using The KISS method
$filename = $_REQUEST['name'] ? $_REQUEST['name'] : 'excelreport';
$contents = $_REQUEST['data'] ? $_REQUEST['data'] : "testdata1\ttestdata2\ttestdata3\ntestdata4\ttestdata5\ttestdata6\n";


if (substr(strtolower($filename)-4,4)!='.tsv') {
$filename .= '.tsv';
}


// header('Content-type: application/ms-excel');
header("Content-Type: text/tab-delimited-values");
header('Content-Disposition: attachment; filename='.$filename);


echo $contents;
?>

No comments:

Post a Comment