所有单元格居中:
$objPHPExcel->getDefaultStyle()->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getDefaultStyle()->getAlignment()->setVertical(\PHPExcel_Style_Alignment::VERTICAL_CENTER);
单个单元格居中:
$objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
合并单元格:
$objPHPExcel->getActiveSheet()->mergeCells( 'A1:AH1' );
背景填充颜色 :
//设置填充的样式和背景色
$objPHPExcel->getActiveSheet()->getStyle( 'A1:E1')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle( 'A1:E1')->getFill()->getStartColor()->setARGB('FF808080');
设置字体颜色 :
$objPHPExcel->getActiveSheet()->getStyle( 'A1:E1)->getFont()->getColor()->setARGB(PHPExcel_Style_Color::COLOR_WHITE);
设置字体加粗 :
$excel_php->setActiveSheetIndex(0)->getStyle("A2:A19")->getFont()->setBold(true);
设置单元格边框 锚:bbb
$styleThinBlackBorderOutline = array(
'borders' => array (
'outline' => array (
'style' => \PHPExcel_Style_Border::BORDER_THIN, //设置border样式 'color' => array ('argb' => \PHPExcel_Style_Color::COLOR_WHITE), //设置border颜色),
)
);
$phpSheet->getStyle( 'A1:I2')->applyFromArray($styleThinBlackBorderOutline);
ASCII数字转换为字母:
$i =65;
$ch = chr($i);
ASCII字母转换为数字:
$ch ='A';
$i = ord($ch);
网友评论