|
-
July 31st, 2009, 05:24 PM
#1
C# Word automation - footer added but not visible
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.
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
-
July 31st, 2009, 06:06 PM
#2
Re: C# Word automation - footer added but not visible
Start the Macro Recorder, turn on the Header/Footer, type something, then turn them off again.
Stop the recorder, and you should see what you left off. Check if they're OFF, then turn them ON
-
August 3rd, 2009, 08:31 AM
#3
Re: C# Word automation - footer added but not visible
Thanks worked, here's the line of code I'm using
Code:
wordApp.ActiveWindow.ActivePane.View.Type = Microsoft.Office.Interop.Word.WdViewType.wdPrintPreview;
However, that seems a bit hacky to me, up until that point in my code I wasn't having to deal with any ActiveWindow stuff, everything was done on the document.
It seems like there should be an option on the document itself to display or not display the headers and footers. Another thing leading me to believe this is that I saved an old version (no headers/footers displayed) as XML and a new version (headers/footers displayed) as XML and did a text compare. The only difference was that in the old document I had this tag defined and in the new one I did not
<w ocPr>
<w ontDisplayPageBoundaries/>
So if any one has dealt with this before, I'm still hopeful for a more appropriate way to turn on headers and footers.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|