Java programs convert Word documents directly to HTML files

Source: Internet
Author: User
word| Program | Convert Jacob is a COM bridge under Java and Windows, through which we can invoke COM components in Java programs. If your JDK is 1.4, then you need to download Jacob1.9 's JNI library to work properly, and earlier versions have some problems with JDK1.4.

       
        
Package com; /***〈p〉title:word Document Turn HTML Class 〈/p〉*〈p〉description:〈/p〉*〈p〉copyright: () 2002〈/p〉* @author Helmsman * @version 1.0*/import com.jacob.com.*; Import com.jacob.activex.*; public class Wordtohtml {/*** document conversion function * @param docfile the absolute path of the Word document plus the file name (including extension) * @param htmlfile the converted HTML file absolute path and filename (without extension) * * public static void Change (string docfile, String htmlfile) {activexcomponent app = new Activexcomponent ("Word.Application "); Start Wordtry {app.setproperty ("Visible", new Variant (FALSE);//Set Word not visible object docs = App.getproperty ("Documents"). Todispatch (); Object doc = Dispatch.invoke (docs, "Open", Dispatch.method,new object[] {docfile, new variant (FALSE), new variant (TRUE)}, New Int[1]). Todispatch (); Open the Word file Dispatch.invoke (doc, "SaveAs", Dispatch.method, new object[] {htmlfile, new Variant (8)}, new int[1]); Save to temporary file as HTML format variant F = new Variant (FALSE); Dispatch.call (Doc, "Close", f); catch (Exception e) {e.printstacktrace ();} finally {App.invoke ("Quit", New variant[]{});} public static voidMain (string[] strs) {Wordtohtml.change ("c:\\a\\ Transport Management Dispatch system overall scenario. Doc", "c:\\a\\t");} 
       


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.