Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7502113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:45:28+00:00 2026-05-29T20:45:28+00:00

I have an Excel file made with PHPExcel which have an header with a

  • 0

I have an Excel file made with PHPExcel which have an header with a left aligned logo and right aligned date & user text. For the first page, I want a similar header (same logo and same date & user text) but with some added information (title and parameters of the file centered a couples lines later).

This is what I’m doing so far:

<?php

    $sheet = $this->_spreadsheet->getActiveSheet(); //_spreadsheet is an instance of PHPExcel

    $logo = new PHPExcel_Worksheet_HeaderFooterDrawing();
    $logo->setName('Logo');
    $logo->setPath(DOCUMENT_ROOT . '/public/logo.jpg'); //Path is OK & tested under PHP
    $logo->setHeight(38); //If image is larger/smaller than that, image will be proportionally resized
    $sheet->getHeaderFooter()->addImage($logo, PHPExcel_Worksheet_HeaderFooter::IMAGE_HEADER_LEFT);

    $sheet->getHeaderFooter()->setOddHeader('&L&G&RExport date: ' . date('Y-m-d H:i:s') . "\n" . 'User: ' . $user->name);

    if ($grid->getTitle() != '') {
        $sheet->getHeaderFooter()->setDifferentFirst(true);

        $sheet->getHeaderFooter()->addImage($logo, PHPExcel_Worksheet_HeaderFooter::IMAGE_HEADER_LEFT);
        $sheet->getHeaderFooter()->setFirstHeader('&L&G&C&"-,Bold"' . "\n\n\n" . $grid->getTitle() . "\n" . $grid->getParameters() . '&RExport date: ' . date('Y-m-d H:i:s') . "\n" . 'User: ' . $user->name);
    }

?>

For the “regular” header, logo and text is all there so everything is OK. For the first page header I have 2 problems:

  1. The logo isn’t showing on the first page header (but the text is OK).
  2. Since the centered title will be followed by some text (dynamically loaded with getParameters) I want the first page header to stretch to fit it’s content.

How can I do this with PHPExcel?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T20:45:29+00:00Added an answer on May 29, 2026 at 8:45 pm

    I don’t have an answer for why the logo isn’t showing on the first page header, but to stretch the height to fit the content you need to manually alter the page margins.

    I’m not sure the best way to do it, whether counting newline characters or what. But once you know how many lines you have, you could do something like:

    $headerHeight = ( $imageHeight / 72 ) + ( $headerLineCount * $lineHeight );
    $objPHPExcel->getActiveSheet()->getPageMargins()->setHeader( $margin );
    $objPHPExcel->getActiveSheet()->getPageMargins()->setTop( $margin + $headerHeight );
    

    ** The “$imageHeight / 72” clause is just a guess at how to convert your image’s screen height into inches.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an excel file which has more than 65536 rows. However, I can
I have an Excel file with one column which is filled with numbers. I
I have data of program usage in excel file, the data has date and
I have a function which is processing rows from an excel file.In this function,I
I'm using a text file to save the changes made by a user on
I have an Excel file (which has data imported from Oracle 10G Database) one
I have an excel file with four text columns: one of them is called
I have a JSP form which is made of <input type=file/> tag alone for
I have an Excel file that has a bunch of VBA and macro code
I have an Excel file that I need to import into a (new) Oracle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.