Create Excel file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Create Excel file

Post by shiznatix »

Heyooo

Ok so I need to create an excel file on the fly. I took at look at the pear package one but I don't have PEAR installed and I don't know how to install it and whatnot and it just seams like overkill right now. I then tried some other ones from php classes and elsewhere to no avail yet.

Does anyone know of a good script that works to create excel files?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

if it's a windows server and you have excel installed, you can use COM to create the file.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

linux server, thanks though
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Visit PHP Classes and search there. I found one a few years ago that still serves me very well.

EDIT | I swear to all that is cheesy about pizza that I cannot write the word s-e-r-v-e without adding an 'r' to the end of it. :evil:
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

while I am searching there can someone tell me what is wrong with this code? I am making a csv file on the fly and trying to send it to excel but excel just opens with a blank spreadsheat. I know the csv file has everything in it correct so I donno.

Code: Select all

$Lines = array();
while ($info = mysql_fetch_assoc($query))
{
    $Lines[] = '"'.$info['file_name'].'",'.$info['first_name'];
}

$Lines = implode("\n", $Lines);

$handle = fopen('tmpfile.csv', 'w');
fwrite($handle, $Lines);
fclose($handle);

header ('Content-Type: application/msexcel');
header ('Content-Disposition: attachment; filename="tmpfile.csv"');
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

readfile() yaaaa

But I got it with a fun excel writer that was found. The one I am gonna use is: http://www.phpclasses.org/browse/package/2037.html
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Looks clean enough. Let us know how it goes.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

after minimal testing it is working awesome. its really really easy to create collums and whatnot so i highly recommend this
Post Reply