Sign In  Sign Up Live-Chat

Header and Footer clear method

Last post 05-12-2008, 11:07 PM by yogesh.agrawal. 4 replies.
Sort Posts: Previous Next
  •  05-08-2008, 5:20 AM 125992

    Header and Footer clear method

    Hi

    I want to delete the header or footer depending on our requirment.

    At present I see that there is only

    section.HeadersFooters.Clear(); Which will delete both header and footer in the section.

    Is there some method which will  delete only  Header or footer.

     


    Ashwini Raghavendra
     
  •  05-08-2008, 5:39 AM 125993 in reply to 125992

    Re: Header and Footer clear method

    Hi

     

    Thanks for your request. I think that the following code could be useful for you.

     

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

    //Loop through all section in document

    foreach (Section section in doc.Sections)

    {

        //Loop through HeaderFooter nodes

        foreach (HeaderFooter hf in section.HeadersFooters)

        {

            //Remove Primary footer (as an example)

            if (hf.HeaderFooterType == HeaderFooterType.FooterPrimary)

                hf.Remove();

        }

    }

    //Save output document

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

     

    Hope this helps.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  05-09-2008, 1:41 AM 126156 in reply to 125993

    Re: Header and Footer clear method

    Hi

    This will work only if section.HeadersFooters count is 1 .

    but if I have count more than one it will not loop through all.

     

    foreach (Section section in doc.Sections)

    {

        //Loop through HeaderFooter nodes

        foreach (HeaderFooter hf in section.HeadersFooters)

        {

            //Remove Primary footer (as an example)

            if (hf.HeaderFooterType == HeaderFooterType.FooterPrimary)

                hf.Remove();

        }

    }


    Ashwini Raghavendra
     
  •  05-09-2008, 6:00 AM 126203 in reply to 126156

    Re: Header and Footer clear method

    Hi

     

    Thanks for your request. Please try using the following code:

     

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

    //Loop through all section in document

    foreach (Section section in doc.Sections)

    {

        ArrayList hfList = new ArrayList();

        //Loop through HeaderFooter nodes

        foreach (HeaderFooter hf in section.HeadersFooters)

        {

            //Remove Primary footer (as an example)

            if (hf.HeaderFooterType == HeaderFooterType.FooterPrimary)

                hfList.Add(hf);

        }

        //Remove headerfooters

        foreach (HeaderFooter hf in hfList)

        {

            hf.Remove();

        }

    }

    //Save output document

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

     

    Hope this helps.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  05-12-2008, 11:07 PM 126600 in reply to 126203

    Re: Header and Footer clear method

    Thanks,This helps
    Ashwini Raghavendra
     
View as RSS news feed in XML