请问可以使用jacob操作WORD文档的页眉页脚吗?谢谢!

chkbf
05-08-16 1 753

请问可以使用jacob操作WORD文档的页眉页脚吗?文档的内容已经可以使用JACOB操作,可是页眉页脚呢?请诸位赐教。小弟实在有些摸不着头脑,或者使用其他的解决办法也可以,只要能够实现将一个已存在的WORD文档插入指定的页眉页脚,谢谢!

chkbf
2005-08-16 10:52

已经自己解决了,还是谢谢大家!
以下是代码部分,实在是班门弄斧,也许能给大家一点点帮助吧。
try {
String sInputDoc = "d:\\test\\test1.doc";
String sOutputDoc = "d:\\test\\test2.doc";
String sOldText = "113";
String sNewText = "测试替换语句";
boolean tVisible = true;
boolean tSaveOnExit = false;
/////////////////////////////////////////////////////////////
ActiveXComponent oWord = new ActiveXComponent("Word.Application");
oWord.setProperty("Visible", new Variant(tVisible));
Object oDocuments = oWord.getProperty("Documents").toDispatch();
Object oDocument = Dispatch.call(oDocuments, "Open", sInputDoc).toDispatch();
Object oSelection = oWord.getProperty("Selection").toDispatch();

Object oFind = oWord.call(oSelection, "Find").toDispatch();

Object alignment = Dispatch.get(oSelection, "ParagraphFormat").toDispatch();
Object image = Dispatch.get(oSelection, "InLineShapes").toDispatch();

//取得活动内容对象
Object ActiveDocument = oWord.getProperty("ActiveDocument").toDispatch();
//取得活动窗体对象
Object ActiveWindow = oWord.getProperty("ActiveWindow").toDispatch();
//取得活动窗格对象
Object ActivePane = Dispatch.get(ActiveWindow, "ActivePane").toDispatch();
//取得视窗对象
Object View = Dispatch.get(ActivePane, "View").toDispatch();

Dispatch.put(View, "SeekView", "9");
Dispatch.put(oSelection, "Text", "页眉你出来吧!! ");
Dispatch.call(oSelection, "MoveRight");
Dispatch.call(image, "AddPicture", "d:\\test\\1.gif");