php method to set cell format: 1. Set the cell background color through the "setRGB('FFFF00');" method; 2. Merge cells through the "mergeCells('A1:F1')" method ;3. Set the font to be bold through the "setBold(true)" method.
php set cell format
Recommended: "PHP Video Tutorial"
PHPExcel Set style, background color, center, width, cell merge
//设置第一行背景色为FFFF00 $objPHPExcel->getActiveSheet()->getStyle('A1')->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setRGB('FFFF00'); //合并单元格 $objPHPExcel->getActiveSheet()->mergeCells('A1:F1'); //设置居中 $objPHPExcel->getActiveSheet()->getStyle('A1:F1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel->getActiveSheet()->getStyle('E2')->getFont()->setName('宋体') //字体 // ->setBold(true); //字体加粗 //设置宽度 $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
The above is the detailed content of How to format cells in php. For more information, please follow other related articles on the PHP Chinese website!