0

I figured out there is a way to open a file in Excel using Java but I can´t figure out how. The path of Excel should be variable because the programm should run on different computers.

Can you give me advice how to manage this problem ?

This was my try:

Process p = Runtime.getRuntime().exec(System.getenv(\"windir\") +\"\\\\system32\\\\excel.exe\"); 
  • Do you want to start excel with the file open, or read the excel file. If the latter, is it possible to convert the file to CSV and use a CSV reader such as: https://commons.apache.org/proper/commons-csv/ (which may also support xls/xlsx files)? – William Moore Jul 20 '15 at 11:20
  • yeah the file should be opened too – MegaCleptomaniac Jul 20 '15 at 11:22

2 Answers2

2

If you want to open your Excel file in Excel via Java, for example, clicking on a button should open Excel which displays a file, then you can simply use the Desktop class, Desktop.open( File ) to be more exact:

http://docs.oracle.com/javase/7/docs/api/java/awt/Desktop.html

If you want to read the file into Java, instead of opening the Excel application itself, then you need a library for that. I suggest using Apache POI for that...

https://poi.apache.org/

Florian Schaetz
  • 10,454
  • 5
  • 32
  • 58
0

You can Get the path from the registry

[HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\excel.exe]

Witch contains the path, To read from it you can use the Code of the Answer provided Below :

https://stackoverflow.com/a/6163701/4967126

Community
  • 1
  • 1