Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi [FEHLER] PowerPoint mit Delphi ansteuern (https://www.delphipraxis.net/130501-%5Bfehler%5D-powerpoint-mit-delphi-ansteuern.html)

T3rm1 9. Mär 2009 16:35


[FEHLER] PowerPoint mit Delphi ansteuern
 
Hi,
ich versuche gerade automatisch Bilder von Folien einer PowerPoint Präsentation zu erstellen.
Dazu habe ich die Type Library MSPPT.olb importiert und die entsprechenden Units erzeugt.

So sieht der Code aus, den ich benutze:

Delphi-Quellcode:
procedure PPT2Image(Path: string);
var PowerPoint: PowerPointApplication;
  AppWasRunning: Boolean;
  OleResult: HRESULT;
  Unknown: IUnknown;
begin
  AppWasRunning := False;
  OleResult := GetActiveObject(CLASS_PowerPointApplication, nil, Unknown);
  if (OleResult = MK_E_UNAVAILABLE) then
    PowerPoint := CoPowerPointApplication.Create
  else begin
    OleCheck(OleResult);
    OleCheck(Unknown.QueryInterface(PowerPointApplication, PowerPoint));
    AppWasRunning := True;
  end;
  try
    PowerPoint.Presentations.Open2007(Path, msoTrue, msoTrue, msoFalse, msoFalse);
    PowerPoint.ActivePresentation.SaveAs(ExtractFilePath(Path) + 'blub.png', ppSaveAsPNG, msoFalse);
    PowerPoint.ActivePresentation.Close;
  finally
    if not AppWasRunning then
      PowerPoint.Quit;
  end;
end;
Leider funktioniert das nicht. Bei PowerPoint.Presentations.Open2007(Path, msoCTrue, msoCTrue, msoFalse, msoFalse); kommt es zu einer Exception "Unbekannter Fehler". Ich hab es auch schon mit Open und einer 2003er Präsentation versucht, aber auch da kommt der gleiche Fehler.

Hat wer eine Idee?

EDIT: Benutze Delphi 2009

mkinzler 9. Mär 2009 16:41

Re: [FEHLER] PowerPoint mit Delphi ansteuern
 
Das Interface von O2k7 scheint nicht mehr rückwärtskompatibel zu sein

T3rm1 9. Mär 2009 16:49

Re: [FEHLER] PowerPoint mit Delphi ansteuern
 
Ich versuche ja auch eine pptx Datei mit Open2007(..) zu öffnen. Office 12 ist installiert. Und es ist auch die Type Library von Office 12.
Also egal was ich mache, es kommt immer zum unekanntem Fehler beim Öffnen der Präsentation. Mit dem Problem beschäftige ich mich schon den ganzen Tag. Langsam bin ich der Auffassung, dass es an Delphi liegen muss.

mkinzler 9. Mär 2009 16:57

Re: [FEHLER] PowerPoint mit Delphi ansteuern
 
Zitat:

Delphi-Quellcode:
PowerPoint: PowerPointApplication;

ist ein Referenz auf das Interface von OfficeXP.
Verwende mal ein OleVariant

T3rm1 9. Mär 2009 17:00

Re: [FEHLER] PowerPoint mit Delphi ansteuern
 
Hab ich schon versucht. Gleicher Fehler!
Delphi-Quellcode:
procedure PPT2Image2(Path: string);
var
  PowerPointApp: OLEVariant;
begin
  try
    PowerPointApp := CreateOleObject('PowerPoint.Application');
  except
    ShowMessage('Error...');
    Exit;
  end;
  // Make Powerpoint visible
  PowerPointApp.Visible := True;

  // Show powerpoint version
  ShowMessage(Format('Powerpoint version: %s',[PowerPointApp.Version]));

  // Open a presentation
  PowerPointApp.Presentations.Open(path, False, False, True);

  // Show number of slides
  ShowMessage(Format('%s slides.',[PowerPointApp.ActivePresentation.Slides.Count]));


  // Close Powerpoint
  PowerPointApp.Quit;
//  PowerPointApp := unassigned;
end;

toms 9. Mär 2009 18:00

Re: [FEHLER] PowerPoint mit Delphi ansteuern
 
Hallo

Ich habe den CreateOleObject() Code unter PP 2003 / WinXP / D2009 getestet und funktioniert ohne Probleme.
Liegt evtl. an deiner PP-Installation.

T3rm1 9. Mär 2009 18:02

Re: [FEHLER] PowerPoint mit Delphi ansteuern
 
Ok, also, das Problem lässt sich eingrenzen. Folgender Code lies sich ohne Probleme auf zwei anderen Systemen ausführen (einer Office 11, einer Office 12). Auf meinem System kommt aber nach wie vor der gleiche Fehler:
Delphi-Quellcode:
procedure PPT2Image(Path: string);
var PowerPoint: PowerPointApplication;
  AppWasRunning: Boolean;
  OleResult: HRESULT;
  Unknown: IUnknown;
begin
  AppWasRunning := False;
  OleResult := GetActiveObject(CLASS_PowerPointApplication, nil, Unknown);
  if (OleResult = MK_E_UNAVAILABLE) then
    PowerPoint := CoPowerPointApplication.Create
  else begin
    OleCheck(OleResult);
    OleCheck(Unknown.QueryInterface(PowerPointApplication, PowerPoint));
    AppWasRunning := True;
  end;
  try
    if ExtractFileExt(Path) = '.pptx' then
      PowerPoint.Presentations.Open2007(Path, msoTrue, msoFalse, msoFalse, msoFalse)
    else
    PowerPoint.Presentations.Open(Path, msoTrue, msoFalse, msoFalse);
    PowerPoint.Presentations.Item(1).SaveAs(ExtractFilePath(Path) + 'blub.png', ppSaveAsPNG, msoFalse);
    PowerPoint.Presentations.Item(1).Close;
  finally
    if not AppWasRunning then
      PowerPoint.Quit;
  end;
end;
Hat jemand eine Idee, wo bei meiner Office Installation der Fehler liegen könnte?

toms 9. Mär 2009 18:04

Re: [FEHLER] PowerPoint mit Delphi ansteuern
 
Öffnest du eine .pptx oder .ppt Datei? Tritt der Fehler nach einer Neuinstallation von PP immer noch auf?

T3rm1 9. Mär 2009 18:09

Re: [FEHLER] PowerPoint mit Delphi ansteuern
 
Zitat:

Zitat von toms
Öffnest du eine .pptx oder .ppt Datei? Tritt der Fehler nach einer Neuinstallation von PP immer noch auf?

Fehler tritt bei beiden auf.
Neuinstallieren wollte ich eigentlich nicht :/ Hatte die Hoffnung, dass es sich irgendwie ohne lösen lasst. So alt ist die Installation auch noch gar nicht. Office Diagnose Programm findet auch keine Fehler :P

toms 9. Mär 2009 18:13

Re: [FEHLER] PowerPoint mit Delphi ansteuern
 
Eine neue Installation dauert ja nicht allzu lange und liegt auf der Hand, wenn der Code auf anderen Computern mit gleicher PP Version funktioniert.


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:29 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz