RichText in Header/Footer

Jan 6, 2010 at 9:59 PM
Edited Jan 6, 2010 at 10:05 PM

I need to be able to have rich text in a footer. I know how to do it for a cell but I can't seem to find any documentation on adding it to a header or a footer.

The end result needs to be:

                      Page 1
1-800-555-5555 www.website.com

Thanks

Developer
Jan 14, 2010 at 11:16 AM

I have added the following tip in section "Setting the print header and footer of a worksheet" under the table with all the codes that can be used for header/footer in the "PHPExcel developer documentation" to address your question.


The above table of codes may seem overwhelming first time you are trying to figure out how to write some header or footer. Luckily, there is an easier way. Let Microsoft Office Excel do the work for you.

For example, create in Microsoft Office Excel an xlsx file where you insert the header and footer as desired using the programs own interface. Save file as test.xlsx. Now, take that file and read off the values using PHPExcel as follows:

$objPHPexcel = PHPExcel_IOFactory::load('test.xlsx');
$objWorksheet = $objPHPexcel->getActiveSheet();
var_dump($objWorksheet->getHeaderFooter()->getOddFooter());
var_dump($objWorksheet->getHeaderFooter()->getEvenFooter());
var_dump($objWorksheet->getHeaderFooter()->getOddHeader());
var_dump($objWorksheet->getHeaderFooter()->getEvenHeader());


That reveals the codes for the even/odd header and footer. Experienced users may find it easier to rename test.xlsx to test.zip, unzip it, and inspect directly the contents of the relevant xl/worksheets/sheetX.xml to find the codes for header/footer.