Autor Beitrag
schorsew
Hält's aus hier
Beiträge: 10

XP, SUSE 9.1
D7E
BeitragVerfasst: Sa 05.02.05 13:00 
Hallo,

ich möchte Daten aus meiner Datenbank in eine vorhandene Exceltabelle exportiern. :?:

Wie fang ich das an?

Ole oder nicht ole?

Kann mir da bitte mal jemand weiterhelfen, vielen dank! :D

Gruss
Schorsew
cartridge
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 209

Win XP
D4 Prof,D6 Prof
BeitragVerfasst: So 06.02.05 00:31 
Hier findest Du die Lösung:

www.dsdt.info/tipps/?id=559

Gruß
Ingo
schorsew Threadstarter
Hält's aus hier
Beiträge: 10

XP, SUSE 9.1
D7E
BeitragVerfasst: Mi 09.02.05 14:14 
Danke!!

Ich hab jetzt schon stundenlang probiert aber ich rall das irgendwie net!!!(leider) :(

Aber jetzt bräuchte ich mal Hilfestellung wo ich welche
Variable setzen muss und was in die Variablen rein muss. :roll:

Für schnelle Hilfe wäre ich sehr dankbar. :lol:

Gruss
schorsew
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Mi 09.02.05 14:18 
Titel: hmm,
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:
procedure Tfrm_main.ExportToExcel(tmpQy:TQuery);
var app_excel : Variant;
    i,j, akt_row:integer;
    s:string;
Begin
  app_excel := CreateOleObject('Excel.Application');
  app_excel.visible := true;
  app_excel.workbooks.add;
  akt_row := 1;
  For i:=0 to tmpQy.FieldCount -1 do
  begin
    app_excel.workbooks[1].sheets[1].cells[akt_row,i+1] := tmpQy.Fields[i].displayname;
  end;
  tmpQy.First;
  For i:= 0 to tmpQy.recordcount-1 do
  Begin
    inc(akt_row);
    For j:=0 to tmpQy.FieldCount -1 do
    begin
      app_excel.workbooks[1].sheets[1].cells[akt_row,j+1] := tmpQy.Fieldbyname(tmpQy.Fields[j].displayname).asString;
    end;
    tmpQy.next;
  end;
  Excel_autofit(app_excel,1,1)
end;

procedure Tfrm_main.Excel_autofit(app_Excel:Variant;wb,sh:integer);
begin
  app_Excel.workbooks[wb].sheets[sh].Cells.select;
  app_Excel.Selection.Columns.autofit;
end;


so mach ich das, du übergibst einfach eine TQuery und brauchst dich um nichtsmehr zu kümmern.

_________________
mfg. Joel


Zuletzt bearbeitet von JoelH am Mi 09.02.05 14:26, insgesamt 1-mal bearbeitet
schorsew Threadstarter
Hält's aus hier
Beiträge: 10

XP, SUSE 9.1
D7E
BeitragVerfasst: Mi 09.02.05 14:26 
Danke,

Und die Procedure kopiert alle Daten aus einer dbgrid
in excel?

Und iwe ging das mit dem tquery nochmal?

Gruss
schorsew
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Mi 09.02.05 14:28 
Titel: hmm,
dein DB Grid muss ja die Daten irgenwo her bekommen, dafür verwende ich eine TQuery die das SQl-Statement absetzt, daran hänge ich eine DataSource Komponente und daran häng ich das DBGrid, das grid gibt ja nur die Informationen weiter.

_________________
mfg. Joel
schorsew Threadstarter
Hält's aus hier
Beiträge: 10

XP, SUSE 9.1
D7E
BeitragVerfasst: Mi 09.02.05 14:31 
danke!

funktioniert das auch mit einer vorhandenen Exceltabelle?

Gruss
schorsew
JoelH
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 806
Erhaltene Danke: 17

Win10
Delphi Alexandria 11.2 Patch 1
BeitragVerfasst: Mi 09.02.05 14:32 
Titel: hmm,
klar, dann musst du nur eine bestimmte Exceldatei offnen und schaun dass du das Sheet bzw. Workbook richtig auswählst.

_________________
mfg. Joel
schorsew Threadstarter
Hält's aus hier
Beiträge: 10

XP, SUSE 9.1
D7E
BeitragVerfasst: Mi 09.02.05 14:42 
ich mach das mit einer ttable komponente.

Geht das auch?
Wenn ja wie?

Danke

schorsew