Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel Interop: Formatting Footers

I am creating an Excel Worksheet from C# using Microsoft.Office.Interop.Excel, and I have not been able to get the footers the way the User wants them.

1) How can I put footer text in BOLD? 2) How can I put the page number in the footer? (Putting @"Page @[Page]" in as text does not work.)

Possible? Not Possible?

like image 752
SeaDrive Avatar asked Dec 01 '22 12:12

SeaDrive


2 Answers

The following codes are from the SpreadsheetGear for .NET help and are compatible with Excel:

  • &P - the current page number.
  • &N - the total number of pages.
  • &B - use a bold font*.
  • &I - use an italic font*.
  • &U - use an underline font*.
  • && - the '&' character.
  • &D - the current date.
  • &T - the current time.
  • &F - workbook name.
  • &A - worksheet name.
  • &"FontName" - use the specified font name*.
  • &N - use the specified font size*.

* Font codes appearing after any text or non-font codes will be ignored by SpreadsheetGear's printing engine.

like image 56
Joe Erickson Avatar answered Dec 04 '22 11:12

Joe Erickson


1) worksheet.PageSetup.LeftFooter = "&B Bold text &B"

2) worksheet.PageSetup.CenterFooter = "Page &P"

A tip - open Excel and set up the footer you require via the UI, recording a macro of the actions you take. Then open the VBA editor. The generated VBA will give you clues for how to acheive the same thing via the API. This trick can be used in lots of scenarios when automating Excel.

like image 42
Adam Ralph Avatar answered Dec 04 '22 13:12

Adam Ralph