Autor Beitrag
phombaa
Hält's aus hier
Beiträge: 10



BeitragVerfasst: Sa 13.03.04 22:53 
Guten Abend,

Gibt es eine Möglichkeit, den Text eines offenen Word Dokuments
in einem RichEdit anzuzeigen?
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Mo 15.03.04 19:17 
Hi,

Habe auf www.swissdelphicenter.com gerade ein Beispiel gepostet:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
uses 
  Word_TLB, ActiveX, ComObj; 

function GetRTFFormat(DataObject: IDataObject; var RTFFormat: TFormatEtc): Boolean; 
var 
  Formats: IEnumFORMATETC; 
  TempFormat: TFormatEtc; 
  pFormatName: PChar; 
  Found: Boolean; 
begin 
  try 
    OleCheck(DataObject.EnumFormatEtc(DATADIR_GET, Formats)); 
    Found := False; 
    while (not Found) and (Formats.Next(1, TempFormat, nil) = S_OK) do 
    begin 
      pFormatName := AllocMem(255); 
      GetClipBoardFormatName(TempFormat.cfFormat, pFormatName, 254); 
      if (string(pFormatName) = 'Rich Text Format') then 
      begin 
        RTFFormat := TempFormat; 
        Found := True; 
      end; 
      FreeMem(pFormatName); 
    end; 
    Result := Found; 
  except 
    Result := False; 
  end; 
end; 

function GetRTF: string; 
var 
  DataObject: IDataObject; 
  RTFFormat: TFormatEtc; 
  ReturnData: TStgMedium; 
  Buffer: PChar; 
  WordDoc: _Document; 
  WordApp: _Application; 
begin 
  Result := ''; 
  try 
    GetActiveOleObject('Word.Application').QueryInterface(_Application, WordApp); 
  except 
    ShowMessage('Error: MSWord is not running'); 
    Exit; 
  end; 
  if (WordApp <> nil) then 
    try 
      WordDoc := WordApp.ActiveDocument; 
      WordDoc.QueryInterface(IDataObject, DataObject); 
      if GetRTFFormat(DataObject, RTFFormat) then 
      begin 
        OleCheck(DataObject.GetData(RTFFormat, ReturnData)); 
        //RTF is passed through global memory 
        Buffer := GlobalLock(ReturnData.hglobal); 
        //Buffer is a pointer to the RTF text 
        Result := StrPas(Buffer); 
        GlobalUnlock(ReturnData.hglobal); 
        ReleaseStgMedium(ReturnData); 
      end; 
    except 
      // Error occured... 
    end; 
end; 

procedure TForm1.Button1Click(Sender: TObject); 
var 
  ss: TStringstream; 
  rtfText: string; 
begin 
  rtfText := GetRTF; 
  ss := TStringStream.Create(rtfText); 
  try 
    ss.Position := 0; 
    Memo1.Text := rtfText; 
    RichEdit1.Lines.LoadFromStream(ss); 
  finally 
    ss.Free 
  end; 
end;


www.swissdelphicente...showcode.php?id=2059