package com.test;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
public class WordBean extends java.awt.Panel {
private ActiveXComponent MsWordApp = null;
private Dispatch document = null;
public WordBean() {
super();
}
// 開啟word文檔
public void openWord(boolean makeVisible) {
if (MsWordApp == null) {
MsWordApp = new ActiveXComponent("Word.Application");
}
// 設定開啟word文檔是否可見
Dispatch.put(MsWordApp, "Visible", new Variant(makeVisible));
}
// 開啟wordDocument
public void openWordDocument(String openFile) {
Dispatch documents = Dispatch.get(MsWordApp, "Documents").toDispatch();
document = Dispatch.invoke(documents, "Open",Dispatch.Method,
new Object[] { openFile, new Variant(false),
new Variant(true) }, new int[1]).toDispatch();
}
// 建立word文檔
public void createNewDocument() {
// Find the Documents collection object maintained by Word
Dispatch documents = Dispatch.get(MsWordApp, "Documents").toDispatch();
document = Dispatch.call(documents,