Marine1969
IS-IT--Management
I found a script online to export my data to excel but when it opens the spreadsheet is blank. I have modified the top of the script to get the data that I need and the array is ok. This is the first time I am exporting data to a ss and am having a little trouble finding the issue. Is there an error in the script? Below is the script that is supposed to export data...
PHP:
function filterData(&$str){
$str = preg_replace("/\t/", "\\t", $str);
$str = preg_replace("/\r?\n/", "\\n", $str);
if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
}
// file name for download
$fileName = "invoices.xls";
// headers for download
header("Content-Disposition: attachment; filename=\"$fileName\"");
header("Content-Type: application/vnd.ms-excel");
$flag = false;
foreach($data as $row) {
if(!$flag) {
// display column names as first row
echo implode("\t", array_keys($row)) . "\n";
$flag = true;
}
// filter data
array_walk($row, 'filterData');
echo implode("\t", array_values($row)) . "\n";
}