?
Solved

C# Word Header / Footer, using a table

Posted on 2009-04-08
1
Medium Priority
?
2,801 Views
Last Modified: 2012-05-06
I'm creating a dynamic word document, in which I am adding headers & footers. I have ran into an issue where I need to add page numbers on the left of my footer, and a disclaimer on the right of my footer. I figured the best way to do this would be to add a table to my footer, and separate the text with cells. Though I can't get it to work.

The code I added to the Code section is what I have tried so far.
Though after adding text to oTableFooter, its just being added to the body, not the footer.

All help is greatly appreciated.
Thanks!
Mike
Microsoft.Office.Interop.Word.Range wrdRng = oDoc.Bookmarks.get_Item(ref oEndOfDoc).Range;
oDoc.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekCurrentPageFooter;
Microsoft.Office.Interop.Word.Table oTableFooter = oDoc.ActiveWindow.Selection.Tables.Add(wrdRng, 1, 2, ref oMissing, ref oMissing);

Open in new window

0
Comment
Question by:jouwstrm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 3

Accepted Solution

by:
jouwstrm earned 0 total points
ID: 24100158
I think I just figured it out myself.

I resulted to just writing tabs to my footer, to try and space the text out... though it appears when you add tabs, it'll automatically assume you want the text in the left, center or right side of the page.

The following code snippet will add page numbers to the left side of each footer page, the date the document was created in the center of each footer page, and disclaimer text on the right of each footer page.

It is relative to how the text is aligned though. Aligning the text to the right, the first text you write to the footer will show up on the right. After doing one tab, the next text will be in the center.

Hope this helps anyone else having the same problem.
oDoc.ActiveWindow.ActivePane.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekCurrentPageFooter;
                    oDoc.ActiveWindow.ActivePane.Selection.Paragraphs.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
oDoc.ActiveWindow.Selection.Font.Name = "Times New Roman";
oDoc.ActiveWindow.Selection.Font.Size = 10;
oDoc.ActiveWindow.Selection.TypeText("Page ");
Object CurrentPage = Microsoft.Office.Interop.Word.WdFieldType.wdFieldPage;
                    oDoc.ActiveWindow.Selection.Fields.Add(oDoc.ActiveWindow.Selection.Range, ref CurrentPage, ref oMissing, ref oMissing);
oDoc.ActiveWindow.Selection.TypeText(" of ");
Object TotalPages = Microsoft.Office.Interop.Word.WdFieldType.wdFieldNumPages;
                    oDoc.ActiveWindow.Selection.Fields.Add(oDoc.ActiveWindow.Selection.Range, ref TotalPages, ref oMissing, ref oMissing);
oDoc.ActiveWindow.Selection.TypeText("\t");
 
string dt = DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
oDoc.ActiveWindow.Selection.TypeText(dt);
oDoc.ActiveWindow.Selection.TypeText("\t");
oDoc.ActiveWindow.Selection.TypeText("Disclaimer...");

Open in new window

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question