|
楼主 |
发表于 2009-3-22 18:05:02
|
显示全部楼层
本帖最后由 linger308 于 2009-3-22 18:11 编辑
下载个excel plugins ,安装后运行的效果一样,插件名to_excel_pi.php,路径:system\plugins下,插件代码为:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
function to_excel($query, $filename='exceloutput',$fields=FALSE)
{
$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();
if (!$fields) {
$fields = $query->list_fields();
}
if ($query->num_rows() == 0) {
echo '<p>The table appears to have no data.</p>';
} else {
foreach ($fields as $field) {
$headers .= $field . "\t";
}
foreach ($query->result() as $row) {
$line = '';
foreach($row as $value) {
$value = str_replace("\r\n","",$value);
$line .= iconv("UTF-8","GB2312",$value) . "\t";
}
$data .= $line . "\r";
}
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=$filename.xls");
echo "$headers\n$data";
}
}
程序文件
<?php
class Userbaoeexcel extends Controller
{
function Userbaoeexcel()
{
parent::Controller();
}
function index()
{
$this->load->plugin('to_excel');
$sql = "select city,danwei,user,u_sn,mac,cpu,hddid,ip,ipout,time from cdb_upass_faildetail";
$query=$this->db->query($sql);
to_excel($query);
}
}
?>
运行的结果在FIREFOX下正常导出数据到EXCEL,奇怪的是在IE下输入http://localhost/116cii/index.php/Userbaoeexcel/index 每次都提示出错,出错内容如下,再次刷新提示同样错误。
若输入localhost/116cii/index.php/Userbaoeexcel/index去掉http://头,运行一次提示出错,出错内容同上,在次刷新可以导出。此问题困扰小弟两天了,真切希望高手给以指导,诚谢。 |
|