Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPExcel: Setting font size?

Tags:

php

phpexcel

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.

like image 511
AnchovyLegend Avatar asked Jan 09 '13 17:01

AnchovyLegend


People also ask

How do I change font size in phpExcel?

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

How do I change text color in phpExcel?

$phpExcel = new PHPExcel(); $phpExcel->getActiveSheet()->getStyle("A1")->getFont()->setBold(true) ->setName('Verdana') ->setSize(10) ->getColor()->setRGB('6F6F6F');


2 Answers

Use setSize method instead setFontSize, it should work:

$objPHPExcel->getActiveSheet()->getStyle("F1:G1")->getFont()->setSize(16); 
like image 133
vvolkov Avatar answered Nov 03 '22 18:11

vvolkov


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); 
like image 27
simhumileco Avatar answered Nov 03 '22 18:11

simhumileco