【发布时间】:2017-10-09 20:04:13
【问题描述】:
我使用 COM Interop 自动创建了一个 MS-Project 文件,并在其中添加了一些任务。
我正在尝试在此文件中自动添加页眉和页脚,类似于它在 MS-Word 中的工作方式,如下所示:
foreach (Microsoft.Office.Interop.Word.Section section in myDoc.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.wdAlignParagraphRight;
}
但我没有找到有关该主题的文档,是否至少有可能?
编辑
我已经尝试过这种语法:
Application.FilePageSetupHeader , 1, "Date: &[Date]"
但它看起来像 VBA 语法,我正在使用 C# 和 Interop COM。
我已经尝试过在做一些测试时发现的这条指令:
project.Application.FilePageSetupHeader(1, PjAlignment.pjCenter, "Date");
但它总是给我这个错误System.Runtime.InteropServices.COMException: 'The argument value is not valid.'
有人知道 C# 中的简洁语法或 FilePageSetupHeader 在 C# 中的工作方式吗?
【问题讨论】:
标签: c# ms-word ms-project office-automation