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

Free Support Forum - aspose.com

Access Header & Footers


Hi,

I'm having trouble finding out how to access the headers and footers of an Excel document.

Using Aspose.Words, it is as simple as Document.Section(x).HeadersFooters, but I can’t seem to find the equivalent in the Cells assembly anywhere.

(What I need to do is remove all header sand footers in a workbook, so if there is an easy method to achieve this, please let me know.)

Many Thanks,

Shane

Hi Shane.

Well, Aspose.Cells for .NET does have API for your requirement, see some description.

1) To get header, you may use methods like:
PageSetup.GetHeader(int section).

2) To get footer, you may try:
PageSetup.GetFooter(int section).

3) To remove a header in a section(first section), please use:
PageSetup.SetHeader(0, “”)


I have also created a sample code for your reference:

Workbook excel = new Workbook();
excel.Open(“e:\test\hftest.xls”);
Worksheet worksheet = excel.Worksheets[0];
PageSetup pagesetup = worksheet.PageSetup;
string headersection1 = pagesetup.GetHeader(0);
string headersection2 = pagesetup.GetHeader(1);
string headersection3 = pagesetup.GetHeader(2);

string footersection3 = pagesetup.GetFooter(2);

//Remove the headers in first and second section of the sheet.
worksheet.PageSetup.SetHeader(0, “”);
worksheet.PageSetup.SetHeader(1, “”);

excel.Save(“e:\test\outhfbookout.xls”);

Thank you.

That’s great Amjad, I will give it a try now.

Thanks


That works fine - but is there a more efficent method than this?

(assumes a workbook object called Wbook):

For Each Sheet As Aspose.Cells.Worksheet In Wbook.Worksheets
For Section As Integer = 0 To 2

Sheet.PageSetup.SetHeader(Section, “”)
Sheet.PageSetup.SetFooter(Section, “”)

Next
Next


I’m thinking that there maybe a method to clear all headers and footers on a worksheet, similar to Words: Section.HeadersFooters.Clear()?

Thanks,

Shane

Hi,

Thanks for your suggestion.

We will add PageSetup.ClearHeaderFooter() method for your need.

We have added your feature request into our internal issue tracking system with an issue id:
CELLSNET-13935.

Thank you.


Thank you very much Amjad, that is very kind of you.

Shane

Hi,

Please try the attached version.

<span style=“font-size: 10pt; font-family: “Calibri”,“sans-serif”;”>We
have added PageSetup.ClearHeaderFooter() method.<o:p></o:p>



Thank you.

The issues you have found earlier (filed as 13935) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan