Home >php教程 >php手册 >Codeigniter生成Excel文档的简单方法

Codeigniter生成Excel文档的简单方法

WBOY
WBOYOriginal
2016-06-13 09:33:46979browse

之前看了使用PHPExcel中导出数据到Excel文件的方法,但是似乎比较复杂。icech找到了一个针对Codeigniter的类:CI-Excel-Generation-Library,使用方法十分简单。

1、下载CI-Excel-Generation-Library

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

2、将Excel.php放到libraries里面

3、使用方法:

从数据库生成excel

复制代码 代码如下:

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



从数组生成excel

复制代码 代码如下:

public function export() {
$titles = array('field1', 'field2', 'field3');
$array = array();
for ($i = 0; $i $array[] = array($i, $i+1, $i+2);
}
$this->excel->make_from_array($titles, $array);
}
?>



怎么样,很简单吧?
Statement:
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