[ View menu ]

PHP Excel Export class

Written on March 27, 2007

Following the code that I found here, I made a quick PHP4 class that creates a single sheet Excel file. The class has a download() function that will send the appropriate headers for a binary download.

ExcelExport.php - Rename to ExcelExport.php.

Usage
require_once "ExcelExport.php";
 
$xls = new ExcelExport();
 
$xls->addRow(Array("First Name","Last Name","Website","ID"));
$xls->addRow(Array("james","lin","www.chumby.net",0));
$xls->addRow(Array("bhaven","mistry","www.mygumballs.com",1));
$xls->addRow(Array("erica","truex","www.wholegrainfilms.com",2));
$xls->addRow(Array("eliot","gann","www.dissolvedfish.com",3));
$xls->addRow(Array("trevor","powell","gradius.classicgaming.gamespy.com",4));
$xls->download("websites.xls");

Filed in: php, web development.

5 Comments

Write comment - TrackBack - RSS Comments

  1. Comment by meilander:

    How can i use this script with array’s?
    I want to get all de field names from my Database and set this at the first line of my excel file?

    April 10, 2008 @ 12:34 am
  2. Comment by GreenDude:

    Really nice.

    How can I make it output the data in utf-8?

    April 22, 2008 @ 7:30 am
  3. Comment by GuzZzt:

    I have tested your Excel export script and it works great except one thing. It seems to have problem if the text is longer than 255 characters in the same cell. Do you know why?

    June 23, 2008 @ 10:52 am
  4. Comment by kunalm:

    Hey! Nice class. Works very well. But how can I add a auto sum formula on the generated excel sheet?

    August 22, 2008 @ 4:09 pm
  5. Comment by kamasheto:

    Thanks for providing this. ツ

    August 28, 2008 @ 5:48 am

You have to be logged in to post a comment.