![]() |
RTF in Word einfügen
Folg. Problem:
Ich habe mehrere RTF-Dateien. Diese sind Grundlage! Ich möchte diese jetzt in ein vorhandenes Word-Dokument einfügen:
Delphi-Quellcode:
Ich weiß, dass es die Prozedur WordApplication1.Selection.InsertFile gibt , weiß aber nicht ob die dafür geeignet ist und wie ich diese verwende. Hab nix in Google, DP oder Hilfe gefunden...
procedure ....... ;
var FileName, newFile: OleVariant; FPara: Paragraph; //Absatz FRange: Range; //Bereich vWhat, vBookmark:OleVariant; begin FileName := 'c:\vorlage.dot'; WordApplication1.Connect; WordApplication1.Documents.Open(FileName, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam); WordDocument1.ConnectTo(WordApplication1.ActiveDocument); //ANZEIGEN WordApplication1.visible := true; FileName := false; //Jump-To-End vWhat:=wdGoToBookmark; vBookmark:='Einfug'; WordApplication1.Selection.GoTo_(vWhat,emptyParam,emptyParam,vBookmark); //Formatierung vorab WordApplication1.Selection.Font.Name := 'Arial'; WordApplication1.Selection.Font.Size := 10; //hiernach kommt später noch ne Schleife um mehrere RTFs einzufügen... WordApplication1.Selection.Font.Bold := integer(True); WordApplication1.Selection.TypeText('Lfd.-Nr.: '+DatMod.MTaLfdNr.AsString+#13); WordApplication1.Selection.Font.Bold := integer(False); WordApplication1.Selection.TypeText('Datenblatt:'+#13); // HIER MUSS DIE RTF EINGEFÜGT WERDEN!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //speichern SaveDialog1.InitialDir := ExtractFilePath(Application.ExeName)+'ausdruck\'; SaveDialog1.Filter := 'Microsoft Word-Dokument (*.DOC)|*.doc'; SaveDialog1.DefaultExt := 'doc'; SaveDialog1.FileName := ''; SaveDialog1.Title := 'Speichern...'; if Haupt.SaveDialog1.Execute then begin newFile := SaveDialog1.FileName; WordDocument1.SaveAs(newFile); end; //Schließen WordDocument1.Close(FileName); WordDocument1.Disconnect; WordApplication1.Quit; WordApplication1.Disconnect; end; ThX Marcus |
Re: RTF in Word einfügen
Hi!
Warumm lädst du die RTF-Datei nicht vorher in ein Richedit und "überträgst" sie dann? Ciao Frederic |
Re: RTF in Word einfügen
Nun ja. In den RTFs sind vorwiegend Tabellen. Wie soll ich die den von RichEdit (in diesem Fall Jedi RichEdit, JVCL) zum Word-Dokument übertragen.
Oder was vielleicht besser ist: Wie kann ich eine Word-Datei (DOC) in einer andere Einfügen? Wenn ich von vornherein auf DOCs umsteige, ist es eh besser. [edit=Admin]'Pushen' erst nach 24 Stunden. Folgenden 'Push'-Beitrag entfernt. Mfg, Daniel[/edit] |
Re: RTF in Word einfügen
okay. Nach langem Suchen bin ich auf
![]() MfG Marcus |
Re: RTF in Word einfügen
Zitat:
Ist ja klar warum, denn es wird ja dies jedesmal aufgerufen:
Delphi-Quellcode:
WordApp.Documents.Add(...
|
Re: RTF in Word einfügen
Okay. Ich möchte nicht unhöflich erscheinen, aber das Kommentar bringt mich trotzdem nicht weiter.
Anmerkung: Ich selbst habe auch schon versucht, diese Zeile einfach wegzulassen, doch dann ist das Ergebnis immernoch nicht das, was gewünscht ist. Er lädt, dann zwar eine Memo ein aber löscht die zuvor eingeladene DOT-Datei. Also die Prozedur dxWinXPBar3Items3Click startet das Ganze. ButtonStartWord2 startet Word, wird aufgerufen aus dxWinXPBar3Items3Click. GetRTFFormat und WriteToMSWord ist für das Einladen einer RTF da. Es kann doch aber auch nicht so schwer sein, eine Word-Datei in eine anderen an beliebiger Stelle einzufügen!!! :x Ich gebe ma den kompletten Quellcode, hoffe jemand kann mir da echt ma helfen, wird knapp, muss das ganze doch bald abgeben :cry: :
Delphi-Quellcode:
procedure THaupt.ButtonStartWord2;
begin if not Assigned(FWordApp) then FWordApp := TWordApplication.Create(Self); try FWordApp.Connect; except on E: Exception do begin FreeAndNil(FWordApp); Showmessage('Die Verbindung zu Word konnte nicht ' + 'hergestellt werden:' + #10#13 + E.Message); Raise; end; // on E end; // try except FWordApp.Visible := True; FWordApp.WindowState := wdWindowStateMinimize; // FWordApp.OnQuit := OnWordAppClose; end; 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; procedure THaupt.WriteToMSWord(const RTFText: String); var WordDoc: _Document; DataObj : IDataObject; Formats : IEnumFormatEtc; RTFFormat: TFormatEtc; Medium : TStgMedium; pGlobal : Pointer; begin // WordApplication1.Documents.Add(EmptyParam, EmptyParam, EmptyParam, EmptyParam); WordDoc := WordApplication1.ActiveDocument; OleCheck(WordDoc.QueryInterface(IDataObject,DataObj)); GetRTFFormat(DataObj, RTFFormat); FillChar(Medium,SizeOf(Medium),0); Medium.tymed := RTFFormat.tymed; Medium.hGlobal := GlobalAlloc(GMEM_MOVEABLE, Length(RTFText)+1); try pGlobal := GlobalLock(Medium.hGlobal); CopyMemory(PGlobal,PChar(RTFText),Length(RTFText)+1); GlobalUnlock(Medium.hGlobal); OleCheck(DataOBJ.SetData(RTFFormat,Medium,True)); finally GlobalFree(Medium.hGlobal); ReleaseStgMedium(Medium); end; end; procedure THaupt.dxWinXPBar3Items3Click(Sender: TObject); var FileName, newFile: OleVariant; FPara: Paragraph; //Absatz FRange: Range; //Bereich vWhat, vBookmark:OleVariant; begin DatMod.MTa.First; Datenblatt.RichEdit1.Lines.Clear; OpenDialog1.InitialDir := ExtractFilePath(Application.ExeName)+'drucken\Vorlagen\Maschinenliste\'; OpenDialog1.Filter := 'Dokumentvorlage (*.DOT)|*.dot'; OpenDialog1.DefaultExt := 'dot'; OpenDialog1.Title := 'Sprache laden'; if OpenDialog1.Execute then begin FileName := OpenDialog1.FileName; WordApplication1.Connect; WordApplication1.Documents.Open(FileName, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam); WordDocument1.ConnectTo(WordApplication1.ActiveDocument); //ANZEIGEN WordApplication1.visible := true; FileName := false; //Jump-To-End vWhat:=wdGoToBookmark; vBookmark:='Einfug'; WordApplication1.Selection.GoTo_(vWhat,emptyParam,emptyParam,vBookmark); //Formatierung vorab WordApplication1.Selection.Font.Name := 'Arial'; WordApplication1.Selection.Font.Size := 10; //Datensätze Maschinen DatMod.MTa.First; while not(DatMod.MTa.Eof) do begin WordApplication1.Selection.Font.Bold := integer(True); WordApplication1.Selection.TypeText('Lfd.-Nr.: '+DatMod.MTaLfdNr.AsString+#13); WordApplication1.Selection.Font.Bold := integer(False); WriteToMSWord(Memo1.Text); //WordApplication1.Selection.InsertFile??? GGF.?? WordApplication1.Selection.TypeText('TABELLE'+#13); WordApplication1.Selection.TypeText('Preis / Price: € '+ThouSep(DatMod.MTaVK.AsString, '.')+' '+DatMod.MTaVKV.AsString+#13); WordApplication1.Selection.TypeText('_________________________'+#13); DatMod.MTa.Next; end; //speichern SaveDialog1.InitialDir := ExtractFilePath(Application.ExeName)+'ausdruck\'; SaveDialog1.Filter := 'Microsoft Word-Dokument (*.DOC)|*.doc'; SaveDialog1.DefaultExt := 'doc'; SaveDialog1.FileName := ''; SaveDialog1.Title := 'Speichern...'; if SaveDialog1.Execute then begin newFile := SaveDialog1.FileName; WordDocument1.SaveAs(newFile); end; //Schließen WordDocument1.Close(FileName); WordDocument1.Disconnect; WordApplication1.Quit; WordApplication1.Disconnect; end; end; |
Re: RTF in Word einfügen
Hallo, ich noch einmal.
Ich möchte doch nicht mehr als eine DOC-Datei (Word-Dokument) in eine andere einfügen. Das kann doch nicht so schwer sein. Ich meine, wenn man schon mittels OLE Tabellen erstellen, Grafiken einbinden und sonstige Wunder vollbringen kann, dann kann doch das auch nicht so schwer sein. :cry: :( :cry: MfG Marcus |
Re: RTF in Word einfügen
schon mal per Zwischenablage probiert ?
|
Re: RTF in Word einfügen
du musst doch anstatt
Delphi-Quellcode:
auch auf deines der documents zugreigen und etwas einfügen können. sprich [delphi]WordApp.Documents[0].Insert[/delphi oder irgendsoetwas.
WordApp.Documents.Add(...
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 21:52 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz