Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open excel document in java

Tags:

java

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

like image 384
maks Avatar asked Dec 12 '22 12:12

maks


1 Answers

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"));
like image 186
Lukas Knuth Avatar answered Dec 31 '22 22:12

Lukas Knuth