Get the author and subject of a Word document

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.