Use php to generate an excel file

Source: Internet
Author: User
Welcome to the Linux community forum and interact with 2 million technical staff. I believe that you often encounter the excel file export function during PHP development. Here, you can share a simple code to implement this function. Let's look at the code :? Header (Content-type: applicationvnd. ms-excel); header (Content-Disposition:

Welcome to the Linux community forum and interact with 2 million technical staff> I believe that you often encounter the excel file export function during PHP development. Here, you can share a simple code to implement this function. Let's look at the code :? Header ("Content-type: application/vnd. ms-excel"); header ("Content-Disposition:

Welcome to the Linux community forum and interact with 2 million technicians>

I believe that you often encounter the excel file export function during PHP development. Here, you can share a piece of simple code to implement this function.

Let's look at the Code:

  

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 ";

?>

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.