Autor Beitrag
delphi1
Hält's aus hier
Beiträge: 6



BeitragVerfasst: Fr 19.11.04 10:01 
Hallo,

ich habe folgendes Problem:

Ich suche nach einer Möglichkeit in Delphi, um aus einer vorhandenen doc-Datei eine rtf-Datei zu erzeugen. Beim Beenden meiner Anwendung möchte ich die bestehende rtf-Datei wieder löschen.

Im voraus besten Dank ...


delphi1
vsti
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 43

XP Home
D2005
BeitragVerfasst: Fr 19.11.04 12:04 
So sieht meine funktion aus, kann man sicher noch optimieren aber soweit funzt es für mich :)

ausblenden 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:
function KonvertWordDocZuRTF(DateiName: string): string;
var FileName, FileTyp: OleVariant;
    Hilfe,FileExt: string;
begin
  try
    Result:='';
    WordApplication.Connect;
    FileName:= DateiName;
    Hilfe:= FileName;
    FileExt := ExtractFileExt(FileName);
    Hilfe := StringReplace(Hilfe,FileExt,'.rtf',[rfReplaceAll]);
    while FileExists(Hilfe) do Insert('1',Hilfe,pos('.rtf',OutFile)-1);
    OutFile:= Hilfe;
    WordApplication.Documents.Open(FileName, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam);
    WordDocument.ConnectTo(WordApplication.ActiveDocument);
    FileTyp := wdFormatRTF;
    WordDocument.SaveAs(OutFile,FileTyp);
    WordDocument.Close;
    Result:= Hilfe;
  finally
    WordApplication.Disconnect;
  end;
end;


Dafür brauchst du die Komponenten WorDokument und WordApplication aus dem Server-Reiter. (bei mir Delphi 6 Ent.)

greez

_________________
[size=10:8b472be373]Wer anderen eine Grube gräbt hat Gold im Mund.[/size:8b472be373]