Monday, August 30, 2010

Load Microsoft Excel Using Command in Java

August 30, 2010

Try the following code  to open/load Microsoft Excel in your java code.

import java.io.IOException;

class StartExcel {
public static void main(String args[]) throws IOException{
Runtime.getRuntime().exec("cmd /c start excel.exe");
}
}

To load a worksheet use the following code:

import java.io.IOException;

class StartExcel {
public static void main(String args[]) throws IOException{
String fileName = "C:\\[Directory]\\excelfile.xls";
String[] command = {"cmd", "/c", "start", "\"DummyTitle\"",fileName};
Runtime.getRuntime().exec(command);
}
}

0 comments:

Post a Comment

 

© 2017 Zul. All rights resevered. Designed by Templateism

Back To Top