Autor Beitrag
rob87
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Fr 25.01.08 12:32 
Hallo zusammen.

Ich möchte mit Delphi Werte an Excel übergeben, bekomm allerdings die Fehlermeldung: "Mitglied nicht gefunden"

Ich hab den Eindruck, dass ich beim Öffnen irgendwas vergessen hab:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
var
  Excel : Variant;
  datum : String;
  zaehlerstand : Integer;
  dateiname, sheetname : String;  //Hab den Dateinamen auch schon "hart" angegeben, also in der Art C:\Ordner1\datei.xls

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
  Excel := CreateOleObject('Excel.Application');

  Excel.Workbooks(dateiname).Activate;                        <-- "Mitglied nicht gefunden"
  Excel.Workbooks(dateiname).Worksheets(sheetname).Activate;
  Excel.Sheets[sheetname].Cells[6,1].Value := datum;
  Excel.Sheets[sheetname].Cells[6,2].Value := zaehlerstand;

Vielleicht sieht ja jemand was
Agawain
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 460

win xp
D5, MySQL, devxpress
BeitragVerfasst: Fr 25.01.08 12:48 
Excel.Workbooks(dateiname).open;

_________________
Gruß Aga
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Fr 25.01.08 12:59 
user profile iconAgawain hat folgendes geschrieben:
Excel.Workbooks(dateiname).open;


Hat ich auch schon drin. Dann bringt er mir dieselbe Fehlermeldung schon beim Open (also: Mitglied ...) :roll: :roll:
iKilledKenny
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 8

Win XP
D5 Prof, C# Express 2005
BeitragVerfasst: Fr 25.01.08 13:24 
Sind das nicht auch für die Workbooks Aufzählung eckige Klammern?
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Mo 28.01.08 09:42 
user profile iconiKilledKenny hat folgendes geschrieben:
Sind das nicht auch für die Workbooks Aufzählung eckige Klammern?
Keine Ahnung.

Hab nun des Ganze mal mit eckigen Klammern gelöst. Dann bekomm ich die Fehlermeldung: "Ungültiger Index"
ausblenden Delphi-Quelltext
1:
2:
3:
var
  datum, dateiname, sheetname : String;
  zaehlerstand : Integer;

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
  Excel := CreateOleObject('Excel.Application');

  Excel.Workbooks[dateiname].Open;       <-- Ungültiger Index
  Excel.Workbooks[dateiname].Activate;
  Excel.Workbooks[dateiname].Worksheets[sheetname].Activate;
  Excel.Sheets[sheetname].Cells[6,1].Value := datum;
  Excel.Sheets[sheetname].Cells[6,2].Value := zaehlerstand;
iKilledKenny
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 8

Win XP
D5 Prof, C# Express 2005
BeitragVerfasst: Mo 28.01.08 11:04 
ausblenden Delphi-Quelltext
1:
2:
3:
Excel.Workbooks.Open (FileName);
if Excel.WorkBooks [1].Sheets.Count = 0 then
  raise Exception.Create ('Keine Arbeitsblätter');
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Mo 28.01.08 12:48 
user profile iconiKilledKenny hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
Excel.Workbooks.Open (FileName);
if Excel.WorkBooks [1].Sheets.Count = 0 then
  raise Exception.Create ('Keine Arbeitsblätter');


So schaut nun momentan meine Syntax aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
  Excel := CreateOleObject('Excel.Application');
  // ....
  Excel.Workbooks.Open [dateiname];

  if Excel.Workbooks[1].Sheets.Count = 0 then
    ShowMessage('Keine Arbeitsblätter');

  Excel.Workbooks.Activate [dateiname];    //<-- das hier ist schon falsch "Die Methode Activate wird vom Automatisierungsobjekt nicht unterstützt"
  Excel.Workbooks[dateiname].Worksheets[sheetname].Activate;
  Excel.Sheets[sheetname].Cells[6,1].Value := datum;
  Excel.Sheets[sheetname].Cells[6,2].Value := zaehlerstand;


Dann is meine Syntax ja total durcheinander, oder? Also momentan stimmt sie bis zu der markierten Zeile, denk ich mal.

Kann mir einer sagen, wie dann die allgemeine Syntax richtig wär?
iKilledKenny
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 8

Win XP
D5 Prof, C# Express 2005
BeitragVerfasst: Mo 28.01.08 13:00 
Ich glaube, dir fehlt das grundsätzliche Verständnis.

ausblenden Delphi-Quelltext
1:
Excel := CreateOleObject('Excel.Application');					

erzeugt ein OLE Object.

ausblenden Delphi-Quelltext
1:
Excel.Workbooks.Open (dateiname);					

öffnet eine Excel-Datei. Die Datei steht nun unter
ausblenden Delphi-Quelltext
1:
Excel.Workbooks [1]					

zur Verfügung.

Excel.Workbooks [1] hat nun wiederum verschiedene Properties/Methoden. Eine davon ist z.B. Excel.Workbooks [1].Sheets, eine andere wäre Excel.Workbooks [1].Activate.
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Mo 28.01.08 13:59 
user profile iconiKilledKenny hat folgendes geschrieben:
Ich glaube, dir fehlt das grundsätzliche Verständnis.

ausblenden Delphi-Quelltext
1:
Excel := CreateOleObject('Excel.Application');					

erzeugt ein OLE Object.

ausblenden Delphi-Quelltext
1:
Excel.Workbooks.Open (dateiname);					

öffnet eine Excel-Datei. Die Datei steht nun unter
ausblenden Delphi-Quelltext
1:
Excel.Workbooks [1]					

zur Verfügung.

Excel.Workbooks [1] hat nun wiederum verschiedene Properties/Methoden. Eine davon ist z.B. Excel.Workbooks [1].Sheets, eine andere wäre Excel.Workbooks [1].Activate.


Ja, dieses Verständnis fehlt mir. Ich bin grad dabei mir des Ganze anzueignen. Hab halt immer wieder mal in irgendwelchen Tutorials oder Büchern Bruchstücke aufgenommen. Aber so richtig blick ich noch nicht durch. :roll: Da hast du wohl Recht. Deshalb bin ich über jede Hilfe dankbar.
iKilledKenny
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 394
Erhaltene Danke: 8

Win XP
D5 Prof, C# Express 2005
BeitragVerfasst: Mo 28.01.08 14:37 
Dann versuch doch mal mit dem von mir geposteten Dingen weiterzumachen. Wenn es konkret irgendwo hapert, dann meld dich nochmal.
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Mo 28.01.08 14:53 
Ok. Merci.