Excerpt |
---|
To create and format spreadsheet headers and footers, use |
...
...
object, which can be retrieved using |
...
...
...
methods. |
Info |
---|
To see spreadsheet headers and footers in Excel, open the File menu, select Page Setup, and select the Header/Footer tab. |
To format a header or footer in script, include formatting codes within the SetContent() call, for example:
Code Block | ||||
---|---|---|---|---|
| ||||
using SoftArtisans.OfficeWriter.ExcelWriter; public class HeaderFooterDemo : System.Web.UI.Page { protected void Page_Load(object sender, System.EventArgs e) { ExcelApplication xla = new ExcelApplication(); Workbook wb = xla.Create(); Worksheet sheet1 = wb.Worksheets[0]; PageSetup pgsetup = sheet1.PageSetup; HeaderFooterSection leftHeader = PageSetuppgsetup.GetHeader(HeaderFooterSection.Section.Left); leftHeader.SetContent("Document name: &F"); HeaderFooterSection centerHeader = PageSetuppgsetup.GetHeader(HeaderFooterSection.Section.Center); centerHeader.SetContent("Basic Report"); HeaderFooterSection rightHeader = PageSetuppgsetup.GetHeader(HeaderFooterSection.Section.Right); rightHeader.SetContent("Generated by OfficeWriter"); HeaderFooterSection leftFooter = PageSetuppgsetup.GetFooter(HeaderFooterSection.Section.Left); leftFooter.SetContent("Created on date &D"); HeaderFooterSection centerFooter = PageSetuppgsetup.GetFooter(HeaderFooterSection.Section.Center); centerFooter.SetContent("Page &P of &N"); HeaderFooterSection rightFooter = PageSetuppgsetup.GetFooter(HeaderFooterSection.Section.Right); rightFooter.SetContent("Create at time &T"); } } |
...
When opening an existing Excel spreadsheet, ExcelWriter will preserve the header and footer formatting created in Excel. However, if you change the header/footer text in your ExcelWriter script and do not include Formatting Codes, the formatting created in Excel will be overwritten and default formatting will be applied. To preserve header/footer formatting created in Excel, do not change header/footer text in script.
...
- In Microsoft Excel, open the File menu and select Page Setup... #
- Select the Header/Footer tab.
- # Select a header and/or footer from the drop-down list.
!headerfootertab.jpg!
*
Or*, create a custom header/footer.
!customheader.jpg!
# - Save the spreadsheet.
- # In an ExcelWriter script, open the spreadsheet containing headers/footers. Use either ExcelTemplate.Open or ExcelApplication.Open to open the spreadsheet.
- # Modify the spreadsheet in script. Do not change the text of headers and footers; if you do, the original formatting will be overwritten and default formatting will be applied. \