HTML table with PHP


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. //$HTML_Code is where the actual HTML table goes
  4. //If you don't add a border around your table the border won't show up when you //download the excel file.
  5.  
  6. $HTML_Code = "
  7. <table style=\"border: 2px solid black;\">
  8. <tr>
  9. <td>Row1 Col1</td>
  10. <td>Row1 Col2</td>
  11. <td>Row1 Col3</td>
  12. </tr>
  13. <tr>
  14. <td>Row2 Col1</td>
  15. <td>Row2 Col2</td>
  16. <td>Row2 Col3</td>
  17. </tr>
  18. </table>
  19. ";
  20.  
  21. //$Build file will create the excel file called file_name.xls
  22. //$Build file doesn't add the contents/code into the file.
  23.  
  24. $Build_File = fopen('file_name.xls', 'w');
  25.  
  26. //$Edit_File add the HTML table to the excel file.
  27.  
  28. $Edit_File = fwrite($Build_File,$HTML_Code);
  29.  
  30.  
  31. if(!$Edit_File)
  32. {
  33. die("Error!");
  34. }
  35.  
  36.  
  37. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.