Word format converted to HTML

Source: Internet
Author: User

Package Com.wiseweb.util;import Com.jacob.activex.activexcomponent;import Com.jacob.com.dispatch;import Com.jacob.com.variant;public class Wordtohtml {//---------------------------------------------------------------- --------------//Method Prototype: Change (String paths)//Function Description: Converts all doc files under the specified directory to HTML and stores them in the same directory//input parameters: string//output parameter: none//return value: none// Other instructions: recursive//------------------------------------------------------------------------------public static Boolean        Change (string folderpath,string FileName) {string fileformat = "";        System.out.println (FolderPath);        FileFormat = filename.substring (Filename.length () -4,filename.length ());        System.out.println (FileFormat);            if (Fileformat.equalsignorecase (". Doc")) {String docfile = FolderPath + "//" + FileName;            System.out.println ("Word File path:" +docfile);            The full path of the Word file String htmlfile = docfile.substring (0, (Docfile.length ()-4)) + ". html"; System.out.println ("HTM file path:" +htmlfile);            The full path of the HTML file activexcomponent app = new Activexcomponent ("Word.Application");                Start Word try {app.setproperty ("Visible", new Variant (false));                Set Word program non-visual to run Dispatch docs = app.getproperty ("Documents"). Todispatch (); Dispatch doc = Dispatch.invoke (docs, "Open", Dispatch.method, New Object[]{docfile,new variant (FALSE), new variant (TRUE)                 }, new Int[1]). Todispatch (); Open Word file Dispatch.invoke (doc, "SaveAs", Dispatch.method, New Object[]{htmlfile,new Variant (8)}, new int[1])                ;                Save the file as an HTM format dispatch.call (doc, "Close", new Variant (false));            Close file} catch (Exception e) {e.printstacktrace ();                } finally {App.invoke ("Quit", new variant[] {}); Quit Word Program}//Conversion complete RETurn true;    } return false; }//------------------------------------------------------------------------------//Method prototype: Main (string[] args)// Function Description: Main file//input parameter: none//output parameter: none//return value: none//Other Description: no//------------------------------------------------------------------  ------------public static void Main (string[] args) {//String paths = new String ("e://wordtohtml");  String paths = new String ("E:");//String filename = "A.doc";  String filename = "servlet and JSP Learning Guide (Budi Kurniawan). doc"; Change (paths, filename); }}
In fact, the principle is to use Word to open the document, and then save as HTML format is OK.

Word format converted to HTML

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.