去官网下载PHPExcel
if($_POST['excel']){//如果提交,就执行excel方法
$list = $this->selectAll();//你想要写入excel的数据
$this->excel($list);
}
public function excel($list){
//引入PHPExcel相关文件
require_once "PHPExcel.php";
require_once 'PHPExcel/IOFactory.php';
require_once 'PHPExcel/Writer/Excel5.php';
//新建
$resultPHPExcel = new PHPExcel();
//设置参数
//设值
$resultPHPExcel->getActiveSheet()->setCellValue('A1', 'ID');
$i = 2;
foreach($list as $item){
$resultPHPExcel->getActiveSheet()->setCellValue('A' . $i, $item['id']);
$i ++;
}
//设置导出文件名
$outputFileName = 'total.xls';
$xlsWriter = new PHPExcel_Writer_Excel5($resultPHPExcel);
//ob_start(); ob_flush();
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" );
}
备注:引入PHPExcel路径仅供参考
有个phpexel的插件,自己去网上下,然后嵌入自己的项目就可以了
订单前面 加个复选框呗 提取选中的 订单 信息导出
file_put_contents()