我有一个函数可以在 Word 中的指定位置打开文档:
static void OpenWordDocument(string fileName)
{
Type applicationType = Type.GetTypeFromProgID("Word.Application");
object applicationObject = Activator.CreateInstance(applicationType);
object documentsObject = applicationType.InvokeMember("Documents", System.Reflection.BindingFlags.GetProperty, null, applicationObject, null);
applicationType.InvokeMember("Visible", System.Reflection.BindingFlags.SetProperty, null, applicationObject, new object[] { true });
Type documentsType = documentsObject.GetType();
object documentObject = documentsType.InvokeMember("Open", System.Reflection.BindingFlags.InvokeMethod, null, documentsObject, new Object[] { fileName });
}
它适用于 Office 2003,但在使用 Office 2010 的系统上打开文档时,该文档似乎无法连接到数据源。这可能是什么原因造成的?打开可能阻止连接的文档时,我是否缺少任何属性?