Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb/web234/b2344/sl.harringtonweb/public_html/pmwiki2.php:2) in /hermes/bosweb/web234/b2344/sl.harringtonweb/public_html/pub/skins/simple/simple.php on line 39

Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb/web234/b2344/sl.harringtonweb/public_html/pmwiki2.php:2) in /hermes/bosweb/web234/b2344/sl.harringtonweb/public_html/pmwiki2.php on line 866
Harrington Web : Ben - Exportexcel

Export to Excel

Today I learned a cool trick of how to export data that I have arranged in tables to an excel file quick and easy. Below is a sample of some code. To make it work copy the following code into its own php file. You will notice that in the code there are to function calls to the header. The first is the Content-Type which gives the browser the information needed to use excel to open the document. The second is the Content-disposition. This allows the user the option to save the document as an excel file, with a default or custom filename

<?php
header("Content-Type: application/vnd.ms-excel; name='excel'");
header("Content-disposition:  attachment; filename=test.xls");
?>
<table border="1">
<tr>   <td>test</td><td>=3+4</td> </tr>
<tr>   <td>test</td><td>test2</td> </tr>
<tr>   <td>test</td><td>test2</td> </tr>
</table>

 
Page last modified on June 07, 2006, at 07:25 PM.