Hi,
I want to get only the header and footer string in word 2003 using c#, kindly help me out.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Bharath PeggemPosted Nov 4, 2015, 11:45 PM
oWord = new Microsoft.Office.Interop.Word.Application();
oWord.Visible = false; //to avoid displaying the Word Application
object strDocName = @"d:\test.doc";
object objBool = false;
object objNull = System.Reflection.Missing.Value;
Document oMyDoc = oWord.Documents.Open(ref strDocName, ref objBool, ref objBool, ref objBool, ref objNull,
ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull, ref objNull);
object objReference = System.Reflection.Missing.Value;
object objFoot = "this is footer";
object objStart = 0;
object objEnd = oMyDoc.Words.Count;
if (oMyDoc.Sections.Count > 0)
{
oMyDoc.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text = "My Header";
oMyDoc.Sections[1].Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Text = "My Footer";
}