24 Votes

PHPExcel: Change Font Size

Question by PC Control | 2015-05-31 at 21:20

I am using the library PHPExcel in order to be able to create some Excel documents respectively XLSX files on my website dynamically.

Now, I would like to modify the font size of some cells in the spreadsheet. Up to now, all text is written in the default font size.

Is this possible? And if so, with which function?

ReplyPositiveNegative
2Best Answer2 Votes

With getFont()->setSize(), you can set the font size of one or several cells.

As an example, the following code we are setting the text in cell A1 to font size 18:

$objPHPExcel->getActiveSheet()
            ->getStyle("A1")
            ->getFont()
            ->setSize(18);

If we would like to adjust multiple cells at the same time, we can also define a larger range:

$objPHPExcel->getActiveSheet()
            ->getStyle("B1:B10")
            ->getFont()
            ->setSize(18);

For instance, here, we are selecting the cells B1 to B10, with which we are setting the font size in some fields of the second column.
2015-06-01 at 18:35

ReplyPositive Negative
Reply

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.