Free Support Forum -

Page number in footer for java


I would like to add automatic page numbers to the footer of a worksheet. Such can be done in excel by setting the footer text to "&[Page] of &[Pages]". However, when I try this:

outSheet = outBook.getActiveSheet();
outSheet.getPageSetup().setCenterFooter("&[Page] of &[Pages]");

My footer prints out as: "Page] of Pages]"

Is it possible to include automatic page number in the footer of an excel sheet? If so, how?



You should use setCenterFooter("&P of &N");

Please check

Excellent, thank you.

One minor suggestion, It would be nice to include a succinct version of information such as this in the javadocs. Many java devlopers use javadoc as the first place to look for information such as this. Also, copies of javadoc can be stored locally and easily accesible when programming without an internet connection.

I will however, more carefully check the wiki in the future :)


You can check declarations of PageSetup.setCenterFooter() method.

There are "See Also" tags which refer to the PageSetup.setCenterFooter() method in all other setting/getting header and footer mathods' doc .