Autor Beitrag
Stecky2000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 51



BeitragVerfasst: Do 03.02.11 12:02 
Hallo,

ich hab mal wieder ein Problem und komme mit den durch die Suchfunktion gefundenen Dingen nicht klar, da sie auf mein Problem nicht ganz passen.

Ich habe folgenden Code
ausblenden Delphi-Quelltext
1:
If (Excel.Cells[StrToInt(V_Ini_Excel_9ProzentX), StrToInt(V_Ini_Excel_9ProzentY)] = 'X'then					


und genau da löst er die EVariantInvalidOpError aus.

Ich habe schon abgewandelt in

ausblenden Delphi-Quelltext
1:
If (Excel.Cells[StrToInt('27'), StrToInt('19')] = 'X'then					


und

ausblenden Delphi-Quelltext
1:
If (Excel.Cells[2719] = 'X'then					



Excel hab ich übrigens auf zwei verschiedene Arten deklariert:

mal so: Excel: OLEVariant;
und auch mal so: Excel: Variant;

Immer der gleiche Effekt.


Also insgesamt (gekürzt) so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
var
Excel: Variant; //OLEVariant;


begin

...        

        try
          excel := CreateOleObject('Excel.Application');
          excel.visible := False;   
        except
          ShowMessage('Excel konnte nicht gestartet werden !');
        end;

        Excel.DisplayAlerts:=False;
        Excel.Workbooks.Open(OpenDialog1.Filename);  

        If (Excel.Cells[StrToInt(V_Ini_Excel_9ProzentX), StrToInt(V_Ini_Excel_9ProzentY)] = 'X'or 
           (Excel.Cells[StrToInt(V_Ini_Excel_9ProzentX), StrToInt  (V_Ini_Excel_9ProzentY)] = 'x'then
           RadioGroup6.ItemIndex := 4;

...


Die Variablen V_Ini_Excel_9ProzentX und V_Ini_Excel_9ProzentY sind übrigens String.

aber immer der gleiche Effekt.

Ich glaube nicht, dass ich da was am Code geändert hätte und das hat ja sonst immer funktioniert.

Habt Ihr einen Tipp?


Zuletzt bearbeitet von Stecky2000 am Do 03.02.11 12:20, insgesamt 1-mal bearbeitet
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Do 03.02.11 12:11 
ich greife immer über Sheets zu ...

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
Function  TMSOLE.Cell(xpos,ypos:integer;sheet:String=''):Variant;
begin
  if Length(Sheet)=0 then Result:=FExcel.Sheets[1].Cells[xpos,ypos]
  else Result:=FExcel.Worksheets[Sheet].Cells[xpos,ypos];
end;

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS
Stecky2000 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 51



BeitragVerfasst: Do 03.02.11 12:15 
Der Zugriff auf Excel ist ja eigentlich kein Problem, yumal es in der datei die ich ;ffne nur ein Sheet gibt.

Ich habe eine Prozedur mit der ich nach excel schreibe und diese mmit der ich aus Excel lese.

Die schreibende funktioniert noch wie zuvor, die zum Lesen löst beim Vergleich (ist Zellinhalt = X) diesen Fehler aus.
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Do 03.02.11 13:12 
so gehts ...
ausblenden Delphi-Quelltext
1:
Cells[a,b].Text					

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Do 03.02.11 13:24 
Bzw über Cells[x,y].Value geht es auch soweit ich weiß, wenn du direkt zahlen vergleichen willst später mal. Und zwar aus dem grund weil dir Value ein Variant zurückliefert.

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
Bergmann89
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Do 03.02.11 14:04 
Hey,

pack dir den Inhalt der Zelle vorher in ne String-Variable
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
var
  str: String

str := Excel.Cells[StrToInt(V_Ini_Excel_9ProzentX), StrToInt(V_Ini_Excel_9ProzentY)];
If (str = 'X'then {...}


MfG Bergmann

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^


Zuletzt bearbeitet von Bergmann89 am Do 03.02.11 14:29, insgesamt 2-mal bearbeitet
bummi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1248
Erhaltene Danke: 187

XP - Server 2008R2
D2 - Delphi XE
BeitragVerfasst: Do 03.02.11 14:05 
@Bergmann89
da bekommst Du nur eine Referenz, keinen String. Value oder Text sind richtig.

_________________
Das Problem liegt üblicherweise zwischen den Ohren H₂♂
DRY DRY KISS
Stecky2000 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 51



BeitragVerfasst: Fr 25.02.11 08:44 
Sorry das ich mich so lange nicht gemeldet habe.

Ich wollte mich nur noch mal für die Tipps bedanken. Ich habe es mit .Text gemacht und es funktioniert.

Unter Delphi 7 ging es auch ohne, in Delphi 2010 braucht es das wohl.


Also, nochmals vielen Dank.