How can I set the font size for the Footer of sheet?

Topics: User Forum
Apr 26, 2009 at 7:21 PM
I've try below code:

$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&16&CSet the Font to 16px');
AND:
$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&font size16&CSet the Font to 16px');

But the font size of footer isn't changed...What's the matter? Please help me, thanks!
Developer
Apr 26, 2009 at 7:51 PM
$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&C&16Set the Font to 16px');

Tip:
1. Create the workbook like you want it to be in MS Office Excel.
2. Read the file using PHPExcel_Reader_Excel2007

$reader = PHPExcel_IOFactory::createReader('Excel2007');
$excel = $reader->load('template.xlsx');

$sheet = $excel->getActiveSheet();
var_dump($sheet->getHeaderFooter()->getOddHeader());
var_dump($sheet->getHeaderFooter()->getEvenHeader());
var_dump($sheet->getHeaderFooter()->getOddFooter());
var_dump($sheet->getHeaderFooter()->getEvenFooter());

This will give you how to write the header or footer.

3. Alternatively, rename template.xlsx to template.zip, unzip it, and inspect file:

worksheets/sheet1.xml

Look towards the end for something like this:

<headerFooter><oddHeader>&amp;16&amp;CSet the Font to 16px</oddHeader></headerFooter>

This will also give you how to write the header or footer.

Just keep in mind that &amp; should be written as & when you write the string in PHPExcel.

Apr 27, 2009 at 2:09 AM
Edited Apr 27, 2009 at 2:11 AM
Sorry,I can not catch your meaning, the start section of my code is as:

$objPHPExcel = new PHPExcel();


//Set default font & size of Excel File
$objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setSize(8);
$objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setBold(false);

//Set Header
$objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setName('Arial');
$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&16&CComment');

......
Can you please show me how to setup it?
I just can found it out from the Developer documentation:

&N

Code for "total pages"<o:p></o:p>

&font size

Code for "text font size", where font size is a font size in points.<o:p></o:p>

but it doesn't work when I do by following it.

Thanks!
Developer
Apr 27, 2009 at 12:23 PM
Try to run this:

<?php
$objPHPExcel = new PHPExcel();

$objWorksheet = $objPHPExcel->getActiveSheet();
$objWorksheet->getHeaderFooter()->setOddHeader('&C&16Set the Font to 16px');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('test.xlsx');
?>


Apr 28, 2009 at 5:52 AM

I have made it by run as:

$objWorksheet->getHeaderFooter()->setOddHeader('&C&16Set the Font to 16px');   //okay!

However, the differnce with my wrote code is the order sequence of "&C" and "&16":

$objWorksheet->getHeaderFooter()->setOddHeader('&16&CSet the Font to 16px');  //don't work

I just don't know why.

thanks so much koyama!