Php: generate an excel file without using COM

Source: Internet
Author: User
Php: generate an excel file without using COM. use php to generate an excel file.

Header ("Content-type: application/vnd. ms-excel ");
Header ("Content-Disposition: filename=test.xls ");
Echo "test1 \ t ";
Echo "test2 \ t \ n ";
Echo "test1 \ t ";
Echo "test2 \ t \ n ";
Echo "test1 \ t ";
Echo "test2 \ t \ n ";
Echo "test1 \ t ";
Echo "test2 \ t \ n ";
Echo "test1 \ t ";
Echo "test2 \ t \ n ";
Echo "test1 \ t ";
Echo "test2 \ t \ n ";
?>
When you run the above code in the php environment, you can see the browser asking you whether to download the excel document, click save, and an excel file is added to the hard disk, you can see the final result when using excel.
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, use 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 easier to process various types of files.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.