We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Footer Page number not displaying correctly

With Aspose 20.4 I’m finding with the following code…

const string FooterBold = "&\"Arial,Bold\"&6";
const string FooterStandard = "&\"Arial,Standard\"&6";

string testFile = "Book1.xlsx";
using (var inputStream = File.OpenRead($@"E:\Temp\{testFile}"))
	using (var outputStream = File.Create($@"E:\Temp\{DateTime.Now:yyyyMMdd-HHmm-ss}_{testFile}"))

		Workbook workbook = new Workbook(inputStream);
		foreach (Worksheet sheet in workbook.Worksheets)
			PageSetup pageSetup = sheet.PageSetup;

			pageSetup.SetFooter(0, $"{FooterStandard}XXX-XXXX-XX-0000-00.0");

			string footerText = $"{FooterBold}Approver {FooterStandard}| Xxxxxxxxxxx Xxxxxxx | ";
			footerText += $"{FooterBold}Owner {FooterStandard}| Xxxxxxxxxxx Xxxxxxx | ";
			footerText += $"{FooterBold}Effective {FooterStandard}| 26/07/2019";

			// Set Footer

			string footerPage = "&\"Arial,Standard\"&6P. &P of &N";
			pageSetup.SetFooter(2, footerPage);

		SaveFormat format = FileFormatUtil.ExtensionToSaveFormat(".xslx");
		workbook.Save(outputStream, format);

I’m finding the text in the right hand section appearing in the excel document is "P. " I was expecting something like “P. 1 of 5”.

When you comment out the code for either the right hand section or the middle section, mysteriously the expected text in the right hand section is output.


Thanks for the code segment and details.

After an initial test, I am able to reproduce the issue as you mentioned by using your sample code with a simple Excel file (I created it manually having some data in it). I found the text in the right hand (footer) section appearing in the Excel document is cut, i.e., "P. " only instead of something like “P. 1 of 4”. When I commented out the code of setting footer for either the left hand section or the middle section, strangely the expected text in the right hand section is displayed. I have logged a ticket with an id “CELLSNET-47331” for your issue. We will look into it soon.

Once we have an update on it, we will let you know.

It is limitation of Ms Excel that the length of whole header/footer must be less than 256.
The whole footer is
string footer = “&L” + pageSetup.GetFooter(0) + “&C” + footerText + “&R” + footerPage;

We have to remove exceeded the setting ,otherwise MS Excel will report that the file is corrupted.

Hi thanks, for this information, I was wondering if you would be able to tell us is that 256 header and footer combined? Or 256 characters allowed in the header and 256 characters allowed in the footer?


A max of 255 chars are allowed in whole header. Similarly there should not be more than 255 chars in the whole footer.