📄 wordactivex1.java
字号:
package cn.com.chengang.swt.activex;
import java.io.File;
import java.net.URISyntaxException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.ole.win32.OleClientSite;
import org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
public class WordActiveX1 {
public static void main(String[] args) throws URISyntaxException {
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(500, 450);
// ---------创建窗口中的其他界面组件-------------
shell.setLayout(new FillLayout());
OleFrame oleFrame = new OleFrame(shell, SWT.NONE);// 该对象是ActiveX控件的容器,并管理该控件的生命周期。
File file = new File(WordActiveX1.class.getResource("a.doc").toURI());// 创建文档的File对象
OleClientSite clientSite = new OleClientSite(oleFrame, SWT.NONE, file);// 创建一个ole嵌入面板
// File file = new File(WordActiveX1.class.getResource("a.txt").toURI());
// // "Word.Document.8"是Word控件在Windows系统中的唯一标识符。也可以用"Word.Document",则将自动使用当前版本的Word控件
// OleClientSite clientSite = new OleClientSite(oleFrame, SWT.NONE, "Word.Document.8", file);
System.out.println(clientSite.getProgramID());// 打印控件的唯一标识符
// -----------------END------------------------
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -