PHPExcel getting started tutorial-PHP source code

Source: Internet
Author: User
PHPExcel is a very powerful plug-in for excel operations. We can use the PHPExcel plug-in to read and write excel. Let's take a look at it. PHPExcel is a very powerful plug-in for excel operations. We can use the PHPExcel plug-in to read and write excel. Let's take a look at it.

Script ec (2); script

PHPExcel is a powerful excel export/import plug-in that can even export pdf files. It is a very useful php plug-in and is essential for php learning. So how to use it? Below is an example of PHPExcel Getting Started:

Php source code reference:

Require_once ("PHPExcel/PHPExcel. php ");
$ Excel = new PHPExcel (); // instantiate the PHPExcel class

// Set the author (optional)
$ Excel-> getProperties ()-> setCreator ("Reson ");

// The data to be exported is as follows:
$ Datas = array (
Array (
0 => 'uid ',
1 => 'username ',
2 => 'gender'
),
Array (
0 => '1 ',
1 => 'reson ',
2 => 'male'
),
Array (
0 => '2 ',
1 => 'anyse ',
2 => female'
)
);

// Start exporting. Note that $ I starts from 1 and cannot start from 0. The reason is as follows: 'A'. $ I. When I = 1, it is A1 (the first row, the first grid)
$ I = 1;
Foreach ($ datas as $ key => $ val ){
$ Excel-> getActiveSheet ()-> setCellValue ('A'. $ I, $ val ['0']);
$ Excel-> getActiveSheet ()-> setCellValue ('B'. $ I, $ val ['1']);
$ Excel-> getActiveSheet ()-> setCellValue ('C'. $ I, $ val ['2']);
$ I ++;
}

$ Excel-> getActiveSheet ()-> setTitle ('php learner list'); // For more information, see

$ FileName = 'test ';
Header ("Pragma: public ");
Header ("Expires: 0 ");
Header ("Cache-Control: must-revalidate, post-check = 0, pre-check = 0 ");
Header ("Content-Type: application/force-download ");
Header ("Content-Type: application/vnd. ms-execl ");
Header ("Content-Type: application/octet-stream ");
Header ("Content-Type: application/download ");;
Header ('content-Disposition: attachment; filename = "'.w.filename.'.xls "');
Header ("Content-Transfer-Encoding: binary ");

$ ObjWriter = PHPExcel_IOFactory: createWriter ($ excel, 'excel5 ');
$ ObjWriter-> save ('php: // output ');
?>




It looks like this, isn't it very useful?

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.