Header:
foreach (Word.Section section in this.Application.ActiveDocument.Sections)
{
object fieldEmpty = Word.WdFieldType.wdFieldEmpty;
object autoText = "AUTOTEXT \"Page X of Y\" ";
object preserveFormatting = true;
section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Fields.Add(
section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range,
ref fieldEmpty, ref autoText, ref preserveFormatting);
section.Headers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary]
.Range.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;
}
Footer:
Word.Document document = this.Application.ActiveDocument;
foreach (Word.Section wordSection in document.Sections)
{
wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary]
.Range.Font.ColorIndex = Word.WdColorIndex.wdDarkRed;
wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary]
.Range.Font.Size = 20;
wordSection.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary]
.Range.Text = "Confidential";
}
Difference between Rollup and Cube
14 years ago
Hello
ReplyDeleteI have try for header code.but header is not display in word document.
me tooo
ReplyDelete