Opening an Excel file using the default program

后端 未结 3 1177
一整个雨季
一整个雨季 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:08

    You probably did the Runtime.exec incorrectly. Give this a look to see if that's the case.

    If you just want to open an Excel file with Java, I'd recommend using Andy Khan's JExcel API. Perhaps using that with a Swing JTable will be just the ticket.

    0 讨论(0)
  • 2020-12-05 21:18

    The most simple and efficient way.

    Desktop.getDesktop().open(new File("inputFilePath"));
    
    0 讨论(0)
  • 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);
    
    0 讨论(0)
提交回复
热议问题