Autor Beitrag
FloL
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29

Win XP
Delphi 2005
BeitragVerfasst: Di 29.08.06 13:55 
Hallöchen,
ich wollte mal fragen, wie man über Delphi die Arbeitsblätter/Tabellenblätter in Excel auswählen kann, da ich aus verschiedenen Arbeitsblätter etwas auslesen möchte.
Würde mir auch schon ausreichen, wenn mir einer sagt, wie man verschieden Arbeitsblätter "aktiv" bekommt.

Gruß

Florian
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Di 29.08.06 14:12 
Per OLE excel.Sheets[x] kannst du auf die verschiedenben Sheets zugreifen.

_________________
Markus Kinzler.
FloL Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29

Win XP
Delphi 2005
BeitragVerfasst: Di 29.08.06 14:20 
Danke für die schnelle antwort. Funktioniert bestens ;)
Hinweis, falls einer die Frag auch mal hat...

excel.Sheets['x']
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Di 29.08.06 14:33 
excel.Sheets['x'] x war als Variable gedacht, diese kann auch der Index sein (Zahl) dann ohne Hochkommas.

_________________
Markus Kinzler.
FloL Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29

Win XP
Delphi 2005
BeitragVerfasst: Mi 30.08.06 23:16 
Hab da doch nen kleines Problem, ich kann zwar Daten aus der excel-datei laden, aber irgendwie interessiert ihn das gar nicht, welches excel-tabellenblat aktiv ist, sondern er nimmt immer nur das erste Blatt...
Weiss einer wie man das Problem beheben kann..
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
procedure TFgebaeude.Baeckerei;
var ExcelApp: OLEVariant;
begin
try
 ExcelApp := CreateOleObject ('Excel.Application');
 ExcelApp.Workbooks.Open(ExtractFilePath(Application.ExeName)+ 'rohstoffe.xls');
 ExcelApp.Sheets['Baeckerei'];
                                // Spalte, Zeile
 eholzben.Text:=  ExcelApp.Cells[2 + CBBaeckerei.itemindex , 2];
 elehmben.Text:=  ExcelApp.Cells[2 + CBBaeckerei.itemindex, 3];
 eeisenben.Text:=  ExcelApp.Cells[2 + CBBaeckerei.itemindex, 4];
 egetreideben.Text:=  ExcelApp.Cells[2 + CBBaeckerei.itemindex, 5];
 egetreidever.Text:=  ExcelApp.Cells[2 + CBBaeckerei.itemindex, 6];
 ekp.text:=ExcelApp.Cells[2 + CBBaeckerei.itemindex, 7];
 uhr:=round(StrToFloat(ExcelApp.Cells[30 + CBBaeckerei.itemindex,2 + CBHauptgebaeude.itemindex]) / 0.0000115740740741499);
 finally
 ExcelApp.ActiveWorkbook.Saved:=true;
 ExcelApp.Workbooks.close;
end;
zeit;
end;
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Do 31.08.06 05:27 
Versuch mal das gewünschte als aktiv zu setzen (ExcelApp.ActiveWorkbook)

_________________
Markus Kinzler.
FloL Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29

Win XP
Delphi 2005
BeitragVerfasst: Do 31.08.06 20:26 
Ne, tut sie leider nicht ;(

Kommt immer die Fehlermeldung .....

Die Methode wird vom Automatiesierungsobjekt nicht unterstützt.
FloL Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29

Win XP
Delphi 2005
BeitragVerfasst: Do 31.08.06 21:31 
So habs endlich gelöst.....
so funktionierts.

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:
procedure TFgebaeude.Saegewerk;
var ExcelApp, WS: OLEVariant;
begin
try

 ExcelApp := CreateOleObject ('Excel.Application');
 ExcelApp.Workbooks.Open(ExtractFilePath(Application.ExeName)+ 'rohstoffe.xls');
 WS := ExcelApp.Worksheets.Item['Saegewerk'];   // hier mit bekommt man die sch** aktiv
 WS.Activate;                                   //  ""

 eholzben.Text:=  ExcelApp.Cells[2 + CBSaegewerk.itemindex , 2];
 elehmben.Text:=  ExcelApp.Cells[2 + CBSaegewerk.itemindex, 3];
 eeisenben.Text:=  ExcelApp.Cells[2 + CBSaegewerk.itemindex, 4];
 egetreideben.Text:=  ExcelApp.Cells[2 + CBSaegewerk.itemindex, 5];
 egetreidever.Text:=  ExcelApp.Cells[2 + CBSaegewerk.itemindex, 6];
 ekp.text:=ExcelApp.Cells[2 + CBSaegewerk.itemindex, 7];
 uhr:=round(StrToFloat(ExcelApp.Cells[30 + CBSaegewerk.itemindex,2 + CBHauptgebaeude.itemindex]) / 0.0000115740740741499);
 finally
 ExcelApp.ActiveWorkbook.Saved:=true;
 ExcelApp.Workbooks.close;
end;
zeit;
end;
FloL Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29

Win XP
Delphi 2005
BeitragVerfasst: Do 31.08.06 22:04 
Hier gibts auch sehr nützliche Sachen dafür

teil1
teil2