nbsp;Use php to generate excel files
Haha, I learned another trick today. It is too simple to generate excel documents with php. I think everyone will use it, so
share it.
Let’s take a look at the code:
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=test.xls" );
echo "test1 ";
echo "test2 ";
echo "test1 ";
echo "test2 ";
echo "test1 ";
echo "test2 ";
echo "test1 ";
echo "test2 ";
echo "test1 ";
echo "test2 ";
echo "test1 ";
echo "test2 ";
?>
Run the above code in the php environment, and you can see the browser asking the user whether to download the excel
document, click Save, and there will be an extra excel file on the hard disk. Open it with excel. See
the final result, how nice it is.
In fact, when making a real application, you can take the data out of the database, and then echo it out by adding
at the end of each column of data and adding at the end of each row of data, at the beginning of php
Use header("Content-type:application/vnd.ms-excel"); to indicate that the output is an
excel file, and use header("Content-Disposition:filename=test.xls"); to indicate
The output file name is text.xls. That's OK.
We can also modify the header to allow it to output files in more formats, so that PHP will be more convenient in processing various types of
files.
Yorgo Sun (yorgo@163.net)
2000/11/14
Reprinting is welcome, but please ensure the document is complete and notify the author. Thank you :-)