AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Sprachen und Entwicklungsumgebungen Sonstige Fragen zu Delphi Delphi Eigenschaften eines Worddukuments auslesen und ändern
Thema durchsuchen
Ansicht
Themen-Optionen

Eigenschaften eines Worddukuments auslesen und ändern

Ein Thema von chalasis · begonnen am 8. Sep 2008 · letzter Beitrag vom 11. Sep 2008
Antwort Antwort
chalasis

Registriert seit: 30. Dez 2007
Ort: Österreich
11 Beiträge
 
Delphi 6 Personal
 
#1

Eigenschaften eines Worddukuments auslesen und ändern

  Alt 8. Sep 2008, 19:25
Hallo Delphifreunde!
Ich habe folgende Frage :
Gibt es Funktionen mit denen man die Felder der Eigenschaften eines Worddokuments auslesen bzw. ändern (beisp. Feld Stichwörter) kann.

Danke
chalasis
  Mit Zitat antworten Zitat
Benutzerbild von toms
toms
(CodeLib-Manager)

Registriert seit: 10. Jun 2002
4.648 Beiträge
 
Delphi XE Professional
 
#2

Re: Eigenschaften eines Worddukuments auslesen und ändern

  Alt 11. Sep 2008, 07:09
Hallo

Anbei mal 2 Möglichkeiten:

1. Via OLE

Delphi-Quellcode:
uses
  ComObj;

procedure TForm1.Button1Click(Sender: TObject);
const
  wdPropertyTitle = $00000001;
  wdPropertySubject = $00000002;
  wdPropertyAuthor = $00000003;
  wdPropertyKeywords = $00000004;
  wdPropertyComments = $00000005;
  wdPropertyTemplate = $00000006;
  wdPropertyLastAuthor = $00000007;
  wdPropertyRevision = $00000008;
  wdPropertyAppName = $00000009;
  wdPropertyTimeLastPrinted = $0000000A;
  wdPropertyTimeCreated = $0000000B;
  wdPropertyTimeLastSaved = $0000000C;
  wdPropertyVBATotalEdit = $0000000D;
  wdPropertyPages = $0000000E;
  wdPropertyWords = $0000000F;
  wdPropertyCharacters = $00000010;
  wdPropertySecurity = $00000011;
  wdPropertyCategory = $00000012;
  wdPropertyFormat = $00000013;
  wdPropertyManager = $00000014;
  wdPropertyCompany = $00000015;
  wdPropertyBytes = $00000016;
  wdPropertyLines = $00000017;
  wdPropertyParas = $00000018;
  wdPropertySlides = $00000019;
  wdPropertyNotes = $0000001A;
  wdPropertyHiddenSlides = $0000001B;
  wdPropertyMMClips = $0000001C;
  wdPropertyHyperlinkBase = $0000001D;
  wdPropertyCharsWSpaces = $0000001E;
const
  AWordDoc = 'C:\Test.doc';
  wdSaveChanges = $FFFFFFFF;
var
  WordApp: OLEVariant;
  SaveChanges: OleVariant;
begin
  try
    WordApp := CreateOleObject('Word.Application');
  except
    // Error....
    Exit;
  end;
  try
    WordApp.Visible := False;
    WordApp.Documents.Open(AWordDoc);
    WordApp.ActiveDocument.BuiltInDocumentProperties[wdPropertyTitle].Value := 'Your Title...';
    WordApp.ActiveDocument.BuiltInDocumentProperties[wdPropertySubject].Value := 'Your Subject...';
    // ...
    // ...
  finally
    SaveChanges := wdSaveChanges;
    WordApp.Quit(SaveChanges, EmptyParam, EmptyParam);
  end;
end;
2. Via Structured Storage


Delphi-Quellcode:
{2. Read MS Word properties via Structured Storage.
  by Serhiy Perevoznyk}


uses
  ComObj, ActiveX;

const
  FmtID_SummaryInformation: TGUID =
    '{F29F85E0-4FF9-1068-AB91-08002B27B3D9}';

function FileTimeToDateTimeStr(F: TFileTime): string;
var
  LocalFileTime: TFileTime;
  SystemTime: TSystemTime;
  DateTime: TDateTime;
begin
  if Comp(F) = 0 then Result := '-'
  else
  begin
    FileTimeToLocalFileTime(F, LocalFileTime);
    FileTimeToSystemTime(LocalFileTime, SystemTime);
    with SystemTime do
      DateTime := EncodeDate(wYear, wMonth, wDay) +
        EncodeTime(wHour, wMinute, wSecond, wMilliseconds);
    Result := DateTimeToStr(DateTime);
  end;
end;

function GetDocInfo(const FileName: WideString): string;
var
  I: Integer;
  PropSetStg: IPropertySetStorage;
  PropSpec: array[2..19] of TPropSpec;
  PropStg: IPropertyStorage;
  PropVariant: array[2..19] of TPropVariant;
  Rslt: HResult;
  S: string;
  Stg: IStorage;
begin
  Result := '';
  try
    OleCheck(StgOpenStorage(PWideChar(FileName), nil, STGM_READ or
      STGM_SHARE_DENY_WRITE,
      nil, 0, Stg));
    PropSetStg := Stg as IPropertySetStorage;
    OleCheck(PropSetStg.Open(FmtID_SummaryInformation,
      STGM_READ or STGM_SHARE_EXCLUSIVE, PropStg));
    for I := 2 to 19 do
    begin
      PropSpec[I].ulKind := PRSPEC_PROPID;
      PropSpec[I].PropID := I;
    end;
    Rslt := PropStg.ReadMultiple(18, @PropSpec, @PropVariant);
    OleCheck(Rslt);
    if Rslt <> S_FALSE then for I := 2 to 19 do
      begin
        S := '';
        if PropVariant[I].vt = VT_LPSTR then
          if Assigned(PropVariant[I].pszVal) then
            S := PropVariant[I].pszVal;
        case I of
          2: S := Format('Title: %s', [S]);
          3: S := Format('Subject: %s', [S]);
          4: S := Format('Author: %s', [S]);
          5: S := Format('Keywords: %s', [S]);
          6: S := Format('Comments: %s', [S]);
          7: S := Format('Template: %s', [S]);
          8: S := Format('Last saved by: %s', [S]);
          9: S := Format('Revision number: %s', [S]);
          10: S := Format('Total editing time: %g sec',
              [Comp(PropVariant[I].filetime) / 1.0E9]);
          11: S := Format('Last printed: %s',
              [FileTimeToDateTimeStr(PropVariant[I].filetime)]);
          12: S := Format('Create time/date: %s',
              [FileTimeToDateTimeStr(PropVariant[I].filetime)]);
          13: S := Format('Last saved time/date: %s',
              [FileTimeToDateTimeStr(PropVariant[I].filetime)]);
          14: S := Format('Number of pages: %d', [PropVariant[I].lVal]);
          15: S := Format('Number of words: %d', [PropVariant[I].lVal]);
          16: S := Format('Number of characters: %d',
              [PropVariant[I].lVal]);
          17:; // thumbnail
          18: S := Format('Name of creating application: %s', [S]);
          19: S := Format('Security: %.8x', [PropVariant[I].lVal]);
        end;
        if S <> 'then Result := Result + S + #13;
      end;
  finally
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
    ShowMessage(GetDocInfo(OpenDialog1.FileName));
end;
Thomas
  Mit Zitat antworten Zitat
MrKnogge

Registriert seit: 9. Jun 2003
Ort: Pforzheim
2.458 Beiträge
 
Delphi 2007 Professional
 
#3

Re: Eigenschaften eines Worddukuments auslesen und ändern

  Alt 11. Sep 2008, 07:38
Gibt es da noch eine Möglichkeit ohne COM bzw., dass Word installiert sein muss?
Auslesen würde völlig reichen.
Christian Bootz
Einstein ist tot, Newton ist tot,
und mir ist auch schon ganz schlecht...
  Mit Zitat antworten Zitat
Benutzerbild von toms
toms
(CodeLib-Manager)

Registriert seit: 10. Jun 2002
4.648 Beiträge
 
Delphi XE Professional
 
#4

Re: Eigenschaften eines Worddukuments auslesen und ändern

  Alt 11. Sep 2008, 07:53
Zitat von MrKnogge:
Gibt es da noch eine Möglichkeit ohne COM bzw., dass Word installiert sein muss?
Auslesen würde völlig reichen.
Ich denke via Structured Storage sollte es funktionieren, auch wenn Word nicht installiert ist.
Thomas
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:42 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