Last active
August 29, 2015 14:18
-
-
Save AnowarCST/1a50280f012b558bedfe to your computer and use it in GitHub Desktop.
Export Report as Excel & Doc
This file contains 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
public function exportReport($report_id,$type){ | |
$reportData = $this->getReportById($report_id); | |
$filename=preg_replace("/[^a-zA-Z]+/", "", $reportData['REPORT_TITLE']); | |
include_once "report_helper.php"; | |
if($type =='word'){ | |
header('Content-Type: application/msword'); | |
header("Content-Disposition: attachment; filename=$filename.doc"); | |
}else{ | |
header("Content-Type: application/vnd.ms-excel; charset=utf-8"); | |
header("Content-Disposition: attachment; filename=$filename.xls"); | |
} | |
//File name extension was wrong | |
header("Expires: 0"); | |
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); | |
header("Cache-Control: private",false); | |
report_gen_exp($reportData['REPORT_DATA'],$reportData['REPORT_TITLE']); | |
exit(); | |
} | |
public function report_gen_exp($data,$report_title){ | |
?> | |
<table border="1"> | |
<caption><h2><?php echo $report_title; ?></h2></caption> | |
<?php if (count($data) > 0) { ?> | |
<thead> | |
<tr> | |
<?php foreach ($data[0] as $key => $value) {echo '<th>' . $key . '</th>';} ?> | |
</tr> | |
</thead> | |
<tbody> | |
<?php foreach ($data as $row): ?> | |
<tr> | |
<?php foreach ($row as $key=>$field_value):?> | |
<td><?php echo $field_value . ' '; ?></td> | |
<?php endforeach;?> | |
</tr> | |
<?php endforeach; ?> | |
</tbody> | |
<?php | |
} else { | |
echo '<caption><h4>Data Not Found!</h4></caption>'; | |
} | |
?> | |
</table> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment