Word For Mac 2008 Hw To Delete Header And Footer

Word For Mac 2008 Hw To Delete Header And Footer 9,9/10 8697 votes

How to delete Header and Footer from the first page of a Word Document: Many times users may not want to include header or footer to appear on the first page of the Word Document. As most of the times users like to make the first page as the title page of their document.

-->

This topic shows how to use the classes in the Open XML SDK 2.5 forOffice to programmatically remove all headers and footers in a wordprocessing document. It contains an example RemoveHeadersAndFooters method to illustrate thistask.

To use the sample code in this topic, you must install the Open XML SDK 2.5. Youmust then explicitly reference the following assemblies in your project.

  • WindowsBase

  • DocumentFormat.OpenXml (installed by the Open XML SDK)

You must also use the following usingdirectives or Imports statements to compilethe code in this topic.

RemoveHeadersAndFooters Method

You can use the RemoveHeadersAndFootersmethod to remove all header and footer information from a wordprocessing document. Be aware that you must not only delete the headerand footer parts from the document storage, you must also delete thereferences to those parts from the document too. The sample codedemonstrates both steps in the operation. The RemoveHeadersAndFooters method accepts a singleparameter, a string that indicates the path of the file that you want tomodify.

The complete code listing for the method can be found in the Sample Code section.

Calling the Sample Method

To call the sample method, pass a string for the first parameter thatcontains the file name of the document that you want to modify as shownin the following code example. Gpredict config file.

How the Code Works

The RemoveHeadersAndFooters method workswith the document you specify, deleting all of the header and footerparts and references to those parts. The code starts by opening thedocument, using the Open method and indicating that thedocument should be opened for read/write access (the final trueparameter). Given the open document, the code uses the MainDocumentPart property to navigate tothe main document, storing the reference in a variable named docPart.

Confirm Header/Footer Existence

Given a reference to the document part, the code next determines if ithas any work to do─that is, if the document contains any headers orfooters. To decide, the code calls the Count method of both the HeaderParts and FooterParts properties of the documentpart, and if either returns a value greater than 0, the code continues.Be aware that the HeaderParts and FooterParts properties each return anIEnumerable ofHeaderPart or FooterPart objects, respectively.

Remove the Header and Footer Parts

Given a collection of references to header and footer parts, you couldwrite code to delete each one individually, but that is not necessarybecause of the Open XML SDK 2.5. Instead, you can call the DeleteParts<T> method, passing in thecollection of parts to be deleted─this simple method provides a shortcutfor deleting a collection of parts. Therefore, the following few linesof code take the place of the loop that you would otherwise have towrite yourself.

Work with the Document Content

At this point, the code has deleted the header and footer parts, but thedocument still contains orphaned references to those parts. Before theorphaned references can be removed, the code must retrieve a referenceto the content of the document (that is, to the XML content containedwithin the main document part). Later, after the changes are made, thecode must ensure that they persist by explicitly saving them. Betweenthese two operations, the code must delete the orphaned references, asshown in the section that follows the following code example.

Delete the Header and Footer References

To remove the stranded references, the code first retrieves a collectionof HeaderReference elements, converts the collection to a List, and thenloops through the collection, calling the Remove method for each element found. Notethat the code converts the IEnumerablereturned by the Descendants method into a List so that itcan delete items from the list, and that the HeaderReference type that is provided bythe Open XML SDK 2.5 makes it easy to refer to elements of type HeaderReference in the XML content. (Without thatadditional help, you would have to work with the details of the XMLcontent directly.) Once it has removed all the headers, the code repeatsthe operation with the footer elements.

Sample Code

The following is the complete RemoveHeadersAndFooters code sample in C# andVisual Basic.

See also

I'm trying to format a manuscript using a Createaspace template. I had a hard time getting the pages numbers to work right (had to put in the last page number first, not the first page number first.) While I was figuring page numbers out, a single line appeared below the header and above the footer. I thought they were only there to show the limits of the text, but when I uploaded the file, they were still there.
Word For Mac 2008 Hw To Delete Header And FooterI've tried all the help topics Page setup - style - borders and anything else that might be related, but the lines won't go away.
I'm sure it's something simple, but I can't find it. How do I make the lines go away?
Thanks for any suggestions.
I'm using Windows Vista and I think OO 3.3