Author: Bertrand Goetzmann
How read or write in the summary information of an Offiche document ?
Answer:
An Office document file is a structured storage file that an application can read
with the StgOpenStorage function from the Windows API. This kind of file is made of
storages and streams.
COM defines a standard common property set for storing summary information about
document. This information is stored in a stream under the root storage. The
following function shows how you can get the author property by giving a filename :
1 uses ActiveX, ComObj, SysUtils;
2 3 function GetSummaryInfAuthor(FileName: TFileName): string;
4 var5 PFileName: PWideChar;
6 Storage: IStorage;
7 PropSetStg: IPropertySetStorage;
8 PropStg: IPropertyStorage;
9 ps: PROPSPEC;
10 pv: PROPVARIANT;
11 const12 FMTID_SummaryInformation: TGUID = '{F29F85E0-4FF9-1068-AB91-08002B27B3D9}';
13 begin14 PFileName := StringToOleStr(FileName);
15 try16 // Open compound storage17 OleCheck(StgOpenStorage(PFileName, nil, STGM_DIRECT or STGM_READ or18 STGM_SHARE_EXCLUSIVE, nil, 0, Storage));
19 finally20 SysFreeString(PFileName);
21 end;
22 23 // Summary information is in a stream under the root storage24 PropSetStg := Storage as IPropertySetStorage;
25 // Get the IPropertyStorage26 OleCheck(PropSetStg.Open(FMTID_SummaryInformation, STGM_DIRECT or STGM_READ or27 STGM_SHARE_EXCLUSIVE, PropStg));
28 29 // We want the author property value30 ps.ulKind := PRSPEC_PROPID;
31 ps.propid := PIDSI_AUTHOR;
32 33 // Read this property34 PropStg.ReadMultiple(1, @ps, @pv);
35 36 Result := pv.pszVal;
37 end;
See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/stgasstg_7agk.asphttp://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/stgasstg_7agk.asp for more information about the Summary Information Property Set.