Codeigniter: a simple method for generating Excel documents. I used PHPExcel to export data to an Excel file, but it seems complicated. Icech found a class for Codeigniter: CI-Excel-Generation-Library. before using this class, I learned how to export data to an Excel file in PHPExcel, but it seems complicated. Icech found a class for Codeigniter: CI-Excel-Generation-Library, which is easy to use.
1. download CI-Excel-Generation-Library
Address: https://github.com/JOakley77/CI-Excel-Generation-Library
2. put Excel. php in libraries.
3. usage:
Generate an excel file from a database
The code is as follows:
Public function export (){
$ This-> load-> library ('table ');
$ This-> load-> library ('Excel ');
$ SQL = $ this-> db-> get ('dbtable ');
$ Query-> result ();
$ This-> excel-> filename = 'abc123 ';
$ This-> excel-> make_from_db ($ SQL );
}
?>
Generate an excel file from an array
The code is as follows:
Public function export (){
$ Titles = array ('field1', 'field2', 'field3 ');
$ Array = array ();
For ($ I = 0; $ I <= 100; $ I ++ ){
$ Array [] = array ($ I, $ I + 1, $ I + 2 );
}
$ This-> excel-> make_from_array ($ titles, $ array );
}
?>
How are you doing?
Bytes. Icech found a class for Codeigniter: CI-Excel-Generation-Library. how to use it...