The most recent project is to automate the operation of the Fund's trading contracts. Then you'll want to use Java code to manipulate macro buttons in Excel, and then create a word version of the contract.
The specific Java code is as follows:
import Org.junit.assert;import org.junit.Test; Public classExceltoolsservicetest {PrivateExceltoolsservice Service; @Test Public voidTestmacro () {Try{String path="c:/users/admin.admin-pc.000/desktop/vb/merged template/contract template. xlsm";Service =NewExceltoolsservice (); Service.execmacro (Path,"text substitution. Generating a document"); } Catch(Exception e) {E.printstacktrace (); Assert.fail (); } }}
Import com.jacob.activeX.ActiveXComponent;
Import Com.jacob.com.ComThread;
Import Com.jacob.com.Dispatch;
Import com.jacob.com.Variant;
public class Exceltoolsservice {
public void Execmacro (string excelpath, String macroName, Variant ... params) throws Exception {
Activexcomponent excel = null;
Dispatch workbooks = null;
Dispatch workbook = null;
Long start = System.currenttimemillis ();
System.out.println (start);
try {
Comthread.initsta ();
Excel = new Activexcomponent ("Excel.Application");
workbooks = Excel.getproperty ("workbooks"). Todispatch ();
Workbook = Dispatch.call (workbooks, "Open", Excelpath). Todispatch ();
if (null = = Params | | Params.length < 1) {
Dispatch.call (Excel, "Run", New Variant (MacroName));
} else {
Dispatch.call (Excel, "Run", New Variant (MacroName), params);
}
Dispatch.call (Workbook, "Save");
} catch (Exception e) {
E.printstacktrace ();
} finally {
if (null! = Workbook) {//Close document
Dispatch.call (Workbook, "Close", new Variant (false));
}
if (null! = Workbooks) {
Dispatch.call (workbooks, "Close");
}
if (null! = Excel) {
Excel.invoke ("Quit", new variant[] {});
}
Close the Excel process
Comthread.release ();
Long end = System.currenttimemillis ();
SYSTEM.OUT.PRINTLN ("Processing file [{}] macro [{}], time spent {}s" + Excelpath + macroName
+ ((End-start)/1000 + 1));
}
}
}
This is achieved by automating the creation of the Fund's contract through Excel macros.
The operation of calling macros in Excel is implemented through Java code.