我目前正在使用eclipse Kepler作为开发工作的ID。我想知道如何打开MS word文件并在eclipse ID中查看相同内容。提前谢谢。
答案 0 :(得分:0)
您应该使用OleClientSite(...,File)。
public class WordSample {
private Shell shell;
private OleFrame frame;
private OleClientSite site;
public WordSample() {
Display display = new Display();
shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setSize(800, 600);
Menu bar = new Menu(shell, SWT.BAR);
shell.setMenuBar(bar);
MenuItem fileMenu = new MenuItem(bar, SWT.CASCADE);
fileMenu.setText("&File");
Menu menuFile = new Menu(fileMenu);
fileMenu.setMenu(menuFile);
MenuItem menuOpen = new MenuItem(menuFile, SWT.CASCADE);
menuOpen.setText("&Open");
menuOpen.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
FileDialog fileDialog = new FileDialog(shell, SWT.OPEN);
fileDialog.setFilterExtensions(new String[] {"*.doc"});
String doc = fileDialog.open();
if (doc != null && !doc.equals("")) {
openDocument(doc);
}
}
});
frame = new OleFrame(shell, SWT.NONE);
frame.setFileMenus(new MenuItem[] {fileMenu});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
private void openDocument(String doc) {
if (site != null && !site.isDisposed()) site.dispose();
site = new OleClientSite(frame, SWT.NONE, "Word.Document", new
File(doc));
site.doVerb(OLE.OLEIVERB_SHOW);
}
public static void main(String[] args) {
WordSample sample = new WordSample();
}
}