Php directly generates an excel file on the webpage to provide the download method-php Tutorial

Source: Internet
Author: User
Php directly generates an excel file on the webpage to provide the download method
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 \ t after each column of data ends, after each row ends, add the \ n method for echo and 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.

  1. Header ("Content-type: application/vnd. ms-excel ");
  2. Header ("Content-Disposition: filename=test.xls ");
  3. Echo "test1 \ t ";
  4. Echo "test2 \ t \ n ";
  5. Echo "test1 \ t ";
  6. Echo "test2 \ t \ n ";
  7. Echo "test1 \ t ";
  8. Echo "test2 \ t \ n ";
  9. Echo "test1 \ t ";
  10. Echo "test2 \ t \ n ";
  11. Echo "test1 \ t ";
  12. Echo "test2 \ t \ n ";
  13. Echo "test1 \ t ";
  14. Echo "test2 \ t \ n ";
  15. ?>


Php, excel

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.