cartergarth
03-01-2012, 08:09 AM
Hello everyone! How do you write a PHP function in codeigniter that lets user download data to an Excel file?
Thank You.
Thank You.
|
||||
How to download data to excel file?cartergarth 03-01-2012, 08:09 AM Hello everyone! How do you write a PHP function in codeigniter that lets user download data to an Excel file? Thank You. litebearer 03-01-2012, 12:31 PM http://www.the-art-of-web.com/php/dataexport/ devnty06 03-03-2012, 07:25 AM <?PHP function cleanData(&$str) { $str = preg_replace("/\t/", "\\t", $str); $str = preg_replace("/\r?\n/", "\\n", $str); if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"'; } # filename for download $filename = "website_data_" . date('Ymd') . ".xls"; header("Content-Disposition: attachment; filename=\"$filename\""); header("Content-Type: application/vnd.ms-excel"); $flag = false; foreach($data as $row) { if(!$flag) { # display field/column names as first row echo implode("\t", array_keys($row)) . "\r\n"; $flag = true; } array_walk($row, 'cleanData'); echo implode("\t", array_values($row)) . "\r\n"; } exit; ?> web development services (http://www.prodigyapex.com) |
| |||
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum