ASP.NET Operating Word (Simple)

xiaoxiao2021-03-06  46

The first to add a reference: COM ----> Microsoft Word 9.0 Object Library to use this namespace: System.Reflectionvoid opWord () {Word.Application oWord; Word._Document oDoc; object docBuiltInProps; object oMissing = Missing.Value Object source = server.mappath ("liu.doc"); object unknown = type.missing; ooord = new word.application (); try {odocc = 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

// The following code can get Word text response.write (odoc.words.count.tostring ()); response.write ("


"); response.words.Application.documents.toString () ); Object a = 0; object b = (object) odoc.words.count; word.range = odoc.range (Ref a, ref b); response.write (oooo.text); response.write ("< hr /> "); // ----------------------------

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 (); response.write (PropsValue);

// 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 (); Response.Write (propsValue);} Finally {// Turn off Word process Object Save = false; OWORD.QUIT (Ref Save, Ref unknown, Ref unknown);

System.Runtime.InteropServices.Marshal.ReleaseComobject (OWORD);}}

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

New Post(0)