Use php (as the mainstream development language) to generate an excel file & nbsp; & lt ;? Header (Content-type: application/vnd. ms-excel); header (Content-Disposition: filenametest.xls); echotest1; echotest2; echo uses php (as the mainstream development language) to generate an excel file
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 (as the mainstream development language) environment. you can see the browser asking you if you want to download the excel document and click save, an excel file is added to the hard disk, and the final result is displayed when you open the file in excel. how can this problem be solved.
In fact, when doing real applications, you can extract the data from the database, and then add the data following each column, and echo the method after each row of data ends, header ("Content-type: application/vnd. ms-excel ") indicates that the excel file is output, and the file name output is text.xls using header (" Content-Disposition: filename=test.xls. In this case, OK.
We can modify the header so that it can output more files in different formats. This makes php (as the mainstream development language) easier to process various types of files.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.