0

I want to open an Excel-file with Java.

I saw this Opening an Excel file using the default program and this works perfectly.

(In short the solution would be:)

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

or

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

But I also want to know when the Excel-file is closed again. Am I able to track, if the user closes the Excel-sheet? And would I use the process or the desktop-solution for this? What is the difference between this solutions?

I want to create an E-Mail after closing the Excel-file.

Thanks to the comments

I have a solution now.

ProcessBuilder pb = new ProcessBuilder("cmd.exe","/c",path);

Process p = pb.start();
Community
  • 1
  • 1
Loki
  • 4,065
  • 4
  • 29
  • 51
  • The latter will allow you to monitor the subprocess created, although I would use a ProcessBuilder instead of Runtime.exec(...). – Hovercraft Full Of Eels Aug 03 '13 at 12:20
  • 1
    You can wait for the process to finish; the desktop option doesnt allow this, and sucks badly, too. You can check this answer http://stackoverflow.com/questions/18004150/desktop-api-is-not-supported-on-the-current-platform/18004334#18004334 – MightyPork Aug 03 '13 at 12:20
  • With the Processbuilder, how would I open excel? I searched for it, but I don't know what I'm doing wrong: `ProcessBuilder pb = new ProcessBuilder("excel",path);` – Loki Aug 03 '13 at 12:28
  • If you know how to set up the Runtime.exec(...) you can set up the ProcessBuilder. Please check the API. – Hovercraft Full Of Eels Aug 03 '13 at 12:34
  • Use `ProcessBuilder pb = new ProcessBuilder("cmd.exe","/c",path);`. This calls a "cmd.exe" that will open your Excel file with default program. – dic19 Aug 03 '13 at 12:35

0 Answers0