记住用户名密码
$param = $this->request->param(); $ids = explode(',',$param['ids']); vendor("PHPExcel.PHPExcel"); $objPHPExcel = new \PHPExcel(); //水平居中 $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); //设置表头 $objPHPExcel->getActiveSheet() -> setCellValue('A1', '编号'); $objPHPExcel->getActiveSheet() -> setCellValue('B1', '昵称'); $objPHPExcel->getActiveSheet() -> setCellValue('C1', '手机号'); $objPHPExcel->getActiveSheet() -> setCellValue('D1', '注册时间'); $objPHPExcel->getActiveSheet() -> setCellValue('E1', '头像'); // 垂直居中 $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->setActiveSheetIndex(0)->getStyle('D')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->setActiveSheetIndex(0)->getStyle('E')->getAlignment()->setVertical(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); //设置宽 $subObject = $objPHPExcel->getSheet(); $subObject->getColumnDimension('A')->setWidth(10); $subObject->getColumnDimension('B')->setWidth(40); $subObject->getColumnDimension('C')->setWidth(40); $subObject->getColumnDimension('D')->setWidth(40); $subObject->getColumnDimension('E')->setWidth(16); $where['id'] = array('IN',$ids); $result = Db::name('users')->where($where)->select(); foreach ($result as $k=>&$v){ $v['time'] = date("Y-m-n H:i:s",$v['time']); $num = $k+2; $objPHPExcel->getActiveSheet()->setTitle("用户信息"); $objPHPExcel->getActiveSheet()->setCellValue('A'.$num, $v['id']); $objPHPExcel->getActiveSheet()->setCellValue('B'.$num, $v['nickname']); $objPHPExcel->getActiveSheet()->setCellValue('C'.$num, $v['mobile']); $objPHPExcel->getActiveSheet()->setCellValue('D'.$num, $v['time']); //导出图片 if($v['header_pic']){ $objDrawing[$num] = new \PHPExcel_Worksheet_Drawing(); $objDrawing[$num]->setPath('.'.$v['header_pic']); $objDrawing[$num]->setHeight(30);//照片高度 $objDrawing[$num]->setWidth(30); //照片宽度 $objDrawing[$num]->setCoordinates('E'.$num); $objDrawing[$num]->setOffsetX(18); $objDrawing[$num]->setOffsetY(5); $objDrawing[$num]->setWorksheet($objPHPExcel->getActiveSheet()); } //设置全表格高度 $objPHPExcel->getActiveSheet()->getRowDimension($num)->setRowHeight(50); } $objPHPExcel->getActiveSheet()->setCellValue(); $objPHPExcel->getActiveSheet()->getRowDimension()->setRowHeight(-1); $objPHPExcel->getActiveSheet()->getStyle()->getAlignment()->setWrapText(true); $objPHPExcel->createSheet(); $fileName = date('YmdHis'); ob_end_clean(); //清除缓存,防止乱码 header('pragma:public'); header('Content-type:application/vnd.ms-excel;charset=utf-8;'); header("Content-Disposition:attachment;filename={$fileName}.xls");//attachment新窗口打印inline本窗口打印 $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); exit;
目前有 0 条留言 其中:访客:0 条, 博主:0 条