/// <Summary> /// convert a word document to an Html file // </summary> /// <param name = "wordFileName"> word file name </param>/ // <param name = "htmlFileName"> name of the html file to be saved </param> // <returns> </returns> public static bool WordToHtml (string wordFileName, string htmlFileName) {try {Object oMissing = System. reflection. missing. value; Word. _ Application WordApp = new Word. application (); WordApp. visible = false; object filename = wordFileName; _ Document WordDoc = WordApp. documents. open (ref filename, ref oMissing, ref oMissing, ref oMissing, ref oMissing); // Type wordType = WordApp. getType (); // open the file Type docsType = WordApp. documents. getType (); // convert the format and save it as Type docType = WordDoc. getType (); object saveFileName = htmlFileName; docType. invokeMember ("SaveAs", System. reflection. bindingFlags. invokeMethod, null, WordDoc, new object [] {saveFileName, WdSaveFormat. wdFormatHTML}); // save WordDoc. save (); WordDoc. close (ref oMissing, ref oMissing, ref oMissing); WordApp. quit (ref oMissing, ref oMissing, ref oMissing); return true;} catch (Exception e) {Console. writeLine (e. message); Console. writeLine (e. stackTrace); return false;} if not used
During conversion in the program, another simple conversion method is to click Save in word and select html format to save the type in the saved dialog box.