public function wExcel() { vendor("PHPExcel.PHPExcel"); // Create new PHPExcel object $objPHPExcel = new PHPExcel(); // Set properties $objPHPExcel->getProperties()->setCreator("ctos") ->setLastModifiedBy("ctos") ->setTitle("Office 2007 XLSX Test Document") ->setSubject("Office 2007 XLSX Test Document") ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.") ->setKeywords("office 2007 openxml php") ->setCategory("Test result file"); //set width $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(8); $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(10); $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(25); $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(12); $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(20); $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(10); $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(12); $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(12); $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(12); $objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(30); $objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(12); $objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(12); $objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(12); $objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(12); $objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(12); $objPHPExcel->getActiveSheet()->getColumnDimension('P')->setWidth(12); $objPHPExcel->getActiveSheet()->getColumnDimension('Q')->setWidth(12); $objPHPExcel->getActiveSheet()->getColumnDimension('R')->setWidth(12); $objPHPExcel->getActiveSheet()->getColumnDimension('S')->setWidth(12); $objPHPExcel->getActiveSheet()->getColumnDimension('T')->setWidth(12); $objPHPExcel->getActiveSheet()->getColumnDimension('U')->setWidth(12); $objPHPExcel->getActiveSheet()->getColumnDimension('V')->setWidth(12); $objPHPExcel->getActiveSheet()->getColumnDimension('W')->setWidth(12); //设置行高度 $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(22); $objPHPExcel->getActiveSheet()->getRowDimension('2')->setRowHeight(20); //set font size bold $objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setSize(10); $objPHPExcel->getActiveSheet()->getStyle('A2:W2')->getFont()->setBold(true); $objPHPExcel->getActiveSheet()->getStyle('A2:W2')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('A2:W2')->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN); //设置水平居中 // $objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT); // $objPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); // $objPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); // $objPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('F')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); // $objPHPExcel->getActiveSheet()->getStyle('G')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); // $objPHPExcel->getActiveSheet()->getStyle('H')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); // $objPHPExcel->getActiveSheet()->getStyle('I')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); // set table header content $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A1', '公司1:' . date('Y-m-d H:i:s')) ->setCellValue('A2', '公司') ->setCellValue('B2', '公司') ->setCellValue('C2', '公司') ->setCellValue('D2', '公司') ->setCellValue('E2', '公司') ->setCellValue('F2', '公司') ->setCellValue('G2', '公司') ->setCellValue('H2', '公司') ->setCellValue('I2', '公司') ->setCellValue('J2', '公司') ->setCellValue('K2', '公司') ->setCellValue('L2', '公司') ->setCellValue('M2', '公司') ->setCellValue('N2', '公司') ->setCellValue('O2', '年期') ->setCellValue('P2', '公司') ->setCellValue('Q2', '公司') ->setCellValue('R2', '公司') ->setCellValue('S2', '公司') ->setCellValue('U2', '公司') ->setCellValue('V2', '公司') ->setCellValue('W2', '公司'); // Miscellaneous glyphs, UTF-8 for ($i = 0; $i < count($data) - 1; $i++) { $objPHPExcel->getActiveSheet(0)->setCellValue('A' . ($i + 3), $data[$i]['id']); $objPHPExcel->getActiveSheet(0)->setCellValue('B' . ($i + 3), $data[$i]['code']); $objPHPExcel->getActiveSheet(0)->setCellValue('C' . ($i + 3), $data[$i]['company']['name']); $objPHPExcel->getActiveSheet(0)->setCellValue('D' . ($i + 3), $data[$i]['document_done'] == 1 ? "是" : "否"); $objPHPExcel->getActiveSheet(0)->setCellValue('E' . ($i + 3), $data[$i]['deliver_date']); $objPHPExcel->getActiveSheet(0)->setCellValue('F' . ($i + 3), $data[$i]['receiver']); $objPHPExcel->getActiveSheet(0)->setCellValue('G' . ($i + 3), $data[$i]['subproduct']['product']['insurance_company']['name'] . " - " . $data[$i]['subproduct']['product']['name'] . " - " . $data[$i]['subproduct']['name']); $objPHPExcel->getActiveSheet(0)->setCellValue('H' . ($i + 3), $data[$i]['sales']['name']); $objPHPExcel->getActiveSheet(0)->setCellValue('I' . ($i + 3), $data[$i]['contract_code']); $objPHPExcel->getActiveSheet(0)->setCellValue('J' . ($i + 3), $data[$i]['customer_name']); $objPHPExcel->getActiveSheet(0)->setCellValue('K' . ($i + 3), $data[$i]['policy_name_en']); $objPHPExcel->getActiveSheet(0)->setCellValue('L' . ($i + 3), $data[$i]['policy_name_cn']); $objPHPExcel->getActiveSheet(0)->setCellValue('M' . ($i + 3), $data[$i]['premium_usd']); $objPHPExcel->getActiveSheet(0)->setCellValue('N' . ($i + 3), $data[$i]['payment_method']); $objPHPExcel->getActiveSheet(0)->setCellValue('O' . ($i + 3), $data[$i]['maturity']); $objPHPExcel->getActiveSheet(0)->setCellValue('P' . ($i + 3), $data[$i]['begin_date']); $objPHPExcel->getActiveSheet(0)->setCellValue('Q' . ($i + 3), $data[$i]['status'] == 1 ? ($data[$i]['status'] == 2 ? ($data[$i]['status'] == 3 ? "已经提交管理员" : "待审核") : "需复查") : "审核通过"); $objPHPExcel->getActiveSheet(0)->setCellValue('R' . ($i + 3), $data[$i]['remark']); $objPHPExcel->getActiveSheet(0)->setCellValue('S' . ($i + 3), $data[$i]['sold_date']); $objPHPExcel->getActiveSheet(0)->setCellValue('T' . ($i + 3), ""); $objPHPExcel->getActiveSheet(0)->setCellValue('U' . ($i + 3), $data[$i]['rate_sales']); $objPHPExcel->getActiveSheet(0)->setCellValue('V' . ($i + 3), $data[$i]['admin_id']); $objPHPExcel->getActiveSheet(0)->setCellValue('W' . ($i + 3), $data[$i]['is_pay_all'] == 1 ? "是" : "否"); $objPHPExcel->getActiveSheet()->getStyle('A' . ($i + 3) . ':W' . ($i + 3))->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('A' . ($i + 3) . ':W' . ($i + 3))->getBorders()->getAllBorders()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN); $objPHPExcel->getActiveSheet()->getRowDimension($i + 3)->setRowHeight(16); } // sheet命名 $objPHPExcel->getActiveSheet()->setTitle('汇总表'); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0); // excel头参数 header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="数据(' . date('Ymd-His') . ').xls"'); //日期为文件名后缀 header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); //excel5为xls格式,excel2007为xlsx格式 $objWriter->save('php://output'); }