Home > Backend Development > PHP Tutorial > A simple way to generate Excel documents with Codeigniter_PHP tutorial

A simple way to generate Excel documents with Codeigniter_PHP tutorial

WBOY
Release: 2016-07-13 10:28:23
Original
1004 people have browsed it

I looked at the method of exporting data to Excel files using PHPExcel before, but it seemed more complicated. icech found a class for Codeigniter: CI-Excel-Generation-Library, which is very simple to use.

1. Download CI-Excel-Generation-Library

Address: https://github.com/JOakley77/CI-Excel-Generation-Library

2. Put Excel.php into libraries

3. How to use:

Generate excel from database

Copy code 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 excel from array

Copy code 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 about it, it’s very simple, right?

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/788631.htmlTechArticleI have seen the method of exporting data to Excel files using PHPExcel before, but it seems more complicated. icech found a class for Codeigniter: CI-Excel-Generation-Library, using the method...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template