Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi stringgrid nach Excel exportieren (https://www.delphipraxis.net/39781-stringgrid-nach-excel-exportieren.html)

wussi 7. Feb 2005 17:41


stringgrid nach Excel exportieren
 
Hallo,
ich möchte ein stringgrid variabler Größe nach Excel exportieren (D4).
Code:
Delphi-Quellcode:
       var Excel: variant;
       ...
       Excel := CreateOleObject('Excel.Application');
       Excel.Workbooks.Add;
       For zeile:=1 to 5 do
         For spalte:=1 to 5 do
           begin
           stringgrid1.cells[spalte-1,zeile-1]:=inttostr(spalte+(zeile-              1)*5);
           Excel.Cells[zeile,spalte].Value:=stringgrid1.cells[spalte-              1,zeile-1];
           end;
       Excel.Worksheets.add;
       Excel.Worksheets[1].Activate;
Diese Zeile funktioniert:
Delphi-Quellcode:
       Excel.Worksheets['Tabelle1'].Range['A1:E5'].copy;
ABER DIESE generiert eine Fehlermeldung(Schreibweise für variable Größe):
Delphi-Quellcode:
       Excel.Worksheets['Tabelle1'].Range[[Excel.Cells[1,1],
                                          [Excel.Cells[5,5]].Copy;

       
       
       ...   //Excel ordnungsgemäß schließen
Vielleicht hat jemand eine Idee.

[edit=sakura] [delphi]-Tags Mfg, sakura[/edit]

mwiesbau 17. Feb 2005 19:28

Re: stringgrid nach Excel exportieren
 
dieser befehl fügt in einen excel sheet an spalte 5 zeile 1 ÜM ein

Delphi-Quellcode:
excel:=createoleobject('excel.application');
excel.application.sheetsinnewworkbook:=stationABFL.count;
excel.workbooks.add;

  for k:=1 to temp.count-1 do
    begin
      excel.sheets[k].name:='Abschnitt'+inttostr(k);
      excel.sheets[k].cells[1,1].value:='TM='+temp[k];
      excel.sheets[k].cells[1,5].value:='ÜM';
      excel.sheets[k].cells[1,6].value:='DS';
      excel.sheets[k].cells[1,7].value:='ÜP';

sieh dir mal meinen code an ;-)
du sagst excel nich in welches worksheet du die werte eintragen möchtest.


Alle Zeitangaben in WEZ +1. Es ist jetzt 02:24 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