views:

229

answers:

2

Hello Stackers

Does anyone have an idea on how to include or input the page numbers in the excel sheet generated using C# code.

I use the libraries available in Microsoft.Office.Interop.Excel to generate the file.

However by default in the output i cannot see the page numbers. I know to enable this via

excel options (View --> Header and Footer ...) but i want to automate this via C#.

Is this possible, if yes kindly share the snippet for the same.

Thanks Constant Learner

+2  A: 

If I don't know how to code something in Office, I record my action as a macro and then I look at the generated code in the built-in Visual Basic editor. This is the relevant code it generated for adding a footer with page numbers:

ActiveSheet.PageSetup.CenterFooter = "Page &P of &N"

LeftFooter and RightFooter are also available.

ZippyV
A: 

Is it not possible without the usage of a macro ??

constant learner
Of course the code I provided is almost the same as the Excel interop. Just make sure to replace ActiveSheet with the variable that holds your Excel sheet.
ZippyV