Write Microsoft Word Document Header and Footer with C#

Again I am rewriting some of the more popular entries in this blog as C#. It’s good exercise for me and good for you because you get the code another way. Well at least that’s the theory! This entry writes to the header and footer of a document in Microsoft Word The vb.net version was here. The only downside to all of this is that this is only tested against Office 2010. The old version I had Office 2000, XP and 2003 on my machine. Essentially however it is the same code. If you have any questions of course please feel free to leave a comment or email me.

public void WriteHeaderandFooterinWordDocument()
Word.Document oDoc = new Word.Document();
oDoc.Application.Visible = true;
oDoc.Content.Application.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekCurrentPageHeader;// = Convert.ToInt32(Word.WdSeekView.wdSeekCurrentPageHeader);
oDoc.Content.Application.Selection.TypeText(“Martens “);
oDoc.Content.Application.Selection.Fields.Add(oDoc.Content.Application.Selection.Range, Word.WdFieldType.wdFieldEmpty, “PAGE”);
oDoc.Content.Application.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekMainDocument;
oDoc.Content.Application.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekCurrentPageFooter;
oDoc.Content.Application.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekMainDocument;

I’m on Facebook

, , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

  1. [RESOLVED]read MS word document Header and footer using c#. | ASP Questions & Answers
  2. [RESOLVED]read MS word document Header and footer using c#. | ASP Web Form Data Control
  3. [RESOLVED]read MS word document Header and footer using c#. | ASP.NET MVC

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: