當(dāng)然要先添加對(duì)word地組件地引用,添加命名空間地引用,代碼:
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();
//獲取作者
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 );
//獲取主題
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
{
//關(guān)閉word進(jìn)程
object save = false;
oword.quit(ref save,ref unknown,ref unknown);
system.runtime.interopservices.marshal.releasecomobject(oword);
}
更多信息請(qǐng)查看IT技術(shù)專欄