From: http://hi.baidu.com/trstones/blog/item/7fca145426436c57d0090663.html
There is no simple way to convert word to html in java. The openOffice implementation should be regarded as "Pull the big ones in the cookbook ".
1. First download openOffice. This is a third-party open-source project dedicated to writing similar word documents in the java environment (if a word cannot be edited, java will become a role in the layman's mind ). I downloaded OpenOffice.org 3.2.
2. Download and install. Run cmd to go to the "installation directory \ OpenOffice.org 3 \ program" folder. Run the following command:
Soffice-headless-accept = "socket, host = 127.0.0.1, port = 8100; urp;"-nofirststartwizard
It means to start a service of openoffice for use by other programs (look at how generous our open-source leaders are, not as stingy as Microsoft, for fear of using them ).
3. Test whether port 8100 can be used. Run the cmd command "telnet localhost 8100". If it is enabled, there will be a screen that cannot be blacklisted. If it is not enabled, a connection failure message will appear.
4. Download The jodconverter project, which is 2.2.2. (We will not duplicate the wheel. Just get on the bus !)
5. Create your own project and reference all jar packages in the lib folder of jodconverter. Then write the following code
Public static void main (String args []) {
File inputFile = new File ("D: \ test \ Ad test .doc ");
File outputFile = new File ("D: \ test \ Ad test .html ");
OpenOfficeConnection connection = new SocketOpenOfficeConnection (8100 );
Try {
Connection. connect ();
} Catch (Exception e ){
E. printStackTrace ();
}
DocumentConverter converter = new OpenOfficeDocumentConverter (connection );
Converter. convert (inputFile, outputFile );
Connection. disconnect ();
}
Then run it. It should be okay. Of course, "D: \ test \ Ad test .doc" must exist in advance (the program cannot be sold independently ).
6. Others. The above Code doc-> html;
For xls-> html, change "D: \ test \ Ad test .doc" to "D: \ test \ ***. xls ";
If it is doc-> example, you can change the advertisement test .html#into an advertisement test example ".
Let's test the two. Let's explore them by yourself. You can open the openoffice client program and check the files that are supported. You can save the files in those formats. Good Fool!