Java – using runtime getRuntime(). Exec run Excel

try {
try {
    Runtime.getRuntime().exec("excel C:\\file.xls");
} catch (IOException ex) {
    System.out.println(ex);
}

no way. I have to put it in Excel Exe to work How do I make it generic (for any excel folder / Version)? Useful when I run the same line from the operating system using windows run (start – > run) Is there any code in Java to simulate the run command of windows?

Solution

Why not try to use the desktop class (API doc here) with this method introduced in JDK6

public void open(File file) throws IOException

Record what you want to do:

Of course, this assumption Xls extension is mapped from OS to excel Then you can go

Desktop.getDesktop().open(new File("c:\\file.xls"));
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>