dannyl
July 31st, 2009, 05:24 PM
I'm using automation to create a word document using C#. I've got it working pretty well but need to add a footer. I've done this with the following code.
foreach (Microsoft.Office.Interop.Word.Section section in wordDoc.Sections)
{
Object CurrentPage = Microsoft.Office.Interop.Word.WdFieldType.wdFieldPage;
section.Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Fields.Add(section.Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range, ref CurrentPage, ref oMissing, ref oMissing);
section.Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.set_Style(ref oBodyStyleCenter);
}
That works fine, but when I open the word doc up after my application closes the headers and footers are not displayed. If I go to View->Header and Footers, they show up with my page number in them.
So my question is, how do I programatically get them to show up? I'm sure I'm missing some stupid little thing.
Thanks
foreach (Microsoft.Office.Interop.Word.Section section in wordDoc.Sections)
{
Object CurrentPage = Microsoft.Office.Interop.Word.WdFieldType.wdFieldPage;
section.Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Fields.Add(section.Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range, ref CurrentPage, ref oMissing, ref oMissing);
section.Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.set_Style(ref oBodyStyleCenter);
}
That works fine, but when I open the word doc up after my application closes the headers and footers are not displayed. If I go to View->Header and Footers, they show up with my page number in them.
So my question is, how do I programatically get them to show up? I'm sure I'm missing some stupid little thing.
Thanks