app/Controller/[Name]sController.php
<?php echo $this->Html->link(__('Export to excel'), array('action' => 'export_xls')); ?>
app/View/Layouts/export_xls.ctp
<?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.xls" );
header ("Content-Description: Generated Report" );
?>
<?php echo $content_for_layout ?>
app/View/[Name]/export_xls.ctp
<STYLE type="text/css">
.tableTd {
border-width: 0.5pt;
border: solid;
}
.tableTdContent{
border-width: 0.5pt;
border: solid;
}
#titles{
font-weight: bolder;
}
</STYLE>
<table>
<tr>
<td><b>[Name]s Data Export<b></td>
</tr>
<tr>
<td><b>Exported Date:</b></td>
<td><?php echo date("F j, Y, g:i a"); ?></td>
</tr>
<tr>
<td><b>Number of Rows:</b></td>
<td style="text-align:left"><?php echo count($rows);?></td>
</tr>
<tr>
<td></td>
</tr>
<tr id="titles">
<td class="tableTd">Id</td>
<td class="tableTd">Name</td>
</tr>
<?php foreach($rows as $row):
echo '<tr>';
echo '<td class="tableTdContent">'.$row['[Name]']['id'].'</td>';
echo '<td class="tableTdContent">'.$row['[Name]']['name'].'</td>';
echo '</tr>';
endforeach;
?>
</table>
app/View/[Name]/index.ctp
<?php echo $this->Html->link(__('Export to excel'), array('action' => 'export_xls')); ?>
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.