<?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[Excel und OLE]]></title><description><![CDATA[<p>Hallo,<br />
steuere Excel an und übergebe aus einem StringGrid Daten.<br />
Klappt alles wunderbar; nur bei der Spaltenbreite und Selektierung<br />
der Tabelle bekomme ich Fehlermeldung &quot;...falscher Variablentyp..&quot;<br />
Witzigerweise wird die Funktion aber jeweils in Excel korrekt umgesetzt...!?</p>
<pre><code class="language-cpp">void __fastcall TForm21::frm21_btnExcelClick(TObject *Sender)
{try {                                                                          // Fehllerroutine Start
 Integer iRow,iCol,iSumme; AnsiString z1,z2,zFile;                              // Vars definieren
 Variant Excel,vSheet,vFont,vCell,vCol,vRange;                                  // Vars definieren

 if(FileExists(zExcel)==false) {                                                // Pfad falsch
  ShowMessage(&quot;MS Excel Pfadangabe nicht korrekt bzw. Programm nicht gefunden.\rBitte geben Sie den korrekten Pfad an.\r\r=&gt; &quot;+zExcel); // Info geben
  frm21_btnAuswahlClick(0);                                                     // und Auswahl ermöglichen
  return;                                                                       // und raus
 }                                                                              // ende if(FileExists

 z1=&quot;Statistik &quot;+frm21_cbStatistik-&gt;Text;                                       // Bezeichnung Arbeitsmappe
 zFile=Form1-&gt;PrgPfad+&quot;Ablage\\excel_&quot;+z1+&quot;.xls&quot;;                               // Filename erzeugen

 Excel=CreateOleObject(&quot;Excel.Application&quot;);                                    // Excel OLE anmelden
 Excel.OlePropertySet(&quot;Visible&quot;,true);                                          // Excel sichtbar machen

 Excel=Excel.OlePropertyGet(&quot;Workbooks&quot;);                                       // Zugriff auf die Workbooks
 Excel.OleFunction(&quot;Add&quot;);                                                      // 1. Arbeitsblatt erstellen
 vSheet=Excel.OlePropertyGet(&quot;Item&quot;,1);                                         // Zugriff auf das erste Worksheet
 vSheet=vSheet.OlePropertyGet(&quot;Worksheets&quot;);                                    // und
 vSheet.OlePropertyGet(&quot;Item&quot;,1).OlePropertySet(&quot;Name&quot;,z1.c_str());             // Dem Worksheet einen Namen geben

 vSheet=vSheet.OlePropertyGet(&quot;Item&quot;,1);                                        // Zugriff auf das erste Worksheet

 iCol=frm21_grdStatistik-&gt;ColCount;                                             // Anzahl Spalten
 iRow=frm21_grdStatistik-&gt;RowCount;                                             // Anzahl Zeilen
 for (int i1=0;i1&lt;iRow;i1++) {                                                  // alle Zeilen
  for (int i0=0;i0&lt;iCol;i0++) {                                                 // alle Spalten
   z1=frm21_grdStatistik-&gt;Cells[i0][i1];                                        // Text auslesen
   vCell=vSheet.OlePropertyGet(&quot;Cells&quot;).OlePropertyGet(&quot;Item&quot;,i1+2,i0+2);       // Zelle ermitteln
   vCell.OlePropertySet(&quot;Value&quot;, z1.c_str());                                   // Zelle beschreiben

   if(i1==0) {                                                                  // ÜBERSCHRIFT
    vFont=vCell.OlePropertyGet(&quot;Font&quot;);                                         // Fontzugriff übergeben
    vFont.OlePropertySet(&quot;Name&quot;, WideString(&quot;Arial&quot;));                          // Schriftname
    vFont.OlePropertySet(&quot;Size&quot;, 10);                                           // Schriftgrösse
    vFont.OlePropertySet(&quot;Bold&quot; ,true);                                         // Fontstil
    vFont.OlePropertySet(&quot;Color&quot;,clBlue);                                       // Farbe des Textes
   }                                                                            // ende if(i1==0

  }                                                                             // ende for(int i0
 }                                                                              // ende for(int i1
 z1=&quot;Summen&quot;; z2=IntToStr(frm21_grdChart-&gt;Tag);
 vSheet.OlePropertyGet(&quot;Cells&quot;).OlePropertyGet(&quot;Item&quot;,iRow+3,2).OlePropertySet(&quot;Value&quot;, z1.c_str()); // Summenzeile 1. Spalte
 vSheet.OlePropertyGet(&quot;Cells&quot;).OlePropertyGet(&quot;Item&quot;,iRow+3,3).OlePropertySet(&quot;Value&quot;, z2.c_str()); // Summenzeile 2. Spalte
 vSheet.OlePropertyGet(&quot;Cells&quot;).OlePropertyGet(&quot;Item&quot;,iRow+3,4).OlePropertySet(&quot;Value&quot;, &quot;100&quot;);      // Summenzeile 3. Spalte

 vCol=vSheet.OlePropertyGet(&quot;Columns&quot;,&quot;C&quot;);                                     // Spalte C
 vCol.OlePropertySet(&quot;HorizontalAlignment&quot;,alRight);                            // rechtsbündig ausrichten
 vCol=vSheet.OlePropertyGet(&quot;Columns&quot;,&quot;D&quot;);                                     // Spalte D
 vCol.OlePropertySet(&quot;HorizontalAlignment&quot;,alRight);                            // rechtsbündig ausrichten

 // Ab hier Abstürze mit Breite ???
 vCol=vSheet.OlePropertyGet(&quot;Columns&quot;,&quot;B&quot;);                                     // Spalte B
 //vCol.OlePropertySet(&quot;ColumnWidth&quot;,300);
 //try { vCol.OlePropertySet(&quot;AutoFit&quot;,true); } catch(...) {}                     // und Breite auf Optimal

 // Ab hier Abstürze und Selektierung ???
 //vRange=vSheet.OlePropertyGet(&quot;Range&quot;,&quot;B2:D&quot;+IntToStr(iRow+2));                 // Tabelle auswählen
 //try { vRange.OlePropertySet(&quot;Select&quot;,true); } catch(...) {}                    // und selektieren

 Excel=Unassigned;                                                              // und auflösen
 }                                                                              // try ende
 catch(...) {                                                                   // Fehlerroutine Step
  ShowMessage(&quot;Fehler -&gt; TForm21::frm21_btnExcelClick()&quot;); }                    // Fehler anzeigen
}
</code></pre>
<p>Die Zeilen der Abstürze sind am Emde; habe alles mögliche probiert, komme aber nicht weiter. Wie kann ich aus der Tabelle ein Diagramm erzeugen bzw. ein weiteres Arbeitsblatt erzeugen (da stürzt er mir auch immer ab...)</p>
<p>Danke für jeden Tipp<br />
Grüsse Stefan</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/157470/excel-und-ole</link><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Apr 2026 03:32:35 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/157470.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 26 Aug 2006 06:11:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Excel und OLE on Sat, 26 Aug 2006 06:11:14 GMT]]></title><description><![CDATA[<p>Hallo,<br />
steuere Excel an und übergebe aus einem StringGrid Daten.<br />
Klappt alles wunderbar; nur bei der Spaltenbreite und Selektierung<br />
der Tabelle bekomme ich Fehlermeldung &quot;...falscher Variablentyp..&quot;<br />
Witzigerweise wird die Funktion aber jeweils in Excel korrekt umgesetzt...!?</p>
<pre><code class="language-cpp">void __fastcall TForm21::frm21_btnExcelClick(TObject *Sender)
{try {                                                                          // Fehllerroutine Start
 Integer iRow,iCol,iSumme; AnsiString z1,z2,zFile;                              // Vars definieren
 Variant Excel,vSheet,vFont,vCell,vCol,vRange;                                  // Vars definieren

 if(FileExists(zExcel)==false) {                                                // Pfad falsch
  ShowMessage(&quot;MS Excel Pfadangabe nicht korrekt bzw. Programm nicht gefunden.\rBitte geben Sie den korrekten Pfad an.\r\r=&gt; &quot;+zExcel); // Info geben
  frm21_btnAuswahlClick(0);                                                     // und Auswahl ermöglichen
  return;                                                                       // und raus
 }                                                                              // ende if(FileExists

 z1=&quot;Statistik &quot;+frm21_cbStatistik-&gt;Text;                                       // Bezeichnung Arbeitsmappe
 zFile=Form1-&gt;PrgPfad+&quot;Ablage\\excel_&quot;+z1+&quot;.xls&quot;;                               // Filename erzeugen

 Excel=CreateOleObject(&quot;Excel.Application&quot;);                                    // Excel OLE anmelden
 Excel.OlePropertySet(&quot;Visible&quot;,true);                                          // Excel sichtbar machen

 Excel=Excel.OlePropertyGet(&quot;Workbooks&quot;);                                       // Zugriff auf die Workbooks
 Excel.OleFunction(&quot;Add&quot;);                                                      // 1. Arbeitsblatt erstellen
 vSheet=Excel.OlePropertyGet(&quot;Item&quot;,1);                                         // Zugriff auf das erste Worksheet
 vSheet=vSheet.OlePropertyGet(&quot;Worksheets&quot;);                                    // und
 vSheet.OlePropertyGet(&quot;Item&quot;,1).OlePropertySet(&quot;Name&quot;,z1.c_str());             // Dem Worksheet einen Namen geben

 vSheet=vSheet.OlePropertyGet(&quot;Item&quot;,1);                                        // Zugriff auf das erste Worksheet

 iCol=frm21_grdStatistik-&gt;ColCount;                                             // Anzahl Spalten
 iRow=frm21_grdStatistik-&gt;RowCount;                                             // Anzahl Zeilen
 for (int i1=0;i1&lt;iRow;i1++) {                                                  // alle Zeilen
  for (int i0=0;i0&lt;iCol;i0++) {                                                 // alle Spalten
   z1=frm21_grdStatistik-&gt;Cells[i0][i1];                                        // Text auslesen
   vCell=vSheet.OlePropertyGet(&quot;Cells&quot;).OlePropertyGet(&quot;Item&quot;,i1+2,i0+2);       // Zelle ermitteln
   vCell.OlePropertySet(&quot;Value&quot;, z1.c_str());                                   // Zelle beschreiben

   if(i1==0) {                                                                  // ÜBERSCHRIFT
    vFont=vCell.OlePropertyGet(&quot;Font&quot;);                                         // Fontzugriff übergeben
    vFont.OlePropertySet(&quot;Name&quot;, WideString(&quot;Arial&quot;));                          // Schriftname
    vFont.OlePropertySet(&quot;Size&quot;, 10);                                           // Schriftgrösse
    vFont.OlePropertySet(&quot;Bold&quot; ,true);                                         // Fontstil
    vFont.OlePropertySet(&quot;Color&quot;,clBlue);                                       // Farbe des Textes
   }                                                                            // ende if(i1==0

  }                                                                             // ende for(int i0
 }                                                                              // ende for(int i1
 z1=&quot;Summen&quot;; z2=IntToStr(frm21_grdChart-&gt;Tag);
 vSheet.OlePropertyGet(&quot;Cells&quot;).OlePropertyGet(&quot;Item&quot;,iRow+3,2).OlePropertySet(&quot;Value&quot;, z1.c_str()); // Summenzeile 1. Spalte
 vSheet.OlePropertyGet(&quot;Cells&quot;).OlePropertyGet(&quot;Item&quot;,iRow+3,3).OlePropertySet(&quot;Value&quot;, z2.c_str()); // Summenzeile 2. Spalte
 vSheet.OlePropertyGet(&quot;Cells&quot;).OlePropertyGet(&quot;Item&quot;,iRow+3,4).OlePropertySet(&quot;Value&quot;, &quot;100&quot;);      // Summenzeile 3. Spalte

 vCol=vSheet.OlePropertyGet(&quot;Columns&quot;,&quot;C&quot;);                                     // Spalte C
 vCol.OlePropertySet(&quot;HorizontalAlignment&quot;,alRight);                            // rechtsbündig ausrichten
 vCol=vSheet.OlePropertyGet(&quot;Columns&quot;,&quot;D&quot;);                                     // Spalte D
 vCol.OlePropertySet(&quot;HorizontalAlignment&quot;,alRight);                            // rechtsbündig ausrichten

 // Ab hier Abstürze mit Breite ???
 vCol=vSheet.OlePropertyGet(&quot;Columns&quot;,&quot;B&quot;);                                     // Spalte B
 //vCol.OlePropertySet(&quot;ColumnWidth&quot;,300);
 //try { vCol.OlePropertySet(&quot;AutoFit&quot;,true); } catch(...) {}                     // und Breite auf Optimal

 // Ab hier Abstürze und Selektierung ???
 //vRange=vSheet.OlePropertyGet(&quot;Range&quot;,&quot;B2:D&quot;+IntToStr(iRow+2));                 // Tabelle auswählen
 //try { vRange.OlePropertySet(&quot;Select&quot;,true); } catch(...) {}                    // und selektieren

 Excel=Unassigned;                                                              // und auflösen
 }                                                                              // try ende
 catch(...) {                                                                   // Fehlerroutine Step
  ShowMessage(&quot;Fehler -&gt; TForm21::frm21_btnExcelClick()&quot;); }                    // Fehler anzeigen
}
</code></pre>
<p>Die Zeilen der Abstürze sind am Emde; habe alles mögliche probiert, komme aber nicht weiter. Wie kann ich aus der Tabelle ein Diagramm erzeugen bzw. ein weiteres Arbeitsblatt erzeugen (da stürzt er mir auch immer ab...)</p>
<p>Danke für jeden Tipp<br />
Grüsse Stefan</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1124788</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1124788</guid><dc:creator><![CDATA[Stefan71242]]></dc:creator><pubDate>Sat, 26 Aug 2006 06:11:14 GMT</pubDate></item><item><title><![CDATA[Reply to Excel und OLE on Mon, 28 Aug 2006 05:42:35 GMT]]></title><description><![CDATA[<p>versuchs mal so:</p>
<pre><code class="language-cpp">vCol=vSheet.OlePropertyGet(&quot;Columns&quot;,&quot;B&quot;);
 vCol.OlePropertySet(&quot;ColumnWidth&quot;,30);
 vCol.OleFunction(&quot;Autofit&quot;);

 String test = &quot;B2:D&quot;+IntToStr(iRow+2);
 vRange=vSheet.OlePropertyGet(&quot;Range&quot;,test.c_str());
 vRange.OleFunction(&quot;Select&quot;);
</code></pre>
<p>ein einfacher Test im Excel ergab, dass die Spaltenbreite maximal 255 sein kann</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1125848</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1125848</guid><dc:creator><![CDATA[Linnea]]></dc:creator><pubDate>Mon, 28 Aug 2006 05:42:35 GMT</pubDate></item><item><title><![CDATA[Reply to Excel und OLE on Mon, 28 Aug 2006 07:03:17 GMT]]></title><description><![CDATA[<p>Hallo, Linnea</p>
<p>Supertip! Vielen Dank... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":-)"
      alt="🙂"
    /><br />
Werde mich jetzt an die Diagramme wagen..</p>
<p>Grüsse, Stefan</p>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f44d.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--thumbs_up"
      title=":+1:"
      alt="👍"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1125872</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1125872</guid><dc:creator><![CDATA[Stefan71242]]></dc:creator><pubDate>Mon, 28 Aug 2006 07:03:17 GMT</pubDate></item></channel></rss>