Created
December 6, 2013 00:23
-
-
Save EricYue2012/7816628 to your computer and use it in GitHub Desktop.
How to generate excel file in cakephp
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
//excel layout | |
<?php | |
header ("Expires: Mon, 28 Oct 2008 05:00:00 GMT"); | |
header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT"); | |
header ("Cache-Control: no-cache, must-revalidate"); | |
header ("Pragma: no-cache"); | |
header ("Content-type: application/vnd.ms-excel"); | |
header ("Content-Disposition: attachment; filename=\"report_".date('dmy_His').".xls" ); | |
header ("Content-Description: Generated Report" ); | |
?> | |
<?php echo $content_for_layout ?> | |
//$content_for_layout example : basic table | |
<table> | |
<tr> | |
<th width="10%">Guest Name</th> | |
<th width="10%">Partner Name</th> | |
<th width="10%">Company Name</th> | |
</tr> | |
<?php | |
foreach ($bookings as $booking): | |
?> | |
<tr> | |
<td> | |
<?php | |
echo $booking['Guest']['name'] . ' ' . $booking['Guest']['surname']; | |
?> | |
</td> | |
<td> | |
<?php | |
echo $booking['Partner']['name'] . ' ' . $booking['Partner']['surname']; | |
?> | |
</td> | |
</tr> | |
<?php endforeach; ?> | |
</table> | |
//controller: the layout 'excel' is the one defined above | |
$this->render($render,'excel'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment