<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Zugriff auf MS-Word-Dokument]]></title><description><![CDATA[<p>Hallo,<br />
möchte aus dem Programm auf ein MS-Word-Dokument zugreifen und nach bestimmte Textpasagenb ändern. Gibt es Schnittstellen dafür? Hat jemand ein Beispiel?<br />
Gibt es Quellcodebeispiele? Bitte schreibt etwas.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/191572/zugriff-auf-ms-word-dokument</link><generator>RSS for Node</generator><lastBuildDate>Mon, 17 Aug 2026 18:31:39 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/191572.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 04 Sep 2007 13:24:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Zugriff auf MS-Word-Dokument on Tue, 04 Sep 2007 13:24:18 GMT]]></title><description><![CDATA[<p>Hallo,<br />
möchte aus dem Programm auf ein MS-Word-Dokument zugreifen und nach bestimmte Textpasagenb ändern. Gibt es Schnittstellen dafür? Hat jemand ein Beispiel?<br />
Gibt es Quellcodebeispiele? Bitte schreibt etwas.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1358782</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1358782</guid><dc:creator><![CDATA[radain]]></dc:creator><pubDate>Tue, 04 Sep 2007 13:24:18 GMT</pubDate></item><item><title><![CDATA[Reply to Zugriff auf MS-Word-Dokument on Tue, 04 Sep 2007 13:34:13 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>Suchfunktion benutzen! Zum Beispiel das <a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-116841-and-highlight-is-%2Aword%2A.html" rel="nofollow">hier</a> habe ich mit *word* gefunden.</p>
<p>bis bald<br />
akari</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1358789</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1358789</guid><dc:creator><![CDATA[akari]]></dc:creator><pubDate>Tue, 04 Sep 2007 13:34:13 GMT</pubDate></item><item><title><![CDATA[Reply to Zugriff auf MS-Word-Dokument on Tue, 04 Sep 2007 13:39:29 GMT]]></title><description><![CDATA[<p>Danke dir akari.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1358793</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1358793</guid><dc:creator><![CDATA[radian]]></dc:creator><pubDate>Tue, 04 Sep 2007 13:39:29 GMT</pubDate></item><item><title><![CDATA[Reply to Zugriff auf MS-Word-Dokument on Wed, 05 Sep 2007 10:50:24 GMT]]></title><description><![CDATA[<p>Hallo,<br />
habe nun eindlich mal das Beispiel von [url]<br />
<a href="http://www.bytesandmore.de/rad/index.htm?http://www.bytesandmore.de/rad/cpp/main/snip_cnt.htm" rel="nofollow">http://www.bytesandmore.de/rad/index.htm?http://www.bytesandmore.de/rad/cpp/main/snip_cnt.htm</a><br />
[/url]<br />
ausprobiert. Die EXE-Datei lief einwandfrei. Danach habe ich den Quelltext in mein Programm eingearbeitet. Nun entstand folgendes Problem.<br />
Die im Word-Dokument makierten Textstellen (Textmarken in Word) wurden nicht wie gewünscht von dem Programm ersetzt. Ziel war es, die makierten Textpasagen durch Texte aus TLabel-Objekten zu ersetzen.<br />
Leider wurden die Texte hintereinander in die erste Zeile geschrieben.<br />
Ich dachte nun, dass es am Programm liegt oder aber am Dokument. Konnte aber keinen Fehler fesstellen. Daher Compilierte ich das Beispiel von der oben aufgeführten Seite neu. Siehe da, es entstand das Gleiche Problem bei der Ausführung.<br />
Wie ich schnell sehr schnell feststellte, wurde das Beispielprogramm mit dem C++ Builder 5 geschrieben und compiliert. Ich hingegen nutze das Developer Studio 2006<br />
(C++ Builder). Somit habe ich nun ein Problem das in den Griff zu bekommen. Ich werde nun meinen Queltext Posten in der Hoffnung, dass jemand mir an den entscheidenen Stellen einen Tip geben kann.</p>
<p>Headerdatei:</p>
<pre><code class="language-cpp">//---------------------------------------------------------------------------

#ifndef CertifcateH
#define CertifcateH
//---------------------------------------------------------------------------
#include &lt;Classes.hpp&gt;
#include &lt;Controls.hpp&gt;
#include &lt;StdCtrls.hpp&gt;
#include &lt;Forms.hpp&gt;
#include &lt;ExtCtrls.hpp&gt;
#include &quot;Certifcate.h&quot;
#include &lt;ComObj.hpp&gt;
#include &lt;utilcls.h&gt;
#include &quot;CRCTest.h&quot;
//---------------------------------------------------------------------------
// Definiton der Variablen für die Übergabe an &quot;GoTo&quot;-Funktion
typedef enum WdGoToItem
{
  wdGoToBookmark = 0xFFFFFFFF, 
  wdGoToSection = 0, 
  wdGoToPage = 1, 
  wdGoToTable = 2, 
  wdGoToLine = 3, 
  wdGoToFootnote = 4, 
  wdGoToEndnote = 5, 
  wdGoToComment = 6,
  wdGoToField = 7, 
  wdGoToGraphic = 8, 
  wdGoToObject = 9, 
  wdGoToEquation = 10, 
  wdGoToHeading = 11, 
  wdGoToPercent = 12, 
  wdGoToSpellingError = 13, 
  wdGoToGrammaticalError = 14, 
  wdGoToProofreadingError = 15
} WdGoToItem;

class TForm_Certificate : public TForm
{
__published:	// Von der IDE verwaltete Komponenten
	TPanel *Panel_Certificate;
	TPanel *Panel_Date;
	TRadioGroup *RG_Language;
	TLabel *Label1;
	TLabel *Label2;
	TEdit *Edit_Start;
	TEdit *Edit_Ende;
	TLabel *Label3;
	TLabel *Label4;
	TButton *Button1;
	TButton *Button2;
	void __fastcall Button1Click(TObject *Sender);
	void __fastcall Button2Click(TObject *Sender);
private:	// Benutzer-Deklarationen
  // Initialisierung des Word OLE-Servers
  bool __fastcall InitOleServer(Variant &amp;vOLEWord);

  // Word-Dokument erzeugen, ggf. speichern und/oder drucken
  void __fastcall CreateDocument(Variant &amp;vOLEWord,
    AnsiString slTemplateFile, AnsiString slSaveFile, bool blPrint);

  // Beenden des Word OLE-Servers
  void __fastcall TerminateOleServer(Variant &amp;vOLEWord);
public:		// Benutzer-Deklarationen
	__fastcall TForm_Certificate(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm_Certificate *Form_Certificate;
//---------------------------------------------------------------------------
#endif
</code></pre>
<p>CPP-Datei</p>
<pre><code class="language-cpp">//---------------------------------------------------------------------------

#include &lt;vcl.h&gt;
#pragma hdrstop

#include &quot;Certifcate.h&quot;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TForm_Certificate *Form_Certificate;
//---------------------------------------------------------------------------
__fastcall TForm_Certificate::TForm_Certificate(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------

//******************************************************************************
// Start und Beenden des OLE-Servers
// Initialisierung des Word OLE-Servers
bool __fastcall TForm_Certificate::InitOleServer(Variant &amp;vOLEWord)
{
  vOLEWord = Unassigned;
  try
  {
	// vielleicht läuft Word ja bereits (wenn nicht, wird hier
	// eine Exception generiert - aber die ist ja behandelt :)
 	vOLEWord = GetActiveOleObject(&quot;Word.Application&quot;);
	return false;
  }
  catch(...)
  {
	 try
	 {
	   // vielleicht läuft Word ja bereits...
	   vOLEWord = CreateOleObject(&quot;Word.Application&quot;);
	   return true;
	 }
	 catch(Exception&amp; e)
	 {
		// Wahrscheinlich kein Word auf dem Rechner...
		Application-&gt;MessageBox(e.Message.c_str(),&quot;OLE-Error&quot;,MB_ICONERROR);
		vOLEWord = Unassigned;
	 }
  }
  return true;
}

//------------------------------------------------------------------------------
// Beenden des Word OLE-Servers
void __fastcall TForm_Certificate::TerminateOleServer(Variant &amp;vOLEWord)
{
  // Word OLE-Server beenden:
  if(!vOLEWord.IsEmpty())
  {
    vOLEWord.OlePropertyGet(&quot;Application&quot;).OleProcedure(&quot;Quit&quot;);
	vOLEWord = Unassigned;
  }
}
//******************************************************************************

//******************************************************************************
// Word-Dokument erzeugen, ggf. speichern und/oder drucken
void __fastcall TForm_Certificate::CreateDocument(Variant &amp;vOLEWord,
  AnsiString slTemplateFile, AnsiString slSaveFile, bool blPrint)
{
  try
  {
    // falls Word-Fenster sichtbar sein soll,
    // muss folgende Zeile aktiviert werden:
    // vOLEWord.OlePropertySet(&quot;Visible&quot;, true);

    // Falls die Vorlagen-Datei nicht existiert, schimpfen und beenden:
    if(!FileExists(slTemplateFile))
    {
      Application-&gt;MessageBox(&quot;Vorlagendatei nicht gefunden !&quot;,
        &quot;Abbruch&quot;,MB_ICONERROR);
      return;
    }

    // Referenz auf die &quot;Documents&quot;-Eigenschaft besorgen
    Variant vDokuments = vOLEWord.OlePropertyGet(&quot;Documents&quot;);
    // neues Dokument mit slTemplateFile als Dokumentenvorlage erzeugen:
    vDokuments.Exec(Procedure(&quot;Add&quot;) &lt;&lt; slTemplateFile &lt;&lt; 0);

    //--------------------------------------------------
    // Formular-Felder ausfüllen
    //--------------------------------------------------

    // Referenz auf die &quot;Selection&quot;-Eigenschaft besorgen
    Variant vSelection = vOLEWord.OlePropertyGet(&quot;Selection&quot;);

	// Zu Textmarke &quot;Name&quot; gehen:
	vSelection.Exec(Procedure(&quot;GoTo&quot;) &lt;&lt; (int)wdGoToBookmark &lt;&lt;
	   0 &lt;&lt; 0 &lt;&lt; &quot;Name&quot;);
	// den Text aus dem Eingabefeld eintragen:
	vSelection.OleProcedure(&quot;TypeText&quot;,(VARIANT)
	  ((Variant)Form_Main-&gt;EditName-&gt;Text.c_str()));

	// Zu Textmarke &quot;Start&quot; gehen:
	vSelection.Exec(Procedure(&quot;GoTo&quot;) &lt;&lt; (int)wdGoToBookmark &lt;&lt;
	   0 &lt;&lt; 0 &lt;&lt; &quot;Start&quot;);
	// den Text aus dem Eingabefeld eintragen:
	vSelection.OleProcedure(&quot;TypeText&quot;,(VARIANT)
	  ((Variant)Edit_Start-&gt;Text.c_str()));

	// Zu Textmarke &quot;Ende&quot; gehen:
	vSelection.Exec(Procedure(&quot;GoTo&quot;) &lt;&lt; (int)wdGoToBookmark &lt;&lt;
	   0 &lt;&lt; 0 &lt;&lt; &quot;Start&quot;);
	// den Text aus dem Eingabefeld eintragen:
	vSelection.OleProcedure(&quot;TypeText&quot;,(VARIANT)
	  ((Variant)Edit_Ende-&gt;Text.c_str()));

	// Zu Textmarke &quot;USER&quot; gehen:
	vSelection.Exec(Procedure(&quot;GoTo&quot;) &lt;&lt; (int)wdGoToBookmark &lt;&lt;
	   0 &lt;&lt; 0 &lt;&lt; &quot;USER&quot;);
	// den Text aus dem Eingabefeld eintragen:
	vSelection.OleProcedure(&quot;TypeText&quot;,(VARIANT)
	  ((Variant)Form_Main-&gt;PwName-&gt;Text.c_str()));

	// Zu Textmarke &quot;Password&quot; gehen:
	vSelection.Exec(Procedure(&quot;GoTo&quot;) &lt;&lt; (int)wdGoToBookmark &lt;&lt;
	   0 &lt;&lt; 0 &lt;&lt; &quot;Password&quot;);
	// den Text aus dem Eingabefeld eintragen:
   //	vSelection.OleProcedure(&quot;TypeText&quot;,(VARIANT)
	 // ((Variant)Form_Main-&gt;PwCRC-&gt;Text.c_str()));

	// ggf. drucken:
	if(blPrint)
	  vOLEWord.OlePropertyGet(&quot;Application&quot;).OleProcedure(&quot;PrintOut&quot;);

	// ggf. speichern:
	Variant vActiveDocument = vOLEWord.OlePropertyGet(&quot;ActiveDocument&quot;);
	if(slSaveFile != EmptyStr)
	  vActiveDocument.Exec(Procedure(&quot;SaveAs&quot;) &lt;&lt; slSaveFile &lt;&lt; 0 &lt;&lt; 0
		&lt;&lt; &quot;&quot; &lt;&lt; 1 &lt;&lt; &quot;&quot; &lt;&lt; 0 &lt;&lt; 0 &lt;&lt; 0 &lt;&lt; 0 &lt;&lt; 0 );

	// &quot;gespeichert&quot;-Flag in Word setzen, damit keine Nachfragen kommen
	vActiveDocument.OlePropertySet(&quot;Saved&quot;, true);

	// Datei schließen:
	vActiveDocument.Exec(Procedure(&quot;Close&quot;));
  }
  catch(Exception&amp; e)
  {
	Application-&gt;MessageBox( e.Message.c_str(),&quot;OLE-Error&quot;,MB_ICONERROR);
  }
}
//------------------------------------------------------------------------------
void __fastcall TForm_Certificate::Button1Click(TObject *Sender)
{
	// OLE-Server initialisieren, die Variable blWordStarted
	// wird auf true gesetzt falls Word nicht bereits aktiv war
	Variant vOLEWord;
	bool blWordStarted = InitOleServer(vOLEWord);

	  // Falls die Initialisierung des OLE-Servers erfolgreich,
	  // Dokument erzeugen und speichern:
	  if(!vOLEWord.IsEmpty())
		CreateDocument(vOLEWord, ExtractFilePath(ParamStr(0))+&quot;seavis_password_5_DE_xxx.doc&quot;,
		ExtractFilePath(ParamStr(0))+&quot;seavis_password.doc&quot;, false);

	  // Word nur beenden, wenn es von uns zuvor gestartet wurde:
	  if(blWordStarted) TerminateOleServer(vOLEWord);
}
//---------------------------------------------------------------------------

void __fastcall TForm_Certificate::Button2Click(TObject *Sender)
{
	// OLE-Server initialisieren, die Variable blWordStarted
	// wird auf true gesetzt falls Word nicht bereits aktiv war
	Variant vOLEWord;
	bool blWordStarted = InitOleServer(vOLEWord);

	// Falls die Initialisierung des OLE-Servers erfolgreich,
	// Dokument erzeugen und drucken:
	if(!vOLEWord.IsEmpty())
		CreateDocument(vOLEWord, ExtractFilePath(ParamStr(0))+&quot;seavis_password_5_DE_xxx.doc&quot;,
		EmptyStr, true);
	// Word nur beenden, wenn es von uns zuvor gestartet wurde:
	if(blWordStarted) TerminateOleServer(vOLEWord);
}
//---------------------------------------------------------------------------
</code></pre>
<p>Bitte helft mir.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1359312</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1359312</guid><dc:creator><![CDATA[radian]]></dc:creator><pubDate>Wed, 05 Sep 2007 10:50:24 GMT</pubDate></item><item><title><![CDATA[Reply to Zugriff auf MS-Word-Dokument on Wed, 05 Sep 2007 14:02:42 GMT]]></title><description><![CDATA[<p>Hallo, ich konnte bis jetzt leider noch immer keine passende Lösung finden. Aber vieleicht hat hier doch noch jemand eine Lösung.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1359474</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1359474</guid><dc:creator><![CDATA[radian]]></dc:creator><pubDate>Wed, 05 Sep 2007 14:02:42 GMT</pubDate></item></channel></rss>