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?