I didn't expect to "easily connect the bridge of Java connection COM object", but now I have written two, I can know that netizens who explore the technology on our network are quite very much, very gratifying! This content is to replace strings in the Word document using Jacob. For the use of Jacob, please see "Easy to easily connect the bridge of Java connection COM object", which is implemented as follows: import com.jacob.Com. *; Import com.jacob.activex. *;
public class Exam_9 {public static void main (String [] args) {ActiveXComponent app = new ActiveXComponent ( "Word.Application"); // start word String inFile = "H: // Majix-1_2_2_full // sample // my. "; // to replace the word file Boolean flag = false; try {app.setproperty (" 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 (false)}, new int}}, new int [1]). Todispatch ); // Open the Word file, note that the third parameter is set to false, this parameter indicates whether it is opened in a read-only mode, because we have to save the original file, so open. Object content = dispatch.get (DOC, "Content"). Todispatch (); // Extract Word Document Content Object Object Finder = Dispatch.Get (Content, "Find"). Todispatch (); // Extract Find object, also Just find the object of the object Variant F = New Variant (False); Boolean RT = True; While (RT) {RT = Dispatch.Invoke (Finder, "Execute", Dispatch.Method, New Object [] {"OLD", F, f, f, f, f, f, f, "new", new variant (true)}, new int [1]). TOBOOLEAN (); // Replace OLD ---> new} dispatch. Call (DOC, "Save"); // Save Dispatch.call (DOC, "Close", F); Flag = true;} catch (exception e) {E.PrintStackTrace ();} finally {app.invoke Quit ", new variant [] {});}}}
Have doubt zlesssson@163.net