Save word content as HTML

Source: Internet
Author: User
/// <Summary> /// convert Word to HTML /// </Summary> /// <Param name = "wordfilename"> complete path, for example, F: \ words \ xxx.doc </param> // <returns> </returns> Public String wordtohtml (string wordfilename) {// place the user here Code To initialize the page Microsoft. office. interOP. word. applicationclass word = new Microsoft. office. interOP. 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 as 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. re Flection. bindingflags. invokemethod, null, Doc, null); // exit word wordtype. invokemember ("quit", system. reflection. bindingflags. invokemethod, null, word, null); Return savefilename. tostring ();} private void changeword () {MSWord. application wordapp; MSWord. document worddoc; object nothing = missing. value; console. writeline ("input path:"); Object Path = console. readline (); Path = @ "F: \ words \ Chen.. Net resume. Doc "; wordapp = new MSWord. applicationclass (); worddoc = wordapp. documents. add (ref path, ref nothing); object format = MSWord. wdsaveformat. wdformatfilteredhtml; object newpath = @ "F: \ 111111111111111111111111111111.html"; worddoc. saveas (ref newpath, ref format, ref nothing, ref not Hing, ref nothing, ref nothing); worddoc. close (ref nothing, ref nothing, ref nothing); wordapp. quit (ref nothing, ref nothing, ref nothing); console. writeline ("created! ");}

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.