Autor Beitrag
Adam Weishaupt
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40



BeitragVerfasst: So 25.04.04 15:46 
ich soll ein programm schreiben, welches etwa so arbeitet:

man gibt einen suchbegriff ein (in einer edit-komponente) und klickt z.b. auf einen button...
dann ladet das programm von einer .xls-tabelle einen eintrag einer zelle, das den suchbegriff beinhaltet
und zeigt diesen in der komponente: ValueListEditor an.

beispiel: man hat in einer xls-tabelle seine spiele geordnet.. Name, Genre, Preis.

dann gibt man beim programm ein: SimCity
und schon ladet das programm von der xls-tabelle die zeile wo SimCity steht samt Genre und Preis und schreibt dies in eine zeile des ValueListEditors

und nu die frage: wie lade ich einen zelleneintrag samt der zeile (die nebenstehenden zellen) von einer xls-tabelle?

danke
Adam Weishaupt Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40



BeitragVerfasst: So 25.04.04 16:37 
Beim ValueListEditor kann man irgendwie nur 2 Titel benutzen.
Kann man nicht mehr? Oder gibt es eine andere Komponente, die so aufgebaut ist wie ValueListEditor nur mit mehreren Titeln?
UGrohne
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Veteran
Beiträge: 5502
Erhaltene Danke: 220

Windows 8 , Server 2012
D7 Pro, VS.NET 2012 (C#)
BeitragVerfasst: Mo 26.04.04 20:06 
ValueListEditor kann (wie man evtl. dem Namen entnehmen könnte) nur diese zwei, eben Name und Wert. Willst Du ne Tabelle, dann nimm ein StringGrid.

Zum Excel-Problem kann ich Dir nicht viel sagen, außer mal die Suche zu verwenden: Suche in: Delphi-Forum, Delphi-Library EXCEL
Adam Weishaupt Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40



BeitragVerfasst: Mi 28.04.04 10:16 
habe schon nach excel gesucht, aber es kam nicht so richtig das, was ich wollte..

ich will, dass nur der suchbegriff angezeigt wird im TStringGrid
DeCodeGuru
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1333
Erhaltene Danke: 1

Arch Linux
Eclipse
BeitragVerfasst: Mi 28.04.04 10:42 
Schon mal nach Suche in: Delphi-Forum, Delphi-Library EXCEL AND AUSLESEN gesucht. Dort findest du im vierten Topic von oben einen Hinweis. "Man kann Excel auch per OLE ansteuern." Also schwups mit der Foren-Suche nach Suche in: Delphi-Forum, Delphi-Library EXCEL AND OLE suchen und schon hat man 19 Topic zu dem Thema "Excel an bzw. fernsteuern". :wink:

Man sieht also, dass man auch ein bissl lesen muss, damit man mehr ggf. brauchbare Ergebnisse findet.

P.S.: Leider kann ich dir bei deinem Problem nicht helfen. :?

_________________
Viele Grüße
Jakob
Adam Weishaupt Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40



BeitragVerfasst: Mi 28.04.04 11:36 
DeCodeGuru hat folgendes geschrieben:
Schon mal nach Suche in: Delphi-Forum, Delphi-Library EXCEL AND AUSLESEN gesucht. Dort findest du im vierten Topic von oben einen Hinweis. [...]


das sieht gut aus.. dort steht was von "Torry" kennst du den link dazu?
Adam Weishaupt Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40



BeitragVerfasst: Fr 30.04.04 13:43 
habs geschafft! hab einfach den suchbegriff, der durch die Edit-Komponente eingegeben wurde mit den zellen im stringgrid verglichen und bei nicht uebereinstimmung einfach die zelle geloescht.
Adam Weishaupt Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40



BeitragVerfasst: Sa 01.05.04 14:44 
Ich habe jetzt versucht alles in Button1Click unterzubringen.

Variablen:
Archimedes = Excel-Tabelle
i = Zeilen von der Excel-Tabelle
h = Spalten der Excel-Tabelle (4 Stueck)
Philo = Spalten beim StringGrid
y = Letzte beschriebene Zeile der Excel-Tabelle


Das sieht dann so aus:

ausblenden volle Höhe 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:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
uses ComObj;


var   
  Archimedes, Socrates: OLEVariant;
  Philo: Integer;


procedure TForm1.Button1Click(Sender: TObject);
var i,h,y:integer;
begin
Philo:=-1;
Archimedes:=CreateOLEObject('Excel.Application');
Archimedes.Visible:=false;
Archimedes.Workbooks.Open(Edit1.Text);
<span style="text-decoration: underline"> Socrates:=Archimedes.Workbooks[ExtractFilename(Edit1.Text)].Worksheets[1]; </span>
Socrates.Cells.SpecialCells(xlCellTypeLastCell,EmptyParam).Activate;
y:=Archimedes.ActiveCell.Row;
for h:=0 to 3 do begin
  for i:=0 to y do begin
    if Edit2.Text=Archimedes.Cells[h,i] then begin
      case h of
        0: begin
             StringGrid1.Cells[0,Philo+1]:=Archimedes.Cells[0,i];
             StringGrid1.Cells[1,Philo+1]:=Archimedes.Cells[1,i];
             StringGrid1.Cells[2,Philo+1]:=Archimedes.Cells[2,i];
             StringGrid1.Cells[3,Philo+1]:=Archimedes.Cells[3,i];
           end;
        1: begin
             StringGrid1.Cells[1,Philo+1]:=Archimedes.Cells[1,i];
             StringGrid1.Cells[2,Philo+1]:=Archimedes.Cells[2,i];
             StringGrid1.Cells[3,Philo+1]:=Archimedes.Cells[3,i];
             StringGrid1.Cells[0,Philo+1]:=Archimedes.Cells[0,i];
           end;
        2: begin
             StringGrid1.Cells[2,Philo+1]:=Archimedes.Cells[2,i];
             StringGrid1.Cells[3,Philo+1]:=Archimedes.Cells[3,i];
             StringGrid1.Cells[0,Philo+1]:=Archimedes.Cells[0,i];
             StringGrid1.Cells[1,Philo+1]:=Archimedes.Cells[1,i];
           end;
        3: begin
             StringGrid1.Cells[3,Philo+1]:=Archimedes.Cells[3,i];
             StringGrid1.Cells[0,Philo+1]:=Archimedes.Cells[0,i];
             StringGrid1.Cells[1,Philo+1]:=Archimedes.Cells[1,i];
             StringGrid1.Cells[2,Philo+1]:=Archimedes.Cells[2,i];
           end;
        end;
      end;
    end;
  end;
end;



Doch nun kommt ein Fehler in der unterstrichenen Zeile: [Error] Unit1.pas(44): Undeclared identifier: 'xlCellTypeLastCell'

Weiss jemand, woran das liegt?
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Sa 01.05.04 14:54 
Hi,

Zitat:
Weiss jemand, woran das liegt?


Steht doch alles:
Zitat:
Undeclared identifier: 'xlCellTypeLastCell'


xlCellTypeLastCell wurde nirgends deklariert, d.h ist dem Compiler unbekannt.

Zum Glück gibt's da Google:
Suche bei Google XLCELLTYPELASTCELL DELPHI
Adam Weishaupt Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40



BeitragVerfasst: Sa 01.05.04 14:57 
hab den fehler selbst entdeckt....

bei Button1Click musste noch hin:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Button1Click(Sender: TObject);
const
  xlCellTypeLastCell = $0000000B;
var i,h,y:integer;


const
xlCellTypeLastCell = $0000000B;

hat also gefehlt.. ich danke allen :-)
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Sa 01.05.04 15:03 
Zitat:
case h of
0: begin
StringGrid1.Cells[0,Philo+1]:=Archimedes.Cells[0,i];
StringGrid1.Cells[1,Philo+1]:=Archimedes.Cells[1,i];
StringGrid1.Cells[2,Philo+1]:=Archimedes.Cells[2,i];
StringGrid1.Cells[3,Philo+1]:=Archimedes.Cells[3,i];
end;
1: begin
StringGrid1.Cells[1,Philo+1]:=Archimedes.Cells[1,i];
StringGrid1.Cells[2,Philo+1]:=Archimedes.Cells[2,i];
StringGrid1.Cells[3,Philo+1]:=Archimedes.Cells[3,i];
StringGrid1.Cells[0,Philo+1]:=Archimedes.Cells[0,i];
end;
2: begin
StringGrid1.Cells[2,Philo+1]:=Archimedes.Cells[2,i];
StringGrid1.Cells[3,Philo+1]:=Archimedes.Cells[3,i];
StringGrid1.Cells[0,Philo+1]:=Archimedes.Cells[0,i];
StringGrid1.Cells[1,Philo+1]:=Archimedes.Cells[1,i];
end;
3: begin
StringGrid1.Cells[3,Philo+1]:=Archimedes.Cells[3,i];
StringGrid1.Cells[0,Philo+1]:=Archimedes.Cells[0,i];
StringGrid1.Cells[1,Philo+1]:=Archimedes.Cells[1,i];
StringGrid1.Cells[2,Philo+1]:=Archimedes.Cells[2,i];
end;
end;


Diesen Code könntest du noch ziemlich vereinfachen!
Adam Weishaupt Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40



BeitragVerfasst: Sa 01.05.04 15:28 
kannst du mir bitte sagen wie? :-)
Adam Weishaupt Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 40



BeitragVerfasst: Mi 05.05.04 13:20 
Adam Weishaupt hat folgendes geschrieben:
Ich habe jetzt versucht alles in Button1Click unterzubringen.
ausblenden Delphi-Quelltext
1:
2:
3:
for i:=0 to y do begin
  for h:=0 to 3 do begin
    if Edit2.Text=Archimedes.Cells[h,i] then begin




edit2.text ist der eingegebene suchbegriff

da ist der naechste fehler.. :( in der letzten zeile..
langsam nervt das.. die anderen fehler konnte ich beheben.. aber den hier !?! :roll:
kreon
Hält's aus hier
Beiträge: 2



BeitragVerfasst: Fr 11.02.05 17:54 
Hallo,

Auch ich benutze das so ähnlich:
Excel:=CreateOleObject('Excel.Application');
Und lese dann die Zeilen aus, z.B. so:
bez:=trim(Excel.Cells[zeile,3].Value);
(Das trim entfernt nur die Leerzeichen)

Problem:

Das ist mir zu langsam

Fragen:


1. Gibt es eine schnellere Möglichkeit als OLE?

2. Gibt es eine schnellere Möglihkeit, als die Zellen einzeln auszulesen?
z.B. gleich eine ganze Spalte?


Vielen Dank bereits,
Oliver Bayer


--
Durch das Benutzen der Suchfunktion im Forum habe ich diesen Thread gefunden, der am Besten gepasst hat