1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| public wrapperOLERx() {
//System.loadLibrary("jacob-1.17-M2-x64");
ActiveXComponent oWord = new ActiveXComponent("Word.Application");
oWord.setProperty("Visible", new Variant(isVisible));
Dispatch oDocuments = oWord.getProperty("Documents").toDispatch();
Dispatch oDocument = Dispatch.call(oDocuments, "Open", strInputDoc).toDispatch();
Dispatch oSelection = oWord.getProperty("Selection").toDispatch();
Dispatch oFind = oWord.call(oSelection, "Find").toDispatch();
Dispatch.put(oFind, "Text", strOldText);
Dispatch.call(oFind, "Execute");
Dispatch.put(oSelection, "Text", strNewText);
Dispatch.call(oSelection, "MoveDown");
Dispatch.put(oSelection, "Text","nSo we got the next line including BR.n");
Dispatch oFont = Dispatch.get(oSelection, "Font").toDispatch();
Dispatch.put(oFont, "Bold", "1");
Dispatch.put(oFont, "Italic", "1");
Dispatch.put(oFont, "Underline", "0");
Dispatch oAlign = Dispatch.get(oSelection, "ParagraphFormat").toDispatch();
Dispatch.put(oAlign, "Alignment", "3");
Dispatch oWordBasic = (Dispatch) Dispatch.call(oWord, "WordBasic").getDispatch();
Dispatch.call(oWordBasic, "FileSaveAs", strOutputDoc);
Dispatch.call(oDocument, "Close", new Variant(isSaveOnExit));
oWord.invoke("Quit", new Variant[0]);
}
} |
Partager