0
我想页眉/页脚添加到取决于用户的选择组合框中选择一个word文档。添加标题为Word文档(Word加载C#)
我可以得到它的一个新的文档时,有人可以解释如何得到它的工作对当前活动文档。
我目前的代码是:
private void btnAddHeader_Click(object sender, RibbonControlEventArgs e)
{
Microsoft.Office.Interop.Word.Document document = new Microsoft.Office.Interop.Word.Document();
foreach (Microsoft.Office.Interop.Word.Section section in document.Sections)
{
Microsoft.Office.Interop.Word.Range headerRange = section.Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
headerRange.Fields.Add(headerRange, Microsoft.Office.Interop.Word.WdFieldType.wdFieldPage);
headerRange.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
headerRange.Font.ColorIndex = Microsoft.Office.Interop.Word.WdColorIndex.wdRed;
headerRange.Font.Size = 8;
headerRange.Font.Bold = 1;
headerRange.Font.Name = "Arial";
headerRange.Text = cbClassification.Text;
}
}
当按钮被点击时,上面的代码运行,但更新当前打开的活动文档,目前上面创建一个新文档,并增加了什么我需要的是已被选中。
太棒了!工作一种享受,知道我为什么在一个新文档中打开,只是不知道当前文档的语法。欣赏它! – user1700974