Page 1 of 1

Create Excel file

Posted: Thu Nov 16, 2006 1:44 pm
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?

Posted: Thu Nov 16, 2006 1:47 pm
by Burrito
if it's a windows server and you have excel installed, you can use COM to create the file.

Posted: Thu Nov 16, 2006 1:49 pm
by shiznatix
linux server, thanks though

Posted: Thu Nov 16, 2006 1:56 pm
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:

Posted: Thu Nov 16, 2006 2:03 pm
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"');

Posted: Thu Nov 16, 2006 2:07 pm
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

Posted: Thu Nov 16, 2006 3:05 pm
by RobertGonzalez
Looks clean enough. Let us know how it goes.

Posted: Thu Nov 16, 2006 3:32 pm
by shiznatix
after minimal testing it is working awesome. its really really easy to create collums and whatnot so i highly recommend this