0
我需要爲Word文檔中的「BookMarks」添加值。在那裏我需要使用後期綁定來實現這一點。與.NET的後期綁定Excel
我已提取upto書籤,但如何更改值?
object bookMark = @"OfferRef";
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("Add", BindingFlags.InvokeMethod, null, documentsObject,
new Object[] { @"e:\offer.doc"});
Type documentType = documentObject.GetType();
object fieldsBookMarks = documentType.InvokeMember("BookMarks", BindingFlags.GetProperty, null, documentObject, null);
Type typeBookMarks = fieldsBookMarks.GetType();
object bookMark = typeBookMarks.InvokeMember("Item", BindingFlags.InvokeMethod, null, fieldsBookMarks, new object[] { bookMark });
Type type = bookMark.GetType();
object Range = type.InvokeMember("Range", BindingFlags.GetProperty, null, bookMark, null);
type = Range.GetType();