import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;public class MSWordManager {
public static void main(String[] args) {
ComThread.InitSTA();// 初始化com的线程,非常重要!!使用结束后要调用 realease方法
ActiveXComponent objWord = new ActiveXComponent("Word.Application");
Dispatch wordObject = (Dispatch) objWord.getObject();
//word.setProperty("Visible", new Variant(visible));
Dispatch.put((Dispatch) wordObject, "Visible", new Variant(false));// new Variant(true)表示word应用程序可见
Dispatch documents = objWord.getProperty("Documents").toDispatch(); //documents表示word的所有文档窗口,(word是多文档应用程序)
Dispatch document = Dispatch.call(documents, "Open","e:\\wow.doc").toDispatch(); // 使用Add命令创建一个新文档,用Open命令可以打开一个现有文档
Dispatch selection = Dispatch.get(objWord, "Selection").toDispatch(); //光标位置
//Dispatch wordContent = Dispatch.get(document, "Content").toDispatch(); // 取得word文件的内容
Dispatch tables = Dispatch.get(document, "Tables").toDispatch();
Dispatch table = Dispatch.call(tables, "Item",new Variant(1)).toDispatch() ;
Dispatch rows = Dispatch.get(table, "Rows").toDispatch();// 表格的所有行
Dispatch cell = Dispatch.call(table, "Cell",
new Variant(1),
new Variant(1)).toDispatch(); //得到单元格
Dispatch.call(cell, "Select").toDispatch();// 选中单元格
// Dispatch font = Dispatch.get(selection, "Font").toDispatch();// 设置格式
// Dispatch.put(font, "Bold", "0");
// Dispatch.put(font, "Italic", "0");
Dispatch.put(selection, "Text", "彭小东");// 填入数据
Dispatch.call(document, "SaveAs", new Variant("e:\\178.doc")); // 保存一个新文档
ComThread.Release();//释放com线程。根据jacob的帮助文档,com的线程回收不由java的垃圾回收器处理
}
}
到底有个什么错误,看半天搞不出来,求大牛!
import com.jacob.com.ComThread;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;public class MSWordManager {
public static void main(String[] args) {
ComThread.InitSTA();// 初始化com的线程,非常重要!!使用结束后要调用 realease方法
ActiveXComponent objWord = new ActiveXComponent("Word.Application");
Dispatch wordObject = (Dispatch) objWord.getObject();
//word.setProperty("Visible", new Variant(visible));
Dispatch.put((Dispatch) wordObject, "Visible", new Variant(false));// new Variant(true)表示word应用程序可见
Dispatch documents = objWord.getProperty("Documents").toDispatch(); //documents表示word的所有文档窗口,(word是多文档应用程序)
Dispatch document = Dispatch.call(documents, "Open","e:\\wow.doc").toDispatch(); // 使用Add命令创建一个新文档,用Open命令可以打开一个现有文档
Dispatch selection = Dispatch.get(objWord, "Selection").toDispatch(); //光标位置
//Dispatch wordContent = Dispatch.get(document, "Content").toDispatch(); // 取得word文件的内容
Dispatch tables = Dispatch.get(document, "Tables").toDispatch();
Dispatch table = Dispatch.call(tables, "Item",new Variant(1)).toDispatch() ;
Dispatch rows = Dispatch.get(table, "Rows").toDispatch();// 表格的所有行
Dispatch cell = Dispatch.call(table, "Cell",
new Variant(1),
new Variant(1)).toDispatch(); //得到单元格
Dispatch.call(cell, "Select").toDispatch();// 选中单元格
// Dispatch font = Dispatch.get(selection, "Font").toDispatch();// 设置格式
// Dispatch.put(font, "Bold", "0");
// Dispatch.put(font, "Italic", "0");
Dispatch.put(selection, "Text", "彭小东");// 填入数据
Dispatch.call(document, "SaveAs", new Variant("e:\\178.doc")); // 保存一个新文档
ComThread.Release();//释放com线程。根据jacob的帮助文档,com的线程回收不由java的垃圾回收器处理
}
}
到底有个什么错误,看半天搞不出来,求大牛!
解决方案 »
- S2SH,hibernate二级缓存,报错。 求解。。。 在线等....
- ajax问题,本人初学
- JDBC 连接SQL SERVER 2000 问题
- 高分求助,判断jsp错误原因 100分
- 如何发布所做好的网站,请教大虾
- 初学,问个J2ee的简单问题
- 要用JDBC访问MSSQL,系统该如何配置,哪里能下载到mssqlserver.jar...这3个文件
- 关于eclipse的简单问题
- 关于editplus的配置
- ssh问题用spring管理action,配置后出现下面错误
- 请教腾讯webQQ的实现机制
- 我导师给了我ccp摄像头的源代码,要求我编写一个基于web的远程传输软件来实现远程监控,我不知道该怎么办,我的c++水平一般,网络编程方面更加欠缺,不知该怎么办,请哪位大虾帮帮忙。
这边的toDispatch去掉试试