版权声明:转载请注明出处 https://blog.csdn.net/qq_40162735/article/details/82802273
/**
* @author DevinLiu
* 一键发布报告
* 2018年9月19日下午2:44:19
*/
public class GenerateReport {
public String report(){
//文件名
String FileName="E:\\demo\\SMS_20180320_1014.xlsm";
try {
File file=new File(FileName);
if(file.exists()){
//打开文件
Runtime.getRuntime().exec("cmd /c start "+FileName+"");
}else{
System.out.println("文件不存在");
return "";
}
Thread thread=new Thread();
thread.sleep(2000);
while(true){
thread.sleep(2000);
if(file.renameTo(file)){
//文件未操作
break;
}
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("文件操作结束");
return "";
}
}
excel注意两点:
把点击控件事件(宏)放入Workbook_Open() 下面,加载完毕自动触发按钮控件
Private Sub Workbook_Open()
执行结束自动保存关闭文件
Workbooks(1).Save
Application.Quit