Free Support Forum - aspose.com

How to exclude Header & Footer to process...?

Hi all,

I am using aspose.words for an apllication. and want to scan (process each body text) whole document excluding header and footers. Is there any way to do so by which I can only access text without header and footers.

Thanks in advance.

Regards,

Prafull Gupta

Hi

Thanks for your inquiry. The Body class represents a container for the main text of a section. For more information see the following link.
http://www.aspose.com/Products/Aspose.Words/Api/Aspose.Words.Body.html

Hope this helps.

Please feel free to ask if you have any question about using Aspose.Words, I will be happy to help you.

Best regards.

I have checked that link. But still didn't get solution for my problem.Actually What I want is to exclude header-footers from document processing and at the time of response I need these headers-footers once again. I think I can save header footers and then pass the document for processing and after processing just add the previous header footer. Is there any way to do so. Or if you have some solutions for the same. then please tell me.

Thanks,

Prafull Gupta

Hi

Body content does not contain header and footer. So if you process Body content then you will not process header and footer.

Also you can provide me your code and sample document. I will investigate this and try to help you.

Best regards.

I am now able to extract the header footer details from the document. But When I am going to insert these header footers again the results are not excepted. The footer is come with numbers(I think that is page number). I am using the following code to Add header footer

Dim builder As DocumentBuilder = New DocumentBuilder(myDoc)

builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary)

builder.Write(headerText)

builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary)

builder.Write(footerText)

Now I am not getting why the numbers are coming with footer....

Pls. help

Thanks,

Prafull Gupta

Hi

Thanks for your inquiry, but it is not quite clear for me what you would like to do. If you would like to insert header or footer into the document then please refer this link
http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/create-headersfooters-using-documentbuilder.html

If you would like to remove header or footer from document then you can try using

doc.FirstSection.ClearHeadersFooters();

or

doc.FirstSection.HeadersFooters.Clear();

Best regards.

Hi Let me once again try to clear my requirements:

I have a document with text in black color (body as well as header/footer). Now I want to do the following:

1. Color the alternate charaters in red and blue (only body of the document).

2. No impact on the header and footer text

I know how to color the text but my problem is it is getting applied to Header/Footer text also even if I use the Body object. Please advise.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for additional information. I think that you can try using the following code.

public void Test080()

{

Document doc = new Document(@"Test080\in.doc");

//Create regex

Regex regex = new Regex("test");

foreach (Section section in doc.Sections)

{

//Process only body

section.Body.Range.Replace(regex, new ReplaceEvaluator(Replace080), false);

}

//Save output document

doc.Save(@"Test080\out.doc");

}

ReplaceAction Replace080(object sender, ReplaceEvaluatorArgs e)

{

//Change color

(e.MatchNode as Run).Font.Color = Color.Red;

return ReplaceAction.Skip;

}

Hope this helps.

Best regards.