PHPExcel用法
1.没有提示直接下载到指定目录
> require_once FCPATH.'shared/libraries/PHPExcel.php';
>$resultPHPExcel = new PHPExcel();
>$resultPHPExcel->getActiveSheet()->setCellValue('A1', '用户UID');
>$i = 2;
foreach($dataList as $row){
> $resultPHPExcel->getActiveSheet()->setCellValue('A' . $i, $row['uid']);
>
> $i++;
}
导出文件
$outputFileName = 'order_'.date('Y-m-d',time()).'.xls';
> // $filePath = 'APPPATH.'/logs/stat/'.date('Y/m/',time())';
> $filePath = '/tmp/';
> $objWriter =PHPExcel_IOFactory::createWriter($resultPHPExcel, 'Excel2007');
> $objWriter->save($filePath.$outputFileName);
2.有浏览器提示的下载
> $outputFileName = 'batchCount'.date('Y-m-d',time()).".xls";
> $xlsWriter = new PHPExcel_Writer_Excel5($resultPHPExcel);
> header("Content-Type: application/force-download");
> header("Content-Type: application/octet-stream");
> header("Content-Type: application/download");
> header('Content-Disposition:inline;filename="'.$outputFileName.'"');
> header("Content-Transfer-Encoding: binary");
> header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
> header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
> header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
> header("Pragma: no-cache");
> $xlsWriter->save( "php://output" );