Of course, first add a reference to the component of Word, add a reference to the namespace, code:
Word.Application oword;
Word._document odoc;
object omissing = Missing.Value;
Object Docbuiltinprops;
Object Source = @ "Docpath";
Object Unknown =type.missing;
oword = new Word.Application ();
Try
{
odoc = OWord.Documents.Open (ref source,ref Unknown,
Ref Unknown,ref Unknown,ref Unknown,
Ref Unknown,ref Unknown,ref Unknown,
Ref Unknown,ref Unknown,ref Unknown,
Ref Unknown);
Docbuiltinprops = odoc.builtindocumentproperties;
Type typedocbuiltinprops = Docbuiltinprops.gettype ();
Get author
String index = "Author";
String Propsvalue;
Object DocAuthor = Typedocbuiltinprops.invokemember ("Item",
Bindingflags.default |
BindingFlags.GetProperty,
Null,docbuiltinprops,
New object[] {index});
Type typeDocAuthorProp = Docauthor.gettype ();
Propsvalue = typeDocAuthorProp.InvokeMember ("Value"),
Bindingflags.default |
BindingFlags.GetProperty,
Null,docauthor,
New object[] {}). ToString ();
MessageBox.Show (Propsvalue, "Author");
Get a topic
index = "Subject";
Propsvalue = "The Subject";
Object docsubjectprop = Typedocbuiltinprops.invokemember ("Item",
Bindingflags.default |
BindingFlags.GetProperty,
Null,docbuiltinprops,
New object[] {index});
Type Typedocsubjectprop = Docsubjectprop.gettype ();
Propsvalue = Typedocsubjectprop.invokemember ("Value"),
Bindingflags.default | BindingFlags.GetProperty,
Null,docsubjectprop,
New object[] {}). ToString ();
MessageBox.Show (Propsvalue, "Subject");
}
Finally
{
Close Word Process
Object save = false;
Oword.quit (ref save,ref unknown,ref Unknown);
System.Runtime.InteropServices.Marshal.ReleaseComObject (oword);
}
Note : More wonderful tutorials Please pay attention to the triple computer Tutorials section, triple Office group: 185219299 welcome you to join