Kim Stacks Kim Stacks - 3 months ago 42
PHP Question

set footer in all printed pages using phpexcel

What I want to achieve:

I am currently using PHPExcel and I want to display the filename and the page numbers in all the right hand side footer of all the printed pages.

Basically the format should be

filename.xlsx Page 1 / 2


where
filename.xlsx
is the file name

and 1 is the current page number

and 2 is the total page number

What I have tried:

I have tried the following code:

$this->objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&R&F');
$this->objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&R&P');
$this->objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&R&N');


On the print preview we saw there are 5 sheets

When we press print, the printer printed out 4 only.


  • First page we only see the filename

  • Second page we only see the number 4

  • Third page we only see the number 5

  • Fourth page we only see the number 4



The position is correct in all the pages, ie the right hand side footer.

The value is not.

Please advise.

Answer

If you need the footer displayed on all pages, then you need to save the value for odd and for even footers

$objPHPExcel->getActiveSheet()
    ->getHeaderFooter()->setOddFooter('&R&F Page &P / &N');
$objPHPExcel->getActiveSheet()
    ->getHeaderFooter()->setEvenFooter('&R&F Page &P / &N');
Comments