add image & text to the header

Topics: Developer Forum, Project Management Forum, User Forum
Apr 10, 2009 at 10:45 AM
Edited Apr 10, 2009 at 11:32 AM

Is it possible to add both image and some text to the header?

I tried the following code

// setting page Header && Footer
$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&CPlease treat this document as confidential!');
// adding LOGO to the header
$objDrawing = new PHPExcel_Worksheet_HeaderFooterDrawing();
$objPHPExcel->getActiveSheet()->getHeaderFooter()->addImage($objDrawing, PHPExcel_Worksheet_HeaderFooter::IMAGE_HEADER_CENTER);

but it seems that these elements (image and text) can exist only separatly.

in this example text "Please treat this document as confidential!" is lost somewhere.

although excel2007 allows to add both images and text to header/footer

--edited x2
after some tests I realised, that setOddHeader() method really sets the header, so I have to save previous state before setting new header.

something like that:
$currentHeader = $objPHPExcel->getActiveSheet()->getHeaderFooter()->getOddHeader(); $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader($currentHeader.'&C&G');

I think, the problem is solved, sorry for any inconvenience

Well, that problem has been solved.

Another question is how to put image after the text? like on the next line. in generated file it looks like the text is behind the image. but I want text to be like on the first line and the image like on the second line.
Is it possible?

Well, comparing XML returned by script and Excel I found some differences. You can see:
generated by script: <oddheader>&C&Hsome text! &C&G</oddheader>
generated by Excel: <oddheader>&C&Hsome text! &H&G</oddheader>

I changed that control-symbols and it seems that my another problem is solved. thanks ;)

Aug 27, 2010 at 3:20 PM

i am trying to do like yourself but it does not work. how do you did to work? can you post the code?


Aug 27, 2010 at 3:51 PM

Dear fudim.

Unfortunately I didn't use PHPExcel for about an year and forgot some things.

About your question. I can post the code. As you see, it already posted above.

About your problem. What have you done and what was the problem?

Aug 27, 2010 at 4:05 PM
Edited Aug 27, 2010 at 4:13 PM

i used the same code as you but the image do not appear.

i tryed to put image in one cell and it works fine, but on header do not appear anything.

i already do not know what else to do..=S

here is my code:

$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&CRelatório HACCP');

$objDrawing = new PHPExcel_Worksheet_HeaderFooterDrawing();
$objPHPExcel->getActiveSheet()->getHeaderFooter()->addImage($objDrawing, PHPExcel_Worksheet_HeaderFooter::IMAGE_HEADER_CENTER);

$currentHeader = $objPHPExcel->getActiveSheet()->getHeaderFooter()->getOddHeader();



ps:sorry for my bad english..=)

Aug 27, 2010 at 5:00 PM

do i need to include any file?

Jun 19, 2013 at 7:52 AM
AzriMan wrote:
--edited although excel2007 allows to add both images and text to header/footer
How can you do that? I use excel2007 and I can't add both +;=