废话不多说,直接贴代码,类库是phpexcel1.8,将类库解压出来,把classed文件夹里边的东西放到tp中的vender文件夹下边即可 。找不到可以到我的资源页里边下载

//这里引入PHPExcel文件注意路径修改
vendor("PHPExcel");
vendor("PHPExcel.Writer.Excel5");
vendor("PHPExcel.Writer.Excel2007");
vendor("PHPExcel.IOFactory");
$objExcel = new \PHPExcel();
$objWriter = \PHPExcel_IOFactory::createWriter($objExcel, 'Excel2007');
$objActSheet = $objExcel->getActiveSheet();
$key = ord("A");
$letter =explode(',',"A,B,C,D");
$arrHeader = array('编号','时间','手机号码','设备');
$lenth = count($arrHeader);
for($i = 0;$i < $lenth;$i++) {
$objActSheet->setCellValue("$letter[$i]1","$arrHeader[$i]");
};
foreach($datas as $k=>$v){
$k +=2;
$objActSheet->setCellValue('A'.$k, $v['id']);
$objActSheet->setCellValue('B'.$k, $v['insert_date']);
$objActSheet->setCellValue('C'.$k, $v['phone_num']);
$objActSheet->setCellValue('D'.$k, $v['machine']);
$objActSheet->getRowDimension($k)->setRowHeight(20);
} $outfile = "数据列表.xls";
ob_end_clean();
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header('Content-Disposition:inline;filename="'.$outfile.'"');
header("Content-Transfer-Encoding: binary");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
$objWriter->save('php://output'); //这里直接导出文件

请尊重经验,别只会照搬,谢谢