Asp.net|word
First you add a reference: COM----> Microsoft Word 9.0 Object Library
To use this namespace: System.Reflection
void Opword ()
{
Word. Application oword;
Word. _document odoc;
Object Docbuiltinprops;
object omissing = Missing.Value;
Object Source = Server.MapPath ("Liu.doc");
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);
The following code can get word text
Response.Write (ODoc.Words.Count.ToString ());
Response.Write ("
");
Response.Write (ODoc.Words.Application.Documents.ToString ());
Object a=0;
Object B= (object) ODoc.Words.Count;
Word. Range Oooo=odoc.range (ref a,ref B);
Response.Write (oooo. Text);
Response.Write (" ");
//----------------------------
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 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 ();
Response.Write (Propsvalue);
}
Finally
{
Close Word process
Object save = false;
Oword.quit (ref save,ref unknown,ref Unknown);
System.Runtime.InteropServices.Marshal.ReleaseComObject (oword);
}
}