set footer in all printed pages using phpexcel

不羁的心 提交于 2020-01-02 08:48:07

问题


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.


回答1:


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');



回答2:


Instead of copying your footer configuration you can do this:

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


来源:https://stackoverflow.com/questions/19241635/set-footer-in-all-printed-pages-using-phpexcel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!