如何通过java代码直接打开自己主机上的一个Excel表格,不是表格中的一些数据而是整个Excel表格都要打开!
不知道是不是这个意思,看下面的代码
[code="java"]
import java.io.*;
public class ExecuteCommandBean {
private String command;
private Process process;
private String responseText;
private InputStream is;
private InputStreamReader isr;
private BufferedReader br;
public ExecuteCommandBean(String command) {
this.command = command;
}
public void execute() throws Exception {
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(command);
process.waitFor();
is = process.getInputStream();
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
StringBuffer buffer = new StringBuffer();
String line = null;
while( (line = br.readLine()) != null ) {
buffer.append(line + "\n");
}
responseText = buffer.toString();
}
public String getResponseText() throws Exception {
return responseText;
}
public void close() {
try {
if(br != null) { br.close(); }
} catch(Exception e) {
e.printStackTrace();
}
try {
if(isr != null) { isr.close(); }
} catch(Exception e) {
e.printStackTrace();
}
try {
if(is != null) { is.close(); }
} catch(Exception e) {
e.printStackTrace();
}
try {
if(process != null) { process.destroy(); }
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) throws Exception {
//windows下
String command = "excel c:/books.xls";
ExecuteCommandBean ecb = new ExecuteCommandBean(command);
ecb.execute();
System.out.println(ecb.getResponseText());
}
}
[/code]