Display page numbers in an Excel worksheet generated using C # .NET.

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

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

However, by default, I do not see page numbers on the output. I know to enable this through

excel options (View -> Header and Footer ...), but I want to automate this through C #.

Is it possible, if so, to kindly share a fragment for him.

Thank you regular student

+5
source share
2 answers

, - Office, , Visual Basic. , :

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

LeftFooter RightFooter.

+7

, , : Excel ;

    ws.PageSetup.CenterFooter = "&[Pages]/&[Pages]";  // This did not work

, :

    ws.PageSetup.CenterFooter = "&P/&N"; // This worked correctly

.

    ws.PageSetup.LeftHeader = "&[File]";  // This did not work
    ws.PageSetup.RightHeader = "&[Date]";  // This did not work

    ws.PageSetup.LeftHeader = "&F"; // This worked correctly
    ws.PageSetup.RightHeader = "&D"; // This worked correctly

, , , .

+6

All Articles