Monday, November 06, 2006

How to create microsoft excel(.xls) file using PHP?

<?php
$filepnt = fopen("newfile.xls", 'w+');
$content = "Id\tUsername\tE-mail\tLevel\n"; //"\t" means a TAB and "\n" is a New line
$content .= "1\tWebmaster\twebmaster@example.com\t1\n"; //every new line is a new row in the table
$content .= "2\tmysql_fan\tmysql@php.be\t3\n";
$content .= "3\tfedora\tfedora@redhat.com\t3\n";
fwrite($filepnt, $content);
fclose($filepnt);
echo '<a href="newfile.xls">Download as .xls</a>';
?>

No comments: