OpenOffice4的启动和关闭和之前的版本不太一样,其中,
在开启环节的命令和前版本有差异。
在关闭环节,需要关闭soffice.exe和soffice.bin
直接上代码
/**
*关闭代码
**/
public static void shutdownOpenOfficeService() {
try {
Process pro = Runtime.getRuntime().exec("tasklist");
Scanner in = new Scanner(pro.getInputStream());
while(in.hasNext()) {
String proString = in.nextLine();
if(proString.contains("soffice.exe")) {
String cmd = "taskkill /f /im soffice.exe";
pro = Runtime.getRuntime().exec(cmd);
System.out.println("soffice.exe关闭");
}
if(proString.contains("soffice.bin")) {
String cmd = "taskkill /f /im soffice.bin";
pro = Runtime.getRuntime().exec(cmd);
System.out.println("soffice.bin关闭");
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
开启代码:
public static void startOpenOfficeService(String servicePath) {
String command = servicePath + "program\\soffice -headless -accept=\"socket,host=127.0.0.1,port=8100;urp;\" -nofirststartwizard";
try {
Process pro = Runtime.getRuntime().exec(command);
} catch (IOException e) {
System.out.println("OpenOffice服务启动失败");
}
}
注意:此处servicePath为OpenOffice的安装路径,我的是:
"C:\\Program Files (x86)\\OpenOffice 4\\"
如不是,需自行修改!
--------end---------