Wednesday, March 6, 2013

Java Program : Open Excel File

 Below Program is used to open Excel File :
import java.awt.Desktop;
import java.io.*;

public class OpenExcel {

    /**
     * @param args
     */
    public static void main(String[] args) {
        if (Desktop.isDesktopSupported()) {
            try {
                Desktop.getDesktop().open(new File("File.xls"));
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            try {
                Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + new File("File.xls"));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}

No comments:

Post a Comment