之前看了使用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);
}
?>
怎么样,很简单吧?

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version
Visual web development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version
God-level code editing software (SublimeText3)

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment