没有合适的资源?快使用搜索试试~ 我知道了~
SWT EXCEL OLE
4星 · 超过85%的资源 需积分: 9 26 下载量 60 浏览量
2011-03-21
23:28:24
上传
评论
收藏 24KB DOCX 举报
温馨提示
试读
12页
SWT通过OLE调用Excel,并对其进行操作。Eclipse3.3以上版本使用
资源推荐
资源详情
资源评论
使 Excel 嵌入到 SWT 窗口中
使用的 Eclipse 版本:3.3.1
使用的 jdk 版本:5.0
package com.jrkui.example.excel;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.ole.win32.OLE;
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.Menu;
import org.eclipse.swt.widgets.Shell;
public class ExcelShell {
public static void main(String[] args) {
new ExcelShell().open();
}
public void open()
{
Display display = Display.getDefault();
Shell shell = new Shell();
shell.setSize(600,400);
shell.setText("Excel Window");
shell.setLayout(new FillLayout());
//显示 Excel 的菜单栏
shell.setMenuBar(new Menu(shell,SWT.BAR));
createExcelPart(shell);
shell.open();
while(!shell.isDisposed()){
if(!display.readAndDispatch())
display.sleep();
}
display.close();
}
/**
* 使 Excel 嵌入到 shell 中
* @param shell
*/
private void createExcelPart(Shell shell)
{
//OleFrame 实际上是一个 Composite,用于放置 OLE 控件
OleFrame oleFrame = new OleFrame(shell,SWT.NONE);
//OleClientSite 提供一个场所用于把 OLE 对象嵌入到容器中,在这里“Excel.Sheet”
表示的 OLE 对象是 Excel
OleClientSite clientSite = new
OleClientSite(oleFrame,SWT.NONE,"Excel.Sheet");
//OleClientSite 在 显 示 OLE 对 象 时 所 做 的 动 作 , 这 里 的 动 作 是
OLEIVERB_SHOW,表示显示
clientSite.doVerb(OLE.OLEIVERB_SHOW);
}
}
显示结果:
注意
<!--[if !supportLists]-->嵌入 Excel 的方法是 createExcelPart(Shell shell)
<!--[if !supportLists]-->Excel.Sheet 为 Excel 的 Id,如果要嵌入 Word,则其 Id
为 Word.Document
<!--[endif]-->这是 OleClientSite#doVerb()的参数的解释及可选的值:
verb – an integer value mapping to one of the following pre-deJned verb
values:
<!--[if !supportLists]-->· <!--[endif]-->OLE.OLEIVERB_PRIMARY -
SpeciJes the action that occurs when an end user double-clicks the object in
its container. The object, not the container, determines this action. If the
object supports in-place activation, the primary verb usually activates the
object in place.
<!--[if !supportLists]-->· <!--[endif]-->OLE.OLEIVERB_SHOW -
Instructs an object to show itself for editing or viewing. Called to display newly
inserted objects for initial editing and to show link sources. Usually an alias for
some other object-deJned verb.
<!--[if !supportLists]-->· <!--[endif]-->OLE.OLEIVERB_OPEN -
Instructs an object, including one that otherwise supports in-place activation,
to open itself for editing in a window separate from that of its container. If the
object does not support in-place activation, this verb has the same
semantics as OLEIVERB_SHOW.
<!--[if !supportLists]-->· <!--[endif]-->OLE.OLEIVERB_HIDE -
Causes an object to remove its user interface from the view. Applies only to
objects that are activated in-place.
<!--[if !supportLists]-->· <!--[endif]--
>OLE.OLEIVERB_INPLACEACTIVATE - Activates an object in place without
displaying tools, such as menus and toolbars, that end users need to change
the behavior or appearance of the object. Single-clicking such
an object causes it to negotiate the display of its user-interface tools with its
container. If the container refuses, the object remains active but without its
tools displayed.
<!--[if !supportLists]-->· <!--[endif]-->OLE.OLEIVERB_UIACTIVATE -
Activates an object in place, along with its full set of user-interface tools,
including menus, toolbars, and its name in the title bar of the container
window.
<!--[if !supportLists]-->· <!--[endif]--
>OLE.OLEIVERB_DISCARDUNDOSTATE - Used to tell objects to discard any
undo state that they may be maintaining without deactivating the object.
为 Excel 的 A1 单元格赋值
代码:
package com.jrkui.example.excel;
import java.io.File;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
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.program.Program;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.Shell;
public class ExcelShell {
public static void main(String[] args) {
new ExcelShell().open();
}
public void open()
{
Display display = Display.getDefault();
Shell shell = new Shell();
shell.setSize(600,400);
shell.setText("Excel Window");
shell.setLayout(new FillLayout());
//使 Excel 的菜单栏显示
shell.setMenuBar(new Menu(shell,SWT.BAR));
createExcelPart(shell);
shell.open();
while(!shell.isDisposed()){
if(!display.readAndDispatch())
display.sleep();
}
display.close();
}
/**
* 使 Excel 嵌入到 shell 中
剩余11页未读,继续阅读
资源评论
- niewenbinniewenbin2014-01-02从别的网站上复制出来的,还要3分,不好
- cohenking2014-06-28能用,一看就懂,不错
a27382638
- 粉丝: 1
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- SSCMS登录模块需要的JS文件
- JSP网络购物中心毕业设计(源代码+论文).rar
- 白盒测试报告.docx
- 基于LM5117芯片评估开发板硬件参考设计(原理图+PCB)+中英文数据手册资料.zip
- 照片批量重命名软件(文件批量修改图片文件名)
- app.apk
- 人工智能(AI)是计算机科学的一个分支,旨在开发和应用能够模拟、延伸和扩展人类智能的理论、方法和技术,包括机器人、语言识别、图像
- 嵌入式与物联网开发是当今信息技术领域的两大重要分支,它们相互交织,共同推动着智能化时代的进步 嵌入式开发主要关注在嵌入式操作
- 网络安全,这一看似高深莫测的领域,实则与我们每个人的生活息息相关
- 毕业设计基于深度学习的视觉问答系统源码+文档说明+答辩PPT.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功