Get the author and theme of the Word document

xiaoxiao2021-03-06  46

Of course, add a reference to the Word component to 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.def AULT ​​| BindingFlags.getProperty, Null, DocauThor, New Object [] {}) .tostring (); MessageBox.show (PropsValue, "Author"); // Get the 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

{// Turn off the Word process Object Save = false; OWORD.quit (Ref Save, Ref unknown, ref unknown; system.Runtime.InteropServices.Marshal.ReleaseComobject (Oword);}

Recently, I haven't been developed in the project. I have no good things to take out.

This is ugly

转载请注明原文地址:https://www.9cbs.com/read-115924.html

New Post(0)