Import com.jacob.com. *;
Import com.jacob.activex. *;
Import java.io. *;
/ / Get all the DOC file names below the specified directory
Public Class WordTohtml
{
/ / -------------------------------------------------------------------------------------------- ------------------------------
// Method prototype: Change (String Paths)
// Function Description: Transform all DOC files below the specified directory into HTML and store it in the same directory
// Enter parameters: String
// Output parameters: no
// Return value: no
// Other instructions: recursive
/ / -------------------------------------------------------------------------------------------- ------------------------------
Public Static Void Change (String Paths, String SavePaths)
{
FILE D = New File (paths);
// Get list of all files and directories under the current folder
File Lists [] = D.ListFiles ();
String paths = new string ("");
For (int i = 0; i { IF (Lists [i] .isfile ()) { String filename = lists [i] .Getname (); String filetype = new string ("" "); // Get file type FileType = filename.substring (Filename.length () - 3), filename.length ()); // Judgment Whether or not DOC file IF (FileType.equals ("DOC"))) { System.out.println ("currently being converted ..."); // Print the current directory path System.out.println (Paths); / / Print the Doc file name System.out.println (Filename.Substring (0, (filename.length () - 4)))) ActiveXComponent App = New ActiveXcomponent ("Word.Application"); // Start Word String Docpath = Paths FileName; String htmlpath = savepaths filename.substring (0, (filename.length () - 4)); String infile = docpath; // Word file to be converted String TPFILE = HTMLPATH; // html file Boolean Flag = false; "Visible", new variant (false)); // Setting Word Not visible Object Docs = App.getProperty ("Documents"). Todispatch (); Object Doc = dispatch.invoke (DOCS, "open", dispatch.method, new object [] {infile, new variant (false), new variant (true)}, new int [1]). Todispatch (); // Open Word file dispatch.invoke (DOC, "Saveas", Dispatch.Method, New Object [] {TPFILE, New Variant (8)}, new int [1]); // Save to temporary file Variant f = new variant (false) as HTML format; Dispatch.call (DOC, "Close", F); FLAG = true;} catch (exception e) {E.PrintStackTrace ();} finally {app.invoke ("quit", new variant [] {};} System.out.println ("Transformation!");}} Else {system.out.print ("folder"); pathss = paths; // Go to the next directory Pathss = Pathss Lists [i] .Getname ( ) "//"; // recursively traversed all directories Change (pathss, savepaths);}}} // ----------------------- ------------------------------------------- ---------- // Method prototype: main (string [] args) // function description: main file // input parameter: None // Output parameter: None // Return value: None // Description: No // --------------------------------------------- --------------------------------- public static void main (string "args) {string paths = new String "E: // project //"); string savepath = new string ("d: // javapro /////////////////////////////////////////////////////////////////>