谁有Delphi控制PowerPoint完整的例子(例如从PPT文件中取出图片等)(100分)

  • 主题发起人 主题发起人 huabinhong
  • 开始时间 开始时间
H

huabinhong

Unregistered / Unconfirmed
GUEST, unregistred user!
谁有Delphi控制PowerPoint完整的例子(例如从PPT文件中取出图片等)
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
msppt8, OleServer, office97, StdCtrls, ComCtrls, ExtCtrls, DBCtrls,
Clipbrd;

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
PowerPointPresentation1: TPowerPointPresentation;
PowerPointApplication1: TPowerPointApplication;
PowerPointSlide1: TPowerPointSlide;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
RichEdit1: TRichEdit;
RichEdit2: TRichEdit;
Image1: TImage;
Button9: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
private
{ Private declarations }
{插入新幻灯片}
Procedure AddSlide(BackPicFile: TFileName);
{添加文本}
Procedure AddText(RichEdit: TRichEdit);
{添加图片}
Procedure AddPicture(PicFile: TFileName);
{得到文本}
Procedure GetText;
{得到图片}
Procedure GetPicture;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

{插入新幻灯片}
procedure TForm1.AddSlide(BackPicFile: TFileName);
var
i: integer;
begin
With PowerPointPresentation1 do
begin
Slides.Add(Slides.Count + 1, 1).select;
//PowerPointApplication1.ActiveWindow.View.gotoSlide(Slides.Count);
//Slides.Add(Slides.Count + 1, 1).
PowerPointSlide1.ConnectTo(Slides.Item(Slides.Count));
end;
with PowerPointSlide1 do
begin
{Set background}
FollowMasterBackground := 0;
Background.Fill.Visible := msoTrue;
Background.Fill.ForeColor.RGB := RGB(255, 255, 255);
Background.Fill.BackColor.SchemeColor := ppAccent1;
Background.Fill.Transparency := 0;
Background.Fill.UserPicture(BackPicFile);
for i:=1 to Shapes.Count do
begin
Shapes.Item(1).Delete;
end;
end;
end;

{添加文本}
procedure TForm1.AddText(RichEdit: TRichEdit);
begin
with PowerPointSlide1 do
begin
//expression.AddTextbox(Orientation, Left, Top, Width, Height)
Shapes.AddTextbox(msoTextOrientationHorizontal,100, 100, 500,
200).TextFrame.TextRange.Text:=RichEdit.Lines.Text;
{RichEdit.SelectAll;
RichEdit.CopyToClipboard;
Shapes.Item(Shapes.Count).TextFrame.TextRange.Paste; }
Shapes.Item(Shapes.Count).TextFrame.TextRange.Select;
With Shapes.Item(Shapes.Count).TextFrame.TextRange.Font do
begin
NameAscii := 'Arial';
NameFarEast := '宋体';
NameOther := 'Arial';
Size := 30;
end;
end;
end;

{添加图片}
procedure TForm1.AddPicture(PicFile: TFileName);
begin
with PowerPointSlide1 do
begin
Shapes.AddPicture (PicFile,1, 1, 100, 100, 150, 70);
end;
end;

{得到文本}
procedure TForm1.GetText;
var
i: integer;
begin
with PowerPointSlide1 do
begin
for i:=1 to Shapes.Count do
begin
if Shapes.item(i).Type_=msoTextBox then
begin
Shapes.Item(i).TextFrame.TextRange.Select;
Shapes.Item(i).TextFrame.TextRange.Copy;
RichEdit1.PasteFromClipboard;
end
end;
end;
end;

{得到图片}
procedure TForm1.GetPicture;
var
i: integer;
PptPic: TPicture;
begin
with PowerPointSlide1 do
begin
try
PptPic := TPicture.Create;
for i:=1 to Shapes.Count do
begin
if Shapes.item(i).Type_<>msoTextBox then
begin
Shapes.Item(i).Copy;
PptPic.Assign(Clipboard);
PptPic.SaveToFile('d:/dd.jpg');
end
end;
finally
PptPic.Free;
end;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
try
try
PowerPointApplication1.Connect;
except on E: Exception do
begin
E.Message := 'PowerPoint does not appear to be installed';
raise;
end;
end;
PowerPointApplication1.Visible := 1;
PowerPointPresentation1.ConnectTo(PowerPointApplication1.Presentations.Add(1));
//PowerPointApplication1.ActiveWindow.ViewType :=1;
except
on E: Exception do
begin
Showmessage(E.Message);
PowerPointApplication1.Disconnect;
end;
end;
end;

procedure TForm1.Button7Click(Sender: TObject);
var
i:integer;
begin
with PowerPointSlide1 do
begin
for i:=1 to Shapes.Count do
begin
//Shapes.TextEffect.Text
if Shapes.item(i).Type_=msoTextBox then
begin
Shapes.Item(i).copy;
{Shapes.Item(i).TextFrame.TextRange.Select;
Shapes.Item(i).TextFrame.TextRange.Copy;
RichEdit1.PasteFromClipboard;}
RichEdit1.Lines.Assign(Clipboard);
//RichEdit1.Lines.Add(Shapes.Item(1).TextFrame.TextRange.Text);
//ActiveWindow.Selection.ShapeRange.Item(1).TextEffect.Text
end
else
begin
Shapes.Item(i).Copy;
//Image1.Picture.Bitmap.;
//if Clipboard.HasFormat(CF_BITMAP) then
Image1.Picture.Assign(Clipboard);
//PaintBox1.Assign(Clipboard);
//GetPicture;
end;
end;
end;
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
AddSlide('C:/WINNT/CIBAB.BMP');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
AddText(RichEdit2);
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
AddPicture('C:/WINNT/CIBAS.BMP');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
//PaintBox1.
//DBImage1.CopyToClipboard
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
GetPicture;
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
with PowerPointPresentation1.PageSetup do
begin
SlideSize := ppSlideSizeCustom;
SlideWidth := 680.38;
SlideHeight := 510.25;
FirstSlideNumber := 1;
SlideOrientation := msoOrientationHorizontal;
NotesOrientation := msoOrientationVertical;
//Showmessage(Floattostr(PowerPointPresentation1.PageSetup.SlideWidth));
end;
end;

end.
 
为什么有些不是图片的SHape也被保存出来了?
 
andy263,用你的方法得到的图片的质量没有直接在PPT中点击图片保存得到的图片质量高,请问为什么,有好的解决方案吗?
 
请问你的程序在win98下能够运行吗?
 
To andy263:
如果我想知道插在Ppt中的某张图片的完整路径名,请问有何好方法?
 
我想问一下,我在olecontainer中加载了一个powerpoint,但是却不能够打开或是编辑、播放powerpoint,这是因为olecontainer不支持powerpoint或是我的olecontainer有什么属性没有正确设置???请各位高手给与帮助!
 
后退
顶部