Codeigniter: a simple way to generate an Excel document _ PHP Tutorial

Source: Internet
Author: User
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...

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.