我给你一些资料吧! 1 Are COM Dates compatible with Java Dates? How can I convert one to each other? You can use this http://groups.yahoo.com/group/jacob-project/message/97code. Jacobgen wrappers should handle this conversion automatically. 2. When I downloaded Jacob I didn’t get javadocs, where can I find these? There are not javadocs available for Jacob classes. However, Jacob is almost 1:1 compatible with Microsoft COM access for Java, you can check out the MS docs at http://www.microsoft.com/java/download/dl_sdk40.htm. import com.jacob.com.*; import com.jacob.activeX.*; import java.util.*; public class InvokeCom { public static void main(String[] args) { InvokeCom invoke=new InvokeCom(); invoke.connect(); } public void connect() { try{ ActiveXComponent app = new ActiveXComponent("PROCESSDB.ProcessDBPro"); System.out.println("ActiveXComponent"); Variant[] varConnect=new Variant[4]; Variant varbool; varConnect[0]=new Variant("server2000"); varConnect[1]=new Variant("sa"); varConnect[2]=new Variant("njbool"); varConnect[3]=new Variant("nrRT_DB"); varbool=app.invoke("ConnectDB",varConnect); System.out.println("varbool="+varbool.getBoolean()); float flo=55.6f; Variant[] varInvokeAvg=new Variant[6]; varInvokeAvg[0]=new Variant(3); varInvokeAvg[1]=new Variant(27); varInvokeAvg[2]=new Variant("9/23/2002"); varInvokeAvg[3]=new Variant("9/24/2002"); varInvokeAvg[4]=new Variant(5); varInvokeAvg[5]=new Variant(66.6); varbool=app.invoke("AVG",varInvokeAvg); System.out.println("varbool="+varbool.getBoolean()); System.out.println("4="+varInvokeAvg[4].getInt()); System.out.println("5="+varInvokeAvg[5].getDouble()); } catch(Exception ex) { System.out.println("执行失败!"); } System.out.println("执行完毕!"); } }
我给你一个例子,但必须有jacob包,这个例子表示word文件转化为xml,转换为html, 文件可以相互转化,不知道是否可以, import java.io.File; import com.jacob.com.*; import com.jacob.activeX.*;public class Exam_2 { public static void main(String[] args) { System.out.println("run"); //ActiveXComponent app = new ActiveXComponent("Word.Application");//启动word ActiveXComponent app = new ActiveXComponent("X9.Z.1");//启动word //System.out.println("run1"); // Object obj = app.getObject(); // Object obje=Dispatch.get(obj,"XX"); // System.out.println("first"); System.out.println("version="+app.getProperty("intcom")); //System.out.println("version="+Dispatch.get(obj, "intcom")); String inFile = "D:\\test\\Jacob\\my.doc";//要转换的word文件 String tpFile = "D:\\test\\Jacob\\my.htm";//临时文件 String otFile = "D:\\test\\Jacob\\my.xml";//目标文件 boolean flag = false; System.out.println("first"); try { int x=2; int y=7; Variant[] var=new Variant[2]; Variant var1=new Variant(); var[0]=new Variant(x); var[1]=new Variant(y); System.out.println(var[0].getInt()); // var[1]=new Variant(y); //var1=app.getProperty("x"); // Object docs = app.getProperty("Documents").toDispatch(); //Object doc = Dispatch.invoke(docs,"Open", Dispatch.Method, new Object[]{inFile,new Variant(false), new Variant(true)}, new int[1]).toDispatch();//打开word文件 // Dispatch.invoke("SaveAs", Dispatch.Method, new Object[]{tpFile,new Variant(8)}, new int[1]);//作为html格式保存到临时文件 //var1=app.invoke();
System.out.println("pass"); /*app.setProperty("Visible", new Variant(false));//设置word不可见 System.out.println("second");
System.out.println("three");
System.out.println("four"); Dispatch.invoke(doc,"SaveAs", Dispatch.Method, new Object[]{tpFile,new Variant(8)}, new int[1]);//作为html格式保存到临时文件 System.out.println("five"); Variant f = new Variant(false); System.out.println("six"); Dispatch.call(doc, "Close", f); System.out.println("seven");*/
flag = true; } catch (Exception e) { e.printStackTrace(); } finally { // app.invoke("Quit", new Variant[] {}); } System.out.println("flag="+flag); /*if ( flag ) { app = new ActiveXComponent("Excel.Application");//启动excel try { app.setProperty("Visible", new Variant(false));//设置excel不可见 Object workbooks = app.getProperty("Workbooks").toDispatch(); Object workbook = Dispatch.invoke(workbooks,"Open",Dispatch.Method,new Object[]{tpFile,new Variant(false), new Variant(true)}, new int[1]).toDispatch();//打开临时文件 System.out.println("run excelll"); Dispatch.invoke(workbook,"SaveAs", Dispatch.Method, new Object[]{otFile,new Variant(46)}, new int[1]);//以xml格式保存到目标文件 System.out.println("run pass"); Variant f = new Variant(false); Dispatch.call(workbook, "Close", f); } catch (Exception e) { System.out.println("run exception"); e.printStackTrace(); } finally { System.out.println("run end"); app.invoke("Quit", new Variant[] {}); try { File file = new File(tpFile); file.delete(); } catch (Exception e) {} } }*/ } } /////D:\test\Jacob>javac -classpath jacob.jar Exam_2.java/*D:\test\Jacob>java -cp jacob.jar;. Exam_2 run excelll run exception com.jacob.com.ComFailException: Invoke of: SaveAs Source: Microsoft Excel 8.0 Description: at com.jacob.com.Dispatch.invokev(Native Method) at com.jacob.com.Dispatch.invoke(Dispatch.java) at Exam_2.main(Exam_2.java:38) run end
Runtime.getRuntime().exec(command);
还有你还可以在oracle安装目录下找到一个相同功能的包,
http://jakarta.apache.org/builds/jakarta-poi/release/bin/
我都是向他请教的,我告诉你吧,[email protected]
如果你遇到什么问题的话,我也可以和你一起研究,我的[email protected]
1 Are COM Dates compatible with Java Dates? How can I convert one to each other?
You can use this http://groups.yahoo.com/group/jacob-project/message/97code. Jacobgen wrappers should handle this conversion automatically.
2.
When I downloaded Jacob I didn’t get javadocs, where can I find these?
There are not javadocs available for Jacob classes. However, Jacob is almost 1:1 compatible with Microsoft COM access for Java, you can check out the MS docs at http://www.microsoft.com/java/download/dl_sdk40.htm.
import com.jacob.com.*;
import com.jacob.activeX.*;
import java.util.*;
public class InvokeCom
{
public static void main(String[] args)
{
InvokeCom invoke=new InvokeCom();
invoke.connect();
}
public void connect()
{
try{
ActiveXComponent app = new ActiveXComponent("PROCESSDB.ProcessDBPro");
System.out.println("ActiveXComponent");
Variant[] varConnect=new Variant[4];
Variant varbool;
varConnect[0]=new Variant("server2000");
varConnect[1]=new Variant("sa");
varConnect[2]=new Variant("njbool");
varConnect[3]=new Variant("nrRT_DB");
varbool=app.invoke("ConnectDB",varConnect);
System.out.println("varbool="+varbool.getBoolean());
float flo=55.6f;
Variant[] varInvokeAvg=new Variant[6];
varInvokeAvg[0]=new Variant(3);
varInvokeAvg[1]=new Variant(27);
varInvokeAvg[2]=new Variant("9/23/2002");
varInvokeAvg[3]=new Variant("9/24/2002");
varInvokeAvg[4]=new Variant(5);
varInvokeAvg[5]=new Variant(66.6);
varbool=app.invoke("AVG",varInvokeAvg);
System.out.println("varbool="+varbool.getBoolean());
System.out.println("4="+varInvokeAvg[4].getInt());
System.out.println("5="+varInvokeAvg[5].getDouble());
}
catch(Exception ex)
{
System.out.println("执行失败!");
}
System.out.println("执行完毕!");
}
}
import java.io.File;
import com.jacob.com.*;
import com.jacob.activeX.*;public class Exam_2
{
public static void main(String[] args)
{
System.out.println("run");
//ActiveXComponent app = new ActiveXComponent("Word.Application");//启动word
ActiveXComponent app = new ActiveXComponent("X9.Z.1");//启动word
//System.out.println("run1");
// Object obj = app.getObject();
// Object obje=Dispatch.get(obj,"XX");
// System.out.println("first");
System.out.println("version="+app.getProperty("intcom"));
//System.out.println("version="+Dispatch.get(obj, "intcom"));
String inFile = "D:\\test\\Jacob\\my.doc";//要转换的word文件
String tpFile = "D:\\test\\Jacob\\my.htm";//临时文件
String otFile = "D:\\test\\Jacob\\my.xml";//目标文件
boolean flag = false;
System.out.println("first");
try {
int x=2;
int y=7;
Variant[] var=new Variant[2];
Variant var1=new Variant();
var[0]=new Variant(x);
var[1]=new Variant(y);
System.out.println(var[0].getInt());
// var[1]=new Variant(y);
//var1=app.getProperty("x");
// Object docs = app.getProperty("Documents").toDispatch();
//Object doc = Dispatch.invoke(docs,"Open", Dispatch.Method, new Object[]{inFile,new Variant(false), new Variant(true)}, new int[1]).toDispatch();//打开word文件
// Dispatch.invoke("SaveAs", Dispatch.Method, new Object[]{tpFile,new Variant(8)}, new int[1]);//作为html格式保存到临时文件
//var1=app.invoke();
System.out.println("pass");
/*app.setProperty("Visible", new Variant(false));//设置word不可见
System.out.println("second");
System.out.println("three");
System.out.println("four");
Dispatch.invoke(doc,"SaveAs", Dispatch.Method, new Object[]{tpFile,new Variant(8)}, new int[1]);//作为html格式保存到临时文件
System.out.println("five");
Variant f = new Variant(false);
System.out.println("six");
Dispatch.call(doc, "Close", f);
System.out.println("seven");*/
flag = true;
} catch (Exception e)
{
e.printStackTrace();
}
finally
{
// app.invoke("Quit", new Variant[] {});
}
System.out.println("flag="+flag);
/*if ( flag )
{
app = new ActiveXComponent("Excel.Application");//启动excel
try {
app.setProperty("Visible", new Variant(false));//设置excel不可见
Object workbooks = app.getProperty("Workbooks").toDispatch();
Object workbook = Dispatch.invoke(workbooks,"Open",Dispatch.Method,new Object[]{tpFile,new Variant(false), new Variant(true)}, new int[1]).toDispatch();//打开临时文件
System.out.println("run excelll");
Dispatch.invoke(workbook,"SaveAs", Dispatch.Method, new Object[]{otFile,new Variant(46)}, new int[1]);//以xml格式保存到目标文件
System.out.println("run pass");
Variant f = new Variant(false);
Dispatch.call(workbook, "Close", f);
}
catch (Exception e)
{
System.out.println("run exception");
e.printStackTrace();
}
finally
{
System.out.println("run end");
app.invoke("Quit", new Variant[] {});
try
{
File file = new File(tpFile);
file.delete();
} catch (Exception e) {}
}
}*/
}
}
/////D:\test\Jacob>javac -classpath jacob.jar Exam_2.java/*D:\test\Jacob>java -cp jacob.jar;. Exam_2
run excelll
run exception
com.jacob.com.ComFailException: Invoke of: SaveAs
Source: Microsoft Excel 8.0
Description: at com.jacob.com.Dispatch.invokev(Native Method)
at com.jacob.com.Dispatch.invoke(Dispatch.java)
at Exam_2.main(Exam_2.java:38)
run end
http://www.csdn.net/develop/read_article.asp?id=15311
http://www.csdn.net/develop/read_article.asp?id=15887
Dispath可以定义,也可以用static方法,
你去我给你的网站去看看,我就是那里学的