Generate excel files with php_PHP tutorial

WBOY
Release: 2016-07-20 11:04:39
Original
855 people have browsed it

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 :-)


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445191.htmlTechArticlenbsp;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 I will share it. Let’s take a look at the code: ? header(Conten...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template