Easy Excel export from PHP


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

This is saved from Gerhard Slettens weblog www.gersh.no. I just want yo keep it on snipplr so it easily can be fetched through textmate.


Copy this code and paste it in your HTML
  1. <?php
  2. header("Expires: 0");
  3. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  4. header("Cache-Control: no-store, no-cache, must-revalidate");
  5. header("Cache-Control: post-check=0, pre-check=0", false);
  6. header("Pragma: no-cache");
  7. header("Content-type: application/vnd.ms-excel;charset:UTF-8");
  8. header("Content-Disposition: attachment; filename=filename.xls");
  9. print "\n"; // Add a line, unless excel error..
  10. ?>
  11. <table border="1">
  12. <tr>
  13. <th>header 1</th>
  14. <th>header 2</th>
  15. </tr>
  16. <tr>
  17. <td>data 1</td>
  18. <td>data 2 - nordic letters æ, æ, å</td>
  19. </tr>
  20. </table>

URL: http://www.gersh.no/posts/view/easy-excel-export-from-php

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.