//导出excel 只wps可以打开
public function takexcelAction(){
$name = $this->input->get_post('name');
$id = $this->input->get_post('id');
$time = date('Y-m-d H:i:s',time());
header('Content-type: text/html; charset=utf-8');
header("Content-type:application/vnd.ms-excel;charset=UTF-8");
header("Content-Disposition:filename=".$name."的补漏表-".$time.".xls");
echo "ID\t";
echo "平台ID\t";
echo "唯一标识\t";
echo "网址(pageurl)\t";
echo "错误原因\t";
echo "排序\t";
echo "添加时间\t";
echo "是否展示\t\n";
$result = $this->Dbs->getAll('traps',array(
'where'=>'platform_id = '.$id,
'page'=>'0',
'cur_page'=>'*',
'culumns'=>'*'
));
foreach($result as $res){
echo $res->id."\t";
echo $res->platform_id."\t";
echo $res->unique_id."\t";
echo $res->PageUrl."\t";
echo $res->reason."\t";
echo $res->orderby_id."\t";
echo $res->insert_time."\t";
echo $res->status."\t\n";
}
}
//导出excel(调用插件) 微软的和wps都可以打开
public function takexcel2Action(){
$name = $this->input->get_post('name');
$id = $this->input->get_post('id');
$time = date('Y-m-d H:i:s',time());
//获得数据 ---一般是从数据库中获得数据
$result = $this->Dbs->getAll('traps',array(
'where'=>'platform_id ='.$id,
'page'=>'0',
'cur_page'=>'*',
'culumns'=>'*'
));
L('PHPExcel');
//设置excel列名
$this->PHPExcel->setActiveSheetIndex(0)->setCellValue('A1','ID');
$this->PHPExcel->setActiveSheetIndex(0)->setCellValue('B1','平台ID');
$this->PHPExcel->setActiveSheetIndex(0)->setCellValue('C1','唯一标识');
$this->PHPExcel->setActiveSheetIndex(0)->setCellValue('D1','网址(pageurl)');
$this->PHPExcel->setActiveSheetIndex(0)->setCellValue('E1','错误原因');
$this->PHPExcel->setActiveSheetIndex(0)->setCellValue('F1','排序');
$this->PHPExcel->setActiveSheetIndex(0)->setCellValue('G1','添加时间');
$this->PHPExcel->setActiveSheetIndex(0)->setCellValue('H1','是否展示');
//把数据循环写入excel中
foreach($result as $key => $value){
$key+=2;
$this->PHPExcel->setActiveSheetIndex(0)->setCellValue('A'.$key,$value->id);
$this->PHPExcel->setActiveSheetIndex(0)->setCellValue('B'.$key,$value->platform_id);
$this->PHPExcel->setActiveSheetIndex(0)->setCellValue('C'.$key,$value->unique_id);
$this->PHPExcel->setActiveSheetIndex(0)->setCellValue('D'.$key,$value->PageUrl);
$this->PHPExcel->setActiveSheetIndex(0)->setCellValue('E'.$key,$value->reason);
$this->PHPExcel->setActiveSheetIndex(0)->setCellValue('F'.$key,$value->orderby_id);
$this->PHPExcel->setActiveSheetIndex(0)->setCellValue('G'.$key,$value->insert_time);
$this->PHPExcel->setActiveSheetIndex(0)->setCellValue('H'.$key,$value->status);
}
//导出代码
$this->PHPExcel->getActiveSheet() -> setTitle('bulou');
$this->PHPExcel-> setActiveSheetIndex(0);
$objWriter = PHPExcel_IOFactory::createWriter($this->PHPExcel, 'Excel2007');
$filename = $name."的补漏表-".$time.".xlsx";
header('Content-Type: application/vnd.ms-excel');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Cache-Control: max-age=0');
$objWriter -> save('php://output');
}
插件: (注PHPExcel要改为 Phpexcel,Linux上框架要求)