Excel Plugin
The following plugin will generate a tab-delimited file, and feed it
to the client as an Excel file.
$this->load->plugin('to_excel');
$this->db->use_table('tablename');
$this->db->select('field1', 'field2');
// run joins, order by, where, or anything else here
$query = $this->db->get();
to_excel($query, ['filename']); // filename is optional, without it, the plugin will default to 'exceloutput'
So you could run:
to_excel($query, 'myfile'); // outputs myfile.xls
to_excel($query); // outputs exceloutput.xls
// you could also use a model here
to_excel($this->model_name->functioncall());
/system/plugins/to_excel_pi.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
* Excel library for Code Igniter applications
* Author: Derek Allard, Dark Horse Consulting, www.darkhorse.to, April 2006
*/
function to_excel($query, $filename='exceloutput')
{
$headers = ''; // just creating the var for field headers to append to below
$data = ''; // just creating the var for field data to append to below
$obj =& get_instance();
$fields = $query->field_data();
if ($query->num_rows() == 0) {
echo '<p>The table appears to have no data.</p>';
} else {
foreach ($fields as $field) {
$headers .= $field->name . "\t";
}
foreach ($query->result() as $row) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
}
$data = str_replace("\r","",$data);
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=$filename.xls");
echo "$headers\n$data";
}
}
?>
分享到:
相关推荐
icech找到了一个针对Codeigniter的类:CI-Excel-Generation-Library,使用方法十分简单。1、下载CI-Excel-Generation-Library地址:https://github.com/JOakley77/CI-Excel-Generation-Library2、将Excel.php放到...
PHPExcel是用来操作OfficeExcel文档的一个PHP类库,Codeigniter是一个功能强大的PHP框架。二者结合就能起到非常棒的效果,需要的朋友可以参考下
本文实例讲述了CodeIgniter生成静态页的方法。分享给大家供大家参考,具体如下: 现在我们来开发如何让CI框架生成静态页面.下面直接帖代码: $this->output->get_output(); 使用这个方法,你可以可以得到将要输出的...
1.建立了一个名为sitemap的控制器复制代码 代码如下:<?...defined(‘BASEPATH’)) exit (‘No direct script access allowed’);class Sitemap extends CI_Controller{ public function __construct() { parent::...
NULL 博文链接:https://justcoding.iteye.com/blog/561475
具体用途参见http://blog.csdn.net/u011250882/article/details/49311933
NULL 博文链接:https://justcoding.iteye.com/blog/558776
PHP框架之CodeIgniter留言板实例PHP框架之CodeIgniter留言板实例PHP框架之CodeIgniter留言板实例PHP框架之CodeIgniter留言板实例PHP框架之CodeIgniter留言板实例PHP框架之CodeIgniter留言板实例PHP框架之CodeIgniter...
CodeIgniter最新版本,开源、免费、轻量级的web编程,基于MVC的编程架构能大大提高php编码生产力。
CodeIgniter框架
codeigniter 代码实例分享,基于jquery1.4,codeigniter,eclipse 开发
敏捷php开发框架CodeIgniter 1.7.1中文手册
CodeIgniter_2.1.4.zip
CodeIgniter 架构 教程. CodeIgniter 架构的使用说明教程.
codeigniter分页