PHP generates excel files without using COM

高洛峰
Release: 2023-03-02 21:26:01
Original
926 people have browsed it

Use PHP (as the current mainstream development language) to generate excel files

<?
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";
?>
Copy after login

Running the above code in the PHP (as the current mainstream development language) environment, 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 in excel and you will see the final result. How good is it?
 In fact, when making real applications, you can take the data out of the database, and then echo it out by adding after each column of data and after each row of data, in PHP (as the current mainstream development language) Use header("Content-type:application/vnd.ms-excel"); at the beginning to indicate that the output is an excel file, and use header("Content-Disposition:filename=test.xls"); to indicate that 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 (as the current mainstream development language) will be more convenient in processing various types of files.

Related labels:
php
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!