怎样通过getRuntime()调用word和excel
调用计算机和记事本我就知道,但不知道怎样通过getRuntime()调用word和excel;有高手知道最底下的代码中XX是什么的时候可以调用word和excel
if(e.getActionCommand().equals("calculate")||EventName.equals("calculate")){
Runtime rt = Runtime.getRuntime();
try {
rt.exec("calc");
}
catch (
IOException ex) {
ex.printStackTrace();
}
System.out.println("打开计算器");
EventName = "";
return;
}
if(e.getActionCommand().equals("txt")||EventName.equals("txt")){
Runtime rt = Runtime.getRuntime();
try {
rt.exec("notepad ");
}
catch (IOException ex) {
ex.printStackTrace();
}
System.out.println("记事本");
EventName = "";
return;
}
if(e.getActionCommand().equals("word")||EventName.equals("word")){
Runtime rt = Runtime.getRuntime();
try {
rt.exec("XX ");
}
catch (IOException ex) {
ex.printStackTrace();
}
System.out.println("word");
EventName = "";
return;
}
------解决方案--------------------
我这样可以:
Java code
rt.exec("cmd /c start "+"winword"); //word.运行 excel 把winword换成 excel.