asd

java.awt.Toolkit类里的
getSystemClipboard();

package com.test;

import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;

public class OLETest {

public static void wordToHtml(String docfile, String htmlfile)
throws Exception {
ActiveXComponent app = new ActiveXComponent("Word.Application"); // 启动word
try {
// 设置word不可见。
app.setProperty("Visible", new Variant(false));
// 获取Documents对象。
Dispatch docs = app.getProperty("Documents").toDispatch();
// 打开word文件
Dispatch doc = Dispatch.invoke(
docs,
"Open",
Dispatch.Method,
new Object[] { docfile, new Variant(false),
new Variant(true) }, new int[1]).toDispatch();

// 获得doc的超链接
Dispatch shapes = Dispatch.get(doc, "InLineShapes").toDispatch();
// 获得当中的一项
int count = Dispatch.get(shapes, "Count").getInt();
try {
for (int i = 1; i <= count; i++) {
Dispatch shape = Dispatch.call(shapes, "Item",
new Variant(i)).toDispatch();
int stype = Dispatch.get(shape, "Type").getInt();
// 类型为word的内嵌对像,无论任何类型的

if (1 == stype) {
Dispatch oneo = Dispatch.get(shape, "OLEFormat")
.toDispatch();
String classType = Dispatch.get(oneo, "ClassType")
.toString();
System.out.println(classType);
if ("Word.Document.8".equals(classType)) {
Variant cobj = Dispatch.call(shape, "Select");
Dispatch copy = Dispatch.get(docs, "Application")
.toDispatch();

Dispatch Paste = Dispatch.get(copy, "Selection")
.toDispatch();

Dispatch.call(Paste, "Copy");
// 是word
Dispatch obj = Dispatch.get(oneo, "Object").toDispatch();
//Dispatch o = Dispatch.call(obj, "Edit").toDispatch();

//Dispatch exeType = Dispatch.get(obj, "Container")
// .toDispatch();
String name = Dispatch.get(oneo, "IconPath")
.toString();
String name1 = Dispatch.get(oneo, "IconName")
.toString();
String name2 = Dispatch.get(oneo, "IconLabel")
.toString();
System.out.println("\\" + name + "\\"
+ name1 + "\\" + name2);
//System.out.println(classType + "," + name);
String saveout = "E:\\word2html\\word\\";
Dispatch.invoke(obj, "SaveAs", Dispatch.Method, new Object[] {
saveout+"xx"+".exl"}, new int[1]);
} else {// 不是word,没有Object属性

//Dispatch.call(oneo, "Open").toDispatch();
Dispatch obj = Dispatch.call(oneo, "Object").toDispatch();


//Dispatch exeType = Dispatch.get(obj, "Container")
//.toDispatch();
//String name = Dispatch.get(exeType, "Name")
//.toString();
//System.out.println(name);
// String name0 = Dispatch.call(oneo, "DoVerb")
// .toString();
// String name = Dispatch.get(oneo, "IconPath")
// .toString();
// String name1 = Dispatch.get(oneo, "IconName")
// .toString();
// String name2 = Dispatch.get(oneo, "IconLabel")
// .toString();
// System.out.println(name0 + "\\" + name + "\\"
// + name1 + "\\" + name2);
}
}

}
} catch (Exception e) {
e.printStackTrace();
} finally {
Variant f = new Variant(false);
// 关闭word文件。
//Dispatch.call(doc, "Close", f);
//app.invoke("Quit", new Variant[] {});
}
} catch (Exception e) {
throw e;
}
}

public static void main(String[] args) {
try {
wordToHtml("E:\\word2html\\word\\TestDocBenjamin.doc","E:\\word2html\\word\\TestDocBenjamin.html");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值