1. Import the Microsoft. Office. InterOP. Word. dll file
2. The source code is as follows:
Code
/// <Summary>
/// Convert Word to HTML
/// </Summary>
/// <Param name = "wordfilename"> </param>
Private string wordtohtml (Object wordfilename)
{
// Place user code here to initialize the page
Word. applicationclass word = new word. applicationclass ();
Type wordtype = word. GetType ();
Documents docs = word. documents;
// Open the file
Type docstype = docs. GetType ();
Document Doc = (document) docstype. invokemember ("open ",
System. reflection. bindingflags. invokemethod, null, Docs, new object [] {wordfilename, true, true });
// Convert the format and save it
Type doctype = Doc. GetType ();
String wordsavefilename = wordfilename. tostring ();
String strsavefilename = wordsavefilename. substring (0, wordsavefilename. Length-3) + "html ";
Object savefilename = (object) strsavefilename;
Doctype. invokemember ("saveas", system. reflection. bindingflags. invokemethod,
Null, Doc, new object [] {savefilename, wdsaveformat. wdformatfilteredhtml });
Doctype. invokemember ("close", system. reflection. bindingflags. invokemethod,
Null, Doc, null );
// Exit word
Wordtype. invokemember ("quit", system. reflection. bindingflags. invokemethod,
Null, word, null );
Return savefilename. tostring ();
}