Generate Excel files in PHP

Source: Internet
Author: User
Tags header
Excel| Build Excel

PHP to generate Excel documents is too simple, it is estimated that everyone will use, so share out.
Let's look at the code:
?
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";
?>
In the PHP environment to run the above code, you can see the browser to ask the user whether to download the Excel document, click Save, the hard drive on the more than an Excel file, use Excel to open will see the final results, how good it.
In fact, when doing real application, you can take the data out of the database, and then after each column of data plus \ t, after each row of data added \ n method echo out, in the beginning of PHP with header ("content-type:application/ Vnd.ms-excel "); indicates that the output is an Excel file, with the header (" Content-disposition:filename=test.xls "); The file name for the output is Text.xls. That's OK.


We can also modify the header to let him output more format files so that PHP is more convenient for processing 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.