风之语

posts(201) comments(182) trackbacks(1)
  • BlogJava
  • 联系
  • RSS 2.0 Feed 聚合
  • 管理

常用链接

  • 我的随笔
  • 我的评论
  • 我的参与
  • 最新评论

留言簿

  • 给我留言
  • 查看公开留言
  • 查看私人留言

随笔分类

  • ajax(1)
  • android(1)
  • apache(1)
  • AppFuse(1)
  • BIRT(1)
  • iText(1)
  • JSF(8)
  • kettle(1)
  • linux(5)
  • mac(1)
  • maven(1)
  • MSTR(3)
  • Open XML(1)
  • Oracle(21)
  • RCP
  • Struts(2)
  • Struts2(2)
  • SybaseIQ(6)
  • tapestry
  • tomcat(2)
  • weblogic(1)
  • webservice(1)
  • weka(1)
  • 云计算(1)
  • 收藏(31)
  • 数据仓库(11)
  • 架构设计(3)
  • 生活(2)
  • 集群(1)
  • 项目管理(6)

随笔档案

  • 2012年12月 (4)
  • 2012年11月 (1)
  • 2012年7月 (2)
  • 2011年8月 (1)
  • 2011年7月 (1)
  • 2011年3月 (1)
  • 2010年12月 (2)
  • 2010年11月 (4)
  • 2010年10月 (3)
  • 2010年9月 (5)
  • 2010年8月 (1)
  • 2010年7月 (4)
  • 2010年3月 (1)
  • 2010年2月 (3)
  • 2009年12月 (3)
  • 2009年11月 (4)
  • 2009年9月 (3)
  • 2009年6月 (5)
  • 2009年5月 (3)
  • 2009年4月 (2)
  • 2009年3月 (5)
  • 2009年2月 (4)
  • 2009年1月 (2)
  • 2008年11月 (2)
  • 2008年9月 (1)
  • 2008年7月 (2)
  • 2008年6月 (4)
  • 2008年5月 (6)
  • 2008年4月 (1)
  • 2008年3月 (1)
  • 2007年12月 (2)
  • 2007年11月 (5)
  • 2007年10月 (2)
  • 2007年9月 (3)
  • 2007年8月 (3)
  • 2007年4月 (1)
  • 2007年3月 (2)
  • 2007年2月 (2)
  • 2007年1月 (2)
  • 2006年12月 (3)
  • 2006年8月 (2)
  • 2006年7月 (2)
  • 2006年6月 (2)
  • 2006年4月 (2)
  • 2006年3月 (1)
  • 2006年2月 (3)
  • 2006年1月 (6)
  • 2005年12月 (6)
  • 2005年11月 (4)
  • 2005年10月 (17)
  • 2005年9月 (25)
  • 2005年8月 (16)
  • 2005年7月 (8)

相册

  • 技术图片

收藏夹

  • java

link

My wife

  • My wife's blog

最新随笔

  • 1. apache修改最大连接并用ab网站压力测试
  • 2. Vm虚拟机访问本地硬盘文件
  • 3. NFS文件无法写入的权限问题
  • 4. weblogic设置上传文件访问权限
  • 5. 在android上动态实现ichartjs的3D柱形图
  • 6. 使用Oracle trunc 来指定精确的年月日时分秒
  • 7. Quartz 2.1.5 web应用配置
  • 8. LoginAny 使用笔记
  • 9. MyEclipse 无响应的几种解决办法
  • 10. java.sql.SQLException: No more data to read from socket

搜索

  •  

积分与排名

  • 积分 - 402063
  • 排名 - 139

最新评论

  • 1. re: 使用Oracle trunc 来指定精确的年月日时分秒[未登录]
  • 政治
  • --张三
  • 2. re: 干掉流氓软件vrvrf_c.exe,vrvedp_m.exe[未登录]
  • `
  • --1
  • 3. re: 无需刻录DMG光盘,教你在VMWare下安装MAC OS X Snow Leopard 10.6
  • 我走到了换DMG映像的时候,然后就没有反应了,这个是什么情况,是不是我的映像文件有问题,还是。。。。
  • --玉竹常青
  • 4. re: LoginAny 使用笔记
  • 怎么没一个人留言,现在来是不是在挖坟啊
  • --ellipse
  • 5. MSTR web应用的部署[未登录]
  • 请问,如何用oracle Application Server服务器部署mstr web应用?
  • --rocky

阅读排行榜

评论排行榜

View Post

RCP 中整合 office(excel、word、outlook)

产品中要用到在Rcp程序中操作Excel。在网上goole了一下,发现一篇文章还不错,测试了一下通过。

Integrate Eclipse RCP with Microsoft Applications - Tutorial
Lars Vogel
<webmaster@vogella.de>


Version 0.5


Copyright © 2007 Lars Vogel

01.11.2007

Abstract

The Eclipse Rich Client Platform (RCP) is using the SWT GUI framework. SWT does allow to integrated Microsoft application via OLE (Object Linking and Embedding). This article will demonstrate how SWT can be used within an Eclipse RCP application to integrate / use Microsoft applications. Microsoft Outlook and Microsoft Excel are used as examples

This article assumes that you are already familiar with using the Eclipse IDE and with developing simple Eclipse RCP applications.


--------------------------------------------------------------------------------

Table of Contents

1. Microsoft Object Linking and Embedding
1.1. Overview
2. Microsoft Integration - Sending an email via outlook
2.1. Create Project
2.2. Add action
2.3. Program the action
3. Microsoft Integration - Use Excel in your application.
3.1. Create Project
3.2. Change View code
4. Links and Literature
1. Microsoft Object Linking and Embedding
1.1. Overview
Windows applications use OLE (Object Linking and Embedding) to allow applications to control other application objects. The following will show how to do this using a few examples.

2. Microsoft Integration - Sending an email via outlook
This example assumes you running an MS operating system and that you have a version of Outlook installed.

2.1. Create Project
Create a new project "OutlookTest" (see here how to create a new RCP project). Use the "Hello RCP " as a template.

2.2. Add action
Using extensions add action "sendEmail" (see here how to add an action). The class of this action should be "outlooktest.SendEmail". Run the application. The result should look like the following.

 


2.3. Program the action
Lets program the action. The following coding will create and open the email for the user. It also assumes that you have a file c:\temp\test.txt which will be attached to the email.


    package outlooktest;

import java.io.File;

import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.SWT;
import org.eclipse.swt.ole.win32.OLE;
import org.eclipse.swt.ole.win32.OleAutomation;
import org.eclipse.swt.ole.win32.OleClientSite;
import org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.ole.win32.Variant;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;

public class SendEmail implements IWorkbenchWindowActionDelegate {

 private Shell shell;

 @Override
 public void dispose() {

  // TODO Auto-generated method stub

 }

 @Override
 public void init(IWorkbenchWindow window) {

  shell = window.getShell();

 }

 @Override
 public void run(IAction action) {

  Display display = Display.getCurrent();

  Shell shell = new Shell(display);

  OleFrame frame = new OleFrame(shell, SWT.NONE);

  // This should start outlook if it is not running yet

  OleClientSite site = new OleClientSite(frame, SWT.NONE, "OVCtl.OVCtl");

  site.doVerb(OLE.OLEIVERB_INPLACEACTIVATE);

  // Now get the outlook application

  OleClientSite site2 = new OleClientSite(frame, SWT.NONE,

  "Outlook.Application");

  OleAutomation outlook = new OleAutomation(site2);

  //

  OleAutomation mail = invoke(outlook, "CreateItem", 0 /* Mail item */)

  .getAutomation();

  setProperty(mail, "To", "test@gmail.com"); /* Empty but could also be predefined */
  
  setProperty(mail, "Bcc", "test@gmail.com"); /* Empty but could also be predefined */

  setProperty(mail, "BodyFormat", 2 /* HTML */);

  setProperty(mail, "Subject", "Top News for you");

  setProperty(mail, "HtmlBody",

  "<html>Hello<p>, please find some infos here.</html>");
  File file = new File("c:/temp/test.txt");
  if (file.exists()) {
   OleAutomation attachments = getProperty(mail, "Attachments");

   invoke(attachments, "Add", "c:/temp/test.txt");
  } else {
   MessageDialog

     .openInformation(shell, "Info",
       "Attachment File c:/temp/test.txt not found; will send email with attachment");

  }
  invoke(mail, "Display" /* or "Send" */);

 }

 private static OleAutomation getProperty(OleAutomation auto, String name) {

  Variant varResult = auto.getProperty(property(auto, name));

  if (varResult != null && varResult.getType() != OLE.VT_EMPTY) {

   OleAutomation result = varResult.getAutomation();

   varResult.dispose();

   return result;

  }

  return null;

 }

 private static Variant invoke(OleAutomation auto, String command,

 String value) {

  return auto.invoke(property(auto, command),

  new Variant[] { new Variant(value) });

 }

 @Override
 public void selectionChanged(IAction action, ISelection selection) {

  // TODO Auto-generated method stub

 }

 private static Variant invoke(OleAutomation auto, String command) {

  return auto.invoke(property(auto, command));

 }

 private static Variant invoke(OleAutomation auto, String command, int value) {

  return auto.invoke(property(auto, command),

  new Variant[] { new Variant(value) });

 }

 private static boolean setProperty(OleAutomation auto, String name,

 String value) {

  return auto.setProperty(property(auto, name), new Variant(value));

 }

 private static boolean setProperty(OleAutomation auto, String name,

 int value) {

  return auto.setProperty(property(auto, name), new Variant(value));

 }

 private static int property(OleAutomation auto, String name) {

  return auto.getIDsOfNames(new String[] { name })[0];

 }

}

   

If you now start the application and press the button an email should be prepared and shown to the user.

 


3.  Microsoft Integration - Use Excel in your application.
This example assume that you running on Microsoft and that you have a version of Microsoft Excel installed.

3.1. Create Project
Create a new project "ExcelTest" (see here how to create a new RCP project). Use the "RCP with a view" as a template. Run it and see that is working.

3.2. Change View code
Select View.java and replace the coding with the following.


    
package exceltest;

import org.eclipse.swt.SWT;
import org.eclipse.swt.SWTError;
import org.eclipse.swt.ole.win32.OleClientSite;
import org.eclipse.swt.ole.win32.OleFrame;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.part.ViewPart;

public class View extends ViewPart {

 public static final String ID = "ExcelTest.view";
 private OleClientSite site;

 public View() {
 }

 @Override
 public void createPartControl(Composite parent) {
  try {
   OleFrame frame = new OleFrame(parent, SWT.NONE);
   site = new OleClientSite(frame, SWT.NONE, "Excel.Sheet");
  } catch (SWTError e) {
   System.out.println("Unable to open activeX control");
   return;
  }
 }

 @Override
 public void setFocus() {
  // Have to set the focus see https://bugs.eclipse.org/bugs/show_bug.cgi?id=207688
   site.setFocus();
 }

}

   

Start your application and excel should be displayed.

 


4. Links and Literature
http://www.eclipse.org/ Eclipse Website

http://www.vogella.de/articles/Eclipse/article.html Using Eclipse as IDE - Tutorial

http://www.vogella.de/articles/RichClientPlatform/article.html Eclipse Rich Client Platform - Tutorial

http://www.vogella.de/articles/EclipseCodeAccess/article.html A guide to access the Eclipse Sources

 

posted on 2008-05-17 09:21 风 阅读(1898) 评论(0)  编辑  收藏

新用户注册  刷新评论列表  

只有注册用户登录后才能发表评论。


网站导航:
博客园   IT新闻   Chat2DB   C++博客   博问   管理
 
 
Powered by:
BlogJava
Copyright © 风