5

I want to open excel document from my program in java. Actually I want excel document to be opened when I click on button in my program. I have tried

Runtime.getRuntime().exec("workbook.xls");

where workbook.xls is located in the root of project folder, but it doesn't work. Exception says that it can not open program workbook.xls. How can I do this

2 Answers 2

14

I guess you want to open your Excel-file with it's default program (like Excel)? If so, you can use the Desktop-class:

Desktop.getDesktop().open(new File("path/to/your/file.xls"));
Sign up to request clarification or add additional context in comments.

2 Comments

I agree. Desktop.open() is the way to go.
Desktop.getDesktop().open(file);
1

You can use Apache POI to work with Microsoft documents. Have a look here for examples on how to use this.

2 Comments

I think he doesn't want to use Java to work on the excel file, but to hand it over to Excel for opening, like a file browser does.
The link specified above is gone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.