Creating excel files through PHP

Author: 66 Comments

No need to use complicated or extensive libraries (such as PEAR) to create Excel pages. Just take advantage of the "smart" part of Excel; its ability to parse an HTML table to a nice Excel page.

Just create a regular .PHP file, where you output your data in a nice little html-table. Then place the following snippet in the top of that file (no output can happen before these lines, as they change your headers -- so place these all the way at the top):

header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=excel.xls");

And it's just that easy. If you open the page, you'll see a download-window asking you where to place the file. The headers will tell your computer that it's an Excel-file, which will parse your html-table (assuming you've written it without errors) and display it nicely.

If that's not enough, you can look at more extensive libraries such as PHPExcel. As their examples show, it offers more advanced features.

Comments
  1. Posted by Joshua
  2. Posted by GwB
  3. Posted by Keith
    • Posted by iNav
  4. Posted by Keith
  5. Posted by Matti
    • Posted by Denis
      • Posted by Denis
      • Posted by Matti
      • Posted by Denis
  6. Posted by Tejas
  7. Posted by Matti
  8. Posted by kaptenvu
  9. Posted by Aamir
  10. Posted by -
  11. Posted by UngaMan
  12. Posted by Chris
  13. Posted by Matti
  14. Posted by Dale
  15. Posted by pahan
  16. Posted by James
  17. Posted by Matti
  18. Posted by him_aeng
  19. Posted by Emmanuel
  20. Posted by maddog
  21. Posted by Matti
  22. Posted by Rick
  23. Posted by Dragan
  24. Posted by Bernat
  25. Posted by ndtwc
  26. Posted by Abhishek Goel
  27. Posted by Matti
  28. Posted by Real Drouin
  29. Posted by Matti
  30. Posted by Rishi
  31. Posted by Matti
  32. Posted by sofie
  33. Posted by Matti
    • Posted by Denis
  34. Posted by Chillipit
  35. Posted by Karmel
  36. Posted by shanoger
  37. Posted by Matti
  38. Posted by Sumedha Adhikari
  39. Posted by John jairo
  40. Posted by Matti
  41. Posted by david
  42. Posted by Matti
  43. Posted by Amien
  44. Posted by Anton
  45. Posted by harry
  46. Posted by harry
    • Posted by Matti
  47. Posted by Anton Boutkam
  48. Posted by parth
  49. Posted by Jo
  50. Posted by Alex
  51. Posted by André
    • Posted by Matti
    • Posted by Pavel
      • Posted by olivM
  52. Posted by nick
    • Posted by Andy
  53. Posted by paris
  54. Posted by Egbert O'Foo
  55. Posted by John

Add Your Comment