44

I have been looking to change the font size of some Excel cells using a PHP library called PHPExcel.

This is what I tried:

$objPHPExcel->getActiveSheet()->getStyle("F1:G1")->getFont()->setFontSize(16);

The method above does not work. I was wondering if anyone knows how to do this?

Many thanks in advance.

AnchovyLegend
  • 12,139
  • 38
  • 147
  • 231

3 Answers3

85

Use setSize method instead setFontSize, it should work:

$objPHPExcel->getActiveSheet()->getStyle("F1:G1")->getFont()->setSize(16);
simhumileco
  • 31,877
  • 16
  • 137
  • 115
vvolkov
  • 1,172
  • 8
  • 10
9

If you want to use the style array, then you can do something like this:

$fontStyle = [
    'font' => [
        'size' => 16
    ]
];

$workbook->getActiveSheet()
    ->getStyle("F1:G1")
    ->applyFromArray($fontStyle);
simhumileco
  • 31,877
  • 16
  • 137
  • 115
0

You can using setSize or applyFromArray to setting font size, like code below:

$objPHPExcel->getActiveSheet()->getStyle("F1:G1")->getFont()->setSize(16);

OR

$objPHPExcel->getActiveSheet()->getStyle("F1:G1")->applyFromArray(array(
    "font"  => array(
        "size"  => 16
    )
));
ilham76c
  • 11
  • 1
  • 1