Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Informationen aus MS Office (https://www.delphipraxis.net/1718-informationen-aus-ms-office.html)

poy 19. Dez 2002 14:22


Informationen aus MS Office
 
:?:


Ich muss ein Programmschreiben, welches den Titel, den Autor und den Komentar aus einem Word, Excel und Power Point File rauslesen. Ist es möglich dies zu tun ohne das entsprechende Programm zu starten, sondern direkt aus dem abgespeicherten File zu lesen?
Toll wäre ein Dokumentiertes Sourcebeispiel.

:?:

sakura 19. Dez 2002 14:53

Hier die gewünschte Lösung
Delphi-Quellcode:
uses
  ActiveX, ComObj;

procedure GetDocInfo(aFileName: String; Lines: TStrings);
const
  FMTID_SummaryInformation: TGUID = '{F29F85E0-4FF9-1068-AB91-08002B27B3D9}';
type
  TPropSpecArray = array[0..1000] of TPropSpec;
  PPropSpecArray = ^TPropSpecArray;
  TPropVariantArray = array[0..1000] of TPropVariant;
  PPropVariantArray = ^TPropVariantArray;
var
  stgRoot: IStorage;
  stgPS: IPropertySetStorage;
  stgP: IPropertyStorage;
  ps: PPropSpecArray;
  pv: PPropVariantArray;
begin
  Lines.Clear;
  OleCheck(StgOpenStorage(PWideChar(WideString(aFileName)), nil, STGM_READ or
      STGM_SHARE_EXCLUSIVE, nil, 0, stgRoot));
  stgPS := stgRoot as IPropertySetStorage;
  OleCheck(stgPS.Open(FMTID_SummaryInformation, STGM_READ or
      STGM_SHARE_EXCLUSIVE, stgP));
  ps := nil;
  pv := nil;
  GetMem(ps, SizeOf(TPropSpecArray));
  GetMem(pv, SizeOf(TPropVariantArray));
  try
    ps[0].ulKind := PRSPEC_PROPID;
    ps[0].propid := PIDSI_TITLE;
    ps[1].ulKind := PRSPEC_PROPID;
    ps[1].propid := PIDSI_COMMENTS;
    ps[2].ulKind := PRSPEC_PROPID;
    ps[2].propid := PIDSI_AUTHOR;
    OleCheck(stgP.ReadMultiple(3, @ps[0], @pv[0]));
    Lines.Add('Titel: ' + pv[0].pszVal);
    Lines.Add('Kommentar: ' + pv[1].pszVal);
    Lines.Add('Autor: ' + pv[2].pszVal);
  finally
    FreeMem(ps);
    FreeMem(pv);
  end;
end;
weitere Werte für propid
Code:
const
  // Property IDs for the SummaryInformation Property Set
  {$EXTERNALSYM PIDSI_TITLE}
  PIDSI_TITLE              = $00000002; // VT_LPSTR
  {$EXTERNALSYM PIDSI_SUBJECT}
  PIDSI_SUBJECT            = $00000003; // VT_LPSTR
  {$EXTERNALSYM PIDSI_AUTHOR}
  PIDSI_AUTHOR             = $00000004; // VT_LPSTR
  {$EXTERNALSYM PIDSI_KEYWORDS}
  PIDSI_KEYWORDS           = $00000005; // VT_LPSTR
  {$EXTERNALSYM PIDSI_COMMENTS}
  PIDSI_COMMENTS           = $00000006; // VT_LPSTR
  {$EXTERNALSYM PIDSI_TEMPLATE}
  PIDSI_TEMPLATE           = $00000007; // VT_LPSTR
  {$EXTERNALSYM PIDSI_LASTAUTHOR}
  PIDSI_LASTAUTHOR         = $00000008; // VT_LPSTR
  {$EXTERNALSYM PIDSI_REVNUMBER}
  PIDSI_REVNUMBER          = $00000009; // VT_LPSTR
  {$EXTERNALSYM PIDSI_EDITTIME}
  PIDSI_EDITTIME           = $0000000a; // VT_FILETIME (UTC)
  {$EXTERNALSYM PIDSI_LASTPRINTED}
  PIDSI_LASTPRINTED        = $0000000b; // VT_FILETIME (UTC)
  {$EXTERNALSYM PIDSI_CREATE_DTM}
  PIDSI_CREATE_DTM         = $0000000c; // VT_FILETIME (UTC)
  {$EXTERNALSYM PIDSI_LASTSAVE_DTM}
  PIDSI_LASTSAVE_DTM       = $0000000d; // VT_FILETIME (UTC)
  {$EXTERNALSYM PIDSI_PAGECOUNT}
  PIDSI_PAGECOUNT          = $0000000e; // VT_I4
  {$EXTERNALSYM PIDSI_WORDCOUNT}
  PIDSI_WORDCOUNT          = $0000000f; // VT_I4
  {$EXTERNALSYM PIDSI_CHARCOUNT}
  PIDSI_CHARCOUNT          = $00000010; // VT_I4
  {$EXTERNALSYM PIDSI_THUMBNAIL}
  PIDSI_THUMBNAIL          = $00000011; // VT_CF
  {$EXTERNALSYM PIDSI_APPNAME}
  PIDSI_APPNAME            = $00000012; // VT_LPSTR
  {$EXTERNALSYM PIDSI_DOC_SECURITY}
  PIDSI_DOC_SECURITY       = $00000013; // VT_I4

sakura 19. Dez 2002 15:01

Noch ein wenig Theorie zur Lösung.

Alle MS Office Dokumente basieren auf der Idee von Structured Storage. In diesen Dokumente sind alle Daten in zugeordneten Streams gespeichert. Das ganze funktioniert ähnlich wie ein komplettes Dateisystem innerhalb einer Datei. Daher kann oben genannte Lösung nicht nur für MS Office Dokumente, sondern auch für Dokumente andere Anwendungen genutzt werden, sofern diese das Structure Storage Format nutzen.

Structure Storage wird aber nur auf Windows System ab Win95 nativ unterstützt. :( Die Definitionen für StSt sind ab Delphi 4 in der ActiveX unit gespeichert, für Delphi 3 müssen diese komplett von Hand erstellt werden.

Weitere Infos findet Ihr im Buch Delphi(TM) COM Programming von Eric Harmon, aus welchem auch die Vorlage für obige Löäsung stammt.

poy 20. Dez 2002 07:43

Danke
 
:D
Danke hat mir sehr weitergeholfen
:mrgreen:

sakura 20. Dez 2002 09:58

Re: Danke
 
Zitat:

Zitat von poy
Danke hat mir sehr weitergeholfen

Das freut mich - bis bald und ein "Frohes Fest" und einen "Guten Rutsch".

Matt 25. Jul 2007 13:49

Re: Informationen aus MS Office
 
Hallo DPler,

seid SP2 von Windows XP bekomme ich bei dieser Function immer ein:

EOLESYSERROR: Access denied

Nehme mal an, dass das an den neuen Sicherheitsregeln liegt.
Hat jemand schon eine Lösung, wie man diese Funktion wieder zum laufen bekommt?

Vielen Dank!

Grüße aus HH
Matt


Alle Zeitangaben in WEZ +1. Es ist jetzt 03:16 Uhr.

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