Last active
August 29, 2015 14:01
-
-
Save ken-muturi/74fb37316b09d155d592 to your computer and use it in GitHub Desktop.
Export to excel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$actual_headers = array(); | |
foreach ($data['fields'] as $field) | |
{ | |
$actual_headers [] = $data['actual_headers'][$field]; | |
} | |
$path = realpath(BASEPATH."../assets/fmt/xls/"); | |
$fname = $title."-".time().".csv"; | |
$fp = fopen("{$path}/{$fname}", 'w'); | |
fputcsv($fp, $actual_headers); | |
foreach ($data['result']->result() as $result) | |
{ | |
$row = array(); | |
foreach ($data['fields'] as $field) | |
{ | |
$row [] = $result->{$field}; | |
} | |
fputcsv($fp, $row); | |
} | |
fclose($fp); | |
header('Content-type: application/csv'); | |
header("Content-Disposition: inline; filename=".$fname); | |
readfile("{$path}/{$fname}"); | |
exit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment