Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programmatically creating a Word Doc Problems

Status
Not open for further replies.

dseaver

IS-IT--Management
Jul 13, 2006
467
I am trying to create a word doc via code. I am trying to get a footer to appear on all pages other than the cover, but no matter what I've tried, I can't seem to get it to work. Here is my code for the footer:
Code:
foreach (Microsoft.Office.Interop.Word.Section wordSection in _Doc.Sections)
            {
                if (wordSection.Index == 2)
                {
                    wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary]
                        .Range.Font.Name = "Arial";

                    wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary]
                        .Range.Font.Size = 8;

                    wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary]
                        .Range.Text = "Foorter Text.";
                }
                wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterFirstPage]
                   .Range.Text = "";

            }
wdHeaderFooterPrimary is supposed to only the following pages and wdHeaderFooterFirstPage takes care of the first page. I added a second section to see if that changed things and it still didn't help. Any ideas?
 
I found the solution, I needed to set _Doc.PageSetup.DifferentFirstPageHeaderFooter = -1;
 
Alright, new problem, I can't border the top and bottom of a paragraph wiht a line. Here is the code that I am trying, which doesn't work.
Code:
 Word.Paragraph StatementParagraph = _Doc.Paragraphs.Add(ref oMissing);
            StatementParagraph.Range.Text = "This is a test";
            StatementParagraph.Format.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderTop].LineWidth =
                Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt;

            StatementParagraph.Format.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom].LineWidth =
               Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top