PHP generates Excel directly on the Web page to provide a way to download

Source: Internet
Author: User
In the PHP environment to run the above code, you can see the browser asks the user whether to download the Excel document, click Save, the hard disk on the more than one Excel file, using Excel Open will see the final result, how good it.
In fact, when doing real applications, you can take the data out of the database, and then follow the end of each column to add \ t, after each line of data to add \ n method echo out, at the beginning of PHP with the header ("content-type:application/ Vnd.ms-excel "), indicating that the output is an Excel file, with the header (" Content-disposition:filename=test.xls "), and that the output file name is Text.xls. This will be 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. ?>
Copy Code
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.