AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

RTF in Word einfügen

Ein Thema von TypusMensch · begonnen am 18. Nov 2004 · letzter Beitrag vom 13. Jul 2005
Antwort Antwort
TypusMensch

Registriert seit: 29. Aug 2003
Ort: Goth-A
182 Beiträge
 
Delphi 7 Enterprise
 
#1

RTF in Word einfügen

  Alt 18. Nov 2004, 11:25
Folg. Problem:
Ich habe mehrere RTF-Dateien. Diese sind Grundlage! Ich möchte diese jetzt in ein vorhandenes Word-Dokument einfügen:

Delphi-Quellcode:
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;
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...

ThX
Marcus
  Mit Zitat antworten Zitat
Benutzerbild von fkerber
fkerber
(CodeLib-Manager)

Registriert seit: 9. Jul 2003
Ort: Ensdorf
6.723 Beiträge
 
Delphi XE Professional
 
#2

Re: RTF in Word einfügen

  Alt 18. Nov 2004, 13:46
Hi!

Warumm lädst du die RTF-Datei nicht vorher in ein Richedit und "überträgst" sie dann?


Ciao Frederic
Frederic Kerber
  Mit Zitat antworten Zitat
TypusMensch

Registriert seit: 29. Aug 2003
Ort: Goth-A
182 Beiträge
 
Delphi 7 Enterprise
 
#3

Re: RTF in Word einfügen

  Alt 18. Nov 2004, 15:10
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]
  Mit Zitat antworten Zitat
TypusMensch

Registriert seit: 29. Aug 2003
Ort: Goth-A
182 Beiträge
 
Delphi 7 Enterprise
 
#4

Re: RTF in Word einfügen

  Alt 21. Nov 2004, 13:04
okay. Nach langem Suchen bin ich auf das hier gestoßen. Es lädt eine RTF in ein Doc. Wenn aber ich das in einer Schleife einbinde, öffnet er jedesmal ein neues Dokument, statt es hintereinander einzufügen. Zweiten lädt er auch die RTFs nicht komplett ein. Verstehe ich nicht, vielleicht kann jemand mit dem Quellcode was anfangen, diesen modifizieren auf mein Problem. Ich selbst fühle mich nicht in der Lage. Leider verstehe ich die zwei Funktionen nicht annähernd. Und jeglicher Versuch scheiterte.

MfG
Marcus
  Mit Zitat antworten Zitat
Benutzerbild von toms
toms
(CodeLib-Manager)

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

Re: RTF in Word einfügen

  Alt 21. Nov 2004, 18:26
Zitat von TypusMensch:
okay. Nach langem Suchen bin ich auf das hier gestoßen. Es lädt eine RTF in ein Doc. Wenn aber ich das in einer Schleife einbinde, öffnet er jedesmal ein neues Dokument, statt es hintereinander einzufügen.
Hi,

Ist ja klar warum, denn es wird ja dies jedesmal aufgerufen:
WordApp.Documents.Add(...
Thomas
  Mit Zitat antworten Zitat
TypusMensch

Registriert seit: 29. Aug 2003
Ort: Goth-A
182 Beiträge
 
Delphi 7 Enterprise
 
#6

Re: RTF in Word einfügen

  Alt 22. Nov 2004, 11:53
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!!!

Ich gebe ma den kompletten Quellcode, hoffe jemand kann mir da echt ma helfen, wird knapp, muss das ganze doch bald abgeben :

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;
  Mit Zitat antworten Zitat
TypusMensch

Registriert seit: 29. Aug 2003
Ort: Goth-A
182 Beiträge
 
Delphi 7 Enterprise
 
#7

Re: RTF in Word einfügen

  Alt 23. Nov 2004, 11:19
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.

MfG
Marcus
  Mit Zitat antworten Zitat
Benutzerbild von spacewolf
spacewolf

Registriert seit: 24. Apr 2003
Ort: Magdeburg
218 Beiträge
 
Delphi 7 Professional
 
#8

Re: RTF in Word einfügen

  Alt 13. Jul 2005, 15:05
schon mal per Zwischenablage probiert ?
Andreas Göllner
("`-''-/").___..--''"`-._
`6_ 6 ) `-. ( ).`-.__.`)
"Ich kann Dir nur die Tür zeigen, durchgehen musst Du ganz allein."
Wer ist die Tür? Jesus!
  Mit Zitat antworten Zitat
Benutzerbild von DGL-luke
DGL-luke

Registriert seit: 1. Apr 2005
Ort: Bad Tölz
4.149 Beiträge
 
Delphi 2006 Professional
 
#9

Re: RTF in Word einfügen

  Alt 13. Jul 2005, 16:07
du musst doch anstattWordApp.Documents.Add(... auch auf deines der documents zugreigen und etwas einfügen können. sprich [delphi]WordApp.Documents[0].Insert[/delphi oder irgendsoetwas.
Lukas Erlacher
Suche Grafiktablett. Spenden/Gebrauchtangebote willkommen.
Gotteskrieger gesucht!
For it is the chief characteristic of the religion of science that it works. - Isaac Asimov, Foundation I, Buch 1
  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 10:59 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