首页 技术 正文
技术 2022年11月15日
0 收藏 958 点赞 3,256 浏览 5944 个字

1:定义流的header , OleContainer要求流中要有Header
type

//流Header的结构

TStreamHeader = record

Signature: Integer; //$434F4442

DrawAspect: Integer; //1

DataSize: Integer; //stream.size;

end;

注:OleContainer要求的流=header + 内存流

2:从数据库中取出字段到内存流:

TBlobField(FADOQuery3.FieldByName(‘FContent’)).SaveToStream(AMemoryStream);

保存:

TBlobField(FADOQuery3.FieldByName(‘FContent’)).LoadFromStream(AMemoryStream);

3:从流中读出并显示:

procedure TFrameWord.DispFileContent(AMStream: TMemoryStream);

var

ft: string;

ms: TMemoryStream;

oMemoryStream : TMemoryStream;

Header : TStreamHeader;

begin

ms := AMStream;

if (ms = nil) or (ms.Size = 0) then Exit;

ms.Position := 0;

oMemoryStream := TMemoryStream.Create;

try

with Header do

begin

Signature := $434F4442;

DrawAspect := 1;

DataSize := ms.Size;

end;

ms.Position := 0;

oMemoryStream.WriteBuffer(Header,SizeOf(Header));

oMemoryStream.CopyFrom(ms, 0);

oMemoryStream.Position := 0;

OleContainer.LoadFromStream(oMemoryStream);

OleContainer.DoVerb(ovPrimary);

finally

oMemoryStream.Free;

end;

end;

4: 从文件中读出:

OleContainer.CreateObjectFromFile(‘D:\work\BidBuild_Client\doc\实用ASP组件介绍.DOC’, False);

OleContainer.DoVerb(ovPrimary);

5:设置只读,并隐藏工具菜单和屏蔽右键菜单中的编辑功能:

Word文档:

OleContainer.OleObject.Application.ActiveDocument.Protect(2);

OleContainer.OleObject.application.CommandBars[‘Standard’].Visible:=false;

OleContainer.OleObject.application.CommandBars[‘Formatting’].Visible:=false;

OleContainer.OleObject.application.CommandBars[‘Reviewing’].Visible:=false;

或:

OleContainer.OleObject.Application.ActiveDocument.Protect(2);

OleContainer.OleObject.Application.ActiveWindow.ActivePane.DisplayRulers := False;

Excel文档:

OleContainer.OleObject.Application.ActiveSheet.Protect;

OleContainer.OleObject.application.CommandBars[‘Standard’].Visible:=false;

OleContainer.OleObject.application.CommandBars[‘Formatting’].Visible:=false;

OleContainer.OleObject.application.CommandBars[‘Reviewing’].Visible:=false;

注:以上代码放到OleContainer.DoVerb(ovPrimary)之后

6:关闭

if OleContainer.State <> osEmpty then

OleContainer.Close;

7:OLEContainer 控件的主要属性和方法

1) AllowInPlace property AllowInPlace:Boolean;

这个属性用于决定启动OLE对象服务程序的方式,如果为假,那么运行其间激活OLE对象时,打开整个OLE服务程序,即单独

开一个窗口,而为真时, 则把服务的菜单合并到应用程序中.

2) AutoActive type TAutoActivate=(aaManual,aaGetFocus,aaDoubleClick);

property AutoActivate: TAutoActivate;

找开方式. 其中aaManual时,要激活OLE对象,必须在程序中调用方法DoVerb(OnShow)

3) CanPaste property CanPaste:Boolean;

只读属性,如果剪贴板中的内容适合粘贴到一个OLE对象,则为true, 否则为false

4) CopyOnsave property CopyOnsave:boolean;

为真则表示把OLE对象临时写到一个文件中,反之表示全部留在内在中.

5) Iconic property Iconic:Boolean;

是否以图标方式显示以节省屏幕上的空间

6) Linked property Linked:Boolean;

只读属性,返回真表示OLE对象是连接到文档中,返回假表示OLE对象是嵌入到文档中.

7) Modify property modified:Boolean;

当OLE对象发生了变化时(包括这个对象被删除或被其他OLE对象所替代),这个属性被设置为真

8) NewInserted property NewInserted:Boolean;

只读,如果刚刚调用的InsertObjectDialog函数插入了一个OLE对象,返回真.这时可调用Doverb(OvShow)激活这个OLE对

象.

9) OleClassName property OleClassName:string;

只读. 返回OLE对象的类名, 当程序中有多个OLE对象时,可以用这个属性作为它们各自的标签.

10)OleObject property oleobject:Variant;

只读, 返回OLE容器中的OLE对象, 这个属性很重要,通过这个属性可以访问OLE服务程序.

11) OleObjectInterface property OleObjectInterface:IOleObject;

只读. 返回OLE对象的OleObject接口,在直接调用OLE的API需要用到这个接口.

12) OldStreamFormat property OldStreamFormat:Boolean;

如果为真, OLE对象就以OLE1的格式存储, 为假就以OLE2的格式存储.

13) PrimaryVerb property PrimaryVerb: integer;

只读. 返回OLE对象可进行的操作中主操作的索引号(序号)

14) SizeMode type TSizeMode = (smClip, smCenter, smScale, smStretch, smAutoSize);

property SizeMode:TSizeMode;

smClip, 超过容器的部分将被裁减.

smCenter, 中间.

smScale, 自动适应容器的大小

smStretch, 自动撑满

smAutoSize, 容器自动调整, 以适应OLE的大小.

15) State type TObjectState=(osEmpty,osLoaded,osRunning,osOpen,osInPlaceActive,osUIActive);

property State: TObjectState;

只读, 返回OLE对象的状态,可以是以下值.

osEmpty,容器中没有OLE对象.

osLoaded,容器中有OLE对象.但OLE服务程序没有运行.

osRunning,服务器正在运行.

osOpen,对象正在运行,OLE服务程序单独运行.

osInPlaceActive,对象正在运行,OLE服务程序菜单将要被合并到客户程序中运行.

osUIActive,对象正在运行,OLE服务程序菜单已经被合并到客户程序中运行.

OLEContainer 控件的主要方法

1) ChangeIconDialog function ChangeIconDialog:Boolean;

调用这个函数将打开一个更改图标的对话框. 当OLE对象以图标显示时,就以用户选择的图标显示.

2) Close 过程 procedure Close;

关闭. 如果OLE对象已修改,调用Close将首先保存OLE对象.

3) Copy 过程 procedure copy;

把OLE对象复制到剪贴板中

4) CteateLinkToFile方法 procedure CreateLinkToFile(FileName:string; Iconic:Boolean);

创建一个OLE对象,其内容从指定的文件中读取,创建的OLE对象链接到OLE容器中. 如果OLE容器中已经有一个OLE对象, 这个已有的OLE对象将被删除,未保存的修改也被作废. Iconic参数设为True表示OLE对象以图标显示.

5) CreateObject 过程. procedure CreateObject(const OleClassName:string;Iconic:Boolean);

这个过程用于创建一个OLE对象,OleClassName参数指定对象的识别名,创建后的OLE对象嵌入到OLE容器中,如果OLE容器中已经有一个OLE对象, 这个已有的OLE对象将被删除,未保存的修改也被作废. Iconic参数设为True表示OLE对象以图标显示.

6) CreateObjectFromFile 过程 procedure CreateObjectFromFile(const FileName:string; Iconic:Boolean);

创建一个OLE对象,其内容从指定的文件中读取,创建的OLE对象嵌入到OLE容器中. 如果OLE容器中已经有一个OLE对象, 这个已有的OLE对象将被删除,未保存的修改也被作废. Iconic参数设为True表示OLE对象以图标显示.

7) CreateObjectFromInfo 方法, procedure CreateObjectFromInfo(const CreateInfo:TCreateInfo);

创建一个OLE对象,其内容从CreateInfo参数年指定的记录中读取(这个参数是个记录类型,包含了创建OLE对象所需要的信息)

8) DoVerb 方法. procedure DoVerb(Verb:Integer);

用于对OLE对象进行操作,verb参数指定操作类型.

9) ObjectPropertiesDialog函数 function objectPropertiesDialog:Boolean;

用来打开Windows OLE对象属性对话框,用于修改OLE对象的属性.

10) Run 方法.procedure Run;

用于运行OLE服务程序,但并不激活OLE对象本身,当服务程序处于运行状态后激活OLE对象将非常快.

11) PasteSpecialDialog方法 function PasteSpecialDialog:Boolean;

该方法打开Windows的选择性粘贴对话框.

8:OLE方式Word中插入图片

我是在delphi中用olecontainer操作word,要向其中插入图片,使用粘贴板。但是图片放入后位置是这一行的开始位置,如下:

{ 将一副图片粘贴到word中 }

ClipBoard.Assign(aImage.Picture);

{ 以下为vba代码–可在word中利用录制宏的功能取得——————–bagin }

{ 使用vba之前加 x.OleObject.application 例如:excel添加工作表 }

{ oc.OleObject.application.sheets.Add; }

intInlineShapesIndex:=ocDoc.OleObject.application.ThisDocument.InlineShapes.Count+1;

intShapesIndex:=ocDoc.OleObject.application.ThisDocument.Shapes.Count+1;

//从剪贴板添加一个图片

ocDoc.OleObject.application.Selection.Paste;

//转换为图形

ocDoc.OleObject.application.ThisDocument.InlineShapes(intInlineShapesIndex).ConvertToShape;

//设置文字环绕方式

ocDoc.OleObject.application.ThisDocument.Shapes(intShapesIndex).WrapFormat.Type := ‘wdWrapThrough’;

//将图片中的白色设为透明色

ocDoc.OleObject.application.Selection.InlineShapes(intShapesIndex).PictureFormat.TransparentBackground := ‘msoTrue’;

ocDoc.OleObject.application.Selection.InlineShapes(intShapesIndex).PictureFormat.TransparencyColor:=’RGB(255,255,255)’;

ocDoc.OleObject.application.Selection.InlineShapes(intShapesIndex).Fill.Visible := ‘msoFalse’;

{ 以上为vba代码–可在word中利用录制宏的功能取得———————-end }

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,904
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,430
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,247
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,058
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,690
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,727