Jacom 操作Office Word及Excel 代码示例

来源:互联网 发布:mac 翻墙 免费 知乎 编辑:程序博客网 时间:2024/06/06 04:02

操作Wold代码示例

//获取操作office对象
ActiveXComponent wordApp = new ActiveXComponent("Word.Application");  
//设置office属性
wordApp.setProperty("Visible", new Variant(true));

//根据office对象生成获取officeWord文档
Dispatch document = wordApp.getProperty("Documents").toDispatch(); 

                 //打开Word文档
Dispatch openDoc = Dispatch.call(document, "Open",new Variant("D://Codes//Word2HTML//test.doc")).toDispatch();


操作Exce代码示例

                 //获取操作office对象
ActiveXComponent excelApp = new ActiveXComponent("Excel.Application");
//设置属性
excelApp.setProperty("Visible", new Variant(true));
//获取Excel操作对象
Dispatch excelWorkBooks = excelApp.getProperty("WorkBooks").toDispatch();
//打开Excel
Dispatch excelDoc = Dispatch.call(excelWorkBooks, "Open",new Variant("D:\\Codes\\Word2HTML\\test.xlsx")).toDispatch();