Set Font Color, Font Face and Font Size in PHPExcel

前端 未结 1 1281
无人共我
无人共我 2020-12-07 18:47

I\'m working in PHPExcel. I\'m beginner.When I\'m using following code and its working fine.

$phpExcel = new PHPExcel();

$phpExcel->getActiveSheet()->         


        
相关标签:
1条回答
  • 2020-12-07 19:21

    I recommend you start reading the documentation (4.6.18. Formatting cells). When applying a lot of formatting it's better to use applyFromArray() According to the documentation this method is also suppose to be faster when you're setting many style properties. There's an annex where you can find all the possible keys for this function.

    This will work for you:

    $phpExcel = new PHPExcel();
    
    $styleArray = array(
        'font'  => array(
            'bold'  => true,
            'color' => array('rgb' => 'FF0000'),
            'size'  => 15,
            'name'  => 'Verdana'
        ));
    
    $phpExcel->getActiveSheet()->getCell('A1')->setValue('Some text');
    $phpExcel->getActiveSheet()->getStyle('A1')->applyFromArray($styleArray);
    

    To apply font style to complete excel document:

     $styleArray = array(
       'font'  => array(
            'bold'  => true,
            'color' => array('rgb' => 'FF0000'),
            'size'  => 15,
            'name'  => 'Verdana'
        ));      
     $phpExcel->getDefaultStyle()
        ->applyFromArray($styleArray);
    
    0 讨论(0)
提交回复
热议问题