Background image in header/footer

Topics: Developer Forum, User Forum
Jan 12, 2009 at 9:13 AM

According to the phpExcel documentation it should be possible to add a background image in the header/footer, but I can't make it working.

My code:

$objDrawing = new PHPExcel_Worksheet_HeaderFooterDrawing();
$objDrawing->setPath('./images/test.gif');
$this->getActiveSheet()->getHeaderFooter()->addImage($objDrawing, PHPExcel_Worksheet_HeaderFooter::IMAGE_HEADER_LEFT);

$this->getActiveSheet()->getHeaderFooter()->setOddHeader('&G');

Can someone point me out what I do wrong ?

Thx in advance

Developer
Jan 12, 2009 at 11:36 PM
Are you using Excel2007 or Excel5 writer?

Jan 13, 2009 at 7:57 AM
I'm using Excel2007. I did try in Excel5 which doesn't either.
Developer
Jan 13, 2009 at 9:59 AM
You need a section code, such as for left, center, right

This would be for left section:

$this->getActiveSheet()->getHeaderFooter()->setOddHeader('&L&G');

Tip: When in doubt what values to use, create in MS Office Excel 2007 the spreadsheet the way you want it to look. Then use PHPExcel_Reader_Excel2007 to read off the correct values as they should be set.
Jan 13, 2009 at 11:34 AM
OOOOOH that was it :D :D :D

I tried everything except that :$

Thx koyama !!! Als thx for the tip !
Jan 13, 2009 at 11:53 AM
I do have another issue ..

I need to do the same code but for another sheet in the same workbook ... but this don't work he only puts the background on the first sheet. Each time it repairs the file and removes the drawings ("Removed Part: Drawing shape.")

is there a limitation ?
Developer
Jan 13, 2009 at 12:08 PM
Thanks, I verified the bug. Will post this in the issue tracker!

Developer
Jan 13, 2009 at 12:33 PM
Work item created in the issue tracker:
http://www.codeplex.com/PHPExcel/WorkItem/View.aspx?WorkItemId=8909

Mar 23, 2009 at 9:40 AM
hi,
I have a similar problem with image in header but I'm using excel5.
All is fine but there is no background image.
please What can I do to have a image header on an excel5 file ?


my code :

    require_once 'PHPExcel.php';
    require_once 'PHPExcel/IOFactory.php';
    require_once 'PHPExcel/Writer/Excel5.php';
    require_once 'PHPExcel/Worksheet/Drawing.php';

    $objPHPExcel = new PHPExcel();
    $sheet = $objPHPExcel->getActiveSheet();

    $objDrawing = new PHPExcel_Worksheet_HeaderFooterDrawing();
    $objDrawing->setPath('./image/entete.jpg');
    $objPHPExcel->getActiveSheet()->getHeaderFooter()->addImage($objDrawing,PHPExcel_Worksheet_HeaderFooter::IMAGE_HEADER_LEFT);
    $objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&L&G');

    $objWriter = new PHPExcel_Writer_Excel5($objPHPExcel);
    $objWriter->save("./excel/entete.xls");
    echo("fin");
Developer
Mar 24, 2009 at 7:04 PM
@clionhearts: Excel5 reader/writer does unfortunately not support header/footer images. I think it may be hard to implement, but it might come in the future.

Mar 25, 2009 at 11:09 AM
ok thanks for your answer