HTML to Excel Download In PHP Sample Code
HTML to Excel Download is a very important functionality for any application in order to view reports and Tracking the Work, Account, Sales, etc.. Now PHP has a very good in-built code, by Using this, we can convert HTML to excel without using any third-party plugin. A single line of code makes HTML to excel within a min.
I have seen In Codeigniter or laravel frameworks, they are using a third party and a lot of code for converting HTML to Excel, But In core PHP it’s very easy to handle.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
<?php header('Content-Type: application/vnd.ms-excel'); header('Content-disposition: attachment; filename=download_excel.xls'); echo '<table id="example" cellspacing="0" border="1" width="100%"> <thead> <tr> <th>User Name</th> <th>Email</th> <th>Phone Number</th> <th>Address</th> <th>Zip Code</th> <th>Age</th> </tr> </thead> <tbody>'; echo '<tr> <td>Kishore Vengla</td> <td>Kishore23@gmail.com</td> <td>9090909090</td> <td>Hyderabad, Hitech City</td> <td>500084</td> <td>35</td> </tr> <tr> <td>Saroj Kumar</td> <td>saroj@gmail.com</td> <td>9898989898</td> <td>MP, Near Old City</td> <td>897885</td> <td>54</td> </tr> <tr> <td>Praveen Adduri</td> <td>Praveen123@gmail.com</td> <td>111111111</td> <td>UP, Simpla House</td> <td>343434</td> <td>50</td> </tr> <tr> <td>Rasmi Ranjan</td> <td>Rashmi243@gmail.com</td> <td>7878787878</td> <td>Odisha, Unit-9, Bhubaneswar</td> <td>756756</td> <td>28</td> </tr>'; echo '</tbody></table>'; ?> |