Go to the official website to download PHPExcel. You can select this plug-in. This plug-in is very powerful. Basically all the table formats you need are supported. Here I will only talk about the experience of exporting tables. There are many examples in this section, open it and check whether you can debug it. Here is the simplest method.
The most common table format is the. Xls file type, so find the decompressed file Examples/02types-xls.php and copy it to the desired location. In this file, you only need to change it:
Require_once dirname (_ FILE _). './Classes/PHPExcel. Php ';
You can change it to your file storage directory.
The rest is to loop your data array to the table.
Foreach ($ arrayobj as $ key => $ val ){
$ Excelnum = $ key + 1;
//----------------------------
$ ObjPHPExcel-> getActiveSheet ()
-> SetCellValue ("A $ excelnum", $ val ['result _ Code'])
-> SetCellValue ("B $ excelnum", $ val ['orderstate'])
-> SetCellValue ("C $ excelnum", $ val ['trade _ type'])
-> SetCellValue ("D $ excelnum", $ val ['launchmoney']/100)
-> SetCellValue ("E $ excelnum", $ val ['total _ handler'])
-> SetCellValue ("F $ excelnum", "". $ val ['transaction _ id'])
-> SetCellValue ("G $ excelnum", "". $ val ['Order _ id'])
-> SetCellValue ("H $ excelnum", $ val ['time _ end']);
}
Here, we should note that the array starts from 0, but the table starts from 1. So here we need to add 1, ABCDEF... to represent the columns of the table.
Download my file and put it under the environment where php can be run. Open and run it, a table file will be generated under the source code directory. Here I post the data to my example. I commented out, and I wrote the data directly in it, which can be changed according to my own situation.