Convert a Word document to html (CODE)

Source: Internet
Author: User

/// <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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.