Simple way for Codeigniter to generate Excel documents

  • 2021-06-29 10:27:21
  • OfStack

Previously, you saw how to export data to an Excel file using PHPExcel, but it seems to be more complex.icech found a class for Codeigniter: CI-Excel-Generation-Library, which is easy to use with 10 points.

1. Download CI-Excel-Generation-Library

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

2. Place Excel.php in libraries

3. Usage:

Generating excel from a database

<?php
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

<?php
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);
}
?>


Well, it's easy, isn't it?


Related articles: