操作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();