Opening an Excel file using the default program

后端 未结 3 1191
一整个雨季
一整个雨季 2020-12-05 20:45

My program successfully creates and fills a Excel(.xls) file. Once created, I would like the new file to open in the system\'s default program (Excel in my case). How can I

3条回答
  •  旧巷少年郎
    2020-12-05 21:23

    Try to use Desktop.open() instead of Desktop.edit() :

    Desktop dt = Desktop.getDesktop();
    dt.open(new File(this.outputFilePath));
    

    If Desktop.open() is not available then the Windows file association can be used :

    Process p = 
      Runtime.getRuntime()
       .exec("rundll32 url.dll,FileProtocolHandler " + this.outputFilePath);
    

提交回复
热议问题