begin Found := False; if (PowerPointApplication1.Presentations.Count > 0) and (TN <> nil) then begin for i := 1 to PowerPointApplication1.Presentations.Count do begin TN := TV1.Selected; {Get Parent node to find Presentation name in case a slide is selected} if TN.GetPrev <> nil then TN := TN.Parent; if PowerPointApplication1.Presentations.Item(i).Name = TN.Text then begin Found := True; Break; end; end; if Found then begin PowerPointPresentation1.ConnectTo(PowerPointApplication1.Presentations.Item(i)); with PowerPointPresentation1 do begin SlideShowSettings.AdvanceMode := ppSlideShowUseSlideTimings; // SlideShowSettings.LoopUntilStopped := msoTrue; SWindow := SlideShowSettings.Run; frmMain.SetFocus; end; end else ShowMessage('没有发现演示文稿 ' + TN.Text); end else Showmessage('没有可用的演示文稿'); end;procedure TfrmMain.btnAddPreClick(Sender: TObject); begin try btnOutPutData.Enabled := True; PowerPointPresentation1.ConnectTo(PowerPointApplication1.Presentations.Add(1)); TN := TV1.Items.Insert(TN, PowerPointPresentation1.Name); TN.Selected := True; TV1.SetFocus; except on E: Exception do begin Showmessage(E.Message); end; end; end; procedure TfrmMain.btnCloseClick(Sender: TObject); begin PowerPointApplication1.Quit; PowerPointApplication1.Disconnect; end;procedure TfrmMain.btnRunClick(Sender: TObject); begin try try PowerPointApplication1.Connect; except on E: Exception do begin E.Message := '没有安装PowerPoint'; raise; end; end; PowerPointApplication1.Visible := 1; btnAddPre.Enabled := True; btnClose.Enabled := True; frmMain.SetFocus; except on E: Exception do begin Showmessage(E.Message); PowerPointApplication1.Disconnect; end; end; end;procedure TfrmMain.btnOutPutDataClick(Sender: TObject); begin PowerPointSlide1.ConnectTo(PowerPointPresentation1.Slides.Add(PowerPointPresentation1.Slides.Count + 1, 1)); with PowerPointSlide1 do begin btnPreview.Enabled := True; {Select layout where a bitmap is in the left corner} Layout := 10; {Set background} FollowMasterBackground := 0; Background.Fill.PresetGradient(2, 2, 10); {Set text} Shapes.Item(1).TextFrame.TextRange.InsertAfter(Table1.Fieldbyname('Common_Name').AsString); Shapes.Item(2).TextFrame.TextRange.Font.Name := 'Arial'; Shapes.Item(2).TextFrame.TextRange.InsertAfter('种类 : ' + Table1.FieldByName('Category').AsString + #13 + '名字: ' + Table1.FieldByName('Species Name').AsString); {加入图像} DbImage1.CopyToClipboard; Shapes.Item(3).Delete; Shapes.Paste; Shapes.Item(3).Left := 100; Shapes.Item(3).Top := 180; Shapes.Item(3).Width := 150; Shapes.Item(3).Height := 150; {Set time displayed for each slide} SlideShowTransition.AdvanceOnTime := 1; SlideShowTransition.AdvanceTime := 2; Name := Table1.FieldByName('Common_Name').AsString + (IntToStr(PowerPointPresentation1.Slides.Count)); TV1.Items.AddChild(TN, Name); TN.Selected; TV1.SetFocus; end; end;end.
uses ComObj, ComServ;var OleWord: Variant;
begin
try
OleWord := CreateOleObject('Word.Basic');
OleWord.FileOpen(filename);
OleWord.AppShow;
//OleWord.FileSave;
//OleWord.FileExit;
except
end;
end;
unit Main;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, OleServer, DBCtrls, ExtCtrls, Grids, DBGrids, Db,
DBTables, Msppt8, ComCtrls, ToolWin;type
TfrmMain = class(TForm)
PowerPointApplication1: TPowerPointApplication;
PowerPointSlide1: TPowerPointSlide;
PowerPointPresentation1: TPowerPointPresentation;
Table1: TTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
DBNavigator1: TDBNavigator;
DBImage1: TDBImage;
ToolBar1: TToolBar;
btnPreview: TToolButton;
btnAddPre: TToolButton;
btnClose: TToolButton;
btnRun: TToolButton;
TV1: TTreeView;
Label1: TLabel;
btnOutPutData: TToolButton;
procedure Form1Activate(Sender: TObject);
procedure Form1Close(Sender: TObject; var Action: TCloseAction);
procedure btnPreviewClick(Sender: TObject);
procedure btnAddPreClick(Sender: TObject);
procedure btnCloseClick(Sender: TObject);
procedure btnRunClick(Sender: TObject);
procedure btnOutPutDataClick(Sender: TObject);
private
SWindow:SlideShowWindow;
TN:TTreeNode;
{ Private declarations }
public
{ Public declarations }
end;var
frmMain: TfrmMain;implementation{$R *.dfm}procedure TfrmMain.Form1Activate(Sender: TObject);
begin
Table1.Open;
TN := nil;
end;procedure TfrmMain.Form1Close(Sender: TObject; var Action: TCloseAction);
begin
Table1.Close;
end;procedure TfrmMain.btnPreviewClick(Sender: TObject);
var
i: Integer;
Found: Boolean;
begin
Found := False;
if (PowerPointApplication1.Presentations.Count > 0) and (TN <> nil) then
begin
for i := 1 to PowerPointApplication1.Presentations.Count do
begin
TN := TV1.Selected;
{Get Parent node to find Presentation name in case a slide is selected}
if TN.GetPrev <> nil then
TN := TN.Parent; if PowerPointApplication1.Presentations.Item(i).Name = TN.Text then
begin
Found := True;
Break;
end;
end;
if Found then
begin
PowerPointPresentation1.ConnectTo(PowerPointApplication1.Presentations.Item(i));
with PowerPointPresentation1 do
begin
SlideShowSettings.AdvanceMode := ppSlideShowUseSlideTimings;
// SlideShowSettings.LoopUntilStopped := msoTrue;
SWindow := SlideShowSettings.Run;
frmMain.SetFocus;
end;
end
else
ShowMessage('没有发现演示文稿 ' + TN.Text);
end
else
Showmessage('没有可用的演示文稿');
end;procedure TfrmMain.btnAddPreClick(Sender: TObject);
begin
try
btnOutPutData.Enabled := True;
PowerPointPresentation1.ConnectTo(PowerPointApplication1.Presentations.Add(1));
TN := TV1.Items.Insert(TN, PowerPointPresentation1.Name);
TN.Selected := True;
TV1.SetFocus;
except
on E: Exception do
begin
Showmessage(E.Message);
end;
end;
end;
procedure TfrmMain.btnCloseClick(Sender: TObject);
begin
PowerPointApplication1.Quit;
PowerPointApplication1.Disconnect;
end;procedure TfrmMain.btnRunClick(Sender: TObject);
begin
try
try
PowerPointApplication1.Connect;
except on E: Exception do
begin
E.Message := '没有安装PowerPoint';
raise;
end;
end;
PowerPointApplication1.Visible := 1;
btnAddPre.Enabled := True;
btnClose.Enabled := True;
frmMain.SetFocus;
except
on E: Exception do
begin
Showmessage(E.Message);
PowerPointApplication1.Disconnect;
end;
end;
end;procedure TfrmMain.btnOutPutDataClick(Sender: TObject);
begin
PowerPointSlide1.ConnectTo(PowerPointPresentation1.Slides.Add(PowerPointPresentation1.Slides.Count + 1, 1)); with PowerPointSlide1 do
begin
btnPreview.Enabled := True;
{Select layout where a bitmap is in the left corner}
Layout := 10;
{Set background}
FollowMasterBackground := 0;
Background.Fill.PresetGradient(2, 2, 10);
{Set text}
Shapes.Item(1).TextFrame.TextRange.InsertAfter(Table1.Fieldbyname('Common_Name').AsString);
Shapes.Item(2).TextFrame.TextRange.Font.Name := 'Arial';
Shapes.Item(2).TextFrame.TextRange.InsertAfter('种类 : ' + Table1.FieldByName('Category').AsString + #13 +
'名字: ' + Table1.FieldByName('Species Name').AsString);
{加入图像}
DbImage1.CopyToClipboard;
Shapes.Item(3).Delete;
Shapes.Paste;
Shapes.Item(3).Left := 100;
Shapes.Item(3).Top := 180;
Shapes.Item(3).Width := 150;
Shapes.Item(3).Height := 150;
{Set time displayed for each slide}
SlideShowTransition.AdvanceOnTime := 1;
SlideShowTransition.AdvanceTime := 2;
Name := Table1.FieldByName('Common_Name').AsString + (IntToStr(PowerPointPresentation1.Slides.Count));
TV1.Items.AddChild(TN, Name);
TN.Selected;
TV1.SetFocus;
end;
end;end.