delphi提取ppt文件里的文本函数

function ReadPPt(sName: string): string;

var

n,m,i,j: integer;

PptApp: OleVariant;

begin

try

PptApp := CreateOleObject('PowerPoint.Application');

PptApp.Visible := true;

PptApp.Presentations.Open(sName);

n := PptApp.ActiveWindow.Presentation.Slides.Count;

for i:=1 to n do

begin

m := PptApp.ActiveWindow.Presentation.Slides.item(i).Shapes.Count;

for j:=1 to m do

begin

If PptApp.ActiveWindow.Presentation.Slides.item(i).Shapes.item(j).HasTextFrame Then

result:=result+PptApp.ActiveWindow.Presentation.Slides.item(i).Shapes.item(j).TextFrame.TextRange.Text +#$D#$A;

end;

end;

finally

PptApp.ActiveWindow.Presentation.Saved := true;

PptApp.ActiveWindow.Close;

PptApp.Quit;

PptApp := null;

end;

end;