问题
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