|
废话不多少,方法如下:
1、拷贝PHPExcel到system/libraries/下
2、system/libraries/再新建一个PHPExcel.php文件用来写一个继承原有的PHPExcel类,代码如下:
PHP复制代码
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
set_include_path(get_include_path().PATH_SEPARATOR .BASEPATH .'libraries/PHPExcel/PHPExcel');
require_once("PHPExcel/PHPExcel.php");
require_once("PHPExcel/PHPExcel/Writer/Excel5.php");//如果要生成Excel2007格式,可以加载Excel2007.php
/**
* DK_PHPExcel extends PHPExcel
* Author: Daker.W
* Create Time: 2010/08/10
**/
class DK_PHPExcel extends PHPExcel
{
function DK_PHPExcel ($config = array())
{
$this->CI =& get_instance ();
if ( ! in_array('phpexcel_lang'.EXT , $this->CI->lang->is_loaded, TRUE))
{
$this->CI->lang->load('phpexcel');
}
$this->local_time = time();
if (count($config) > 0)
{
$this->initialize($config);
}
parent ::__construct ();
log_message ('debug', "PHPExcel Class Initialized");
}
function initialize ($config = array())
{
foreach ($config as $key => $val)
{
if (isset($this->$key))
{
$this->$key = $val;
}
}
}
/**
* @param string $sFileName //输出的文件名
* @param string $oPHPExcel //PHPExcel对象
* @param string $sFileType //输出文件类型
* @param string $charset //输出编码
**/
function export_excel ($sFileName, $oPHPExcel, $sFileType='Excel5', $charset='utf-8')
{
$sFileName = iconv($charset, 'gb2312', $sFileName);
header("Content-Type: application/vnd.ms-excel; charset=$sFileType");
header("Content-Disposition: attachment;filename=$sFileName");
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory ::createWriter($oPHPExcel, $sFileType);
$objWriter->save('php://output');
}
}//End Class
?>
复制代码
3、控制器中的调用方法:
PHP复制代码
$this->load->library('phpexcel');
$this->phpexcel->setActiveSheetIndex(0); //取得第一个页
……
复制代码
刚接触CI一个月,请大家多多指教! |
评分
-
查看全部评分
|