这个是个调用office OLE 的例子,你参考一下,然后可以按照第三方控件的方法导入!
unit OleAdvFunc;
interface
uses
OleCtnrs, Dialogs;
type
TOleWordExpand = class
private
FOle: TOleContainer;
FTrack: Boolean;
FUserName: String;
procedure SetOle(const Value: TOleContainer);
procedure SetTrack(const Value: Boolean);
public
procedure AddPicture(AFilename: String);
procedure Activate;
property TrackRevisions: Boolean read FTrack write SetTrack;
property Ole: TOleContainer read FOle write SetOle;
property UserName: String read FUserName write FUserName;
end;
procedure OleActivate(AOle: TOleContainer);
procedure OleDoVerb(AOle: TOleContainer; AVerb: Integer);
procedure OleAddPicture(AOle: TOleContainer; AFilename: String);
procedure OleTrackRevisions(AOle: TOleContainer; ATrack: Boolean);
procedure OleUserName(AOle: TOleContainer; AUserName: String);
procedure OleToolBarShow(AOle: TOleContainer; AShow: Boolean);
procedure OleStandAlone(AOle: TOleContainer);
procedure OleFillField(AOle: TOleContainer; AFieldName, AFieldValue: String);
implementation
uses Word2000, Forms, Controls, ExtCtrls;
procedure OleStandAlone(AOle: TOleContainer);
var
f: TForm;
pnl: TPanel;
begin
pnl := TPanel.Create(Application);
pnl.Align := AOle.Align;
pnl.Left := AOle.Left;
pnl.Top := AOle.Top;
pnl.Width := Aole.Width;
pnl.Height := AOle.Height;
pnl.Parent := AOle.Parent;
f := TForm.Create(pnl);
f.Caption := '';
f.BorderStyle := bsNone;
f.BorderIcons := [];
f.Parent := pnl;
AOle.Parent := f;
f.Show;
f.Align := alClient;
end;
procedure OleDoVerb(AOle: TOleContainer; AVerb: Integer);
begin
AOle.DoVerb(AVerb);
end;
procedure OleActivate(AOle: TOleContainer);
begin
AOle.DoVerb(ovInPlaceActivate);
end;
procedure OleToolBarShow(AOle: TOleContainer; AShow: Boolean);
var
V: Variant;
i: Integer;
begin
V := (AOle.OleObjectInterface as _Document) as IDispatch;
for i:=0 to V.CommandBars.Count-1 do
V.CommandBars.Visible := AShow;
end;
procedure OleAddPicture(AOle: TOleContainer; AFilename: String);
var
V: Variant;
begin
V := (AOle.OleObjectInterface as _Document).Application.Selection.InlineShapes as IDispatch;
V.AddPicture(AFileName);
end;
procedure OleTrackRevisions(AOle: TOleContainer; ATrack: Boolean);
var
V: Variant;
begin
V := (AOle.OleObjectInterface as _Document) as IDispatch;
V.TrackRevisions := ATrack;
end;
procedure OleUserName(AOle: TOleContainer; AUserName: String);
var
V: Variant;
begin
V := (AOle.OleObjectInterface as _Document).Application;
V.UserName := AUserName;
end;
{ TOleWordExpand }
procedure TOleWordExpand.Activate;
begin
FOle.DoVerb(ovInPlaceActivate);
end;
procedure TOleWordExpand.AddPicture(AFilename: String);
var
V: Variant;
begin
if Assigned(FOle) then
begin
Activate;
V := (FOle.OleObjectInterface as _Document).Application.Selection.InlineShapes as IDispatch;
V.AddPicture(AFileName);
Activate;
end;
end;
procedure TOleWordExpand.SetOle(const Value: TOleContainer);
begin
FOle := Value;
end;
procedure TOleWordExpand.SetTrack(const Value: Boolean);
var
V: Variant;
begin
FTrack := Value;
Activate;
V := (FOle.OleObjectInterface as _Document) as IDispatch;
V.TrackRevisions := FTrack;
if Length(FUserName)>0 then
begin
V := (FOle.OleObjectInterface as _Document).Application;
V.UserName := FUserName;
end;
Activate;
end;
procedure OleFillField(AOle: TOleContainer; AFieldName, AFieldValue: String);
var
V: Variant;
begin
V := (AOle.OleObjectInterface as _Document).Application.Selection as IDispatch;
V.Goto(wdGoToBookmark, 0, 0, AFieldName);
V.TypeText(AFieldValue);
end;
end. |