下载 PHPExcel 放到tp中
vendor("PHPExcel.PHPExcel"); vendor("PHPExcel.Reader.Excel2007"); $objPHPExcel = new PHPExcel(); //这里要注意‘’ 要有这个。因为版本是3.1.2了。 $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel); $objPHPExcel->getActiveSheet()->setCellValue('A1', '编号');//这里是设置A1单元格的内容 $objPHPExcel->getActiveSheet()->setCellValue('B1', '二级分类');////这里是设置B1单元格的内容 $objPHPExcel->getActiveSheet()->setCellValue('C1', '名称'); $objPHPExcel->getActiveSheet()->setCellValue('D1', '剩余库存'); foreach ($list as $key => $value) { $i=$key+2;//表格是从1开始的 $objPHPExcel->getActiveSheet()->setCellValue('A'.$i, $value['kehu_goods_id']);//这里是设置A1单元格的内容 $objPHPExcel->getActiveSheet()->setCellValue('B'.$i, $value['cat_two_id']);////这里是设置B1单元格的内容 $objPHPExcel->getActiveSheet()->setCellValue('C'.$i, $value['goods_name']); $objPHPExcel->getActiveSheet()->setCellValue('D'.$i, $value['goods_stock']); } //接下来当然是下载这个表格了,在浏览器输出就好了 header("Pragma: public"); header("Expires: 0"); header("Cache-Control:must-revalidate, post-check=0, pre-check=0"); header("Content-Type:application/force-download"); header("Content-Type:application/vnd.ms-execl"); header("Content-Type:application/octet-stream"); header("Content-Type:application/download");; header('Content-Disposition:attachment;filename=test.xls'); header("Content-Transfer-Encoding:binary"); $objWriter->save('test.xls'); $objWriter->save('php://output');