$objPHPExcel = new PHPExcel();
//设置列宽
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth('11');
//设置默认对齐方式
$objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
//设置默认行高
$objPHPExcel->getActiveSheet()->getDefaultRowDimension()->setRowHeight(25);
//设置第一行高
$objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(80);
//合并单元格
$objPHPExcel->getActiveSheet()->mergeCells('A1:G1');
//设置字体
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(22);
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setName('黑体');
//设置自动换行
$objPHPExcel->getActiveSheet()->getStyle('E10')->getAlignment()->setWrapText(true);
//设置水平居中
$objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
//水平居左
$objPHPExcel->getActiveSheet()->getStyle('A2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
//水平居右
$objPHPExcel->getActiveSheet()->getStyle('C2')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
//设置边框
$objPHPExcel->getActiveSheet()->getStyle('A3')->getBorders()->getTop()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()->getStyle('A3')->getBorders()->getTop()->getColor()->setARGB('FF000000');
$objPHPExcel->getActiveSheet()->getStyle('A3')->getBorders()->getLeft()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()->getStyle('A3')->getBorders()->getLeft()->getColor()->setARGB('FF000000');
$objPHPExcel->getActiveSheet()->getStyle('A3')->getBorders()->getBottom()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()->getStyle('A3')->getBorders()->getBottom()->getColor()->setARGB('FF000000');
$objPHPExcel->getActiveSheet()->getStyle('A3')->getBorders()->getRight()->setBorderStyle(PHPExcel_Style_Border::BORDER_THIN);
$objPHPExcel->getActiveSheet()->getStyle('A3')->getBorders()->getRight()->getColor()->setARGB('FF000000');
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1','')
->setCellValue('A2','编号:' . $BNum)
->setCellValue('B3',$Cz)
->setCellValue('G19',number_format($Czcb, 2, '.', ''))
->setCellValue('C20',round($Cxl,2).'%')
->setCellValue('E22',"鉴定评估师(签章)". $Jdpgs ."\n复核人(签章)\n"."评估日期:".date("Y年m月d日",strtotime($Jdpgs_de)) );
// Rename sheet
$objPHPExcel->getActiveSheet()->setTitle('二手车鉴定评估报告单');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);
// Redirect output to a client's web browser (Excel5)
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('../excel/'. $Pg_Excel .'');
如果想生成多个sheet
$objPHPExcel1 = $objPHPExcel->createSheet(1);
$objPHPExcel1->setTitle('表2');
$objPHPExcel1->setCellValue('A1','');
//第二张表的操作都不需要用getActiveSheet()方法了
$objPHPExcel1->getRowDimension(1)->setRowHeight(80);
转载于:https://www.cnblogs.com/shanmao/p/3286805.html